aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-11-27 20:38:21 -0600
committerRob Landley <rob@landley.net>2014-11-27 20:38:21 -0600
commite7835d79c5b6c2c586bf13a28c6457b012145a36 (patch)
treea8a0bb98fbccc41f5e65c954483e2511586ff40a /toys
parent01e06c4c84a96fcf12c87faccc281134249c5823 (diff)
downloadtoybox-e7835d79c5b6c2c586bf13a28c6457b012145a36.tar.gz
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.
Diffstat (limited to 'toys')
-rw-r--r--toys/pending/sed.c21
1 files changed, 15 insertions, 6 deletions
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)<len) if (*(str++) == '\n') break;
len -= str - line;
memmove(line, str, len);
- line[len] = 0;
- // restart script
- logrus = (void *)TT.pattern;
+ // if "delete" blanks line, disable further processing
+ // otherwise trim and restart script
+ if (!len) {
+ free(line);
+ line = 0;
+ } else {
+ line[len] = 0;
+ logrus = (void *)TT.pattern;
+ }
continue;
} else if (c=='g') {
free(line);