aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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