diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-15 06:12:53 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-15 06:12:53 +0000 |
commit | 6e5687abc3732fac6d8a43a324b8f284f7a5482d (patch) | |
tree | a52bb068db8a2a021bca47a8b8c4b2c486dfc863 | |
parent | 7b3512129799fe07195d188133605fde5c8c6e75 (diff) | |
download | busybox-w32-6e5687abc3732fac6d8a43a324b8f284f7a5482d.tar.gz busybox-w32-6e5687abc3732fac6d8a43a324b8f284f7a5482d.tar.bz2 busybox-w32-6e5687abc3732fac6d8a43a324b8f284f7a5482d.zip |
A test and fix for the sed 'n' command
-rw-r--r-- | editors/sed.c | 8 | ||||
-rw-r--r-- | testsuite/sed/sed-next-line | 12 |
2 files changed, 20 insertions, 0 deletions
diff --git a/editors/sed.c b/editors/sed.c index 00ed20892..8c77a0ffc 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -985,11 +985,19 @@ static void process_file(FILE * file) | |||
985 | next_line = NULL; | 985 | next_line = NULL; |
986 | break; | 986 | break; |
987 | case 'n': /* Read next line from input */ | 987 | case 'n': /* Read next line from input */ |
988 | if (!be_quiet) { | ||
989 | puts(pattern_space); | ||
990 | } | ||
988 | if (next_line) { | 991 | if (next_line) { |
989 | free(pattern_space); | 992 | free(pattern_space); |
990 | pattern_space = next_line; | 993 | pattern_space = next_line; |
991 | next_line = bb_get_chomped_line_from_file(file); | 994 | next_line = bb_get_chomped_line_from_file(file); |
992 | linenum++; | 995 | linenum++; |
996 | } else { | ||
997 | /* Jump to end of script and exist */ | ||
998 | deleted = 1; | ||
999 | free(next_line); | ||
1000 | next_line = NULL; | ||
993 | } | 1001 | } |
994 | break; | 1002 | break; |
995 | case 'N': /* Append the next line to the current line */ | 1003 | case 'N': /* Append the next line to the current line */ |
diff --git a/testsuite/sed/sed-next-line b/testsuite/sed/sed-next-line new file mode 100644 index 000000000..38fe20cf2 --- /dev/null +++ b/testsuite/sed/sed-next-line | |||
@@ -0,0 +1,12 @@ | |||
1 | busybox sed 'n;p'>output <<EOF | ||
2 | a | ||
3 | b | ||
4 | c | ||
5 | EOF | ||
6 | cmp -s output - <<EOF | ||
7 | a | ||
8 | b | ||
9 | b | ||
10 | c | ||
11 | c | ||
12 | EOF | ||