]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed bug in substitution
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 28 Apr 2019 02:48:40 +0000 (22:48 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 28 Apr 2019 02:48:40 +0000 (22:48 -0400)
.gitignore
src/tsed.c

index 0ed572ec62dea3f0d70e1fcd52d753c22ab73f00..08a7f57bdd4bf5249c2b7305bb69eb8a91ae30a2 100644 (file)
@@ -59,3 +59,4 @@ edit
 registrar
 fetch
 tests/test_tide
+bin/tsed
index 22df342cbcce95b4d029008920014ddc06c56ac8..20d20c9082a6f4b91fd099533ff141c6e6f9686f 100644 (file)
@@ -7,7 +7,7 @@
 /* Line buffer flags */
 enum {
     LB_NEWLINE = (1 << 0),
-    LB_DELETE = (1 << 1)
+    LB_DELETE  = (1 << 1)
 };
 
 typedef struct {
@@ -21,7 +21,7 @@ typedef struct {
 enum {
     SUB_GLOBAL = (1 << 0),
     SUB_PRINT  = (1 << 1),
-    IN_RANGE = (1 << 2),
+    IN_RANGE   = (1 << 2),
 };
 
 typedef struct {
@@ -99,6 +99,8 @@ static void cmd_s(Cmd* cmd, LineBuf* lbuf) {
                 }
             }
             pos += match[0].rm_eo;
+            if (!*pos || !(cmd->flags & SUB_GLOBAL))
+                lbputsn(&out, pos, (lbuf->length - (pos - lbuf->buffer) - 1));
         } else {
             lbputsn(&out, pos, (lbuf->length - (pos - lbuf->buffer) - 1));
             break;
@@ -281,11 +283,5 @@ int main(int argc, char** argv) {
     }
     prog_free(prog);
 
-//    (void)argc, (void)argv, (void)rdline;
-//    LineBuf buf = {0};
-//    lbputsn(&buf, "foo", 3);
-//    lbputsn(&buf, "bar", 3);
-//    printf("%s\n", buf.buffer);
-
     return 0;
 }