From 4f368f31152120dcfbaa8ad0bb8b71713d1145af Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 27 Apr 2019 22:48:40 -0400 Subject: [PATCH] fixed bug in substitution --- .gitignore | 1 + src/tsed.c | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 0ed572e..08a7f57 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ edit registrar fetch tests/test_tide +bin/tsed diff --git a/src/tsed.c b/src/tsed.c index 22df342..20d20c9 100644 --- a/src/tsed.c +++ b/src/tsed.c @@ -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; } -- 2.55.0