diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-03-18 11:43:19 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-03-18 11:43:19 -0700 |
commit | fa993f68f6ca85299d816e01914629044857e56e (patch) | |
tree | 047531aa57bcb756ad324ea5455aa683fd649721 | |
parent | f73a6746c99bbd32eeb534125baaf14a9d6e9f06 (diff) | |
download | cppawk-fa993f68f6ca85299d816e01914629044857e56e.tar.gz cppawk-fa993f68f6ca85299d816e01914629044857e56e.tar.bz2 cppawk-fa993f68f6ca85299d816e01914629044857e56e.zip |
Fix broken options quoting system.
Unquoting can't just be done with an interpolation
into the command line; we have to construct an entire
command as shell syntax and eval the whole thing.
-rwxr-xr-x | cppawk | 16 | ||||
-rw-r--r-- | testcases | 10 |
2 files changed, 15 insertions, 11 deletions
@@ -68,12 +68,6 @@ quote() esac } -# convert shell-quoted syntax to datum it denotes -unquote() -{ - eval printf \"%s \" "$1" -} - die() { fmt="$0: $1\n" ; shift @@ -129,20 +123,20 @@ trap 'rm -f $tmp_file' EXIT INT TERM if [ -n "$awk_file" ] ; then tmp_file=$(mktemp) $delhashbang "$awk_file" | \ - $prepro $incopt$(dirname "$awk_file") $(unquote "$prepro_opts") - > $tmp_file + eval '$prepro $incopt"$(dirname "$awk_file")" '"$prepro_opts -" > $tmp_file [ $prepro_only ] \ && cat $tmp_file \ - || $awk $(unquote "$awk_opts") -f $tmp_file "$@" + || eval "$awk $awk_opts -f $tmp_file" "$@" elif [ $# -gt 0 ] ; then tmp_file=$(mktemp) if [ $prepro_only ] ; then printf "%s" "$1" | $delhashbang | \ - $prepro $incopt"$(pwd)" $(unquote "$prepro_opts") - + eval '$prepro $incopt"$(pwd)"'"$prepro_opts -" else printf "%s" "$1" | $delhashbang | \ - $prepro $incopt"$(pwd)" $(unquote "$prepro_opts") - > $tmp_file + eval '$prepro $incopt"$(pwd)" '"$prepro_opts -" > $tmp_file shift - $awk $(unquote "$awk_opts") -f $tmp_file "$@" + eval "$awk $awk_opts -f $tmp_file \"\$@\"" fi else die "awk code must be specified" @@ -126,3 +126,13 @@ BEGIN { } ./cppawk -f testdir/program.cwk : 73 +-- +22: +./cppawk -v foo="abc def" 'BEGIN { print foo }' +: +abc def +-- +23: +./cppawk 'BEGIN { printf("%s:%s:%s\n", ARGC, ARGV[1], ARGV[2]) }' "ab c" "'" +: +3:ab c:' |