From e7835d79c5b6c2c586bf13a28c6457b012145a36 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 27 Nov 2014 20:38:21 -0600 Subject: sed: c needs to trigger range logic like d, D works like d when there isn't anything left in the line, and more tests. --- toys/pending/sed.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'toys') diff --git a/toys/pending/sed.c b/toys/pending/sed.c index b98da05e..4f6941d1 100644 --- a/toys/pending/sed.c +++ b/toys/pending/sed.c @@ -345,7 +345,7 @@ static void walk_pattern(char **pline, long plen) continue; } // Deferred disable from regex end match - if (miss) logrus->hit = 0; + if (miss || logrus->lmatch[1] == TT.count) logrus->hit = 0; } // A deleted line can still update line match state for later commands @@ -377,20 +377,29 @@ static void walk_pattern(char **pline, long plen) str = logrus->arg1+(char *)logrus; if (!logrus->hit || (!logrus->lmatch[1] && !logrus->rmatch[1])) emit(str, strlen(str), 1); - goto done; + free(line); + line = 0; + continue; } else if (c=='d') { free(line); line = 0; continue; } else if (c=='D') { // Delete up to \n or end of buffer - for (str = line; !*str || *str=='\n'; str++); + str = line; + while ((str-line)