diff options
author | Case Duckworth | 2024-02-06 22:11:51 -0600 |
---|---|---|
committer | Case Duckworth | 2024-02-06 22:11:51 -0600 |
commit | 5f74960e17f8862cbe9919071d2c8149bc27bea8 (patch) | |
tree | 138f54214358f59fc6b8ae0552dacd02db306a27 | |
parent | Add link to readme.st (diff) | |
download | subtext-5f74960e17f8862cbe9919071d2c8149bc27bea8.tar.gz subtext-5f74960e17f8862cbe9919071d2c8149bc27bea8.zip |
Fix quoting (sort of)
Honestly shell quoting is such a bugbear that I'm not sure how to solve it. It might just be part of having a shell pass through that quoting will be weird.
-rw-r--r-- | subtext.awk | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/subtext.awk b/subtext.awk index 07dfb76..881ebe2 100644 --- a/subtext.awk +++ b/subtext.awk | |||
@@ -59,11 +59,6 @@ end[endn] && $0 == end[endn] { | |||
59 | $0 = substr($0, 3, RSTART?RSTART-3:length) | 59 | $0 = substr($0, 3, RSTART?RSTART-3:length) |
60 | par = par (par?"\n":"") \ | 60 | par = par (par?"\n":"") \ |
61 | "$$(" ($1 ? $1 " " shquote(2) : "") " << " end[endn] | 61 | "$$(" ($1 ? $1 " " shquote(2) : "") " << " end[endn] |
62 | # par = par (par?"\n":"") \ | ||
63 | # "$$(unquote + << .." \ | ||
64 | # (length>2 ? " | " substr($1,3) " " shquote(2) : "") \ | ||
65 | # slurp("..") \ | ||
66 | # "..\n)" | ||
67 | next | 62 | next |
68 | } | 63 | } |
69 | 64 | ||
@@ -122,14 +117,15 @@ function shquote(begin, end, quoted, out) { | |||
122 | if (!begin) begin = 1 | 117 | if (!begin) begin = 1 |
123 | if (!end) end = NF | 118 | if (!end) end = NF |
124 | for (i=begin; i<=NF; i++) { | 119 | for (i=begin; i<=NF; i++) { |
120 | if ($i ~ /"/) quoted = 1 | ||
125 | if ($i ~ /^\$/) { | 121 | if ($i ~ /^\$/) { |
126 | quoted = 1 | 122 | quoted = 1 |
127 | out = out (out?" ":"") "\"" $i | 123 | $i = "\"" $i |
128 | continue | ||
129 | } | 124 | } |
130 | if (($i ~ /\)$/) && quoted) { | 125 | if ((($i ~ /\)$/) || ($i ~ /"$/)) && quoted) { |
131 | quoted = 0 | 126 | quoted = 0 |
132 | out = out (out?" ":"") $i "\"" | 127 | if ($i !~ /"$/) $i = $i "\"" |
128 | out = out (out?" ":"") $i | ||
133 | continue | 129 | continue |
134 | } | 130 | } |
135 | if (!quoted) { | 131 | if (!quoted) { |