summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2009-08-07 03:30:57 +0000
committerDamien Miller <djm@cvs.openbsd.org>2009-08-07 03:30:57 +0000
commitb0313e5cb2a08d6facbd72ca780665dc7fe6efee (patch)
tree4fde87dc546c39008767d1d9ad819c7d806ddeb1 /usr.bin
parent3f7e782580104cfcda4ce4124faad79a7990307f (diff)
add -E flag to compile regular expressions using the extended POSIX
syntax. The -E flag is compatible with the other BSDs and OSX. -r is also provided as an alias for compatibility with GNU sed. feedback from jmc@ and millert@ ok millert@ pyr@ henning@ marco@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sed/compile.c6
-rw-r--r--usr.bin/sed/extern.h4
-rw-r--r--usr.bin/sed/main.c16
-rw-r--r--usr.bin/sed/sed.119
4 files changed, 29 insertions, 16 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index bc40a514581..60c6cac9330 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compile.c,v 1.28 2008/10/16 16:34:32 millert Exp $ */
+/* $OpenBSD: compile.c,v 1.29 2009/08/07 03:30:56 djm Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -35,7 +35,7 @@
#ifndef lint
/* from: static char sccsid[] = "@(#)compile.c 8.2 (Berkeley) 4/28/95"; */
-static const char rcsid[] = "$OpenBSD: compile.c,v 1.28 2008/10/16 16:34:32 millert Exp $";
+static const char rcsid[] = "$OpenBSD: compile.c,v 1.29 2009/08/07 03:30:56 djm Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -439,7 +439,7 @@ compile_re(char *p, regex_t **repp)
return (p);
}
*repp = xmalloc(sizeof(regex_t));
- if (p && (eval = regcomp(*repp, re, 0)) != 0)
+ if (p && (eval = regcomp(*repp, re, Eflag ? REG_EXTENDED : 0)) != 0)
err(COMPILE, "RE error: %s", strregerror(eval, *repp));
if (maxnsub < (*repp)->re_nsub)
maxnsub = (*repp)->re_nsub;
diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h
index 80e359576f7..51fa89bb230 100644
--- a/usr.bin/sed/extern.h
+++ b/usr.bin/sed/extern.h
@@ -1,4 +1,4 @@
-/* * $OpenBSD: extern.h,v 1.5 2008/10/08 17:26:47 millert Exp $*/
+/* * $OpenBSD: extern.h,v 1.6 2009/08/07 03:30:56 djm Exp $*/
/*-
* Copyright (c) 1992 Diomidis Spinellis.
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@ extern size_t maxnsub;
extern u_long linenum;
extern int appendnum;
extern int lastline;
-extern int aflag, eflag, nflag;
+extern int Eflag, aflag, eflag, nflag;
extern char *fname;
void cfclose(struct s_command *, struct s_command *);
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index fe2158ba4d1..ac151a90262 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.15 2008/10/16 16:34:32 millert Exp $ */
+/* $OpenBSD: main.c,v 1.16 2009/08/07 03:30:56 djm Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -38,7 +38,7 @@ static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
/* from: static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94"; */
-static const char rcsid[] = "$OpenBSD: main.c,v 1.15 2008/10/16 16:34:32 millert Exp $";
+static const char rcsid[] = "$OpenBSD: main.c,v 1.16 2009/08/07 03:30:56 djm Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -86,7 +86,7 @@ struct s_flist {
*/
static struct s_flist *files, **fl_nextp = &files;
-int aflag, eflag, nflag;
+int Eflag, aflag, eflag, nflag;
/*
* Current file and line number; line numbers restart across compilation
@@ -105,8 +105,12 @@ main(int argc, char *argv[])
int c, fflag;
fflag = 0;
- while ((c = getopt(argc, argv, "ae:f:nu")) != -1)
+ while ((c = getopt(argc, argv, "Eae:f:nru")) != -1)
switch (c) {
+ case 'E':
+ case 'r':
+ Eflag = 1;
+ break;
case 'a':
aflag = 1;
break;
@@ -127,8 +131,8 @@ main(int argc, char *argv[])
default:
case '?':
(void)fprintf(stderr,
- "usage: sed [-anu] command [file ...]\n"
- " sed [-anu] [-e command] [-f command_file] [file ...]\n");
+ "usage: sed [-aEnru] command [file ...]\n"
+ " sed [-aEnru] [-e command] [-f command_file] [file ...]\n");
exit(1);
}
argc -= optind;
diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1
index 33270493dc1..d8812d4f145 100644
--- a/usr.bin/sed/sed.1
+++ b/usr.bin/sed/sed.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sed.1,v 1.32 2009/02/08 17:15:10 jmc Exp $
+.\" $OpenBSD: sed.1,v 1.33 2009/08/07 03:30:56 djm Exp $
.\"
.\" Copyright (c) 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" from: @(#)sed.1 8.2 (Berkeley) 12/30/93
.\"
-.Dd $Mdocdate: February 8 2009 $
+.Dd $Mdocdate: August 7 2009 $
.Dt SED 1
.Os
.Sh NAME
@@ -40,11 +40,11 @@
.Nd stream editor
.Sh SYNOPSIS
.Nm sed
-.Op Fl anu
+.Op Fl Eanru
.Ar command
.Op Ar
.Nm sed
-.Op Fl anu
+.Op Fl aEnru
.Op Fl e Ar command
.Op Fl f Ar command_file
.Op Ar
@@ -69,6 +69,11 @@ regardless of their origin.
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl E
+Interpret regular expressions using the POSIX extended regular expression
+syntax (documented in
+.Xr re_format 7 ).
+The default behaviour is to use the POSIX basic regular expression syntax.
.It Fl a
The files listed as parameters for the
.Ql w
@@ -91,6 +96,10 @@ Append the editing commands found in the file
.Ar command_file
to the list of commands.
The editing commands should each be listed on a separate line.
+.It Fl r
+is an alias for
+.Fl E
+(enable POSIX extended regular exressions) for compatibility with GNU sed.
.It Fl n
By default, each line of input is echoed to the standard output after
all of the commands have been applied to it.
@@ -520,7 +529,7 @@ utility is compliant with the
specification.
.Pp
The flags
-.Op Fl au
+.Op Fl aEru
are extensions to that specification.
.Pp
The use of newlines to separate multiple commands on the command line