Add the '-E' option to interpret regexes as extended regexes. While we
are here, fix ordering in usage information by putting '-X' in the proper place. Addition of '-E' was discussed on tech-userlevel.
This commit is contained in:
parent
638ce78980
commit
02dcfb175e
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.27 2007/02/06 13:25:01 elad Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.28 2007/07/19 07:49:30 daniel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
@ -95,4 +95,5 @@ PLAN *c_not(char ***, int);
|
||||
PLAN *c_or(char ***, int);
|
||||
PLAN *c_null(char ***, int);
|
||||
|
||||
extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs;
|
||||
extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs,
|
||||
regcomp_flags;
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: find.1,v 1.65 2007/03/08 21:23:00 wiz Exp $
|
||||
.\" $NetBSD: find.1,v 1.66 2007/07/19 07:49:30 daniel Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -32,7 +32,7 @@
|
||||
.\"
|
||||
.\" from: @(#)find.1 8.7 (Berkeley) 5/9/95
|
||||
.\"
|
||||
.Dd February 8, 2007
|
||||
.Dd July 19, 2007
|
||||
.Dt FIND 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -41,13 +41,13 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Op Fl dhsXx
|
||||
.Op Fl dEhsXx
|
||||
.Ar file
|
||||
.Op Ar file ...
|
||||
.Op Ar expression
|
||||
.Nm
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Op Fl dhsXx
|
||||
.Op Fl dEhsXx
|
||||
.Fl f Ar file
|
||||
.Op Ar file ...
|
||||
.Op Ar expression
|
||||
@ -107,6 +107,14 @@ visits directories in pre-order, i.e., before their contents.
|
||||
Note, the default is
|
||||
.Ar not
|
||||
a breadth-first traversal.
|
||||
.It Fl E
|
||||
The
|
||||
.Fl E
|
||||
option causes
|
||||
.Ar regexp
|
||||
arguments to primaries to be interpreted as extended regular
|
||||
expressions (see
|
||||
.Xr re_format 7 ) .
|
||||
.It Fl f
|
||||
The
|
||||
.Fl f
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: function.c,v 1.63 2007/07/17 21:35:29 christos Exp $ */
|
||||
/* $NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
@ -37,7 +37,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: function.c,v 1.63 2007/07/17 21:35:29 christos Exp $");
|
||||
__RCSID("$NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -55,6 +55,7 @@ __RCSID("$NetBSD: function.c,v 1.63 2007/07/17 21:35:29 christos Exp $");
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <pwd.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -119,7 +120,7 @@ static void run_f_exec(PLAN *);
|
||||
int f_user(PLAN *, FTSENT *);
|
||||
int f_not(PLAN *, FTSENT *);
|
||||
int f_or(PLAN *, FTSENT *);
|
||||
static PLAN *c_regex_common(char ***, int, enum ntype, int);
|
||||
static PLAN *c_regex_common(char ***, int, enum ntype, bool);
|
||||
static PLAN *palloc(enum ntype, int (*)(PLAN *, FTSENT *));
|
||||
|
||||
extern int dotfd;
|
||||
@ -1559,7 +1560,7 @@ f_regex(PLAN *plan, FTSENT *entry)
|
||||
}
|
||||
|
||||
static PLAN *
|
||||
c_regex_common(char ***argvp, int isok, enum ntype type, int regcomp_flags)
|
||||
c_regex_common(char ***argvp, int isok, enum ntype type, bool icase)
|
||||
{
|
||||
char errbuf[LINE_MAX];
|
||||
regex_t reg;
|
||||
@ -1578,7 +1579,8 @@ c_regex_common(char ***argvp, int isok, enum ntype type, int regcomp_flags)
|
||||
snprintf(lineregexp, len, "^%s(%s%s)$",
|
||||
(regcomp_flags & REG_EXTENDED) ? "" : "\\", regexp,
|
||||
(regcomp_flags & REG_EXTENDED) ? "" : "\\");
|
||||
rv = regcomp(®, lineregexp, REG_NOSUB|regcomp_flags);
|
||||
rv = regcomp(®, lineregexp, REG_NOSUB|regcomp_flags|
|
||||
(icase ? REG_ICASE : 0));
|
||||
free(lineregexp);
|
||||
if (rv != 0) {
|
||||
regerror(rv, ®, errbuf, sizeof errbuf);
|
||||
@ -1594,14 +1596,14 @@ PLAN *
|
||||
c_regex(char ***argvp, int isok)
|
||||
{
|
||||
|
||||
return (c_regex_common(argvp, isok, N_REGEX, REG_BASIC));
|
||||
return (c_regex_common(argvp, isok, N_REGEX, false));
|
||||
}
|
||||
|
||||
PLAN *
|
||||
c_iregex(char ***argvp, int isok)
|
||||
{
|
||||
|
||||
return (c_regex_common(argvp, isok, N_IREGEX, REG_BASIC|REG_ICASE));
|
||||
return (c_regex_common(argvp, isok, N_IREGEX, true));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.26 2006/11/09 20:50:53 christos Exp $ */
|
||||
/* $NetBSD: main.c,v 1.27 2007/07/19 07:49:30 daniel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
@ -39,7 +39,7 @@ 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.26 2006/11/09 20:50:53 christos Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.27 2007/07/19 07:49:30 daniel Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -68,6 +68,7 @@ int isdepth; /* do directories on post-order visit */
|
||||
int isoutput; /* user specified output operator */
|
||||
int issort; /* sort directory entries */
|
||||
int isxargs; /* don't permit xargs delimiting chars */
|
||||
int regcomp_flags = REG_BASIC; /* regex compilation flags */
|
||||
|
||||
int main(int, char **);
|
||||
static void usage(void);
|
||||
@ -93,7 +94,7 @@ main(int argc, char *argv[])
|
||||
err(1, NULL);
|
||||
|
||||
ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
|
||||
while ((ch = getopt(argc, argv, "HLPXdf:hsx")) != -1)
|
||||
while ((ch = getopt(argc, argv, "HLPdEf:hsXx")) != -1)
|
||||
switch (ch) {
|
||||
case 'H':
|
||||
ftsoptions &= ~FTS_LOGICAL;
|
||||
@ -107,12 +108,12 @@ main(int argc, char *argv[])
|
||||
ftsoptions &= ~(FTS_COMFOLLOW|FTS_LOGICAL);
|
||||
ftsoptions |= FTS_PHYSICAL;
|
||||
break;
|
||||
case 'X':
|
||||
isxargs = 1;
|
||||
break;
|
||||
case 'd':
|
||||
isdepth = 1;
|
||||
break;
|
||||
case 'E':
|
||||
regcomp_flags = REG_EXTENDED;
|
||||
break;
|
||||
case 'f':
|
||||
*p++ = optarg;
|
||||
break;
|
||||
@ -123,6 +124,9 @@ main(int argc, char *argv[])
|
||||
case 's':
|
||||
issort = 1;
|
||||
break;
|
||||
case 'X':
|
||||
isxargs = 1;
|
||||
break;
|
||||
case 'x':
|
||||
ftsoptions |= FTS_XDEV;
|
||||
break;
|
||||
@ -164,6 +168,6 @@ usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: find [-H | -L | -P] [-Xdhsx] [-f file] file [file ...] [expression]\n");
|
||||
"usage: find [-H | -L | -P] [-dEhsXx] [-f file] file [file ...] [expression]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user