-/* $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.
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#ifndef lint
+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 $");
+static const char rcsid[] =
+ "$FreeBSD: src/usr.bin/find/main.c,v 1.9.6.2 2001/02/25 21:56:59 knu Exp $";
#endif
#endif /* not lint */
#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));
int
int argc;
char *argv[];
{
- char **p, **start;
- int ch;
+ register char **p, **start;
+ 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;
}
- 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
usage()
{
(void)fprintf(stderr,
-"usage: find [-H | -L | -P] [-Xdhx] [-f file] [file ...] [expression]\n");
+"usage: find [-H | -L | -P] [-EXdsx] [-f file] [file ...] [expression]\n");
exit(1);
}