diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-10 11:55:20 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-10 11:55:20 +0200 |
commit | ae68f1133f5d7ea56ac3ea7f0ee439c3496835e8 (patch) | |
tree | 07221d77b35520ae4d38456ffa9d8381f316718c | |
parent | 52a426744e1d58229397d2935e62a1f3e374619c (diff) | |
download | busybox-w32-ae68f1133f5d7ea56ac3ea7f0ee439c3496835e8.tar.gz busybox-w32-ae68f1133f5d7ea56ac3ea7f0ee439c3496835e8.tar.bz2 busybox-w32-ae68f1133f5d7ea56ac3ea7f0ee439c3496835e8.zip |
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>
-rw-r--r-- | editors/sed.c | 23 | ||||
-rwxr-xr-x | testsuite/sed.tests | 5 |
2 files changed, 16 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) | |||
894 | || (!sed_cmd->beg_line && !sed_cmd->end_line | 894 | || (!sed_cmd->beg_line && !sed_cmd->end_line |
895 | && !sed_cmd->beg_match && !sed_cmd->end_match) | 895 | && !sed_cmd->beg_match && !sed_cmd->end_match) |
896 | /* Or did we match the start of a numerical range? */ | 896 | /* Or did we match the start of a numerical range? */ |
897 | || (sed_cmd->beg_line > 0 && (sed_cmd->beg_line == linenum | 897 | || (sed_cmd->beg_line > 0 |
898 | /* "shadowed beginning" case: "1d;1,ENDp" - p still matches at line 2 | 898 | && (sed_cmd->beg_line == linenum |
899 | * even though 1d skipped line 1 which is a start line for p */ | 899 | /* GNU sed compat: |
900 | || (sed_cmd->end_line && sed_cmd->beg_line < linenum && sed_cmd->end_line >= linenum) | 900 | * "shadowed beginning" case: "1d;1,ENDp" - p still matches at line 2 |
901 | || (sed_cmd->end_match && sed_cmd->beg_line < linenum) | 901 | * even though 1d skipped line 1 which is a start line for p */ |
902 | ) | 902 | || (sed_cmd->beg_line < linenum && (sed_cmd->end_line > 0 || sed_cmd->end_match)) |
903 | ) | ||
903 | ) | 904 | ) |
904 | /* Or does this line match our begin address regex? */ | 905 | /* Or does this line match our begin address regex? */ |
905 | || (beg_match(sed_cmd, pattern_space)) | 906 | || (beg_match(sed_cmd, pattern_space)) |
@@ -928,12 +929,10 @@ static void process_files(void) | |||
928 | && (regexec(sed_cmd->end_match, | 929 | && (regexec(sed_cmd->end_match, |
929 | pattern_space, 0, NULL, 0) == 0) | 930 | pattern_space, 0, NULL, 0) == 0) |
930 | ); | 931 | ); |
931 | if (n && sed_cmd->beg_line > 0) { | 932 | } |
932 | /* Once matched, "n,regex" range is dead, disabling it */ | 933 | if (n && sed_cmd->beg_line > 0) { |
933 | regfree(sed_cmd->end_match); | 934 | /* once matched, "n,xxx" range is dead, disabling it */ |
934 | free(sed_cmd->end_match); | 935 | sed_cmd->beg_line = -2; |
935 | sed_cmd->end_match = NULL; | ||
936 | } | ||
937 | } | 936 | } |
938 | sed_cmd->in_match = !n; | 937 | sed_cmd->in_match = !n; |
939 | } | 938 | } |
diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 8af156ae9..677303be1 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests | |||
@@ -220,4 +220,9 @@ testing "sed d does not break n,regex matching #2" \ | |||
220 | "second2\nthird2\n" "" \ | 220 | "second2\nthird2\n" "" \ |
221 | "first\nsecond\nthird\nfourth\n""first2\nsecond2\nthird2\nfourth2\n" | 221 | "first\nsecond\nthird\nfourth\n""first2\nsecond2\nthird2\nfourth2\n" |
222 | 222 | ||
223 | testing "sed 2d;2,1p (gnu compat)" \ | ||
224 | "sed -n '2d;2,1p'" \ | ||
225 | "third\n" "" \ | ||
226 | "first\nsecond\nthird\nfourth\n" | ||
227 | |||
223 | exit $FAILCOUNT | 228 | exit $FAILCOUNT |