This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / usr.bin / find / main.c
CommitLineData
15637ed4 1/*-
6b479535
NW
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
15637ed4
RG
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
6b479535 35static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
15637ed4
RG
36#endif /* not lint */
37
38#include <sys/types.h>
39#include <sys/stat.h>
6b479535
NW
40
41#include <err.h>
42#include <errno.h>
15637ed4 43#include <fcntl.h>
15637ed4 44#include <fts.h>
15637ed4
RG
45#include <stdio.h>
46#include <stdlib.h>
6b479535
NW
47#include <time.h>
48
15637ed4
RG
49#include "find.h"
50
51time_t now; /* time find was run */
52int dotfd; /* starting directory */
53int ftsoptions; /* options for the ftsopen(3) call */
54int isdeprecated; /* using deprecated syntax */
55int isdepth; /* do directories on post-order visit */
56int isoutput; /* user specified output operator */
57int isxargs; /* don't permit xargs delimiting chars */
58
6b479535 59static void usage __P((void));
15637ed4 60
6b479535 61int
15637ed4
RG
62main(argc, argv)
63 int argc;
6b479535 64 char *argv[];
15637ed4
RG
65{
66 register char **p, **start;
15637ed4
RG
67 int ch;
68
69 (void)time(&now); /* initialize the time-of-day */
70
71 p = start = argv;
72 ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
6b479535 73 while ((ch = getopt(argc, argv, "Hdf:hXx")) != EOF)
15637ed4 74 switch(ch) {
6b479535
NW
75 case 'H':
76 ftsoptions |= FTS_COMFOLLOW;
77 break;
15637ed4
RG
78 case 'd':
79 isdepth = 1;
80 break;
81 case 'f':
82 *p++ = optarg;
83 break;
6b479535 84 case 'h':
15637ed4
RG
85 ftsoptions &= ~FTS_PHYSICAL;
86 ftsoptions |= FTS_LOGICAL;
87 break;
88 case 'X':
89 isxargs = 1;
90 break;
91 case 'x':
15637ed4
RG
92 ftsoptions |= FTS_XDEV;
93 break;
94 case '?':
95 default:
96 break;
97 }
98
99 argc -= optind;
100 argv += optind;
101
102 /* Find first option to delimit the file list. */
103 while (*argv) {
104 if (option(*argv))
105 break;
106 *p++ = *argv++;
107 }
108
109 if (p == start)
110 usage();
111 *p = NULL;
112
113 if ((dotfd = open(".", O_RDONLY, 0)) < 0)
6b479535 114 err(1, ".:");
15637ed4
RG
115
116 find_execute(find_formplan(argv), start);
4e97a0eb 117 exit(0);
15637ed4
RG
118}
119
120static void
121usage()
122{
123 (void)fprintf(stderr,
6b479535 124 "usage: find [-HdhXx] [-f file] [file ...] expression\n");
15637ed4
RG
125 exit(1);
126}
6b479535
NW
127
128
129
130
131
132
133
134
135