Add a new flag: -E enables "extended" regular expressions.

This commit is contained in:
Brian Feldman 2000-03-19 19:41:53 +00:00
parent ab853c5a6f
commit 175de1e677
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=58309
4 changed files with 21 additions and 8 deletions

View File

@ -435,7 +435,7 @@ compile_re(p, repp)
return (p);
}
*repp = xmalloc(sizeof(regex_t));
if (p && (eval = regcomp(*repp, re, 0)) != 0)
if (p && (eval = regcomp(*repp, re, rflags)) != 0)
errx(1, "%lu: %s: RE error: %s",
linenum, fname, strregerror(eval, *repp));
if (maxnsub < (*repp)->re_nsub)

View File

@ -47,6 +47,7 @@ extern int appendnum;
extern int lastline;
extern int aflag, eflag, nflag;
extern char *fname;
extern int rflags; /* regex flags to add */
void cfclose __P((struct s_command *, struct s_command *));
void compile __P((void));

View File

@ -95,6 +95,7 @@ struct s_flist {
static struct s_flist *files, **fl_nextp = &files;
int aflag, eflag, nflag;
int rflags = 0;
/*
* Current file and line number; line numbers restart across compilation
@ -118,8 +119,11 @@ main(argc, argv)
(void) setlocale(LC_ALL, "");
fflag = 0;
while ((c = getopt(argc, argv, "ae:f:n")) != -1)
while ((c = getopt(argc, argv, "Eae:f:n")) != -1)
switch (c) {
case 'E':
rflags = REG_EXTENDED;
break;
case 'a':
aflag = 1;
break;
@ -166,7 +170,7 @@ static void
usage()
{
(void)fprintf(stderr, "%s\n%s\n",
"usage: sed script [-an] [file ...]",
"usage: sed script [-Ean] [file ...]",
" sed [-an] [-e script] ... [-f script_file] ... [file ...]");
exit(1);
}

View File

@ -43,11 +43,11 @@
.Nd stream editor
.Sh SYNOPSIS
.Nm sed
.Op Fl an
.Op Fl Ean
.Ar command
.Op Ar file ...
.Nm sed
.Op Fl an
.Op Fl Ean
.Op Fl e Ar command
.Op Fl f Ar command_file
.Op Ar file ...
@ -70,6 +70,11 @@ regardless of their origin.
.Pp
The following options are available:
.Bl -tag -width indent
.It Fl E
Interpret regular expressions as extended (modern) regular expressions
rather than basic regular expressions (BRE's). The
.Xr re_format 7
manual page fully describes both formats.
.It Fl a
The files listed as parameters for the
.Dq w
@ -164,10 +169,13 @@ The
.Nm
regular expressions are basic regular expressions (BRE's, see
.Xr regex 3
for more information).
In addition,
for more information) by default.
.Nm
has the following two additions to BRE's:
can use extended (modern) regular expressions instead if the
.Fl E
flag is given. In addition,
.Nm
has the following two additions to regular expressions:
.sp
.Bl -enum -compact
.It