aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-18 11:20:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-18 11:20:59 -0700
commitf73a6746c99bbd32eeb534125baaf14a9d6e9f06 (patch)
tree0b11e97420cf33ff30f5e725a1d954aa36bc9752
parentc82cf3f4b6970b5fbf0e55d46ccfd8ae5e82589a (diff)
downloadcppawk-f73a6746c99bbd32eeb534125baaf14a9d6e9f06.tar.gz
cppawk-f73a6746c99bbd32eeb534125baaf14a9d6e9f06.tar.bz2
cppawk-f73a6746c99bbd32eeb534125baaf14a9d6e9f06.zip
Rename shell_escape and syntax functions.
-rwxr-xr-xcppawk24
1 files changed, 12 insertions, 12 deletions
diff --git a/cppawk b/cppawk
index 6d883d6..b49940a 100755
--- a/cppawk
+++ b/cppawk
@@ -42,8 +42,8 @@ prepro_only=
# functions
-# convert argument into shell syntax that expands into that argument
-shell_escape()
+# convert argument into quoted shell syntax
+quote()
{
case $1 in
*"'"* )
@@ -68,8 +68,8 @@ shell_escape()
esac
}
-# expand shell syntax for interpolation into command line
-syntax()
+# convert shell-quoted syntax to datum it denotes
+unquote()
{
eval printf \"%s \" "$1"
}
@@ -90,7 +90,7 @@ while [ $# -gt 0 ] ; do
prepro_only=y
;;
-U* | -D* | -I* | -iquote* )
- prepro_opts="$prepro_opts $(shell_escape "$1")"
+ prepro_opts="$prepro_opts $(quote "$1")"
;;
-f )
[ $# -gt 1 ] || die "-f requires argument"
@@ -100,7 +100,7 @@ while [ $# -gt 0 ] ; do
;;
-F | -v | -E | -i | -l | -L )
[ $# -gt 1 ] || die "%s requires argument" $1
- awk_opts="$awk_opts $1 $(shell_escape "$2")"
+ awk_opts="$awk_opts $1 $(quote "$2")"
shift
;;
-- )
@@ -115,7 +115,7 @@ while [ $# -gt 0 ] ; do
prepro_opts="$prepro_opts -D__posix__=1"
;;
-* )
- awk_opts="$awk_opts $(shell_escape "$1")"
+ awk_opts="$awk_opts $(quote "$1")"
;;
* )
break
@@ -129,20 +129,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") $(syntax "$prepro_opts") - > $tmp_file
+ $prepro $incopt$(dirname "$awk_file") $(unquote "$prepro_opts") - > $tmp_file
[ $prepro_only ] \
&& cat $tmp_file \
- || $awk $(syntax "$awk_opts") -f $tmp_file "$@"
+ || $awk $(unquote "$awk_opts") -f $tmp_file "$@"
elif [ $# -gt 0 ] ; then
tmp_file=$(mktemp)
if [ $prepro_only ] ; then
printf "%s" "$1" | $delhashbang | \
- $prepro $incopt"$(pwd)" $(syntax "$prepro_opts") -
+ $prepro $incopt"$(pwd)" $(unquote "$prepro_opts") -
else
printf "%s" "$1" | $delhashbang | \
- $prepro $incopt"$(pwd)" $(syntax "$prepro_opts") - > $tmp_file
+ $prepro $incopt"$(pwd)" $(unquote "$prepro_opts") - > $tmp_file
shift
- $awk $(syntax "$awk_opts") -f $tmp_file "$@"
+ $awk $(unquote "$awk_opts") -f $tmp_file "$@"
fi
else
die "awk code must be specified"