changeset 1562:b5968bffb65c

More sed bugfixes.
author Rob Landley <rob@landley.net>
date Tue, 18 Nov 2014 04:25:27 -0600
parents 162c7cc868e5
children 3d32f9523584
files toys/pending/sed.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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<<l;
-        else if (!corwin->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;