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