From 4a558e4ff58e8ae5339ea8a8fa3faf42078a77c9 Mon Sep 17 00:00:00 2001 From: yar Date: Sun, 1 Apr 2007 13:25:03 +0000 Subject: This trivial change should fix at least 3 similar bugs. All of them are related to the `c' function's need to know if we are at the actual end of the address range. (It must print the text not earlier than the whole pattern space was deleted.) It appears the only sed function with this requirement. There is `lastaddr' set by applies(), which is to notify the `c' function, but it can't always help because it's false when we are hitting the end of file early. There is also a bug in applies() due to which `lastaddr' isn't set to true on degenerate ranges such as `$,$' or `N,$' if N appears the last line number. Handling early EOF condition in applies() could look more logical, but it would effectively revert sed to the unreasonable behaviour rev. 1.26 of main.c fought against, as it would require lastline() be called for each line within each address range. So it's better to call lastline() only if needed by the `c' function. Together with this change to sed go regression tests for the bugs fixed (c1-c3). A basic test of `c' (c0) is also added as it helped me to spot my own error. Discussed with: dds Tested by: the regression tests MFC after: 1 week --- tools/regression/usr.bin/sed/regress.c0.out | 4 ++++ tools/regression/usr.bin/sed/regress.c1.out | 4 ++++ tools/regression/usr.bin/sed/regress.c2.out | 3 +++ tools/regression/usr.bin/sed/regress.c3.out | 3 +++ tools/regression/usr.bin/sed/regress.sh | 14 +++++++++++++- 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tools/regression/usr.bin/sed/regress.c0.out create mode 100644 tools/regression/usr.bin/sed/regress.c1.out create mode 100644 tools/regression/usr.bin/sed/regress.c2.out create mode 100644 tools/regression/usr.bin/sed/regress.c3.out (limited to 'tools/regression/usr.bin/sed') diff --git a/tools/regression/usr.bin/sed/regress.c0.out b/tools/regression/usr.bin/sed/regress.c0.out new file mode 100644 index 0000000..a1f8944 --- /dev/null +++ b/tools/regression/usr.bin/sed/regress.c0.out @@ -0,0 +1,4 @@ +foo +foo +foo +foo diff --git a/tools/regression/usr.bin/sed/regress.c1.out b/tools/regression/usr.bin/sed/regress.c1.out new file mode 100644 index 0000000..21af01e --- /dev/null +++ b/tools/regression/usr.bin/sed/regress.c1.out @@ -0,0 +1,4 @@ +input +data +for validation +foo diff --git a/tools/regression/usr.bin/sed/regress.c2.out b/tools/regression/usr.bin/sed/regress.c2.out new file mode 100644 index 0000000..6c54a8d --- /dev/null +++ b/tools/regression/usr.bin/sed/regress.c2.out @@ -0,0 +1,3 @@ +input +data +foo diff --git a/tools/regression/usr.bin/sed/regress.c3.out b/tools/regression/usr.bin/sed/regress.c3.out new file mode 100644 index 0000000..6c54a8d --- /dev/null +++ b/tools/regression/usr.bin/sed/regress.c3.out @@ -0,0 +1,3 @@ +input +data +foo diff --git a/tools/regression/usr.bin/sed/regress.sh b/tools/regression/usr.bin/sed/regress.sh index 45d8f85..3e7ba5f 100644 --- a/tools/regression/usr.bin/sed/regress.sh +++ b/tools/regression/usr.bin/sed/regress.sh @@ -2,7 +2,7 @@ REGRESSION_START($1) -echo '1..11' +echo '1..15' REGRESSION_TEST(`G', `sed G < regress.in') REGRESSION_TEST(`P', `sed P < regress.in') @@ -15,5 +15,17 @@ REGRESSION_TEST(`s4', `echo foo | sed s/,*/,/4') REGRESSION_TEST(`s5', `echo foo | sed s/,*/,/5') REGRESSION_TEST(`hanoi', `echo ":abcd: : :" | sed -f hanoi.sed') REGRESSION_TEST(`math', `echo "4+7*3+2^7/3" | sed -f math.sed') +REGRESSION_TEST(`c0', `sed ''`c\ +foo +''`< regress.in') +REGRESSION_TEST(`c1', `sed ''`4,$c\ +foo +''`< regress.in') +REGRESSION_TEST(`c2', `sed ''`3,9c\ +foo +''`< regress.in') +REGRESSION_TEST(`c3', `sed ''`3,/no such string/c\ +foo +''`< regress.in') REGRESSION_END() -- cgit v1.1