summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/compile.c2
-rw-r--r--usr.bin/sed/extern.h1
-rw-r--r--usr.bin/sed/main.c8
-rw-r--r--usr.bin/sed/sed.118
4 files changed, 21 insertions, 8 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index 136f56c..0fb5cca 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -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)
diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h
index 7e77923..d03ad5b 100644
--- a/usr.bin/sed/extern.h
+++ b/usr.bin/sed/extern.h
@@ -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));
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 88f4ea5..1c5e885 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -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);
}
diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1
index 31286c5..936b754 100644
--- a/usr.bin/sed/sed.1
+++ b/usr.bin/sed/sed.1
@@ -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
+can use extended (modern) regular expressions instead if the
+.Fl E
+flag is given. In addition,
.Nm
-has the following two additions to BRE's:
+has the following two additions to regular expressions:
.sp
.Bl -enum -compact
.It
OpenPOWER on IntegriCloud