From fa993f68f6ca85299d816e01914629044857e56e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 18 Mar 2022 11:43:19 -0700 Subject: 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. --- cppawk | 16 +++++----------- testcases | 10 ++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cppawk b/cppawk index b49940a..1b2f1d6 100755 --- a/cppawk +++ b/cppawk @@ -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" diff --git a/testcases b/testcases index 8011eca..1dd1f52 100644 --- a/testcases +++ b/testcases @@ -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:' -- cgit v1.2.3