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 9 static char sccsid[] = "@(#)main.c 5.11 (Berkeley) 06/01/92"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 #include <sys/stat.h> 14 #include <fcntl.h> 15 #include <time.h> 16 #include <fts.h> 17 #include <errno.h> 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include "find.h" 21 22 time_t now; /* time find was run */ 23 int dotfd; /* starting directory */ 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 */ 28 int isxargs; /* don't permit xargs delimiting chars */ 29 30 static void usage(); 31 32 main(argc, argv) 33 int argc; 34 char **argv; 35 { 36 register char **p, **start; 37 PLAN *find_formplan(); 38 int ch; 39 40 (void)time(&now); /* initialize the time-of-day */ 41 42 p = start = argv; 43 ftsoptions = FTS_NOSTAT|FTS_PHYSICAL; 44 while ((ch = getopt(argc, argv, "Hdf:hXx")) != EOF) 45 switch(ch) { 46 case 'H': 47 ftsoptions |= FTS_COMFOLLOW; 48 break; 49 case 'd': 50 isdepth = 1; 51 break; 52 case 'f': 53 *p++ = optarg; 54 break; 55 case 'h': 56 ftsoptions &= ~FTS_PHYSICAL; 57 ftsoptions |= FTS_LOGICAL; 58 break; 59 case 'X': 60 isxargs = 1; 61 break; 62 case 'x': 63 ftsoptions &= ~FTS_NOSTAT; 64 ftsoptions |= FTS_XDEV; 65 break; 66 case '?': 67 default: 68 break; 69 } 70 71 argc -= optind; 72 argv += optind; 73 74 /* Find first option to delimit the file list. */ 75 while (*argv) { 76 if (option(*argv)) 77 break; 78 *p++ = *argv++; 79 } 80 81 if (p == start) 82 usage(); 83 *p = NULL; 84 85 if ((dotfd = open(".", O_RDONLY, 0)) < 0) 86 err(".: %s", strerror(errno)); 87 88 find_execute(find_formplan(argv), start); 89 exit(0); 90 } 91 92 static void 93 usage() 94 { 95 (void)fprintf(stderr, 96 "usage: find [-HdhXx] [-f file] [file ...] expression\n"); 97 exit(1); 98 } 99 100 101 102 103 104 105 106 107 108