aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-24 04:01:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-24 04:01:04 -0700
commit39c8fd12550671adac2a44061a5646d0102e95db (patch)
tree0e27088a2ee0f61ca9da102b27a83418a1cdf4de
parent8aacb4d5fbb4909efa1531e7883c14865387ccd5 (diff)
downloadcppawk-39c8fd12550671adac2a44061a5646d0102e95db.tar.gz
cppawk-39c8fd12550671adac2a44061a5646d0102e95db.tar.bz2
cppawk-39c8fd12550671adac2a44061a5646d0102e95db.zip
bugfix: collapse: don't eat blank lines.
-rwxr-xr-xcppawk13
-rw-r--r--testcases13
2 files changed, 21 insertions, 5 deletions
diff --git a/cppawk b/cppawk
index 7b166a0..cb6987e 100755
--- a/cppawk
+++ b/cppawk
@@ -78,21 +78,24 @@ collapse()
awk '
$1 == "#" { if ($2 != curline || $3 != curfile)
{ print
- if (line != "")
+ if (have_line)
{ printf("%s\n", line);
- line = "" } }
+ line = ""
+ have_line = 0 } }
startline = $2
curline = startline - 1
curfile = $3;
next }
1 { if (++curline > startline)
- { if (line != "")
+ { if (have_line)
{ printf("%s\n", line)
line = "" } }
else
{ sub(/^[ \t]+/, "") }
- line = line $0 }
- END { printf("%s\n", line); }'
+ line = line $0
+ have_line = 1 }
+ END { if (have_line)
+ printf("%s\n", line); }'
}
prepro_opts="$prepro_opts -I$selfdir/cppawk-include"
diff --git a/testcases b/testcases
index 02c9dfe..fd81e02 100644
--- a/testcases
+++ b/testcases
@@ -210,3 +210,16 @@ gone
./cppawk --prepro-only -f testdir/program.cwk | grep BEGIN
:
BEGIN { print ((42) > (73) ? (42) : (73)) }
+--
+39:
+./cppawk --prepro-only 'foo
+
+bar
+
+baz' | ./cppawk '/foo/,/baz/'
+:
+foo
+
+bar
+
+baz