A test and fix for the sed 'n' command
authorGlenn L McGrath <bug1@ihug.co.nz>
Mon, 15 Sep 2003 06:12:53 +0000 (06:12 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Mon, 15 Sep 2003 06:12:53 +0000 (06:12 -0000)
editors/sed.c
testsuite/sed/sed-next-line [new file with mode: 0644]

index 00ed208..8c77a0f 100644 (file)
@@ -985,11 +985,19 @@ static void process_file(FILE * file)
                                        next_line = NULL;
                                        break;
                                case 'n':       /* Read next line from input */
+                                       if (!be_quiet) {
+                                               puts(pattern_space);
+                                       }
                                        if (next_line) {
                                                free(pattern_space);
                                                pattern_space = next_line;
                                                next_line = bb_get_chomped_line_from_file(file);
                                                linenum++;
+                                       } else {
+                                               /* Jump to end of script and exist */
+                                               deleted = 1;
+                                               free(next_line);
+                                               next_line = NULL;
                                        }
                                        break;
                                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 (file)
index 0000000..38fe20c
--- /dev/null
@@ -0,0 +1,12 @@
+busybox sed 'n;p'>output <<EOF
+a
+b
+c
+EOF
+cmp -s output - <<EOF
+a
+b
+b
+c
+c
+EOF