# HG changeset patch # User Rob Landley # Date 1416306327 21600 # Node ID b5968bffb65c317da5434b7ce17bb12ab16bc635 # Parent 162c7cc868e57ac601e370a66d2faa82fba1c7d2 More sed bugfixes. diff -r 162c7cc868e5 -r b5968bffb65c toys/pending/sed.c --- a/toys/pending/sed.c Mon Nov 17 21:21:04 2014 -0600 +++ b/toys/pending/sed.c Tue Nov 18 04:25:27 2014 -0600 @@ -573,8 +573,10 @@ j = stridx(from, line[i]); if (j != -1) line[i] = to[j]; } - } else if (c=='=') xprintf("%ld\n", TT.count); - else if (!strchr(":{}", c)) error_exit("todo: %c", c); + } else if (c=='=') { + sprintf(toybuf, "%ld", TT.count); + emit(toybuf, strlen(toybuf), 1); + } else if (!strchr(":{}", c)) error_exit("todo: %c", c); logrus = logrus->next; } @@ -630,11 +632,16 @@ char *tmp; if (i) { + struct step *primal; + if (!fd && *name=='-') { error_msg("no -i on stdin"); return; } TT.fdout = copy_tempfile(fd, name, &tmp); + TT.count = 0; + for (primal = (void *)TT.pattern; primal; primal = primal->next) + primal->hit = 0; } do_lines(fd, name, walk_pattern); if (i) { @@ -653,6 +660,7 @@ // Ok, what happens if we xexec() sed with constant arguments then? // TODO: ^^^ that +// also screws up error reporting for bad patterns // returns length of processed string, *pstr advances to next unused char, // if delim (or *delim) is 0 uses starting char as delimiter, otherwise @@ -690,7 +698,7 @@ // Check escaped end delimiter before printf style escapes. if (from[1] == d) from++; - else { + else if (from[1]!='\\') { char c = unescape(from[1]); if (c) { @@ -818,7 +826,7 @@ if (isspace(*line)) continue; if (0 <= (l = stridx("igp", *line))) corwin->sflags |= 1<sflags >> 3 && 0<(l = strtol(line, &line, 10))) { + else if (!(corwin->sflags>>3) && 0<(l = strtol(line, &line, 10))) { corwin->sflags |= l << 3; line--; } else break;