| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/arrayfunc.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* arrayfunc.c -- High-level array functions used by other parts of the shell. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | /* Copyright (C) 2001-2016 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | This file is part of GNU Bash, the Bourne Again SHell. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | Bash is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | Bash is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #include "config.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # include <unistd.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #include "bashintl.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | #include "shell.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #include "execute_cmd.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | #include "pathexp.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | #include "shmbutil.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | #if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # include <mbstr.h> /* mbschr */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #include "builtins/common.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | /* This variable means to not expand associative array subscripts more than | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | once, when performing variable expansion. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | int assoc_expand_once = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | /* Ditto for indexed array subscripts -- currently unused */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | int array_expand_once = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | static SHELL_VAR *bind_array_var_internal __P((SHELL_VAR *, arrayind_t, char *, char *, int)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | static SHELL_VAR *assign_array_element_internal __P((SHELL_VAR *, char *, char *, char *, int, char *, int)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | static char *quote_assign __P((const char *)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | static void quote_array_assignment_chars __P((WORD_LIST *)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | static char *array_value_internal __P((const char *, int, int, int *, arrayind_t *)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | /* Standard error message to use when encountering an invalid array subscript */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | const char * const bash_badsub_errmsg = N_("bad array subscript"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | /* **************************************************************** */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | /* */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | /* Functions to manipulate array variables and perform assignments */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | /* */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | /* **************************************************************** */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | /* Convert a shell variable to an array variable. The original value is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | saved as array[0]. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | convert_var_to_array (var) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | char *oldval; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | oldval = value_cell (var); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | array = array_create (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | if (oldval)
| 18-65 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | array_insert (array, 0, oldval); executed 65 times by 1 test: array_insert (array, 0, oldval);Executed by:
| 65 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | FREE (value_cell (var)); executed 65 times by 1 test: sh_xfree((((var)->value)), "arrayfunc.c", 80);Executed by:
| 18-65 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | var_setarray (var, array); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | /* these aren't valid anymore */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | var->dynamic_value = (sh_var_value_func_t *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | var->assign_func = (sh_var_assign_func_t *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | INVALIDATE_EXPORTSTR (var); never executed: end of block
| 0-83 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | if (exported_p (var))
| 0-83 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | array_needs_making++; never executed: array_needs_making++; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | VSETATTR (var, att_array); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | VUNSETATTR (var, att_invisible); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | /* Make sure it's not marked as an associative array any more */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | VUNSETATTR (var, att_assoc); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | /* Since namerefs can't be array variables, turn off nameref attribute */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | VUNSETATTR (var, att_nameref); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | return var; executed 83 times by 1 test: return var;Executed by:
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | /* Convert a shell variable to an array variable. The original value is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | saved as array[0]. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | convert_var_to_assoc (var) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | char *oldval; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | HASH_TABLE *hash; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | oldval = value_cell (var); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | hash = assoc_create (0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | if (oldval)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | assoc_insert (hash, savestring ("0"), oldval); executed 2 times by 1 test: assoc_insert (hash, (char *)strcpy (sh_xmalloc((1 + strlen ("0")), "arrayfunc.c", 115), ("0")), oldval);Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | FREE (value_cell (var)); executed 2 times by 1 test: sh_xfree((((var)->value)), "arrayfunc.c", 117);Executed by:
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | var_setassoc (var, hash); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | /* these aren't valid anymore */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | var->dynamic_value = (sh_var_value_func_t *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | var->assign_func = (sh_var_assign_func_t *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | INVALIDATE_EXPORTSTR (var); never executed: end of block
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | if (exported_p (var))
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | array_needs_making++; never executed: array_needs_making++; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | VSETATTR (var, att_assoc); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | VUNSETATTR (var, att_invisible); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | /* Make sure it's not marked as an indexed array any more */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | VUNSETATTR (var, att_array); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | /* Since namerefs can't be array variables, turn off nameref attribute */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | VUNSETATTR (var, att_nameref); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | return var; executed 2 times by 1 test: return var;Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | make_array_variable_value (entry, ind, key, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | char *key; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | SHELL_VAR *dentry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | char *newval; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | /* If we're appending, we need the old value of the array reference, so | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | fake out make_variable_value with a dummy SHELL_VAR */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | if (flags & ASS_APPEND)
| 14-14214 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | dentry = (SHELL_VAR *)xmalloc (sizeof (SHELL_VAR)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | dentry->name = savestring (entry->name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | if (assoc_p (entry))
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | newval = assoc_reference (assoc_cell (entry), key); executed 7 times by 1 test: newval = assoc_reference ((HASH_TABLE *)((entry)->value), key);Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | newval = array_reference (array_cell (entry), ind); executed 7 times by 1 test: newval = array_reference ((ARRAY *)((entry)->value), ind);Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | if (newval)
| 3-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | dentry->value = savestring (newval); executed 11 times by 1 test: dentry->value = (char *)strcpy (sh_xmalloc((1 + strlen (newval)), "arrayfunc.c", 162), (newval));Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | dentry->value = (char *)xmalloc (1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | dentry->value[0] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | dentry->exportstr = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | dentry->attributes = entry->attributes & ~(att_array|att_assoc|att_exported); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | /* Leave the rest of the members uninitialized; the code doesn't look | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | at them. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | newval = make_variable_value (dentry, value, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | dispose_variable (dentry); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | newval = make_variable_value (entry, value, flags); executed 14214 times by 1 test: newval = make_variable_value (entry, value, flags);Executed by:
| 14214 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | return newval; executed 14228 times by 1 test: return newval;Executed by:
| 14228 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | static SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | bind_array_var_internal (entry, ind, key, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | char *key; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | char *newval; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | newval = make_array_variable_value (entry, ind, key, value, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | if (entry->assign_func)
| 5-14193 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | (*entry->assign_func) (entry, newval, ind, key); executed 5 times by 1 test: (*entry->assign_func) (entry, newval, ind, key);Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | else if (assoc_p (entry))
| 523-13670 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | assoc_insert (assoc_cell (entry), key, newval); executed 523 times by 1 test: assoc_insert ((HASH_TABLE *)((entry)->value), key, newval);Executed by:
| 523 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | array_insert (array_cell (entry), ind, newval); executed 13670 times by 1 test: array_insert ((ARRAY *)((entry)->value), ind, newval);Executed by:
| 13670 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | FREE (newval); executed 14198 times by 1 test: sh_xfree((newval), "arrayfunc.c", 199);Executed by:
| 0-14198 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | VUNSETATTR (entry, att_invisible); /* no longer invisible */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | return (entry); executed 14198 times by 1 test: return (entry);Executed by:
| 14198 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | /* Perform an array assignment name[ind]=value. If NAME already exists and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | is not an array, and IND is 0, perform name=value instead. If NAME exists | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | and is not an array, and IND is not 0, convert it into an array with the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | existing value as name[0]. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | If NAME does not exist, just create an array variable, no matter what | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | IND's value may be. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | bind_array_variable (name, ind, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | char *name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | entry = find_shell_variable (name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | if (entry == (SHELL_VAR *) 0)
| 48-10384 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | /* Is NAME a nameref variable that points to an unset variable? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | entry = find_variable_nameref_for_create (name, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | if (entry == INVALID_NAMEREF_VALUE)
| 5-43 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | return ((SHELL_VAR *)0); executed 5 times by 1 test: return ((SHELL_VAR *)0);Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | if (entry && nameref_p (entry))
| 0-41 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | entry = make_new_array_variable (nameref_cell (entry)); executed 2 times by 1 test: entry = make_new_array_variable (((entry)->value));Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } executed 43 times by 1 test: end of blockExecuted by:
| 43 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | if (entry == (SHELL_VAR *) 0)
| 41-10386 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | entry = make_new_array_variable (name); executed 41 times by 1 test: entry = make_new_array_variable (name);Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | else if ((readonly_p (entry) && (flags&ASS_FORCE) == 0) || noassign_p (entry))
| 0-10376 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | if (readonly_p (entry))
| 0-10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | err_readonly (name); executed 10 times by 1 test: err_readonly (name);Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | return (entry); executed 10 times by 1 test: return (entry);Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | else if (array_p (entry) == 0)
| 24-10352 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | entry = convert_var_to_array (entry); executed 24 times by 1 test: entry = convert_var_to_array (entry);Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | /* ENTRY is an array variable, and ARRAY points to the value. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | return (bind_array_var_internal (entry, ind, 0, value, flags)); executed 10417 times by 1 test: return (bind_array_var_internal (entry, ind, 0, value, flags));Executed by:
| 10417 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | bind_array_element (entry, ind, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | return (bind_array_var_internal (entry, ind, 0, value, flags)); executed 141 times by 1 test: return (bind_array_var_internal (entry, ind, 0, value, flags));Executed by:
| 141 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | bind_assoc_variable (entry, name, key, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | char *name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | char *key; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | if ((readonly_p (entry) && (flags&ASS_FORCE) == 0) || noassign_p (entry))
| 0-371 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | if (readonly_p (entry))
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | err_readonly (name); executed 2 times by 1 test: err_readonly (name);Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | return (entry); executed 2 times by 1 test: return (entry);Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | return (bind_array_var_internal (entry, 0, key, value, flags)); executed 371 times by 1 test: return (bind_array_var_internal (entry, 0, key, value, flags));Executed by:
| 371 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | /* Parse NAME, a lhs of an assignment statement of the form v[s], and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | assign VALUE to that array element by calling bind_array_variable(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | Flags are ASS_ assignment flags */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | assign_array_element (name, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | char *name, *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | char *sub, *vname; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | int sublen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | vname = array_variable_name (name, (flags & ASS_NOEXPAND) != 0, &sub, &sublen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | if (vname == 0)
| 11-10787 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | return ((SHELL_VAR *)NULL); executed 11 times by 1 test: return ((SHELL_VAR *) ((void *)0) );Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | if ((ALL_ELEMENT_SUB (sub[0]) && sub[1] == ']') || (sublen <= 1))
| 0-10785 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | free (vname); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | err_badarraysub (name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | return ((SHELL_VAR *)NULL); executed 16 times by 1 test: return ((SHELL_VAR *) ((void *)0) );Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | entry = find_variable (vname); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | entry = assign_array_element_internal (entry, name, vname, sub, sublen, value, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | free (vname); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | return entry; executed 10762 times by 1 test: return entry;Executed by:
| 10762 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | static SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | assign_array_element_internal (entry, name, vname, sub, sublen, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | SHELL_VAR *entry; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | char *name; /* only used for error messages */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | char *vname; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | char *sub; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | int sublen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | char *akey; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | if (entry && assoc_p (entry))
| 48-10723 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | sub[sublen-1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | if ((flags & ASS_NOEXPAND) == 0)
| 10-362 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | akey = expand_assignment_string_to_string (sub, 0); /* [ */ executed 362 times by 1 test: akey = expand_assignment_string_to_string (sub, 0);Executed by:
| 362 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | akey = savestring (sub); executed 10 times by 1 test: akey = (char *)strcpy (sh_xmalloc((1 + strlen (sub)), "arrayfunc.c", 325), (sub));Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | sub[sublen-1] = ']'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | if (akey == 0 || *akey == 0)
| 0-371 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | err_badarraysub (name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | FREE (akey); never executed: sh_xfree((akey), "arrayfunc.c", 330);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | return ((SHELL_VAR *)NULL); never executed: return ((SHELL_VAR *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | entry = bind_assoc_variable (entry, vname, akey, value, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } executed 371 times by 1 test: end of blockExecuted by:
| 371 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ind = array_expand_index (entry, sub, sublen, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | /* negative subscripts to indexed arrays count back from end */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | if (entry && ind < 0)
| 14-10343 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | ind = (array_p (entry) ? array_max_index (array_cell (entry)) : 0) + 1 + ind; executed 14 times by 1 test: ind = (((((entry)->attributes) & (0x0000004))) ? (((ARRAY *)((entry)->value))->max_index) : 0) + 1 + ind;Executed by:
| 0-14 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | if (ind < 0)
| 10-10381 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | err_badarraysub (name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | return ((SHELL_VAR *)NULL); executed 10 times by 1 test: return ((SHELL_VAR *) ((void *)0) );Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | entry = bind_array_variable (vname, ind, value, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } executed 10381 times by 1 test: end of blockExecuted by:
| 10381 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | return (entry); executed 10752 times by 1 test: return (entry);Executed by:
| 10752 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | /* Find the array variable corresponding to NAME. If there is no variable, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | create a new array variable. If the variable exists but is not an array, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | convert it to an indexed array. If FLAGS&1 is non-zero, an existing | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | variable is checked for the readonly or noassign attribute in preparation | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | for assignment (e.g., by the `read' builtin). If FLAGS&2 is non-zero, we | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | create an associative array. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | find_or_make_array_variable (name, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | char *name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | var = find_variable (name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | if (var == 0)
| 202-269 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | /* See if we have a nameref pointing to a variable that hasn't been | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | created yet. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | var = find_variable_last_nameref (name, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | if (var && nameref_p (var) && invisible_p (var))
| 0-188 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | internal_warning (_("%s: removing nameref attribute"), name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | VUNSETATTR (var, att_nameref); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | if (var && nameref_p (var))
| 5-188 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | if (valid_nameref_value (nameref_cell (var), 2) == 0)
| 1-8 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | sh_invalidid (nameref_cell (var)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | return ((SHELL_VAR *)NULL); executed 8 times by 1 test: return ((SHELL_VAR *) ((void *)0) );Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | var = (flags & 2) ? make_new_assoc_variable (nameref_cell (var)) : make_new_array_variable (nameref_cell (var));
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } executed 194 times by 1 test: end of blockExecuted by:
| 194 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | if (var == 0)
| 188-275 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | var = (flags & 2) ? make_new_assoc_variable (name) : make_new_array_variable (name); executed 188 times by 1 test: var = (flags & 2) ? make_new_assoc_variable (name) : make_new_array_variable (name);Executed by:
| 0-188 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | else if ((flags & 1) && (readonly_p (var) || noassign_p (var)))
| 0-275 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | if (readonly_p (var))
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | err_readonly (name); executed 11 times by 1 test: err_readonly (name);Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | return ((SHELL_VAR *)NULL); executed 11 times by 1 test: return ((SHELL_VAR *) ((void *)0) );Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | else if ((flags & 2) && array_p (var))
| 0-252 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | last_command_exit_value = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | report_error (_("%s: cannot convert indexed to associative array"), name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | return ((SHELL_VAR *)NULL); never executed: return ((SHELL_VAR *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | else if (array_p (var) == 0 && assoc_p (var) == 0)
| 29-174 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | var = convert_var_to_array (var); executed 29 times by 1 test: var = convert_var_to_array (var);Executed by:
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | return (var); executed 452 times by 1 test: return (var);Executed by:
| 452 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | /* Perform a compound assignment statement for array NAME, where VALUE is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | the text between the parens: NAME=( VALUE ) */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | assign_array_from_string (name, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | char *name, *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | int vflags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | vflags = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | if (flags & ASS_MKASSOC)
| 12-407 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | vflags |= 2; executed 12 times by 1 test: vflags |= 2;Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | var = find_or_make_array_variable (name, vflags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | if (var == 0)
| 15-404 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | return ((SHELL_VAR *)NULL); executed 15 times by 1 test: return ((SHELL_VAR *) ((void *)0) );Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | return (assign_array_var_from_string (var, value, flags)); executed 404 times by 1 test: return (assign_array_var_from_string (var, value, flags));Executed by:
| 404 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | /* Sequentially assign the indices of indexed array variable VAR from the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | words in LIST. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | assign_array_var_from_word_list (var, list, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | register arrayind_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | register WORD_LIST *l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | a = array_cell (var); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | i = (flags & ASS_APPEND) ? array_max_index (a) + 1 : 0;
| 0-25 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | for (l = list; l; l = l->next, i++)
| 25-148 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | bind_array_var_internal (var, i, 0, l->word->word, flags & ~ASS_APPEND); executed 148 times by 1 test: bind_array_var_internal (var, i, 0, l->word->word, flags & ~0x0001);Executed by:
| 148 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | VUNSETATTR (var, att_invisible); /* no longer invisible */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | return var; executed 25 times by 1 test: return var;Executed by:
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | WORD_LIST * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | expand_compound_array_assignment (var, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | WORD_LIST *list, *nlist; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | char *val; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | int ni; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | /* This condition is true when invoked from the declare builtin with a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | command like | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | declare -a d='([1]="" [2]="bdef" [5]="hello world" "test")' */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | if (*value == '(') /*)*/
| 80-435 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | ni = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | val = extract_array_assignment_list (value, &ni); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | if (val == 0)
| 0-80 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | return (WORD_LIST *)NULL; never executed: return (WORD_LIST *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } executed 80 times by 1 test: end of blockExecuted by:
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | val = value; executed 435 times by 1 test: val = value;Executed by:
| 435 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | /* Expand the value string into a list of words, performing all the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | shell expansions including pathname generation and word splitting. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | /* First we split the string on whitespace, using the shell parser | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | (ksh93 seems to do this). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | list = parse_string_to_word_list (val, 1, "array assign"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | if (var && assoc_p (var))
| 0-515 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | if (val != value)
| 12-65 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | free (val); executed 12 times by 1 test: sh_xfree((val), "arrayfunc.c", 483);Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | return list; executed 77 times by 1 test: return list;Executed by:
| 77 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | /* If we're using [subscript]=value, we need to quote each [ and ] to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | prevent unwanted filename expansion. This doesn't need to be done | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | for associative array expansion, since that uses a different expansion | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | function (see assign_compound_array_list below). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | if (list)
| 27-411 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | quote_array_assignment_chars (list); executed 411 times by 1 test: quote_array_assignment_chars (list);Executed by:
| 411 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | /* Now that we've split it, perform the shell expansions on each | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | word in the list. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | nlist = list ? expand_words_no_vars (list) : (WORD_LIST *)NULL;
| 27-411 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | dispose_words (list); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | if (val != value)
| 66-369 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | free (val); executed 66 times by 1 test: sh_xfree((val), "arrayfunc.c", 501);Executed by:
| 66 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | return nlist; executed 435 times by 1 test: return nlist;Executed by:
| 435 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | /* Callers ensure that VAR is not NULL */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | assign_compound_array_list (var, nlist, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | WORD_LIST *nlist; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | HASH_TABLE *h; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | char *w, *val, *nval, *savecmd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | int len, iflags, free_val; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | arrayind_t ind, last_ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | char *akey; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | a = (var && array_p (var)) ? array_cell (var) : (ARRAY *)0;
| 0-512 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | h = (var && assoc_p (var)) ? assoc_cell (var) : (HASH_TABLE *)0;
| 0-512 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | akey = (char *)0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | ind = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | /* Now that we are ready to assign values to the array, kill the existing | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | value. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | if ((flags & ASS_APPEND) == 0)
| 14-498 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | if (a && array_p (var))
| 0-428 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | array_flush (a); executed 428 times by 1 test: array_flush (a);Executed by:
| 428 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | else if (h && assoc_p (var))
| 0-70 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | assoc_flush (h); executed 70 times by 1 test: assoc_flush (h);Executed by:
| 70 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } executed 498 times by 1 test: end of blockExecuted by:
| 498 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | last_ind = (a && (flags & ASS_APPEND)) ? array_max_index (a) + 1 : 0;
| 7-435 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | for (list = nlist; list; list = list->next)
| 509-3173 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | /* Don't allow var+=(values) to make assignments in VALUES append to | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | existing values by default. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | iflags = flags & ~ASS_APPEND; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | w = list->word->word; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | /* We have a word of the form [ind]=value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | if ((list->word->flags & W_ASSIGNMENT) && w[0] == '[')
| 0-2108 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | /* Don't have to handle embedded quotes specially any more, since | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | associative array subscripts have not been expanded yet (see | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | above). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | len = skipsubscript (w, 0, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | /* XXX - changes for `+=' */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | if (w[len] != ']' || (w[len+1] != '=' && (w[len+1] != '+' || w[len+2] != '=')))
| 0-2108 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | if (assoc_p (var))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | err_badarraysub (w); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | nval = make_variable_value (var, w, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | if (var->assign_func)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | (*var->assign_func) (var, nval, last_ind, 0); never executed: (*var->assign_func) (var, nval, last_ind, 0); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | array_insert (a, last_ind, nval); never executed: array_insert (a, last_ind, nval); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | FREE (nval); never executed: sh_xfree((nval), "arrayfunc.c", 567);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | last_ind++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | if (len == 1)
| 10-2098 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | err_badarraysub (w); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | continue; executed 10 times by 1 test: continue;Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | if (ALL_ELEMENT_SUB (w[1]) && len == 2)
| 0-2098 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | last_command_exit_value = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | if (assoc_p (var))
| 4-10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | report_error (_("%s: invalid associative array key"), w); executed 4 times by 1 test: report_error ( dcgettext (((void *)0), "%s: invalid associative array key" , 5) , w);Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | report_error (_("%s: cannot assign to non-numeric index"), w); executed 10 times by 1 test: report_error ( dcgettext (((void *)0), "%s: cannot assign to non-numeric index" , 5) , w);Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | continue; executed 14 times by 1 test: continue;Executed by:
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | if (array_p (var))
| 156-1928 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | ind = array_expand_index (var, w + 1, len, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | /* negative subscripts to indexed arrays count back from end */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | if (ind < 0)
| 11-1914 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | ind = array_max_index (array_cell (var)) + 1 + ind; executed 11 times by 1 test: ind = (((ARRAY *)((var)->value))->max_index) + 1 + ind;Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | if (ind < 0)
| 10-1915 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | err_badarraysub (w); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | continue; executed 10 times by 1 test: continue;Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | last_ind = ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } executed 1915 times by 1 test: end of blockExecuted by:
| 1915 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | else if (assoc_p (var))
| 0-156 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | /* This is not performed above, see expand_compound_array_assignment */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | w[len] = '\0'; /*[*/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | akey = expand_assignment_string_to_string (w+1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | w[len] = ']'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | /* And we need to expand the value also, see below */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | if (akey == 0 || *akey == 0)
| 0-156 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | err_badarraysub (w); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | FREE (akey); never executed: sh_xfree((akey), "arrayfunc.c", 612);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } executed 156 times by 1 test: end of blockExecuted by:
| 156 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | /* XXX - changes for `+=' -- just accept the syntax. ksh93 doesn't do this */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | if (w[len + 1] == '+' && w[len + 2] == '=')
| 0-2067 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | iflags |= ASS_APPEND; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | val = w + len + 3; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | val = w + len + 2; executed 2067 times by 1 test: val = w + len + 2;Executed by:
| 2067 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | else if (assoc_p (var))
| 15-1050 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | last_command_exit_value = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | report_error (_("%s: %s: must use subscript when assigning associative array"), var->name, w); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | continue; executed 15 times by 1 test: continue;Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | else /* No [ind]=value, just a stray `=' */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | ind = last_ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | val = w; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } executed 1050 times by 1 test: end of blockExecuted by:
| 1050 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | free_val = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | /* See above; we need to expand the value here */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | if (assoc_p (var))
| 156-2965 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | val = expand_assignment_string_to_string (val, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | if (val == 0)
| 5-151 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | val = (char *)xmalloc (1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | val[0] = '\0'; /* like do_assignment_internal */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | free_val = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } executed 156 times by 1 test: end of blockExecuted by:
| 156 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | savecmd = this_command_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | if (integer_p (var))
| 55-3066 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | this_command_name = (char *)NULL; /* no command name for errors */ executed 55 times by 1 test: this_command_name = (char *) ((void *)0) ;Executed by:
| 55 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | bind_array_var_internal (var, ind, akey, val, iflags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | last_ind++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | this_command_name = savecmd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | if (free_val)
| 156-2965 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | free (val); executed 156 times by 1 test: sh_xfree((val), "arrayfunc.c", 659);Executed by:
| 156 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } executed 3121 times by 1 test: end of blockExecuted by:
| 3121 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } executed 509 times by 1 test: end of blockExecuted by:
| 509 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | /* Perform a compound array assignment: VAR->name=( VALUE ). The | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | VALUE has already had the parentheses stripped. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | assign_array_var_from_string (var, value, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | WORD_LIST *nlist; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | if (value == 0)
| 0-484 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | return var; never executed: return var; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | nlist = expand_compound_array_assignment (var, value, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | assign_compound_array_list (var, nlist, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | if (nlist)
| 30-448 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | dispose_words (nlist); executed 448 times by 1 test: dispose_words (nlist);Executed by:
| 448 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | if (var)
| 0-478 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | VUNSETATTR (var, att_invisible); /* no longer invisible */ executed 478 times by 1 test: ((var)->attributes &= ~(0x0001000));Executed by:
| 478 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | return (var); executed 478 times by 1 test: return (var);Executed by:
| 478 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | /* Quote globbing chars and characters in $IFS before the `=' in an assignment | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | statement (usually a compound array assignment) to protect them from | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | unwanted filename expansion or word splitting. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | static char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | quote_assign (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | const char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | size_t slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | int saw_eq; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | char *temp, *t, *subs; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | const char *s, *send; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | int ss, se; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | DECLARE_MBSTATE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | slen = strlen (string); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | send = string + slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | t = temp = (char *)xmalloc (slen * 2 + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | saw_eq = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | for (s = string; *s; )
| 1952-9911 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | if (*s == '=')
| 1955-7956 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | saw_eq = 1; executed 1955 times by 1 test: saw_eq = 1;Executed by:
| 1955 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | if (saw_eq == 0 && *s == '[') /* looks like a subscript */
| 2-7957 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | ss = s - string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | se = skipsubscript (string, ss, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | subs = substring (s, ss, se); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | *t++ = '\\'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | strcpy (t, subs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | t += se - ss; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | *t++ = '\\'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | *t++ = ']'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | s += se + 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | free (subs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | continue; executed 1952 times by 1 test: continue;Executed by:
| 1952 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | if (saw_eq == 0 && (glob_char_p (s) || isifs (*s)))
| 0-7957 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | *t++ = '\\'; never executed: *t++ = '\\'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | COPY_CHAR_P (t, s, send); executed 6438 times by 1 test: mblength = 1;Executed by:
executed 131 times by 1 test: mblength = 1;Executed by:
executed 1390 times by 1 test: end of blockExecuted by:
executed 199 times by 1 test: end of blockExecuted by:
executed 7760 times by 1 test: mblength = (mblength < 1) ? 1 : mblength;Executed by:
executed 9946 times by 1 test: *(t)++ = *(s)++;Executed by:
executed 7959 times by 1 test: end of blockExecuted by:
never executed: *(t)++ = *(s)++;
| 0-9946 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } executed 7959 times by 1 test: end of blockExecuted by:
| 7959 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | *t = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | return temp; executed 1952 times by 1 test: return temp;Executed by:
| 1952 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | /* For each word in a compound array assignment, if the word looks like | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | [ind]=value, quote globbing chars and characters in $IFS before the `='. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | quote_array_assignment_chars (list) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | char *nword; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | WORD_LIST *l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | for (l = list; l; l = l->next)
| 411-2815 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | if (l->word == 0 || l->word->word == 0 || l->word->word[0] == '\0')
| 0-2815 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | continue; /* should not happen, but just in case... */ never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | /* Don't bother if it hasn't been recognized as an assignment or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | doesn't look like [ind]=value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | if ((l->word->flags & W_ASSIGNMENT) == 0)
| 863-1952 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | continue; executed 863 times by 1 test: continue;Executed by:
| 863 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | if (l->word->word[0] != '[' || mbschr (l->word->word, '=') == 0) /* ] */
| 0-1952 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | nword = quote_assign (l->word->word); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | free (l->word->word); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | l->word->word = nword; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | l->word->flags |= W_NOGLOB; /* XXX - W_NOSPLIT also? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } executed 1952 times by 1 test: end of blockExecuted by:
| 1952 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } executed 411 times by 1 test: end of blockExecuted by:
| 411 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | /* skipsubscript moved to subst.c to use private functions. 2009/02/24. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | /* This function is called with SUB pointing to just after the beginning | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | `[' of an array subscript and removes the array element to which SUB | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | expands from array VAR. A subscript of `*' or `@' unsets the array. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | /* If FLAGS&1 we don't expand the subscript; we just use it as-is. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | unbind_array_element (var, sub, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | char *sub; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | int len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | char *akey; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | len = skipsubscript (sub, 0, (flags&1) || (var && assoc_p(var))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | if (sub[len] != ']' || len == 0)
| 0-112 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | builtin_error ("%s[%s: %s", var->name, sub, _(bash_badsub_errmsg)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | sub[len] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | if (ALL_ELEMENT_SUB (sub[0]) && sub[1] == 0)
| 0-109 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | if (array_p (var) || assoc_p (var))
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | unbind_variable (var->name); /* XXX -- {array,assoc}_flush ? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | return (0); executed 13 times by 1 test: return (0);Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | return -2; /* don't allow this to unset scalar variables */ never executed: return -2; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | if (assoc_p (var))
| 9-90 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | akey = (flags & 1) ? sub : expand_assignment_string_to_string (sub, 0);
| 4-5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | if (akey == 0 || *akey == 0)
| 0-9 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | builtin_error ("[%s]: %s", sub, _(bash_badsub_errmsg)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | FREE (akey); never executed: sh_xfree((akey), "arrayfunc.c", 803);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | assoc_remove (assoc_cell (var), akey); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | if (akey != sub)
| 4-5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | free (akey); executed 5 times by 1 test: sh_xfree((akey), "arrayfunc.c", 808);Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | else if (array_p (var))
| 11-79 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | ind = array_expand_index (var, sub, len+1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | /* negative subscripts to indexed arrays count back from end */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | if (ind < 0)
| 8-71 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | ind = array_max_index (array_cell (var)) + 1 + ind; executed 8 times by 1 test: ind = (((ARRAY *)((var)->value))->max_index) + 1 + ind;Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | if (ind < 0)
| 6-73 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | builtin_error ("[%s]: %s", sub, _(bash_badsub_errmsg)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | return -1; executed 6 times by 1 test: return -1;Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | ae = array_remove (array_cell (var), ind); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | if (ae)
| 35-38 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | array_dispose_element (ae); executed 35 times by 1 test: array_dispose_element (ae);Executed by:
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } executed 73 times by 1 test: end of blockExecuted by:
| 73 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | else /* array_p (var) == 0 && assoc_p (var) == 0 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | akey = this_command_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | ind = array_expand_index (var, sub, len+1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | this_command_name = akey; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | if (ind == 0)
| 1-10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | unbind_variable (var->name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | return (0); executed 1 time by 1 test: return (0);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | return -2; /* any subscript other than 0 is invalid with scalar variables */ executed 10 times by 1 test: return -2;Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | return 0; executed 82 times by 1 test: return 0;Executed by:
| 82 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | /* Format and output an array assignment in compound form VAR=(VALUES), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | suitable for re-use as input. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | print_array_assignment (var, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | int quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | char *vstr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | vstr = array_to_assign (array_cell (var), quoted); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | if (vstr == 0)
| 49-224 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | printf ("%s=%s\n", var->name, quoted ? "'()'" : "()"); executed 49 times by 1 test: printf ("%s=%s\n", var->name, quoted ? "'()'" : "()");Executed by:
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | printf ("%s=%s\n", var->name, vstr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | free (vstr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | } executed 224 times by 1 test: end of blockExecuted by:
| 224 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | /* Format and output an associative array assignment in compound form | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | VAR=(VALUES), suitable for re-use as input. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | print_assoc_assignment (var, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | int quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | char *vstr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | vstr = assoc_to_assign (assoc_cell (var), quoted); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | if (vstr == 0)
| 34-85 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | printf ("%s=%s\n", var->name, quoted ? "'()'" : "()"); executed 34 times by 1 test: printf ("%s=%s\n", var->name, quoted ? "'()'" : "()");Executed by:
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | printf ("%s=%s\n", var->name, vstr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | free (vstr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | } executed 85 times by 1 test: end of blockExecuted by:
| 85 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | /***********************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | /* */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | /* Utility functions to manage arrays and their contents for expansion */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | /* */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | /***********************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | /* Return 1 if NAME is a properly-formed array reference v[sub]. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | valid_array_reference (name, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | const char *name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | int r, len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | t = mbschr (name, '['); /* ] */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | if (t)
| 35206-17891781 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | *t = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | r = legal_identifier (name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | *t = '['; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | if (r == 0)
| 3-35203 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | return 0; executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | /* Check for a properly-terminated non-null subscript. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | len = skipsubscript (t, 0, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | if (t[len] != ']' || len == 1)
| 0-35194 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | return 0; executed 9 times by 1 test: return 0;Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | if (t[len+1] != '\0')
| 0-35194 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | #if 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | /* Could check and allow subscripts consisting only of whitespace for | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | existing associative arrays. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | for (r = 1; r < len; r++)
| 30-35232 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | if (whitespace (t[r]) == 0)
| 0-35164 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | return 1; executed 35164 times by 1 test: return 1;Executed by:
| 35164 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | return 0; executed 30 times by 1 test: return 0;Executed by:
| 30 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | /* This allows blank subscripts */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | return 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | return 0; executed 17891781 times by 1 test: return 0;Executed by:
| 17891781 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | /* Expand the array index beginning at S and extending LEN characters. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | arrayind_t | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | array_expand_index (var, s, len, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | int len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | char *exp, *t, *savecmd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | int expok; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | arrayind_t val; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | exp = (char *)xmalloc (len); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | strncpy (exp, s, len - 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | exp[len - 1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | #if 0 /* XXX - not yet -- maybe bash-5.0 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | if ((flags & AV_NOEXPAND) == 0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | t = expand_arith_string (exp, Q_DOUBLE_QUOTES|Q_ARITH|Q_ARRAYSUB); /* XXX - Q_ARRAYSUB for future use */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | t = exp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | t = expand_arith_string (exp, Q_DOUBLE_QUOTES|Q_ARITH|Q_ARRAYSUB); /* XXX - Q_ARRAYSUB for future use */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | savecmd = this_command_name; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | this_command_name = (char *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | val = evalexp (t, 0, &expok); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | this_command_name = savecmd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | if (t != exp)
| 0-27600 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | free (t); executed 27600 times by 1 test: sh_xfree((t), "arrayfunc.c", 953);Executed by:
| 27600 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | free (exp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | if (expok == 0)
| 12-27588 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | last_command_exit_value = EXECUTION_FAILURE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | if (no_longjmp_on_fatal_error)
| 0-12 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | top_level_cleanup (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | jump_to_top_level (DISCARD); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | return val; executed 27588 times by 1 test: return val;Executed by:
| 27588 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | /* Return the name of the variable specified by S without any subscript. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | If SUBP is non-null, return a pointer to the start of the subscript | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | in *SUBP. If LENP is non-null, the length of the subscript is returned | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | in *LENP. This returns newly-allocated memory. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | array_variable_name (s, flags, subp, lenp) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | char **subp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | int *lenp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | char *t, *ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | int ind, ni; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | t = mbschr (s, '['); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | if (t == 0)
| 0-64120 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | if (subp)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | *subp = t; never executed: *subp = t; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | if (lenp)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | *lenp = 0; never executed: *lenp = 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | ind = t - s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | ni = skipsubscript (s, ind, flags); /* XXX - was 0 not flags */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | if (ni <= ind + 1 || s[ni] != ']')
| 0-64109 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | err_badarraysub (s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | if (subp)
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | *subp = t; executed 11 times by 1 test: *subp = t;Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | if (lenp)
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | *lenp = 0; executed 11 times by 1 test: *lenp = 0;Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | return ((char *)NULL); executed 11 times by 1 test: return ((char *) ((void *)0) );Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | *t = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | ret = savestring (s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | *t++ = '['; /* ] */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | if (subp)
| 30251-33858 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | *subp = t; executed 33858 times by 1 test: *subp = t;Executed by:
| 33858 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | if (lenp)
| 27300-36809 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | *lenp = ni - ind; executed 27300 times by 1 test: *lenp = ni - ind;Executed by:
| 27300 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | return ret; executed 64109 times by 1 test: return ret;Executed by:
| 64109 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | /* Return the variable specified by S without any subscript. If SUBP is | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | non-null, return a pointer to the start of the subscript in *SUBP. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | If LENP is non-null, the length of the subscript is returned in *LENP. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | array_variable_part (s, flags, subp, lenp) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | char **subp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | int *lenp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | t = array_variable_name (s, flags, subp, lenp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | if (t == 0)
| 0-43180 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | return ((SHELL_VAR *)NULL); never executed: return ((SHELL_VAR *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | var = find_variable (t); /* XXX - handle namerefs here? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | free (t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | return var; /* now return invisible variables; caller must handle */ executed 43180 times by 1 test: return var;Executed by:
| 43180 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | #define INDEX_ERROR() \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | do \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | if (var) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | err_badarraysub (var->name); \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | else \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | t[-1] = '\0'; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | err_badarraysub (s); \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | t[-1] = '['; /* ] */\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | return ((char *)NULL); \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | while (0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | /* Return a string containing the elements in the array and subscript | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | described by S. If the subscript is * or @, obeys quoting rules akin | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | to the expansion of $* and $@ including double quoting. If RTYPE | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | is non-null it gets 1 if the array reference is name[*], 2 if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | reference is name[@], and 0 otherwise. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | static char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | array_value_internal (s, quoted, flags, rtype, indp) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | int quoted, flags, *rtype; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | arrayind_t *indp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | int len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | char *akey; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | char *retval, *t, *temp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | WORD_LIST *l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | var = array_variable_part (s, (flags&AV_NOEXPAND) ? 1 : 0, &t, &len); /* XXX */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | /* Expand the index, even if the variable doesn't exist, in case side | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | effects are needed, like ${w[i++]} where w is unset. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | if (var == 0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | return (char *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | if (len == 0)
| 0-16207 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | return ((char *)NULL); /* error message already printed */ never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | /* [ */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | akey = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | if (ALL_ELEMENT_SUB (t[0]) && t[1] == ']')
| 0-15535 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | if (rtype)
| 0-828 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | *rtype = (t[0] == '*') ? 1 : 2; executed 828 times by 1 test: *rtype = (t[0] == '*') ? 1 : 2;Executed by:
| 156-828 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | if ((flags & AV_ALLOWALL) == 0)
| 0-828 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | err_badarraysub (s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | else if (var == 0 || value_cell (var) == 0) /* XXX - check for invisible_p(var) ? */
| 2-823 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | return ((char *)NULL); executed 7 times by 1 test: return ((char *) ((void *)0) );Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | else if (array_p (var) == 0 && assoc_p (var) == 0)
| 9-727 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | l = add_string_to_list (value_cell (var), (WORD_LIST *)NULL); executed 9 times by 1 test: l = make_word_list (make_word(((var)->value)), ((WORD_LIST *) ((void *)0) ));Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | else if (assoc_p (var))
| 85-727 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | l = assoc_to_word_list (assoc_cell (var)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | if (l == (WORD_LIST *)NULL)
| 1-84 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | return ((char *)NULL); executed 1 time by 1 test: return ((char *) ((void *)0) );Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | } executed 84 times by 1 test: end of blockExecuted by:
| 84 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | l = array_to_word_list (array_cell (var)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | if (l == (WORD_LIST *)NULL)
| 26-701 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | return ((char *) NULL); executed 26 times by 1 test: return ((char *) ((void *)0) );Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | } executed 701 times by 1 test: end of blockExecuted by:
| 701 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | /* Caller of array_value takes care of inspecting rtype and duplicating | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | retval if rtype == 0, so this is not a memory leak */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | if (t[0] == '*' && (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)))
| 50-638 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | temp = string_list_dollar_star (l, quoted, (flags & AV_ASSIGNRHS) ? PF_ASSIGNRHS : 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | retval = quote_string (temp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | free (temp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | } executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | else /* ${name[@]} or unquoted ${name[*]} */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | /* XXX - bash-4.4/bash-5.0 test AV_ASSIGNRHS and pass PF_ASSIGNRHS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | retval = string_list_dollar_at (l, quoted, (flags & AV_ASSIGNRHS) ? PF_ASSIGNRHS : 0); executed 744 times by 1 test: retval = string_list_dollar_at (l, quoted, (flags & 0x010) ? 0x08 : 0);Executed by:
| 744 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | dispose_words (l); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | } executed 794 times by 1 test: end of blockExecuted by:
| 794 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | if (rtype)
| 5124-10255 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | *rtype = 0; executed 5124 times by 1 test: *rtype = 0;Executed by:
| 5124 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | if (var == 0 || array_p (var) || assoc_p (var) == 0)
| 12-15367 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | if ((flags & AV_USEIND) == 0 || indp == 0)
| 0-15174 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | ind = array_expand_index (var, t, len, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | if (ind < 0)
| 11-15147 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | /* negative subscripts to indexed arrays count back from end */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | if (var && array_p (var))
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | ind = array_max_index (array_cell (var)) + 1 + ind; executed 11 times by 1 test: ind = (((ARRAY *)((var)->value))->max_index) + 1 + ind;Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | if (ind < 0)
| 1-10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | INDEX_ERROR(); executed 10 times by 1 test: err_badarraysub (var->name);Executed by:
never executed: end of blockexecuted 10 times by 1 test: return ((char *) ((void *)0) );Executed by:
never executed: end of block
| 0-10 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | if (indp)
| 5-15143 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | *indp = ind; executed 15143 times by 1 test: *indp = ind;Executed by:
| 15143 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | } executed 15148 times by 1 test: end of blockExecuted by:
| 15148 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | else if (indp)
| 0-141 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | ind = *indp; executed 141 times by 1 test: ind = *indp;Executed by:
| 141 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | } executed 15289 times by 1 test: end of blockExecuted by:
| 15289 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | else if (assoc_p (var))
| 0-64 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | t[len - 1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | if ((flags & AV_NOEXPAND) == 0)
| 7-57 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | akey = expand_assignment_string_to_string (t, 0); /* [ */ executed 57 times by 1 test: akey = expand_assignment_string_to_string (t, 0);Executed by:
| 57 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | akey = savestring (t); executed 7 times by 1 test: akey = (char *)strcpy (sh_xmalloc((1 + strlen (t)), "arrayfunc.c", 1152), (t));Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | t[len - 1] = ']'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | if (akey == 0 || *akey == 0)
| 0-64 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | FREE (akey); never executed: sh_xfree((akey), "arrayfunc.c", 1156);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | INDEX_ERROR(); never executed: err_badarraysub (var->name);never executed: end of blocknever executed: return ((char *) ((void *)0) );
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | if (var == 0 || value_cell (var) == 0) /* XXX - check invisible_p(var) ? */
| 0-15341 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | FREE (akey); never executed: sh_xfree((akey), "arrayfunc.c", 1163);
| 0-12 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | return ((char *)NULL); executed 12 times by 1 test: return ((char *) ((void *)0) );Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | if (array_p (var) == 0 && assoc_p (var) == 0)
| 63-15214 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | return (ind == 0 ? value_cell (var) : (char *)NULL); executed 63 times by 1 test: return (ind == 0 ? ((var)->value) : (char *) ((void *)0) );Executed by:
| 63 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | else if (assoc_p (var))
| 64-15214 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | retval = assoc_reference (assoc_cell (var), akey); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | free (akey); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | retval = array_reference (array_cell (var), ind); executed 15214 times by 1 test: retval = array_reference ((ARRAY *)((var)->value), ind);Executed by:
| 15214 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | return retval; executed 16072 times by 1 test: return retval;Executed by:
| 16072 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | /* Return a string containing the elements described by the array and | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | subscript contained in S, obeying quoting for subscripts * and @. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | array_value (s, quoted, flags, rtype, indp) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | int quoted, flags, *rtype; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | arrayind_t *indp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | return (array_value_internal (s, quoted, flags|AV_ALLOWALL, rtype, indp)); executed 6102 times by 1 test: return (array_value_internal (s, quoted, flags|0x001, rtype, indp));Executed by:
| 6102 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | /* Return the value of the array indexing expression S as a single string. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | If (FLAGS & AV_ALLOWALL) is 0, do not allow `@' and `*' subscripts. This | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | is used by other parts of the shell such as the arithmetic expression | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | evaluator in expr.c. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | get_array_value (s, flags, rtype, indp) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | int flags, *rtype; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | arrayind_t *indp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | return (array_value_internal (s, 0, flags, rtype, indp)); executed 10105 times by 1 test: return (array_value_internal (s, 0, flags, rtype, indp));Executed by:
| 10105 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | array_keys (s, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | int quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | int len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | char *retval, *t, *temp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | WORD_LIST *l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | SHELL_VAR *var; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | var = array_variable_part (s, 0, &t, &len); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | /* [ */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | if (var == 0 || ALL_ELEMENT_SUB (t[0]) == 0 || t[1] != ']')
| 0-40 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | return (char *)NULL; never executed: return (char *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | if (var_isset (var) == 0 || invisible_p (var))
| 0-40 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | return (char *)NULL; never executed: return (char *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | if (array_p (var) == 0 && assoc_p (var) == 0)
| 0-32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | l = add_string_to_list ("0", (WORD_LIST *)NULL); never executed: l = make_word_list (make_word("0"), ((WORD_LIST *) ((void *)0) )); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | else if (assoc_p (var))
| 8-32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | l = assoc_keys_to_word_list (assoc_cell (var)); executed 32 times by 1 test: l = assoc_keys_to_word_list ((HASH_TABLE *)((var)->value));Executed by:
| 32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | l = array_keys_to_word_list (array_cell (var)); executed 8 times by 1 test: l = array_keys_to_word_list ((ARRAY *)((var)->value));Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | if (l == (WORD_LIST *)NULL)
| 0-40 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | return ((char *) NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | if (t[0] == '*' && (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)))
| 1-38 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | temp = string_list_dollar_star (l, quoted, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | retval = quote_string (temp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | free (temp); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | else /* ${!name[@]} or unquoted ${!name[*]} */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | retval = string_list_dollar_at (l, quoted, 0); executed 39 times by 1 test: retval = string_list_dollar_at (l, quoted, 0);Executed by:
| 39 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | dispose_words (l); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | return retval; executed 40 times by 1 test: return retval;Executed by:
| 40 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | #endif /* ARRAY_VARS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |