|
|
bb9a7e |
diff --git a/arrayfunc.c b/arrayfunc.c
|
|
|
bb9a7e |
--- a/arrayfunc.c
|
|
|
bb9a7e |
+++ b/arrayfunc.c
|
|
|
bb9a7e |
@@ -597,6 +597,27 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
|
|
|
bb9a7e |
free (aval);
|
|
|
bb9a7e |
}
|
|
|
bb9a7e |
}
|
|
|
bb9a7e |
+
|
|
|
bb9a7e |
+/* Return non-zero if L appears to be a key-value pair associative array
|
|
|
bb9a7e |
+ compound assignment. */
|
|
|
bb9a7e |
+int
|
|
|
bb9a7e |
+kvpair_assignment_p (l)
|
|
|
bb9a7e |
+ WORD_LIST *l;
|
|
|
bb9a7e |
+{
|
|
|
bb9a7e |
+ return (l && (l->word->flags & W_ASSIGNMENT) == 0 && l->word->word[0] != '['); /*]*/
|
|
|
bb9a7e |
+}
|
|
|
bb9a7e |
+
|
|
|
bb9a7e |
+char *
|
|
|
bb9a7e |
+expand_and_quote_kvpair_word (w)
|
|
|
bb9a7e |
+ char *w;
|
|
|
bb9a7e |
+{
|
|
|
bb9a7e |
+ char *t, *r;
|
|
|
bb9a7e |
+
|
|
|
bb9a7e |
+ t = w ? expand_assignment_string_to_string (w, 0) : 0;
|
|
|
bb9a7e |
+ r = sh_single_quote (t ? t : "");
|
|
|
bb9a7e |
+ free (t);
|
|
|
bb9a7e |
+ return r;
|
|
|
bb9a7e |
+}
|
|
|
bb9a7e |
#endif
|
|
|
bb9a7e |
|
|
|
bb9a7e |
/* Callers ensure that VAR is not NULL. Associative array assignments have not
|
|
|
bb9a7e |
@@ -640,7 +661,7 @@ assign_compound_array_list (var, nlist, flags)
|
|
|
bb9a7e |
last_ind = (a && (flags & ASS_APPEND)) ? array_max_index (a) + 1 : 0;
|
|
|
bb9a7e |
|
|
|
bb9a7e |
#if ASSOC_KVPAIR_ASSIGNMENT
|
|
|
bb9a7e |
- if (assoc_p (var) && nlist && (nlist->word->flags & W_ASSIGNMENT) == 0 && nlist->word->word[0] != '[') /*]*/
|
|
|
bb9a7e |
+ if (assoc_p (var) && kvpair_assignment_p (nlist))
|
|
|
bb9a7e |
{
|
|
|
bb9a7e |
iflags = flags & ~ASS_APPEND;
|
|
|
bb9a7e |
assign_assoc_from_kvlist (var, nlist, nhash, iflags);
|
|
|
bb9a7e |
diff --git a/arrayfunc.h b/arrayfunc.h
|
|
|
bb9a7e |
--- a/arrayfunc.h
|
|
|
bb9a7e |
+++ b/arrayfunc.h
|
|
|
bb9a7e |
@@ -67,6 +67,9 @@ extern SHELL_VAR *assign_array_var_from_string PARAMS((SHELL_VAR *, char *, int)
|
|
|
bb9a7e |
extern char *expand_and_quote_assoc_word PARAMS((char *, int));
|
|
|
bb9a7e |
extern void quote_compound_array_list PARAMS((WORD_LIST *, int));
|
|
|
bb9a7e |
|
|
|
bb9a7e |
+extern int kvpair_assignment_p PARAMS((WORD_LIST *));
|
|
|
bb9a7e |
+extern char *expand_and_quote_kvpair_word PARAMS((char *));
|
|
|
bb9a7e |
+
|
|
|
bb9a7e |
extern int unbind_array_element PARAMS((SHELL_VAR *, char *, int));
|
|
|
bb9a7e |
extern int skipsubscript PARAMS((const char *, int, int));
|
|
|
bb9a7e |
|
|
|
bb9a7e |
diff --git a/patchlevel.h b/patchlevel.h
|
|
|
bb9a7e |
--- a/patchlevel.h
|
|
|
bb9a7e |
+++ b/patchlevel.h
|
|
|
bb9a7e |
@@ -25,6 +25,6 @@
|
|
|
bb9a7e |
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
|
|
|
bb9a7e |
looks for to find the patch level (for the sccs version string). */
|
|
|
bb9a7e |
|
|
|
bb9a7e |
-#define PATCHLEVEL 3
|
|
|
bb9a7e |
+#define PATCHLEVEL 4
|
|
|
bb9a7e |
|
|
|
bb9a7e |
#endif /* _PATCHLEVEL_H_ */
|
|
|
bb9a7e |
diff --git a/subst.c b/subst.c
|
|
|
bb9a7e |
--- a/subst.c
|
|
|
bb9a7e |
+++ b/subst.c
|
|
|
bb9a7e |
@@ -11604,6 +11604,7 @@ expand_oneword (value, flags)
|
|
|
bb9a7e |
{
|
|
|
bb9a7e |
WORD_LIST *l, *nl;
|
|
|
bb9a7e |
char *t;
|
|
|
bb9a7e |
+ int kvpair;
|
|
|
bb9a7e |
|
|
|
bb9a7e |
if (flags == 0)
|
|
|
bb9a7e |
{
|
|
|
bb9a7e |
@@ -11618,11 +11619,21 @@ expand_oneword (value, flags)
|
|
|
bb9a7e |
{
|
|
|
bb9a7e |
/* Associative array */
|
|
|
bb9a7e |
l = parse_string_to_word_list (value, 1, "array assign");
|
|
|
bb9a7e |
+#if ASSOC_KVPAIR_ASSIGNMENT
|
|
|
bb9a7e |
+ kvpair = kvpair_assignment_p (l);
|
|
|
bb9a7e |
+#endif
|
|
|
bb9a7e |
+
|
|
|
bb9a7e |
/* For associative arrays, with their arbitrary subscripts, we have to
|
|
|
bb9a7e |
expand and quote in one step so we don't have to search for the
|
|
|
bb9a7e |
closing right bracket more than once. */
|
|
|
bb9a7e |
for (nl = l; nl; nl = nl->next)
|
|
|
bb9a7e |
{
|
|
|
bb9a7e |
+#if ASSOC_KVPAIR_ASSIGNMENT
|
|
|
bb9a7e |
+ if (kvpair)
|
|
|
bb9a7e |
+ /* keys and values undergo the same set of expansions */
|
|
|
bb9a7e |
+ t = expand_and_quote_kvpair_word (nl->word->word);
|
|
|
bb9a7e |
+ else
|
|
|
bb9a7e |
+#endif
|
|
|
bb9a7e |
if ((nl->word->flags & W_ASSIGNMENT) == 0)
|
|
|
bb9a7e |
t = sh_single_quote (nl->word->word ? nl->word->word : "");
|
|
|
bb9a7e |
else
|