diff options
Diffstat (limited to 'usr.bin/sed/compile.c')
-rw-r--r-- | usr.bin/sed/compile.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c index 944a226..8ad1b2d 100644 --- a/usr.bin/sed/compile.c +++ b/usr.bin/sed/compile.c @@ -36,7 +36,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)compile.c 8.2 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/types.h> @@ -175,7 +175,6 @@ semicolon: EATSPACE(); cmd->nonsel = cmd->inrange = 0; /* First parse the addresses */ naddr = 0; - cmd->a1 = cmd->a2 = NULL; /* Valid characters to start an address */ #define addrchar(c) (strchr("0123456789/\\$", (c))) @@ -185,16 +184,18 @@ semicolon: EATSPACE(); p = compile_addr(p, cmd->a1); EATSPACE(); /* EXTENSION */ if (*p == ',') { - naddr++; p++; EATSPACE(); /* EXTENSION */ + naddr++; cmd->a2 = xmalloc(sizeof(struct s_addr)); p = compile_addr(p, cmd->a2); - } - } + EATSPACE(); + } else + cmd->a2 = 0; + } else + cmd->a1 = cmd->a2 = 0; nonsel: /* Now parse the command */ - EATSPACE(); if (!*p) err(COMPILE, "command expected"); cmd->code = *p; @@ -208,8 +209,9 @@ nonsel: /* Now parse the command */ "command %c expects up to %d address(es), found %d", *p, fp->naddr, naddr); switch (fp->args) { case NONSEL: /* ! */ - cmd->nonsel = ! cmd->nonsel; p++; + EATSPACE(); + cmd->nonsel = ! cmd->nonsel; goto nonsel; case GROUP: /* { */ p++; @@ -221,6 +223,12 @@ nonsel: /* Now parse the command */ *compile_stream("}", &cmd->u.c, p) = cmd2; cmd->next = cmd2; link = &cmd2->next; + /* + * Short-circuit command processing, since end of + * group is really just a noop. + */ + cmd2->nonsel = 1; + cmd2->a1 = cmd2->a2 = 0; break; case EMPTY: /* d D g G h H l n N p P q x = \0 */ p++; |