aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-03-18 17:53:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-03-18 17:53:22 -0700
commit57f350cf16b45ff02bbad16b96599891049ae41c (patch)
tree86f3f199eec27d5a3857fdd6bd0d2ee46d39cff6
parent9ef584a413fa83775f938dc920d89fa9e0b3bc0c (diff)
downloadcppawk-57f350cf16b45ff02bbad16b96599891049ae41c.tar.gz
cppawk-57f350cf16b45ff02bbad16b96599891049ae41c.tar.bz2
cppawk-57f350cf16b45ff02bbad16b96599891049ae41c.zip
Simplify and revise quoting.
-rwxr-xr-xcppawk14
-rw-r--r--testcases21
2 files changed, 23 insertions, 12 deletions
diff --git a/cppawk b/cppawk
index 67cb152..ebf9ff1 100755
--- a/cppawk
+++ b/cppawk
@@ -48,22 +48,16 @@ quote()
case $1 in
*"'"* )
case $1 in
- *'"'* | *'$'* )
- printf "%s" "'$(printf "%s" "$1" | sed -e "s/'/'\\\\''/g")'"
+ *[\"\$\\]* )
+ printf "'%s'" "$(printf "%s" "$1" | sed -e "s/'/'\\\\''/g")"
;;
* )
- printf "%s" "\"$1\""
+ printf '"%s"' "$1"
;;
esac
;;
- *'"'* | *['$*?[(){};&|<>#']* | '~'* )
- printf "%s" "'$1'"
- ;;
- *' '* | *' '* )
- printf "%s" "\"$1\""
- ;;
* )
- printf "%s" "$1"
+ printf "'%s'" "$1"
;;
esac
}
diff --git a/testcases b/testcases
index 1dd1f52..caef473 100644
--- a/testcases
+++ b/testcases
@@ -127,12 +127,29 @@ BEGIN { }
:
73
--
-22:
+24:
./cppawk -v foo="abc def" 'BEGIN { print foo }'
:
abc def
--
-23:
+25:
./cppawk 'BEGIN { printf("%s:%s:%s\n", ARGC, ARGV[1], ARGV[2]) }' "ab c" "'"
:
3:ab c:'
+--
+26:
+./cppawk -v foo="abc\\ndef" 'BEGIN { print foo }'
+:
+abc
+def
+--
+27:
+./cppawk -v foo='abc\n"def' 'BEGIN { print foo }'
+:
+abc
+"def
+--
+28:
+./cppawk -v foo="abc'def" 'BEGIN { print foo }'
+:
+abc'def