aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlfred Perlstein <alfred@FreeBSD.org>2002-01-30 20:21:18 +0000
committerAlfred Perlstein <alfred@FreeBSD.org>2002-01-30 20:21:18 +0000
commitf0843112af9ba486ec10c280a06fb0e6695020ee (patch)
tree28aa7fd401e9a85ca350e8188a38d68807e83015
parent2e031e8eba932d1e2d14bcbc6a839ff325911d66 (diff)
downloadsrc-f0843112af9ba486ec10c280a06fb0e6695020ee.tar.gz
src-f0843112af9ba486ec10c280a06fb0e6695020ee.zip
Backport sed -E support (extended regex support).
Submitted by: Dan Nelson <dnelson@allantgroup.com>
Notes
Notes: svn path=/stable/3/; revision=89998
-rw-r--r--usr.bin/sed/compile.c2
-rw-r--r--usr.bin/sed/extern.h4
-rw-r--r--usr.bin/sed/main.c8
-rw-r--r--usr.bin/sed/sed.118
4 files changed, 23 insertions, 9 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index 136f56ce1197..0fb5ccae6d59 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 584ac6f6d3af..d03ad5b1de53 100644
--- a/usr.bin/sed/extern.h
+++ b/usr.bin/sed/extern.h
@@ -34,7 +34,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)extern.h 8.1 (Berkeley) 6/6/93
+ * From: @(#)extern.h 8.1 (Berkeley) 6/6/93
+ * $FreeBSD$
*/
extern struct s_command *prog;
@@ -46,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 fcd5e4efdd2b..c189c26be12e 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
@@ -119,8 +120,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;
@@ -170,7 +174,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 31286c5671fc..936b754c8b20 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