X-Git-Url: https://git.saurik.com/apple/shell_cmds.git/blobdiff_plain/44bd5ea795281151bc7b81a65d2dd42c6b8914d8..57cab491e7f6d6f2e4d1854b8d1ee959c064b1bb:/find/main.c?ds=sidebyside diff --git a/find/main.c b/find/main.c index ed2f090..e95e648 100644 --- a/find/main.c +++ b/find/main.c @@ -1,5 +1,3 @@ -/* $NetBSD: main.c,v 1.10 1998/02/10 21:52:51 cgd Exp $ */ - /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -15,10 +13,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -36,17 +30,21 @@ * SUCH DAMAGE. */ -#include +#ifndef lint +static const char copyright[] = +"@(#) Copyright (c) 1990, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + #ifndef lint #if 0 static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; -#else -__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"); -__RCSID("$NetBSD: main.c,v 1.10 1998/02/10 21:52:51 cgd Exp $"); #endif #endif /* not lint */ +#include +__FBSDID("$FreeBSD: src/usr.bin/find/main.c,v 1.23 2011/12/10 18:11:06 ed Exp $"); + #include #include @@ -54,6 +52,8 @@ __RCSID("$NetBSD: main.c,v 1.10 1998/02/10 21:52:51 cgd Exp $"); #include #include #include +#include +#include #include #include #include @@ -67,40 +67,41 @@ int ftsoptions; /* options for the ftsopen(3) call */ int isdeprecated; /* using deprecated syntax */ int isdepth; /* do directories on post-order visit */ int isoutput; /* user specified output operator */ +int issort; /* do hierarchies in lexicographical order */ int isxargs; /* don't permit xargs delimiting chars */ +int mindepth = -1, maxdepth = -1; /* minimum and maximum depth */ +int regexp_flags = REG_BASIC; /* use the "basic" regexp by default*/ -int main __P((int, char **)); -static void usage __P((void)); +static void usage(void); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { char **p, **start; - int ch; + int Hflag, Lflag, ch; - (void)time(&now); /* initialize the time-of-day */ + (void)setlocale(LC_ALL, ""); - /* array to hold dir list. at most (argc - 1) elements. */ - p = start = alloca(argc * sizeof (char *)); + (void)time(&now); /* initialize the time-of-day */ + p = start = argv; + Hflag = Lflag = 0; ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "HLPXdf:x")) != EOF) - switch(ch) { + while ((ch = getopt(argc, argv, "EHLPXdf:sx")) != -1) + switch (ch) { + case 'E': + regexp_flags |= REG_EXTENDED; + break; case 'H': - ftsoptions |= FTS_COMFOLLOW; -#if 0 /* XXX necessary? */ - ftsoptions &= ~FTS_LOGICAL; -#endif + Hflag = 1; + Lflag = 0; break; case 'L': - ftsoptions &= ~FTS_COMFOLLOW; - ftsoptions |= FTS_LOGICAL; + Lflag = 1; + Hflag = 0; break; case 'P': - ftsoptions &= ~(FTS_COMFOLLOW|FTS_LOGICAL); - ftsoptions |= FTS_PHYSICAL; + Hflag = Lflag = 0; break; case 'X': isxargs = 1; @@ -111,21 +112,27 @@ main(argc, argv) case 'f': *p++ = optarg; break; - case 'h': - ftsoptions &= ~FTS_PHYSICAL; - ftsoptions |= FTS_LOGICAL; + case 's': + issort = 1; break; case 'x': ftsoptions |= FTS_XDEV; break; case '?': default: - break; + usage(); } - argc -= optind; + argc -= optind; argv += optind; + if (Hflag) + ftsoptions |= FTS_COMFOLLOW; + if (Lflag) { + ftsoptions &= ~FTS_PHYSICAL; + ftsoptions |= FTS_LOGICAL; + } + /* * Find first option to delimit the file list. The first argument * that starts with a -, or is a ! or a ( must be interpreted as a @@ -150,9 +157,10 @@ main(argc, argv) } static void -usage() +usage(void) { - (void)fprintf(stderr, -"usage: find [-H | -L | -P] [-Xdhx] [-f file] [file ...] [expression]\n"); + (void)fprintf(stderr, "%s\n%s\n", +"usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]", +" find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]"); exit(1); }