@@ -15,6 +15,84 @@ DIRS=()
15
15
LIB_PATHS=()
16
16
BIN_PATHS=()
17
17
18
+ quote_bash_args ()
19
+ {
20
+ # ## This is an internal function to avoid the use of ugly namespace.
21
+ __quote_bash_args () {
22
+ local r=' ' c=' ' l=" $1 "
23
+ # ## backslash/double/single quote mode
24
+ local bq=' ' dq=' ' sq=' '
25
+
26
+ __quote_bash_args_toggle () {
27
+ # ## toggle $1 value
28
+ eval [ -n \"\$ $1 \" ] && eval " $1 =" || eval " $1 =\$ $2 "
29
+ }
30
+
31
+ for (( i= 0 ; i< ${# l} ; i++ )) ; do
32
+ c=" ${l: i: 1} "
33
+
34
+ case " $c " in
35
+ \" )
36
+ # ## toggle double quote mode unless
37
+ # ## in backslash or single quote mode
38
+ [ -n " $bq$sq " ] || __quote_bash_args_toggle dq c
39
+ ;;
40
+ \' )
41
+ # ## toggle single quote mode unless
42
+ # ## in backslash or double quote mode
43
+ [ -n " $bq$dq " ] || __quote_bash_args_toggle sq c
44
+ ;;
45
+ \$ |\` )
46
+ # ## quote special character unless
47
+ # ## in backslash or single quote mode
48
+ [ -n " $bq$sq " ] || bq=\\
49
+ ;;
50
+ \\ )
51
+ # ## toggle backslash quote mode unless
52
+ # ## in single quote mode
53
+ if [ -z " $sq " ]; then
54
+ if [ -z " $bq " ]; then
55
+ # ## enter backslash quote mode
56
+ bq=\\
57
+ continue
58
+ else
59
+ # ## leave backslash quote mode
60
+ r=" $r \\ "
61
+ bq=
62
+ fi
63
+ fi
64
+ ;;
65
+ [!A-Za-z0-9_\ \ ])
66
+ # ## quote non-regular character unless
67
+ # ## in any quote mode
68
+ [ -n " $bq$dq$sq " ] || bq=\\
69
+ ;;
70
+ esac
71
+ r=" $r$bq$c "
72
+ # ## leave backslash quote mode if any
73
+ bq=
74
+ done
75
+
76
+ [ -z " $bq$dq$sq " ] ||
77
+ { message " unmatched character ($bq$dq$sq ) found" ; return 1; }
78
+ __quote_bash_args_out=" $r "
79
+ }
80
+ local __quote_bash_args_rc=0
81
+
82
+ if [ -z " ${2##* [\"\'\$\`\\\\]* } " ]; then
83
+ local __quote_bash_args_out=' '
84
+ __quote_bash_args " $2 " || __quote_bash_args_rc=1
85
+ eval " $1 =\"\$ __quote_bash_args_out\" "
86
+ else
87
+ eval " $1 =\"\$ 2\" "
88
+ fi
89
+
90
+ # ## Remove internal functions from user namespace.
91
+ unset -f __quote_bash_args __quote_bash_args_toggle
92
+
93
+ return $__quote_bash_args_rc
94
+ }
95
+
18
96
in_runtimedir ()
19
97
{
20
98
local f=" ${1# $LOCALBUILDDIR } "
@@ -34,7 +112,7 @@ append_progs()
34
112
[ -n " $1 " ] ||
35
113
return 0
36
114
37
- quote_shell_args args " $1 "
115
+ quote_bash_args args " $1 "
38
116
eval " set -- $args "
39
117
40
118
for n; do
@@ -113,7 +191,7 @@ append_libs()
113
191
[ -n " $1 " ] ||
114
192
return 0
115
193
116
- quote_shell_args args " $1 "
194
+ quote_bash_args args " $1 "
117
195
eval " set -- $args "
118
196
119
197
for n; do
@@ -158,7 +236,7 @@ append_libs()
158
236
get_bin_paths
159
237
get_lib_paths
160
238
161
- quote_shell_args args " ${PUT_FEATURE_DIRS-} $PUT_DIRS "
239
+ quote_bash_args args " ${PUT_FEATURE_DIRS-} $PUT_DIRS "
162
240
eval " set -- $args "
163
241
164
242
for n in \
@@ -184,7 +262,7 @@ append_libs required "${PUT_FEATURE_LIBS-}"
184
262
append_libs optional " ${PUT_FEATURE_OPTIONAL_LIBS-} "
185
263
186
264
if [ -n " ${PUT_FEATURE_PROGS_WILDCARD-} " ]; then
187
- quote_shell_args args " $PUT_FEATURE_PROGS_WILDCARD "
265
+ quote_bash_args args " $PUT_FEATURE_PROGS_WILDCARD "
188
266
eval " set -- $args "
189
267
190
268
while read -d: -r n; do
@@ -209,7 +287,7 @@ if [ -n "${PUT_FEATURE_PROGS_WILDCARD-}" ]; then
209
287
fi
210
288
211
289
if [ -n " ${PUT_FEATURE_FILES-} " ] || [ -n " ${PUT_FILES-} " ]; then
212
- quote_shell_args args " ${PUT_FEATURE_FILES-} ${PUT_FILES-} "
290
+ quote_bash_args args " ${PUT_FEATURE_FILES-} ${PUT_FILES-} "
213
291
eval " set -- $args "
214
292
215
293
for n in " $@ " ; do
0 commit comments