aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcppawk32
-rw-r--r--testcases9
2 files changed, 38 insertions, 3 deletions
diff --git a/cppawk b/cppawk
index f7d0c33..565a445 100755
--- a/cppawk
+++ b/cppawk
@@ -70,6 +70,31 @@ die()
exit 1
}
+# Eliminate tracer lines in cpp output which continue a previous line, and
+# merge the continued lines into one. Awk needs this because spurious newlines
+# break its syntax.
+collapse()
+{
+ awk '
+ $1 == "#" { if ($2 != curline || $3 != curfile)
+ { print
+ if (line != "")
+ { printf("%s\n", line);
+ line = "" } }
+ startline = $2
+ curline = startline - 1
+ curfile = $3;
+ next }
+ 1 { if (++curline > startline)
+ { if (line != "")
+ { printf("%s\n", line)
+ line = "" } }
+ else
+ { sub(/^[ \t]+/, "") }
+ line = line $0 }
+ END { printf("%s\n", line); }'
+}
+
prepro_opts="$prepro_opts -I$selfdir/cppawk-include"
while [ $# -gt 0 ] ; do
@@ -120,7 +145,8 @@ trap 'rm -f $tmp_file' EXIT INT TERM
if [ -n "$awk_file" ] ; then
tmp_file=$(mktemp)
$delhashbang "$awk_file" | \
- eval '$prepro $incopt"$(dirname "$awk_file")" '"$prepro_opts -" > $tmp_file
+ eval '$prepro $incopt"$(dirname "$awk_file")" '"$prepro_opts -" | \
+ collapse > $tmp_file
[ $prepro_only ] \
&& cat $tmp_file \
|| eval "$awk $awk_opts -f $tmp_file -- \"\$@\""
@@ -128,10 +154,10 @@ elif [ $# -gt 0 ] ; then
tmp_file=$(mktemp)
if [ $prepro_only ] ; then
printf "%s" "$1" | $delhashbang | \
- eval '$prepro $incopt"$(pwd)"'"$prepro_opts -"
+ eval '$prepro $incopt"$(pwd)"'"$prepro_opts - | collapse"
else
printf "%s" "$1" | $delhashbang | \
- eval '$prepro $incopt"$(pwd)" '"$prepro_opts -" > $tmp_file
+ eval '$prepro $incopt"$(pwd)" '"$prepro_opts - | collapse" > $tmp_file
shift
eval "$awk $awk_opts -f $tmp_file -- \"\$@\""
fi
diff --git a/testcases b/testcases
index 091f19d..8b7dc81 100644
--- a/testcases
+++ b/testcases
@@ -161,3 +161,12 @@ abc'def
BEGIN { print __cppawk_ver >= 20220318 }'
:
1
+--
+30:
+./cppawk '
+#include <limits.h>
+BEGIN {
+ print INT_MIN, INT_MIN, INT_MIN
+}'
+:
+-2147483648 -2147483648 -2147483648