# HG changeset patch # User Rob Landley # Date 1416169302 21600 # Node ID 47647eebc5f9c9ec8c01be4dd3c71a58526e5ace # Parent 6e720e1e833cc4adc86f91e96aae1bce4a7c2b36 Fix sed 'b' with no label and 'N' in general. diff -r 6e720e1e833c -r 47647eebc5f9 toys/pending/sed.c --- a/toys/pending/sed.c Sat Nov 15 17:19:23 2014 -0600 +++ b/toys/pending/sed.c Sun Nov 16 14:21:42 2014 -0600 @@ -3,6 +3,9 @@ * Copyright 2014 Rob Landley * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html + * + * TODO: lines > 2G could signed int wrap length counters. Not just getline() + * but N and s/// USE_SED(NEWTOY(sed, "(version)e*f*inr", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) @@ -335,10 +338,8 @@ if (c != 'b') tea = 0; if (c=='b' || t^(c=='T')) { + if (!logrus->arg1) break; str = logrus->arg1+(char *)logrus; - - - if (!*str) break; for (logrus = (void *)TT.pattern; logrus; logrus = logrus->next) if (logrus->c == ':' && !strcmp(logrus->arg1+(char *)logrus, str)) break; @@ -388,14 +389,18 @@ break; } else if (c=='N') { + // Can't just grab next line because we could have multiple N and + // we need to actually read ahead to get N;$p EOF detection right. if (pline) { TT.restart = logrus->next; - extend_string(&line, TT.nextline, plen, -TT.nextlen); + extend_string(&line, TT.nextline, len, -TT.nextlen); free(TT.nextline); TT.nextline = line; + TT.nextlen += len + 1; line = 0; } + // Pending append goes out right after N goto done; } else if (c=='p') { if (emit(line, len, eol)) break;