Date: Tue, 30 Jul 2002 14:40:33 +0200 (CEST) From: Cyrille Lefevre <cyrille.lefevre@laposte.net> To: FreeBSD-gnats-submit@FreeBSD.org Cc: "Tim J. Robbins" <tjr@FreeBSD.org> Subject: bin/41159: new sed -c option to allow ; as a separator for b, t and : functions Message-ID: <200207301240.g6UCeXLo040004@gits.gits.dyndns.org>
next in thread | raw e-mail | index | archive | help
>Number: 41159 >Category: bin >Synopsis: new sed -c option to allow ; as a separator for b, t and : functions >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Jul 30 05:50:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Cyrille Lefevre >Release: FreeBSD 4.6-STABLE i386 >Organization: ACME >Environment: System: FreeBSD gits 4.6-STABLE FreeBSD 4.6-STABLE #21: Sun Jul 28 09:42:24 CEST 2002 root@gits:/disk2/freebsd/stable/src/sys/compile/CUSTOM i386 >Description: the current sed implementation can't handle the ; separator for b, t and : functions. this patch set add a new -c (compat) option to allow sed to parse such constructions. maybe -C is better then -c ? >How-To-Repeat: fetch http://queen.rett.polimi.it/~paolob/seders/scripts/sokoban.sed sed -f sokoban.sed sed: 2266: /root/sokoban.sed: unexpected EOF (pending }'s) sed -cf sokoban.sed (weel, it doesn't work yet, but at least, it can be parsed :) >Fix: Index: compile.c =================================================================== RCS file: /home/ncvs/src/usr.bin/sed/compile.c,v retrieving revision 1.13.2.7 diff -u -r1.13.2.7 compile.c --- compile.c 17 Jul 2002 09:35:56 -0000 1.13.2.7 +++ compile.c 30 Jul 2002 12:08:25 -0000 @@ -76,7 +76,7 @@ static char *compile_tr(char *, char **); static struct s_command **compile_stream(struct s_command **); -static char *duptoeol(char *, const char *); +static char *duptoeol(char **, const char *, int); static void enterlabel(struct s_command *); static struct s_command *findlabel(char *); @@ -274,39 +274,43 @@ case WFILE: /* w */ p++; EATSPACE(); - if (*p == '\0') + cmd->t = duptoeol(&p, "w command", 0); + if (cmd->t == NULL) errx(1, "%lu: %s: filename expected", linenum, fname); - cmd->t = duptoeol(p, "w command"); if (aflag) cmd->u.fd = -1; - else if ((cmd->u.fd = open(p, + else if ((cmd->u.fd = open(cmd->t, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) - err(1, "%s", p); + err(1, "%s", cmd->t); break; case RFILE: /* r */ p++; EATSPACE(); - if (*p == '\0') + cmd->t = duptoeol(&p, "read command", 0); + if (cmd->t == NULL) errx(1, "%lu: %s: filename expected", linenum, fname); - else - cmd->t = duptoeol(p, "read command"); break; case BRANCH: /* b t */ p++; EATSPACE(); - if (*p == '\0') - cmd->t = NULL; - else - cmd->t = duptoeol(p, "branch"); + cmd->t = duptoeol(&p, "branch", 1); + if (*p == ';') { + p++; + goto semicolon; + } break; case LABEL: /* : */ p++; EATSPACE(); - cmd->t = duptoeol(p, "label"); - if (strlen(p) == 0) + cmd->t = duptoeol(&p, "label", 1); + if (cmd->t == NULL) errx(1, "%lu: %s: empty label", linenum, fname); enterlabel(cmd); + if (*p == ';') { + p++; + goto semicolon; + } break; case SUBST: /* s */ p++; @@ -738,27 +742,36 @@ /* * duptoeol -- - * Return a copy of all the characters up to \n or \0. + * Return a copy of all the characters up to \n or \0 and maybe `;'. */ static char * -duptoeol(s, ctype) - char *s; +duptoeol(sp, ctype, semi) + char **sp; const char *ctype; + int semi; { size_t len; int ws; - char *p, *start; + char *p, *start, *s; + char c; + c = semi && cflag ? ';' : '\0'; ws = 0; - for (start = s; *s != '\0' && *s != '\n'; ++s) + for (start = s = *sp; *s != '\0' && *s != '\n' && *s != c; ++s) ws = isspace((unsigned char)*s); - *s = '\0'; + *sp = s; + if (*s != c) + *s = '\0'; + if (start == s) + return (NULL); if (ws) warnx("%lu: %s: whitespace after %s", linenum, fname, ctype); len = s - start + 1; if ((p = malloc(len)) == NULL) err(1, "malloc"); - return (memmove(p, start, len)); + s = memmove(p, start, len); + s [len-1] = '\0'; + return (s); } /* Index: extern.h =================================================================== RCS file: /home/ncvs/src/usr.bin/sed/extern.h,v retrieving revision 1.3.6.4 diff -u -r1.3.6.4 extern.h --- extern.h 17 Jul 2002 09:35:56 -0000 1.3.6.4 +++ extern.h 30 Jul 2002 01:59:12 -0000 @@ -45,6 +45,7 @@ extern u_long linenum; extern int appendnum; extern int aflag, eflag, nflag; +extern int cflag; extern const char *fname; extern int rflags; /* regex flags to use */ Index: main.c =================================================================== RCS file: /home/ncvs/src/usr.bin/sed/main.c,v retrieving revision 1.9.2.6 diff -u -r1.9.2.6 main.c --- main.c 17 Jul 2002 09:35:56 -0000 1.9.2.6 +++ main.c 30 Jul 2002 01:59:12 -0000 @@ -99,6 +99,7 @@ static FILE *curfile; /* Current open file */ int aflag, eflag, nflag; +int cflag; /* allow ; to behave as \n for b and t */ int rflags = 0; static int rval; /* Exit status */ @@ -128,7 +129,7 @@ fflag = 0; inplace = NULL; - while ((c = getopt(argc, argv, "Eae:f:i:n")) != -1) + while ((c = getopt(argc, argv, "Eace:f:i:n")) != -1) switch (c) { case 'E': rflags = REG_EXTENDED; @@ -136,6 +137,9 @@ case 'a': aflag = 1; break; + case 'c': + cflag = 1; + break; case 'e': eflag = 1; if ((temp_arg = malloc(strlen(optarg) + 2)) == NULL) @@ -186,8 +190,8 @@ usage() { (void)fprintf(stderr, "%s\n%s\n", - "usage: sed script [-Ean] [-i extension] [file ...]", - " sed [-an] [-i extension] [-e script] ... [-f script_file] ... [file ...]"); + "usage: sed script [-Eacn] [-i extension] [file ...]", + " sed [-acn] [-i extension] [-e script] ... [-f script_file] ... [file ...]"); exit(1); } Index: sed.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/sed/sed.1,v retrieving revision 1.9.2.9 diff -u -r1.9.2.9 sed.1 --- sed.1 27 Jun 2002 13:03:33 -0000 1.9.2.9 +++ sed.1 30 Jul 2002 11:41:57 -0000 @@ -43,11 +43,11 @@ .Nd stream editor .Sh SYNOPSIS .Nm -.Op Fl Ean +.Op Fl Eacn .Ar command .Op Ar .Nm -.Op Fl Ean +.Op Fl Eacn .Op Fl e Ar command .Op Fl f Ar command_file .Op Fl i Ar extension @@ -89,6 +89,17 @@ to delay opening each file until a command containing the related .Dq w function is applied to a line of input. +.It Fl c +Compatible mode to allow the +.Dq \&; +command separator for +.Dq b , +.Dq t +and +.Dq \&: +functions instead of reading the +.Em label +until the eof of line. .It Fl e Ar command Append the editing commands specified by the .Ar command >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207301240.g6UCeXLo040004>