Hi

$ sed -e "{ y/o/u/ }"
sed: 1: "{ y/o/u/ }": extra text at the end of a transform command

but this is allowed according to the manual:

     Functions can be combined to form a function list, a list of sed
     functions separated by newlines, as follows:

           { function
             function
             ...
             function
           }

     The `{' can be preceded or followed by whitespace.  The function can be
     preceded by whitespace as well.  The terminating `}' must be preceded by
     a newline or optional whitespace.


I tried to fix it by adding special cases for '}' to the relevant parts
of the compile_stream() function. Is this correct? OK?


Christopher


Index: compile.c
===================================================================
RCS file: /cvs/src/usr.bin/sed/compile.c,v
retrieving revision 1.36
diff -u -p -r1.36 compile.c
--- compile.c   8 Oct 2014 04:19:08 -0000       1.36
+++ compile.c   22 Oct 2014 15:32:55 -0000
@@ -234,14 +234,19 @@ nonsel:           /* Now parse the command */
                case EMPTY:             /* d D g G h H l n N p P q x = \0 */
                        p++;
                        EATSPACE();
-                       if (*p == ';') {
+                       switch (*p) {
+                       case ';':
                                p++;
                                link = &cmd->next;
+                               /* FALLTHROUGH */
+                       case '}':
                                goto semicolon;
+                       case '\0':
+                               break;
+                       default:
+                               err(COMPILE, "extra characters at the end of "
+                                   "%c command", cmd->code);
                        }
-                       if (*p)
-                               err(COMPILE,
-"extra characters at the end of %c command", cmd->code);
                        break;
                case TEXT:                      /* a c i */
                        p++;
@@ -323,14 +328,19 @@ nonsel:           /* Now parse the command */
                        p++;
                        p = compile_tr(p, (char **)&cmd->u.y);
                        EATSPACE();
-                       if (*p == ';') {
+                       switch (*p) {
+                       case ';':
                                p++;
                                link = &cmd->next;
+                               /* FALLTHROUGH */
+                       case '}':
                                goto semicolon;
-                       }
-                       if (*p)
+                       case '\0':
+                               break;
+                       default:
                                err(COMPILE, "extra text at the end of a"
                                    " transform command");
+                       }
                        break;
                }
        }


-- 
http://gmerlin.de
OpenPGP: http://gmerlin.de/christopher.pub
F190 D013 8F01 AA53 E080  3F3C F17F B0A1 D44E 4FEE

Attachment: signature.asc
Description: PGP signature

Reply via email to