diff options
-rwxr-xr-x | cppawk | 20 | ||||
-rw-r--r-- | testcases | 5 |
2 files changed, 20 insertions, 5 deletions
@@ -41,6 +41,8 @@ delhashbang="sed -e /^#!/d" prepro_only= # functions + +# convert argument into shell syntax that expands into that argument shell_escape() { case $1 in @@ -66,6 +68,12 @@ shell_escape() esac } +# expand shell syntax for interpolation into command line +syntax() +{ + eval printf \"%s \" "$1" +} + die() { fmt="$0: $1\n" ; shift @@ -120,18 +128,20 @@ trap 'rm -f $tmp_file' EXIT INT TERM if [ -n "$awk_file" ] ; then tmp_file=$(mktemp) - $delhashbang "$awk_file" | $prepro $prepro_opts - > $tmp_file - [ $prepro_only ] && cat $tmp_file || $awk $awk_opts -f $tmp_file "$@" + $delhashbang "$awk_file" | $prepro $(syntax "$prepro_opts") - > $tmp_file + [ $prepro_only ] \ + && cat $tmp_file \ + || $awk $(syntax "$awk_opts") -f $tmp_file "$@" elif [ $# -gt 0 ] ; then tmp_file=$(mktemp) if [ $prepro_only ] ; then printf "%s" "$1" | $delhashbang | \ - $prepro $incopt"$(pwd)" $prepro_opts - + $prepro $incopt"$(pwd)" $(syntax $prepro_opts) - else printf "%s" "$1" | $delhashbang | \ - $prepro $incopt"$(pwd)" $prepro_opts - > $tmp_file + $prepro $incopt"$(pwd)" $(syntax "$prepro_opts") - > $tmp_file shift - $awk $awk_opts -f $tmp_file "$@" + $awk $(syntax "$awk_opts") -f $tmp_file "$@" fi else die "awk code must be specified" @@ -116,3 +116,8 @@ gawk ./cppawk --prepro-only 'BEGIN { }' | grep BEGIN : BEGIN { } +-- +22: +./cppawk -v foo="'\"" 'BEGIN { print foo }' +: +'" |