From owner-freebsd-bugs Tue Jul 30 5:50:24 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4C4FD37B400 for ; Tue, 30 Jul 2002 05:50:04 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6553843E5E for ; Tue, 30 Jul 2002 05:50:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g6UCo3JU066789 for ; Tue, 30 Jul 2002 05:50:03 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g6UCo3Y6066788; Tue, 30 Jul 2002 05:50:03 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4ED0337B405 for ; Tue, 30 Jul 2002 05:40:43 -0700 (PDT) Received: from smtp.noos.fr (claudel.noos.net [212.198.2.83]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8349443E67 for ; Tue, 30 Jul 2002 05:40:41 -0700 (PDT) (envelope-from root@gits.dyndns.org) Received: (qmail 36762977 invoked by uid 0); 30 Jul 2002 12:40:39 -0000 Received: from unknown (HELO gits.gits.dyndns.org) ([212.198.229.153]) (envelope-sender ) by 212.198.2.83 (qmail-ldap-1.03) with SMTP for ; 30 Jul 2002 12:40:39 -0000 Received: from gits.gits.dyndns.org (liharbv08t3mp5yw@localhost [127.0.0.1]) by gits.gits.dyndns.org (8.12.5/8.12.5) with ESMTP id g6UCeYq4040005; Tue, 30 Jul 2002 14:40:34 +0200 (CEST) (envelope-from root@gits.dyndns.org) Received: (from root@localhost) by gits.gits.dyndns.org (8.12.5/8.12.5/Submit) id g6UCeXLo040004; Tue, 30 Jul 2002 14:40:33 +0200 (CEST) (envelope-from root) Message-Id: <200207301240.g6UCeXLo040004@gits.gits.dyndns.org> Date: Tue, 30 Jul 2002 14:40:33 +0200 (CEST) From: Cyrille Lefevre Reply-To: Cyrille Lefevre To: FreeBSD-gnats-submit@FreeBSD.org Cc: "Tim J. Robbins" X-Send-Pr-Version: 3.113 Subject: bin/41159: new sed -c option to allow ; as a separator for b, t and : functions Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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