extend assoc_expand_once to indexed arrays; rename to array_expand_once, keeping old name as a synonym; udpate shopt documentation

This commit is contained in:
Chet Ramey
2023-06-13 11:44:33 -04:00
parent d44a45afbc
commit 76112093ec
35 changed files with 1389 additions and 1157 deletions
+10 -11
View File
@@ -932,12 +932,11 @@ builtin_bind_variable (char *name, char *value, int flags)
#if defined (ARRAY_VARS)
/* Callers are responsible for calling this with array references that have
already undergone valid_array_reference checks (read, printf). */
vflags = assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0;
bindflags = flags | (assoc_expand_once ? ASS_NOEXPAND : 0) | ASS_ALLOWALLSUB;
if (flags & ASS_NOEXPAND)
vflags |= VA_NOEXPAND;
if (flags & ASS_ONEWORD)
vflags |= VA_ONEWORD;
/* XXX - should we unconditionally set ASS_NOEXPAND if the shell
compatibility level is > 52? */
bindflags = flags | (array_expand_once ? ASS_NOEXPAND : 0) | ASS_ALLOWALLSUB;
vflags = convert_assign_flags_to_validarray_flags (flags);
vflags |= array_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0;
if (valid_array_reference (name, vflags) == 0)
v = bind_variable (name, value, flags);
@@ -1022,7 +1021,7 @@ builtin_arrayref_flags (WORD_DESC *w, int baseflags)
vflags = baseflags;
/* Don't require assoc_expand_once if we have an argument that's already
/* Don't require array_expand_once if we have an argument that's already
passed through valid_array_reference and been expanded once. That
doesn't protect it from normal expansions like word splitting, so
proper quoting is still required. */
@@ -1031,7 +1030,7 @@ builtin_arrayref_flags (WORD_DESC *w, int baseflags)
# if 0
/* This is a little sketchier but handles quoted arguments. */
if (assoc_expand_once && (t = strchr (w->word, '[')) && t[strlen(t) - 1] == ']')
if (array_expand_once && (t = strchr (w->word, '[')) && t[strlen(t) - 1] == ']')
vflags |= VA_ONEWORD|VA_NOEXPAND;
# endif
@@ -1050,12 +1049,12 @@ set_expand_once (int nval, int uwp)
{
int oa;
oa = assoc_expand_once;
oa = array_expand_once;
if (shell_compatibility_level > 51) /* XXX - internal */
{
if (uwp)
unwind_protect_int (assoc_expand_once);
assoc_expand_once = nval;
unwind_protect_int (array_expand_once);
array_expand_once = nval;
}
return oa;
}
+3 -3
View File
@@ -275,9 +275,9 @@ extern int wait_intr_flag;
#if defined (ARRAY_VARS)
#define SET_VFLAGS(wordflags, vflags, bindflags) \
do { \
vflags = assoc_expand_once ? VA_NOEXPAND : 0; \
bindflags = assoc_expand_once ? ASS_NOEXPAND : 0; \
if (assoc_expand_once && (wordflags & W_ARRAYREF)) \
vflags = array_expand_once ? VA_NOEXPAND : 0; \
bindflags = array_expand_once ? ASS_NOEXPAND : 0; \
if (array_expand_once && (wordflags & W_ARRAYREF)) \
vflags |= VA_ONEWORD|VA_NOEXPAND; \
if (vflags & VA_NOEXPAND) \
bindflags |= ASS_NOEXPAND; \
+1 -1
View File
@@ -393,7 +393,7 @@ declare_internal (WORD_LIST *list, int local_var)
name = savestring (list->word->word);
wflags = list->word->flags;
#if defined (ARRAY_VARS)
assoc_noexpand = assoc_expand_once && (wflags & W_ASSIGNMENT);
assoc_noexpand = array_expand_once && (wflags & W_ASSIGNMENT);
#else
assoc_noexpand = 0;
#endif
+1 -1
View File
@@ -178,7 +178,7 @@ char *posix_builtins[] =
};
/* The builtin commands that can take array references as arguments and pay
attention to `assoc_expand_once'. These are the ones that don't assign
attention to `array_expand_once'. These are the ones that don't assign
values, but need to avoid double expansions. */
char *arrayvar_builtins[] =
{
+1 -1
View File
@@ -866,7 +866,7 @@ unset_builtin (WORD_LIST *list)
nameref = 0;
#if defined (ARRAY_VARS)
base_vflags = assoc_expand_once ? VA_NOEXPAND : 0;
base_vflags = array_expand_once ? VA_NOEXPAND : 0;
#endif
while (list)
+6 -6
View File
@@ -122,7 +122,6 @@ extern int debugging_mode;
#endif
#if defined (ARRAY_VARS)
extern int assoc_expand_once;
extern int array_expand_once;
int expand_once_flag;
#endif
@@ -146,7 +145,7 @@ static int shopt_set_complete_direxpand (char *, int);
#endif
#if defined (ARRAY_VARS)
static int set_assoc_expand (char *, int);
static int set_array_expand (char *, int);
#endif
#if defined (EXTENDED_GLOB)
@@ -180,7 +179,8 @@ static struct {
} shopt_vars[] = {
{ "autocd", &autocd, (shopt_set_func_t *)NULL },
#if defined (ARRAY_VARS)
{ "assoc_expand_once", &expand_once_flag, set_assoc_expand },
{ "array_expand_once", &expand_once_flag, set_array_expand },
{ "assoc_expand_once", &expand_once_flag, set_array_expand },
#endif
{ "cdable_vars", &cdable_vars, (shopt_set_func_t *)NULL },
{ "cdspell", &cdspelling, (shopt_set_func_t *)NULL },
@@ -386,7 +386,7 @@ reset_shopt_options (void)
glob_always_skip_dot_and_dotdot = 1; /* new default as of bash-5.2 */
#if defined (ARRAY_VARS)
expand_once_flag = assoc_expand_once = 0;
expand_once_flag = array_expand_once = 0;
#endif
#if defined (HISTORY)
@@ -914,12 +914,12 @@ initialize_bashopts (int no_bashopts)
#if defined (ARRAY_VARS)
static int
set_assoc_expand (char *option_name, int mode)
set_array_expand (char *option_name, int mode)
{
#if 0 /* leave this disabled */
if (shell_compatibility_level <= 51)
#endif
assoc_expand_once = expand_once_flag;
array_expand_once = expand_once_flag;
return 0;
}
#endif