aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcppawk19
-rw-r--r--testcases5
2 files changed, 19 insertions, 5 deletions
diff --git a/cppawk b/cppawk
index 515a430..d91b2e1 100755
--- a/cppawk
+++ b/cppawk
@@ -38,6 +38,7 @@ awk_file=
awk_opts=
tmp_file=
delhashbang="sed -e /^#!/d"
+prepro_only=
# functions
shell_escape()
@@ -77,6 +78,9 @@ while [ $# -gt 0 ] ; do
-M?* )
die "-M family of cpp options not supported"
;;
+ --prepro-only )
+ prepro_only=y
+ ;;
-U* | -D* | -I* | -iquote* )
prepro_opts="$prepro_opts $(shell_escape "$1")"
;;
@@ -117,13 +121,18 @@ trap 'rm -f $tmp_file' EXIT INT TERM
if [ -n "$awk_file" ] ; then
tmp_file=$(mktemp)
$delhashbang "$awk_file" | $prepro $prepro_opts - > $tmp_file
- $awk $awk_opts -f $tmp_file "$@"
+ [ $prepro_only ] && cat $tmp_file || $awk $awk_opts -f $tmp_file "$@"
elif [ $# -gt 0 ] ; then
tmp_file=$(mktemp)
- printf "%s" "$1" | $delhashbang | \
- $prepro $incopt"$(pwd)" $prepro_opts - > $tmp_file
- shift
- $awk $awk_opts -f $tmp_file "$@"
+ if [ $prepro_only ] ; then
+ printf "%s" "$1" | $delhashbang | \
+ $prepro $incopt"$(pwd)" $prepro_opts -
+ else
+ printf "%s" "$1" | $delhashbang | \
+ $prepro $incopt"$(pwd)" $prepro_opts - > $tmp_file
+ shift
+ $awk $awk_opts -f $tmp_file "$@"
+ fi
else
die "awk code must be specified"
fi
diff --git a/testcases b/testcases
index 04e2971..04e90dd 100644
--- a/testcases
+++ b/testcases
@@ -111,3 +111,8 @@ gawk
20:
./cppawk 'BEGIN { print __posix__ }'
:
+--
+21:
+./cppawk --prepro-only 'BEGIN { }' | grep BEGIN
+:
+BEGIN { }