[hackers] [sbase] sed: support extended regular expressions (-E) || Eivind Uggedal

From: <git_AT_suckless.org>
Date: Wed, 3 Jun 2015 19:51:36 +0200 (CEST)

commit ced76f3b033a7687a46364e393e0846d00d4d6a0
Author: Eivind Uggedal <eivind_AT_uggedal.com>
Date: Tue May 26 21:36:19 2015 +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.

diff --git a/sed.c b/sed.c
index a5ca4b4..6e07143 100644
--- a/sed.c
+++ b/sed.c
_AT_@ -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 */
_AT_@ -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)
_AT_@ -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 {
_AT_@ -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);
         }
_AT_@ -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);
Received on Wed Jun 03 2015 - 19:51:36 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 03 2015 - 20:00:12 CEST