-/* $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.
* 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.
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/usr.bin/find/main.c,v 1.23 2011/12/10 18:11:06 ed Exp $");
+
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
+#include <locale.h>
+#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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;
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
}
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);
}