NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/45981: sed(1) "c" command should start a next cycle



>Number:         45981
>Category:       bin
>Synopsis:       sed(1) "c" command should start a next cycle
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 11 00:10:00 +0000 2012
>Originator:     Valeriy E. Ushakov
>Release:        current
>Organization:
>Environment:
NetBSD felix 5.99.56 NetBSD 5.99.56 (FELIX) #0: Sun Oct 30 04:49:01 MSK 2011  
uwe@shravaka:/mnt/netbsd/cvs/src/sys/arch/landisk/compile/FELIX landisk

>Description:
sed(1) "c" command is in some sense a shorthand for "i"+"d", so,
like "d" it should start the next cycle.  This is explicitly documented
in v7 man page:

  Delete the pattern space.  With 0 or 1 address or at the end of a
  2-address range, place text on the output.  Start the next cycle.

GNU sed and Plan 9 sed do that.

O'Reilly "sed & awk" book also says:

  The change command clears the pattern space, having the same effect
  on the pattern space as the delete command.  No command following
  the change command in the script is applied.


Our sed(1) does NOT do that and continues with the script.

>How-To-Repeat:
$ echo | sed -e '
c\
c1
c\
c2
'
c1
c2

Note that both "c1" and "c2" are printed.

Other sed versions I tested (v7, plan9, gnu) only print "c1".

>Fix:
Index: usr.bin/sed/process.c
===================================================================
RCS file: /cvsroot/src/usr.bin/sed/process.c,v
retrieving revision 1.38
diff -u -p -r1.38 process.c
--- usr.bin/sed/process.c       13 Apr 2009 07:29:55 -0000      1.38
+++ usr.bin/sed/process.c       11 Feb 2012 00:05:06 -0000
@@ -168,7 +168,7 @@ redirect:
                                psl = 0;
                                if (cp->a2 == NULL || lastaddr)
                                        (void)printf("%s", cp->t);
-                               break;
+                               goto new;
                        case 'd':
                                pd = 1;
                                goto new;



Home | Main Index | Thread Index | Old Index