aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-10 11:55:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-10 11:55:20 +0200
commitae68f1133f5d7ea56ac3ea7f0ee439c3496835e8 (patch)
tree07221d77b35520ae4d38456ffa9d8381f316718c /editors
parent52a426744e1d58229397d2935e62a1f3e374619c (diff)
downloadbusybox-ae68f1133f5d7ea56ac3ea7f0ee439c3496835e8.tar.gz
sed: deal with peculiar behavior of '2d;2,1p' in GNU sed
function old new delta process_files 2173 2120 -53 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 2127301d5..ed12e4336 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -894,12 +894,13 @@ static void process_files(void)
|| (!sed_cmd->beg_line && !sed_cmd->end_line
&& !sed_cmd->beg_match && !sed_cmd->end_match)
/* Or did we match the start of a numerical range? */
- || (sed_cmd->beg_line > 0 && (sed_cmd->beg_line == linenum
- /* "shadowed beginning" case: "1d;1,ENDp" - p still matches at line 2
- * even though 1d skipped line 1 which is a start line for p */
- || (sed_cmd->end_line && sed_cmd->beg_line < linenum && sed_cmd->end_line >= linenum)
- || (sed_cmd->end_match && sed_cmd->beg_line < linenum)
- )
+ || (sed_cmd->beg_line > 0
+ && (sed_cmd->beg_line == linenum
+ /* GNU sed compat:
+ * "shadowed beginning" case: "1d;1,ENDp" - p still matches at line 2
+ * even though 1d skipped line 1 which is a start line for p */
+ || (sed_cmd->beg_line < linenum && (sed_cmd->end_line > 0 || sed_cmd->end_match))
+ )
)
/* Or does this line match our begin address regex? */
|| (beg_match(sed_cmd, pattern_space))
@@ -928,12 +929,10 @@ static void process_files(void)
&& (regexec(sed_cmd->end_match,
pattern_space, 0, NULL, 0) == 0)
);
- if (n && sed_cmd->beg_line > 0) {
- /* Once matched, "n,regex" range is dead, disabling it */
- regfree(sed_cmd->end_match);
- free(sed_cmd->end_match);
- sed_cmd->end_match = NULL;
- }
+ }
+ if (n && sed_cmd->beg_line > 0) {
+ /* once matched, "n,xxx" range is dead, disabling it */
+ sed_cmd->beg_line = -2;
}
sed_cmd->in_match = !n;
}