sed: fix "sed n (flushes pattern space, terminates early)" testcase failure
Patch based on work by Dengke Du <dengke.du@windriver.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
9ff910de6b
commit
76d72376e0
@ -1300,16 +1300,17 @@ static void process_files(void)
|
|||||||
case 'n':
|
case 'n':
|
||||||
if (!G.be_quiet)
|
if (!G.be_quiet)
|
||||||
sed_puts(pattern_space, last_gets_char);
|
sed_puts(pattern_space, last_gets_char);
|
||||||
if (next_line) {
|
if (next_line == NULL) {
|
||||||
free(pattern_space);
|
/* If no next line, jump to end of script and exit. */
|
||||||
pattern_space = next_line;
|
goto discard_line;
|
||||||
last_gets_char = next_gets_char;
|
|
||||||
next_line = get_next_line(&next_gets_char, &last_puts_char);
|
|
||||||
substituted = 0;
|
|
||||||
linenum++;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
/* fall through */
|
free(pattern_space);
|
||||||
|
pattern_space = next_line;
|
||||||
|
last_gets_char = next_gets_char;
|
||||||
|
next_line = get_next_line(&next_gets_char, &last_puts_char);
|
||||||
|
substituted = 0;
|
||||||
|
linenum++;
|
||||||
|
break;
|
||||||
|
|
||||||
/* Quit. End of script, end of input. */
|
/* Quit. End of script, end of input. */
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -73,13 +73,9 @@ testing "sed t (test/branch clears test bit)" "sed -e 's/a/b/;:loop;t loop'" \
|
|||||||
testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \
|
testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \
|
||||||
"1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
|
"1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
|
||||||
|
|
||||||
test x"$SKIP_KNOWN_BUGS" = x"" && {
|
|
||||||
# Normal sed end-of-script doesn't print "c" because n flushed the pattern
|
|
||||||
# space. If n hits EOF, pattern space is empty when script ends.
|
|
||||||
# Query: how does this interact with no newline at EOF?
|
|
||||||
testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \
|
testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \
|
||||||
"a\nb\nb\nc\n" "" "a\nb\nc\n"
|
"a\nb\nb\nc\n" "" "a\nb\nc\n"
|
||||||
}
|
|
||||||
# non-GNU sed: N does _not_ flush pattern space, therefore c is eaten @ script end
|
# non-GNU sed: N does _not_ flush pattern space, therefore c is eaten @ script end
|
||||||
# GNU sed: N flushes pattern space, therefore c is printed too @ script end
|
# GNU sed: N flushes pattern space, therefore c is printed too @ script end
|
||||||
testing "sed N (flushes pattern space (GNU behavior))" "sed -e 'N;p'" \
|
testing "sed N (flushes pattern space (GNU behavior))" "sed -e 'N;p'" \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user