sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit ced76f3b033a7687a46364e393e0846d00d4d6a0
parent 844267bce4cda7f8aef4e88b31a4b2cedcecf54b
Author: Eivind Uggedal <eivind@uggedal.com>
Date:   Tue, 26 May 2015 21:36:19 +0000

sed: support extended regular expressions (-E)

Not specified in POSIX.1-2008.
GNU sed uses -r, openbsd uses -E but aliases -r to -E for compat.

Diffstat:
Msed.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sed.c b/sed.c @@ -221,6 +221,7 @@ static String patt, hold, genbuf; static struct { unsigned int n :1; /* -n (no print) */ + unsigned int E :1; /* -E (extended re) */ unsigned int s :1; /* s/// replacement happened */ unsigned int aci_cont:1; /* a,c,i text continuation */ unsigned int s_cont :1; /* s/// replacement text continuation */ @@ -360,6 +361,7 @@ usage(void) /* Differences from POSIX * we allows semicolons and trailing blanks inside {} * we allow spaces after ! (and in between !s) + * we allow extended regular expressions (-E) */ static void compile(char *s, int isfile) @@ -499,7 +501,7 @@ make_addr(Addr *addr, char *s) p -= escapes(s, p, delim, 0); *p++ = '\0'; addr->u.re = emalloc(sizeof(*addr->u.re)); - eregcomp(addr->u.re, s, 0); + eregcomp(addr->u.re, s, gflags.E ? REG_EXTENDED : 0); s = p; } } else { @@ -844,7 +846,7 @@ get_s_arg(Cmd *c, char *s) } else { c->u.s.re = emalloc(sizeof(*c->u.s.re)); /* FIXME: different eregcomp that calls fatal */ - eregcomp(c->u.s.re, s, 0); + eregcomp(c->u.s.re, s, gflags.E ? REG_EXTENDED : 0); } s = p + runelen(delim); } @@ -1689,6 +1691,9 @@ main(int argc, char *argv[]) case 'n': gflags.n = 1; break; + case 'E': + gflags.E = 1; + break; case 'e': arg = EARGF(usage()); compile(arg, 0);