Commit | Line | Data |
---|---|---|
f74e42f0 KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | */ | |
7 | ||
8 | #ifndef lint | |
a39828ca | 9 | static char sccsid[] = "@(#)main.c 5.9 (Berkeley) %G%"; |
f74e42f0 KB |
10 | #endif /* not lint */ |
11 | ||
12 | #include <sys/types.h> | |
13 | #include <sys/stat.h> | |
a39828ca | 14 | #include <fcntl.h> |
ff92ccf9 | 15 | #include <time.h> |
f74e42f0 | 16 | #include <fts.h> |
a39828ca | 17 | #include <errno.h> |
91f10ace KB |
18 | #include <stdio.h> |
19 | #include <stdlib.h> | |
f74e42f0 KB |
20 | #include "find.h" |
21 | ||
ff92ccf9 | 22 | time_t now; /* time find was run */ |
a39828ca | 23 | int dotfd; /* starting directory */ |
ff92ccf9 KB |
24 | int ftsoptions; /* options for the ftsopen(3) call */ |
25 | int isdeprecated; /* using deprecated syntax */ | |
26 | int isdepth; /* do directories on post-order visit */ | |
27 | int isoutput; /* user specified output operator */ | |
ff92ccf9 KB |
28 | int isxargs; /* don't permit xargs delimiting chars */ |
29 | ||
30 | static void usage(); | |
31 | ||
32 | main(argc, argv) | |
f74e42f0 | 33 | int argc; |
ff92ccf9 | 34 | char **argv; |
f74e42f0 | 35 | { |
ff92ccf9 KB |
36 | register char **p, **start; |
37 | PLAN *find_formplan(); | |
f74e42f0 | 38 | int ch; |
f74e42f0 | 39 | |
ff92ccf9 KB |
40 | (void)time(&now); /* initialize the time-of-day */ |
41 | ||
42 | p = start = argv; | |
43 | ftsoptions = FTS_NOSTAT|FTS_PHYSICAL; | |
a39828ca | 44 | while ((ch = getopt(argc, argv, "df:sXx")) != EOF) |
f74e42f0 KB |
45 | switch(ch) { |
46 | case 'd': | |
148184f1 | 47 | isdepth = 1; |
f74e42f0 KB |
48 | break; |
49 | case 'f': | |
ff92ccf9 | 50 | *p++ = optarg; |
f74e42f0 KB |
51 | break; |
52 | case 's': | |
53 | ftsoptions &= ~FTS_PHYSICAL; | |
54 | ftsoptions |= FTS_LOGICAL; | |
55 | break; | |
38ba9b5d KB |
56 | case 'X': |
57 | isxargs = 1; | |
58 | break; | |
f74e42f0 | 59 | case 'x': |
f74e42f0 | 60 | ftsoptions &= ~FTS_NOSTAT; |
1292488d | 61 | ftsoptions |= FTS_XDEV; |
f74e42f0 KB |
62 | break; |
63 | case '?': | |
64 | default: | |
ff92ccf9 | 65 | break; |
f74e42f0 KB |
66 | } |
67 | ||
ff92ccf9 KB |
68 | argc -= optind; |
69 | argv += optind; | |
70 | ||
71 | /* Find first option to delimit the file list. */ | |
72 | while (*argv) { | |
73 | if (option(*argv)) | |
74 | break; | |
75 | *p++ = *argv++; | |
f74e42f0 | 76 | } |
ff92ccf9 KB |
77 | |
78 | if (p == start) | |
79 | usage(); | |
80 | *p = NULL; | |
81 | ||
a39828ca KB |
82 | if ((dotfd = open(".", O_RDONLY, 0)) < 0) |
83 | err(".: %s", strerror(errno)); | |
84 | ||
ff92ccf9 KB |
85 | find_execute(find_formplan(argv), start); |
86 | } | |
87 | ||
88 | static void | |
89 | usage() | |
90 | { | |
91 | (void)fprintf(stderr, | |
a39828ca | 92 | "usage: find [-dsXx] [-f file] [file ...] expression\n"); |
ff92ccf9 | 93 | exit(1); |
f74e42f0 | 94 | } |