diff options
-rwxr-xr-x | cppawk | 18 | ||||
-rw-r--r-- | cppawk.1 | 6 | ||||
-rw-r--r-- | testcases | 8 |
3 files changed, 29 insertions, 3 deletions
@@ -34,6 +34,12 @@ awk=gawk prepro_opts="-D__gawk__=1 -D__cppawk_ver=20220324" # globals +bash=${BASH_VERSION+y} +# if this isn't bash, and there is a /bin/bash, let's re-execute ourselves +# with Bash, so we can use process substitution instead of temp files. +if ! [ $bash ] && [ -x /bin/bash ] ; then + exec /bin/bash "$0" "$@" +fi awk_file= awk_opts= tmp_file= @@ -128,6 +134,9 @@ while [ $# -gt 0 ] ; do ;; esac ;; + --nobash ) + bash= + ;; -U* | -D* | -I* | -iquote* ) prepro_opts="$prepro_opts $(quote "$1")" ;; @@ -171,6 +180,10 @@ if [ -n "$awk_file" ] ; then if [ $prepro_only ] ; then delhashbang_setline "$awk_file" \ | eval "$prepro $incopt\"$awk_file_dir\" $prepro_opts - | collapse" + elif [ $bash ] ; then + prep='delhashbang_setline "$awk_file" \ + | eval "$prepro $incopt\"$awk_file_dir\" $prepro_opts - | collapse"' + eval "$awk $awk_opts -f <($prep) -- \"\$@\"" else trap 'rm -f $tmp_file' EXIT INT TERM tmp_file=$(mktemp) @@ -183,6 +196,11 @@ elif [ $# -gt 0 ] ; then if [ $prepro_only ] ; then printf "%s" "$1" | delhashbang \ | eval "$prepro $incopt"$(pwd)" $prepro_opts - | collapse" + elif [ $bash ] ; then + code=$1; shift + prep='printf "%s" "$code" | delhashbang \ + | eval "$prepro $incopt"$(pwd)" $prepro_opts - | collapse"' + eval "$awk $awk_opts -f <($prep) -- \"\$@\"" else trap 'rm -f $tmp_file' EXIT INT TERM tmp_file=$(mktemp) @@ -84,6 +84,12 @@ is then invoked on this file. The file is deleted when .B awk terminates. +.IP "\fB\-\-nobash\fR" +Pretend that the shell which executes +.B cppawk +isn't GNU Bash, even if it is. This has the effect of disabling +the use of process substitution in favor of the use of a temporary file. + .IP "\fB\-M\fR, \fB\--bignum\fR" These two equivalent GNU Awk options are passed through to .BR awk , @@ -177,8 +177,10 @@ foo_bar foo_bar -- 32: -./cppawk --awk=./testdir/testawk foo +./cppawk --awk=./testdir/testawk foo ; +./cppawk --nobash --awk=./testdir/testawk foo : +[-f][/d][--] [-f][/t][--] -- 33: @@ -197,9 +199,9 @@ mawk=1 gawk=__gawk__ -- 36: -./cppawk --prepro=die --prepro-only x 2>&1 | grep 'not found' +./cppawk --prepro=die --prepro-only x 2>&1 | (grep -q 'die.*not found' && echo "good") : -./cppawk: 1: eval: die: not found +good -- 37: tmp=$(./cppawk --awk=testdir/testdel 1); [ -e $tmp ] || echo gone |