OpenCoverage

setattr.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/setattr.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is setattr.def, from which is created setattr.c.-
2It implements the builtins "export" and "readonly", in Bash.-
3-
4Copyright (C) 1987-2015 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$PRODUCES setattr.c-
22-
23#include <config.h>-
24-
25#if defined (HAVE_UNISTD_H)-
26# ifdef _MINIX-
27# include <sys/types.h>-
28# endif-
29# include <unistd.h>-
30#endif-
31-
32#include <stdio.h>-
33#include "../bashansi.h"-
34#include "../bashintl.h"-
35-
36#include "../shell.h"-
37#include "../execute_cmd.h"-
38#include "../flags.h"-
39#include "common.h"-
40#include "bashgetopt.h"-
41-
42extern sh_builtin_func_t *this_shell_builtin;-
43-
44#ifdef ARRAY_VARS-
45extern int declare_builtin __P((WORD_LIST *));-
46#endif-
47-
48#define READONLY_OR_EXPORT \-
49 (this_shell_builtin == readonly_builtin || this_shell_builtin == export_builtin)-
50-
51$BUILTIN export-
52$FUNCTION export_builtin-
53$SHORT_DOC export [-fn] [name[=value] ...] or export -p-
54Set export attribute for shell variables.-
55-
56Marks each NAME for automatic export to the environment of subsequently-
57executed commands. If VALUE is supplied, assign VALUE before exporting.-
58-
59Options:-
60 -f refer to shell functions-
61 -n remove the export property from each NAME-
62 -p display a list of all exported variables and functions-
63-
64An argument of `--' disables further option processing.-
65-
66Exit Status:-
67Returns success unless an invalid option is given or NAME is invalid.-
68$END-
69-
70/* For each variable name in LIST, make that variable appear in the-
71 environment passed to simple commands. If there is no LIST, then-
72 print all such variables. An argument of `-n' says to remove the-
73 exported attribute from variables named in LIST. An argument of-
74 -f indicates that the names present in LIST refer to functions. */-
75int-
76export_builtin (list)-
77 register WORD_LIST *list;-
78{-
79 return (set_or_show_attributes (list, att_exported, 0));
executed 2537 times by 1 test: return (set_or_show_attributes (list, 0x0000001, 0));
Executed by:
  • Self test
2537
80}-
81-
82$BUILTIN readonly-
83$FUNCTION readonly_builtin-
84$SHORT_DOC readonly [-aAf] [name[=value] ...] or readonly -p-
85Mark shell variables as unchangeable.-
86-
87Mark each NAME as read-only; the values of these NAMEs may not be-
88changed by subsequent assignment. If VALUE is supplied, assign VALUE-
89before marking as read-only.-
90-
91Options:-
92 -a refer to indexed array variables-
93 -A refer to associative array variables-
94 -f refer to shell functions-
95 -p display a list of all readonly variables or functions,-
96 depending on whether or not the -f option is given-
97-
98An argument of `--' disables further option processing.-
99-
100Exit Status:-
101Returns success unless an invalid option is given or NAME is invalid.-
102$END-
103-
104/* For each variable name in LIST, make that variable readonly. Given an-
105 empty LIST, print out all existing readonly variables. */-
106int-
107readonly_builtin (list)-
108 register WORD_LIST *list;-
109{-
110 return (set_or_show_attributes (list, att_readonly, 0));
executed 108 times by 1 test: return (set_or_show_attributes (list, 0x0000002, 0));
Executed by:
  • Self test
108
111}-
112-
113#if defined (ARRAY_VARS)-
114# define ATTROPTS "aAfnp"-
115#else-
116# define ATTROPTS "fnp"-
117#endif-
118-
119/* For each variable name in LIST, make that variable have the specified-
120 ATTRIBUTE. An arg of `-n' says to remove the attribute from the the-
121 remaining names in LIST (doesn't work for readonly). */-
122int-
123set_or_show_attributes (list, attribute, nodefs)-
124 register WORD_LIST *list;-
125 int attribute, nodefs;-
126{-
127 register SHELL_VAR *var;-
128 int assign, undo, any_failed, assign_error, opt;-
129 int functions_only, arrays_only, assoc_only;-
130 int aflags;-
131 char *name;-
132#if defined (ARRAY_VARS)-
133 WORD_LIST *nlist, *tlist;-
134 WORD_DESC *w;-
135 char optw[8];-
136 int opti;-
137#endif-
138-
139 functions_only = arrays_only = assoc_only = 0;-
140 undo = any_failed = assign_error = 0;-
141 /* Read arguments from the front of the list. */-
142 reset_internal_getopt ();-
143 while ((opt = internal_getopt (list, ATTROPTS)) != -1)
(opt = interna...aAfnp")) != -1Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2673 times by 1 test
Evaluated by:
  • Self test
42-2673
144 {-
145 switch (opt)-
146 {-
147 case 'n':
executed 5 times by 1 test: case 'n':
Executed by:
  • Self test
5
148 undo = 1;-
149 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
150 case 'f':
executed 24 times by 1 test: case 'f':
Executed by:
  • Self test
24
151 functions_only = 1;-
152 break;
executed 24 times by 1 test: break;
Executed by:
  • Self test
24
153#if defined (ARRAY_VARS)-
154 case 'a':
executed 10 times by 1 test: case 'a':
Executed by:
  • Self test
10
155 arrays_only = 1;-
156 break;
executed 10 times by 1 test: break;
Executed by:
  • Self test
10
157 case 'A':
executed 1 time by 1 test: case 'A':
Executed by:
  • Self test
1
158 assoc_only = 1;-
159 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
160#endif-
161 case 'p':
executed 1 time by 1 test: case 'p':
Executed by:
  • Self test
1
162 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
163 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
164 default:
executed 1 time by 1 test: default:
Executed by:
  • Self test
1
165 builtin_usage ();-
166 return (EX_USAGE);
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
1
167 }-
168 }-
169 list = loptend;-
170-
171 if (list)
listDescription
TRUEevaluated 2641 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
32-2641
172 {-
173 if (attribute & att_exported)
attribute & 0x0000001Description
TRUEevaluated 2537 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
104-2537
174 array_needs_making = 1;
executed 2537 times by 1 test: array_needs_making = 1;
Executed by:
  • Self test
2537
175-
176 /* Cannot undo readonly status, silently disallowed. */-
177 if (undo && (attribute & att_readonly))
undoDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2636 times by 1 test
Evaluated by:
  • Self test
(attribute & 0x0000002)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2636
178 attribute &= ~att_readonly;
executed 5 times by 1 test: attribute &= ~0x0000002;
Executed by:
  • Self test
5
179-
180 while (list)
listDescription
TRUEevaluated 2646 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2641 times by 1 test
Evaluated by:
  • Self test
2641-2646
181 {-
182 name = list->word->word;-
183-
184 if (functions_only) /* xxx -f name */
functions_onlyDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2622 times by 1 test
Evaluated by:
  • Self test
24-2622
185 {-
186 var = find_function (name);-
187 if (var == 0)
var == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
5-19
188 {-
189 builtin_error (_("%s: not a function"), name);-
190 any_failed++;-
191 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
192 else if ((attribute & att_exported) && undo == 0 && exportable_function_name (name) == 0)
(attribute & 0x0000001)Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
undo == 0Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
exportable_fun...me (name) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
0-14
193 {-
194 builtin_error (_("%s: cannot export"), name);-
195 any_failed++;-
196 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
197 else-
198 SETVARATTR (var, attribute, undo);
executed 17 times by 1 test: ((undo == 0) ? ((var)->attributes |= (attribute)) : ((var)->attributes &= ~(attribute)));
Executed by:
  • Self test
17
199-
200 list = list->next;-
201 continue;
executed 24 times by 1 test: continue;
Executed by:
  • Self test
24
202 }-
203-
204 /* xxx [-np] name[=value] */-
205 assign = assignment (name, 0);-
206-
207 aflags = 0;-
208 if (assign)
assignDescription
TRUEevaluated 208 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2414 times by 1 test
Evaluated by:
  • Self test
208-2414
209 {-
210 name[assign] = '\0';-
211 if (name[assign - 1] == '+')
name[assign - 1] == '+'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 206 times by 1 test
Evaluated by:
  • Self test
2-206
212 {-
213 aflags |= ASS_APPEND;-
214 name[assign - 1] = '\0';-
215 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
216 }
executed 208 times by 1 test: end of block
Executed by:
  • Self test
208
217-
218 if (legal_identifier (name) == 0)
legal_identifier (name) == 0Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2598 times by 1 test
Evaluated by:
  • Self test
24-2598
219 {-
220 sh_invalidid (name);-
221 if (assign)
assignDescription
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
0-24
222 assign_error++;
never executed: assign_error++;
0
223 else-
224 any_failed++;
executed 24 times by 1 test: any_failed++;
Executed by:
  • Self test
24
225 list = list->next;-
226 continue;
executed 24 times by 1 test: continue;
Executed by:
  • Self test
24
227 }-
228-
229 if (assign) /* xxx [-np] name=value */
assignDescription
TRUEevaluated 208 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2390 times by 1 test
Evaluated by:
  • Self test
208-2390
230 {-
231 name[assign] = '=';-
232 if (aflags & ASS_APPEND)
aflags & 0x0001Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 206 times by 1 test
Evaluated by:
  • Self test
2-206
233 name[assign - 1] = '+';
executed 2 times by 1 test: name[assign - 1] = '+';
Executed by:
  • Self test
2
234#if defined (ARRAY_VARS)-
235 /* Let's try something here. Turn readonly -a xxx=yyy into-
236 declare -ra xxx=yyy and see what that gets us. */-
237 if (arrays_only || assoc_only)
arrays_onlyDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 204 times by 1 test
Evaluated by:
  • Self test
assoc_onlyDescription
TRUEnever evaluated
FALSEevaluated 204 times by 1 test
Evaluated by:
  • Self test
0-204
238 {-
239 tlist = list->next;-
240 list->next = (WORD_LIST *)NULL;-
241 /* Add -g to avoid readonly/export creating local variables:-
242 only local/declare/typeset create local variables */-
243 opti = 0;-
244 optw[opti++] = '-';-
245 optw[opti++] = 'g';-
246 if (attribute & att_readonly)
attribute & 0x0000002Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-3
247 optw[opti++] = 'r';
executed 3 times by 1 test: optw[opti++] = 'r';
Executed by:
  • Self test
3
248 if (attribute & att_exported)
attribute & 0x0000001Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
1-3
249 optw[opti++] = 'x';
executed 1 time by 1 test: optw[opti++] = 'x';
Executed by:
  • Self test
1
250 if (arrays_only)
arrays_onlyDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4
251 optw[opti++] = 'a';
executed 4 times by 1 test: optw[opti++] = 'a';
Executed by:
  • Self test
4
252 else-
253 optw[opti++] = 'A';
never executed: optw[opti++] = 'A';
0
254 optw[opti] = '\0';-
255-
256 w = make_word (optw);-
257 nlist = make_word_list (w, list);-
258-
259 opt = declare_builtin (nlist);-
260 if (opt != EXECUTION_SUCCESS)
opt != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2
261 assign_error++;
executed 2 times by 1 test: assign_error++;
Executed by:
  • Self test
2
262 list->next = tlist;-
263 dispose_word (w);-
264 free (nlist);-
265 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
266 else-
267#endif-
268 /* This word has already been expanded once with command-
269 and parameter expansion. Call do_assignment_no_expand (),-
270 which does not do command or parameter substitution. If-
271 the assignment is not performed correctly, flag an error. */-
272 if (do_assignment_no_expand (name) == 0)
do_assignment_...nd (name) == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 200 times by 1 test
Evaluated by:
  • Self test
4-200
273 assign_error++;
executed 4 times by 1 test: assign_error++;
Executed by:
  • Self test
4
274 name[assign] = '\0';-
275 if (aflags & ASS_APPEND)
aflags & 0x0001Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 206 times by 1 test
Evaluated by:
  • Self test
2-206
276 name[assign - 1] = '\0';
executed 2 times by 1 test: name[assign - 1] = '\0';
Executed by:
  • Self test
2
277 }
executed 208 times by 1 test: end of block
Executed by:
  • Self test
208
278-
279 set_var_attribute (name, attribute, undo);-
280 list = list->next;-
281 }
executed 2598 times by 1 test: end of block
Executed by:
  • Self test
2598
282 }
executed 2641 times by 1 test: end of block
Executed by:
  • Self test
2641
283 else-
284 {-
285 SHELL_VAR **variable_list;-
286 register int i;-
287-
288 if ((attribute & att_function) || functions_only)
(attribute & 0x0000008)Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
functions_onlyDescription
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
289 {-
290 variable_list = all_shell_functions ();-
291 if (attribute != att_function)
attribute != 0x0000008Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-13
292 attribute &= ~att_function; /* so declare -xf works, for example */
executed 13 times by 1 test: attribute &= ~0x0000008;
Executed by:
  • Self test
13
293 }
executed 15 times by 1 test: end of block
Executed by:
  • Self test
15
294 else-
295 variable_list = all_shell_variables ();
executed 17 times by 1 test: variable_list = all_shell_variables ();
Executed by:
  • Self test
17
296-
297#if defined (ARRAY_VARS)-
298 if (attribute & att_array)
attribute & 0x0000004Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
5-27
299 {-
300 arrays_only++;-
301 if (attribute != att_array)
attribute != 0x0000004Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
1-4
302 attribute &= ~att_array;
executed 1 time by 1 test: attribute &= ~0x0000004;
Executed by:
  • Self test
1
303 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
304 else if (attribute & att_assoc)
attribute & 0x0000040Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
7-20
305 {-
306 assoc_only++;-
307 if (attribute != att_assoc)
attribute != 0x0000040Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
308 attribute &= ~att_assoc;
never executed: attribute &= ~0x0000040;
0
309 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
310#endif-
311-
312 if (variable_list)
variable_listDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-32
313 {-
314 for (i = 0; var = variable_list[i]; i++)
var = variable_list[i]Description
TRUEevaluated 1188 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
32-1188
315 {-
316#if defined (ARRAY_VARS)-
317 if (arrays_only && array_p (var) == 0)
arrays_onlyDescription
TRUEevaluated 482 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 706 times by 1 test
Evaluated by:
  • Self test
((((var)->attr...000004))) == 0Description
TRUEevaluated 390 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 92 times by 1 test
Evaluated by:
  • Self test
92-706
318 continue;
executed 390 times by 1 test: continue;
Executed by:
  • Self test
390
319 else if (assoc_only && assoc_p (var) == 0)
assoc_onlyDescription
TRUEevaluated 438 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 360 times by 1 test
Evaluated by:
  • Self test
((((var)->attr...000040))) == 0Description
TRUEevaluated 413 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
25-438
320 continue;
executed 413 times by 1 test: continue;
Executed by:
  • Self test
413
321#endif-
322-
323 /* If we imported a variable that's not a valid identifier, don't-
324 show it in any lists. */-
325 if ((var->attributes & (att_invisible|att_imported)) == (att_invisible|att_imported))
(var->attribut...000|0x0008000)Description
TRUEnever evaluated
FALSEevaluated 385 times by 1 test
Evaluated by:
  • Self test
0-385
326 continue;
never executed: continue;
0
327-
328 if ((var->attributes & attribute))
(var->attributes & attribute)Description
TRUEevaluated 109 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 276 times by 1 test
Evaluated by:
  • Self test
109-276
329 {-
330 show_var_attributes (var, READONLY_OR_EXPORT, nodefs);-
331 if (any_failed = sh_chkwrite (any_failed))
any_failed = s...e (any_failed)Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • Self test
0-109
332 break;
never executed: break;
0
333 }
executed 109 times by 1 test: end of block
Executed by:
  • Self test
109
334 }
executed 385 times by 1 test: end of block
Executed by:
  • Self test
385
335 free (variable_list);-
336 }
executed 32 times by 1 test: end of block
Executed by:
  • Self test
32
337 }
executed 32 times by 1 test: end of block
Executed by:
  • Self test
32
338-
339 return (assign_error ? EX_BADASSIGN
executed 2673 times by 1 test: return (assign_error ? 260 : ((any_failed == 0) ? 0 : 1));
Executed by:
  • Self test
2673
340 : ((any_failed == 0) ? EXECUTION_SUCCESS
executed 2673 times by 1 test: return (assign_error ? 260 : ((any_failed == 0) ? 0 : 1));
Executed by:
  • Self test
2673
341 : EXECUTION_FAILURE));
executed 2673 times by 1 test: return (assign_error ? 260 : ((any_failed == 0) ? 0 : 1));
Executed by:
  • Self test
2673
342}-
343-
344/* Show all variable variables (v == 1) or functions (v == 0) with-
345 attributes. */-
346int-
347show_all_var_attributes (v, nodefs)-
348 int v, nodefs;-
349{-
350 SHELL_VAR **variable_list, *var;-
351 int any_failed;-
352 register int i;-
353-
354 variable_list = v ? all_shell_variables () : all_shell_functions ();
vDescription
TRUEnever evaluated
FALSEnever evaluated
0
355 if (variable_list == 0)
variable_list == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
356 return (EXECUTION_SUCCESS);
never executed: return (0);
0
357-
358 for (i = any_failed = 0; var = variable_list[i]; i++)
var = variable_list[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
359 {-
360 show_var_attributes (var, READONLY_OR_EXPORT, nodefs);-
361 if (any_failed = sh_chkwrite (any_failed))
any_failed = s...e (any_failed)Description
TRUEnever evaluated
FALSEnever evaluated
0
362 break;
never executed: break;
0
363 }
never executed: end of block
0
364 free (variable_list);-
365 return (any_failed == 0 ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
never executed: return (any_failed == 0 ? 0 : 1);
0
366}-
367-
368int-
369var_attribute_string (var, pattr, flags)-
370 SHELL_VAR *var;-
371 int pattr;-
372 char *flags; /* filled in with attributes */-
373{-
374 int i;-
375-
376 i = 0;-
377-
378 /* pattr == 0 means we are called from `declare'. */-
379 if (pattr == 0 || posixly_correct == 0)
pattr == 0Description
TRUEevaluated 578 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
posixly_correct == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-578
380 {-
381#if defined (ARRAY_VARS)-
382 if (array_p (var))
((((var)->attr... (0x0000004)))Description
TRUEevaluated 240 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 347 times by 1 test
Evaluated by:
  • Self test
240-347
383 flags[i++] = 'a';
executed 240 times by 1 test: flags[i++] = 'a';
Executed by:
  • Self test
240
384-
385 if (assoc_p (var))
((((var)->attr... (0x0000040)))Description
TRUEevaluated 115 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 472 times by 1 test
Evaluated by:
  • Self test
115-472
386 flags[i++] = 'A';
executed 115 times by 1 test: flags[i++] = 'A';
Executed by:
  • Self test
115
387#endif-
388-
389 if (function_p (var))
((((var)->attr... (0x0000008)))Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 570 times by 1 test
Evaluated by:
  • Self test
17-570
390 flags[i++] = 'f';
executed 17 times by 1 test: flags[i++] = 'f';
Executed by:
  • Self test
17
391-
392 if (integer_p (var))
((((var)->attr... (0x0000010)))Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 570 times by 1 test
Evaluated by:
  • Self test
17-570
393 flags[i++] = 'i';
executed 17 times by 1 test: flags[i++] = 'i';
Executed by:
  • Self test
17
394-
395 if (nameref_p (var))
((((var)->attr... (0x0000800)))Description
TRUEevaluated 95 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 492 times by 1 test
Evaluated by:
  • Self test
95-492
396 flags[i++] = 'n';
executed 95 times by 1 test: flags[i++] = 'n';
Executed by:
  • Self test
95
397-
398 if (readonly_p (var))
((((var)->attr... (0x0000002)))Description
TRUEevaluated 115 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 472 times by 1 test
Evaluated by:
  • Self test
115-472
399 flags[i++] = 'r';
executed 115 times by 1 test: flags[i++] = 'r';
Executed by:
  • Self test
115
400-
401 if (trace_p (var))
((((var)->attr... (0x0000080)))Description
TRUEnever evaluated
FALSEevaluated 587 times by 1 test
Evaluated by:
  • Self test
0-587
402 flags[i++] = 't';
never executed: flags[i++] = 't';
0
403-
404 if (exported_p (var))
((((var)->attr... (0x0000001)))Description
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 551 times by 1 test
Evaluated by:
  • Self test
36-551
405 flags[i++] = 'x';
executed 36 times by 1 test: flags[i++] = 'x';
Executed by:
  • Self test
36
406-
407 if (capcase_p (var))
((((var)->attr... (0x0000400)))Description
TRUEnever evaluated
FALSEevaluated 587 times by 1 test
Evaluated by:
  • Self test
0-587
408 flags[i++] = 'c';
never executed: flags[i++] = 'c';
0
409-
410 if (lowercase_p (var))
((((var)->attr... (0x0000200)))Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 581 times by 1 test
Evaluated by:
  • Self test
6-581
411 flags[i++] = 'l';
executed 6 times by 1 test: flags[i++] = 'l';
Executed by:
  • Self test
6
412-
413 if (uppercase_p (var))
((((var)->attr... (0x0000100)))Description
TRUEnever evaluated
FALSEevaluated 587 times by 1 test
Evaluated by:
  • Self test
0-587
414 flags[i++] = 'u';
never executed: flags[i++] = 'u';
0
415 }
executed 587 times by 1 test: end of block
Executed by:
  • Self test
587
416 else-
417 {-
418#if defined (ARRAY_VARS)-
419 if (array_p (var))
((((var)->attr... (0x0000004)))Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
420 flags[i++] = 'a';
executed 3 times by 1 test: flags[i++] = 'a';
Executed by:
  • Self test
3
421-
422 if (assoc_p (var))
((((var)->attr... (0x0000040)))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
423 flags[i++] = 'A';
never executed: flags[i++] = 'A';
0
424#endif-
425-
426 if (function_p (var))
((((var)->attr... (0x0000008)))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
427 flags[i++] = 'f';
never executed: flags[i++] = 'f';
0
428 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
429-
430 flags[i] = '\0';-
431 return i;
executed 590 times by 1 test: return i;
Executed by:
  • Self test
590
432}-
433-
434/* Show the attributes for shell variable VAR. If NODEFS is non-zero,-
435 don't show function definitions along with the name. If PATTR is-
436 non-zero, it indicates we're being called from `export' or `readonly'.-
437 In POSIX mode, this prints the name of the calling builtin (`export'-
438 or `readonly') instead of `declare', and doesn't print function defs-
439 when called by `export' or `readonly'. */-
440int-
441show_var_attributes (var, pattr, nodefs)-
442 SHELL_VAR *var;-
443 int pattr, nodefs;-
444{-
445 char flags[MAX_ATTRIBUTES], *x;-
446 int i;-
447-
448 i = var_attribute_string (var, pattr, flags);-
449-
450 /* If we're printing functions with definitions, print the function def-
451 first, then the attributes, instead of printing output that can't be-
452 reused as input to recreate the current state. */-
453 if (function_p (var) && nodefs == 0 && (pattr == 0 || posixly_correct == 0))
((((var)->attr... (0x0000008)))Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 559 times by 1 test
Evaluated by:
  • Self test
nodefs == 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
pattr == 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
posixly_correct == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-559
454 {-
455 printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));-
456 nodefs++;-
457 if (pattr == 0 && i == 1 && flags[0] == 'f')
pattr == 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i == 1Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
flags[0] == 'f'Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-12
458 return 0; /* don't print `declare -f name' */
executed 12 times by 1 test: return 0;
Executed by:
  • Self test
12
459 }
never executed: end of block
0
460-
461 if (pattr == 0 || posixly_correct == 0)
pattr == 0Description
TRUEevaluated 552 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
posixly_correct == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-552
462 printf ("declare -%s ", i ? flags : "-");
executed 561 times by 1 test: printf ("declare -%s ", i ? flags : "-");
Executed by:
  • Self test
561
463 else if (i)
iDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
464 printf ("%s -%s ", this_command_name, flags);
executed 3 times by 1 test: printf ("%s -%s ", this_command_name, flags);
Executed by:
  • Self test
3
465 else-
466 printf ("%s ", this_command_name);
never executed: printf ("%s ", this_command_name);
0
467-
468#if defined (ARRAY_VARS)-
469 if (invisible_p (var) && (array_p (var) || assoc_p (var)))
((((var)->attr... (0x0001000)))Description
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 518 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0000004)))Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0000040)))Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
7-518
470 printf ("%s\n", var->name);
executed 23 times by 1 test: printf ("%s\n", var->name);
Executed by:
  • Self test
23
471 else if (array_p (var))
((((var)->attr... (0x0000004)))Description
TRUEevaluated 222 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 319 times by 1 test
Evaluated by:
  • Self test
222-319
472 print_array_assignment (var, 0);
executed 222 times by 1 test: print_array_assignment (var, 0);
Executed by:
  • Self test
222
473 else if (assoc_p (var))
((((var)->attr... (0x0000040)))Description
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 214 times by 1 test
Evaluated by:
  • Self test
105-214
474 print_assoc_assignment (var, 0);
executed 105 times by 1 test: print_assoc_assignment (var, 0);
Executed by:
  • Self test
105
475 else-
476#endif-
477 /* force `readonly' and `export' to not print out function definitions-
478 when in POSIX mode. */-
479 if (nodefs || (function_p (var) && pattr != 0 && posixly_correct))
nodefsDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0000008)))Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
pattr != 0Description
TRUEnever evaluated
FALSEnever evaluated
posixly_correctDescription
TRUEnever evaluated
FALSEnever evaluated
0-209
480 printf ("%s\n", var->name);
executed 5 times by 1 test: printf ("%s\n", var->name);
Executed by:
  • Self test
5
481 else if (function_p (var))
((((var)->attr... (0x0000008)))Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
482 printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
never executed: printf ("%s\n", named_function_string (var->name, (COMMAND *)((var)->value), 0x01|0x02));
0
483 else if (invisible_p (var) || var_isset (var) == 0)
((((var)->attr... (0x0001000)))Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 186 times by 1 test
Evaluated by:
  • Self test
((var)->value != 0) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 185 times by 1 test
Evaluated by:
  • Self test
1-186
484 printf ("%s\n", var->name);
executed 24 times by 1 test: printf ("%s\n", var->name);
Executed by:
  • Self test
24
485 else-
486 {-
487 x = sh_double_quote (value_cell (var));-
488 printf ("%s=%s\n", var->name, x);-
489 free (x);-
490 }
executed 185 times by 1 test: end of block
Executed by:
  • Self test
185
491 return (0);
executed 564 times by 1 test: return (0);
Executed by:
  • Self test
564
492}-
493-
494int-
495show_name_attributes (name, nodefs)-
496 char *name;-
497 int nodefs;-
498{-
499 SHELL_VAR *var;-
500-
501#if 0-
502 var = find_variable_tempenv (name);-
503#else-
504 var = find_variable_noref (name);-
505#endif-
506-
507 if (var /* && invisible_p (var) == 0 */) /* XXX bash-4.4/bash-5.0 */
varDescription
TRUEevaluated 461 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 51 times by 1 test
Evaluated by:
  • Self test
51-461
508 {-
509 show_var_attributes (var, READONLY_OR_EXPORT, nodefs);-
510 return (0);
executed 461 times by 1 test: return (0);
Executed by:
  • Self test
461
511 }-
512 else-
513 return (1);
executed 51 times by 1 test: return (1);
Executed by:
  • Self test
51
514}-
515-
516int-
517show_func_attributes (name, nodefs)-
518 char *name;-
519 int nodefs;-
520{-
521 SHELL_VAR *var;-
522-
523 var = find_function (name);-
524-
525 if (var)
varDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-6
526 {-
527 show_var_attributes (var, READONLY_OR_EXPORT, nodefs);-
528 return (0);
executed 6 times by 1 test: return (0);
Executed by:
  • Self test
6
529 }-
530 else-
531 return (1);
executed 2 times by 1 test: return (1);
Executed by:
  • Self test
2
532}-
533-
534void-
535set_var_attribute (name, attribute, undo)-
536 char *name;-
537 int attribute, undo;-
538{-
539 SHELL_VAR *var, *tv, *v, *refvar;-
540 char *tvalue;-
541-
542 if (undo)
undoDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2593 times by 1 test
Evaluated by:
  • Self test
5-2593
543 var = find_variable (name);
executed 5 times by 1 test: var = find_variable (name);
Executed by:
  • Self test
5
544 else-
545 {-
546 tv = find_tempenv_variable (name);-
547 /* XXX -- need to handle case where tv is a temp variable in a-
548 function-scope context, since function_env has been merged into-
549 the local variables table. */-
550 if (tv && tempvar_p (tv))
tvDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2586 times by 1 test
Evaluated by:
  • Self test
((((tv)->attri... (0x0100000)))Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2586
551 {-
552 tvalue = var_isset (tv) ? savestring (value_cell (tv)) : savestring ("");
((tv)->value != 0)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7
553-
554 var = bind_variable (tv->name, tvalue, 0);-
555 if (var == 0)
var == 0Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
556 {-
557 free (tvalue);-
558 return; /* XXX - no error message here */
never executed: return;
0
559 }-
560 var->attributes |= tv->attributes & ~att_tempvar;-
561 /* This avoids an error message when propagating a read-only var-
562 later on. */-
563 if (var->context == 0 && (attribute & att_readonly))
var->context == 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(attribute & 0x0000002)Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
564 {-
565 /* Don't bother to set the `propagate to the global variables-
566 table' flag if we've just bound the variable in that table */-
567 v = find_global_variable (tv->name);-
568 if (v != var)
v != varDescription
TRUEnever evaluated
FALSEnever evaluated
0
569 VSETATTR (tv, att_propagate);
never executed: ((tv)->attributes |= (0x0200000));
0
570 }
never executed: end of block
0
571 else-
572 VSETATTR (tv, att_propagate);
executed 7 times by 1 test: ((tv)->attributes |= (0x0200000));
Executed by:
  • Self test
7
573 if (var->context != 0)
var->context != 0Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
574 VSETATTR (var, att_propagate);
never executed: ((var)->attributes |= (0x0200000));
0
575 SETVARATTR (tv, attribute, undo); /* XXX */-
576-
577 stupidly_hack_special_variables (tv->name);-
578-
579 free (tvalue);-
580 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
581 else-
582 {-
583 var = find_variable_notempenv (name);-
584 if (var == 0)
var == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2580 times by 1 test
Evaluated by:
  • Self test
6-2580
585 {-
586 /* We might have a nameref pointing to something that we can't-
587 resolve to a shell variable. If we do, skip it. We do a little-
588 checking just so we can print an error message. */-
589 refvar = find_variable_nameref_for_create (name, 0);-
590 if (refvar == INVALID_NAMEREF_VALUE)
refvar == (voi..._invalid_valueDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
1-5
591 return;
executed 1 time by 1 test: return;
Executed by:
  • Self test
1
592 /* Otherwise we probably have a nameref pointing to a variable-
593 that hasn't been created yet. bind_variable will take care-
594 of that. */-
595 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
596 if (var == 0)
var == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2580 times by 1 test
Evaluated by:
  • Self test
5-2580
597 {-
598 var = bind_variable (name, (char *)NULL, 0);-
599 if (var && no_invisible_vars == 0)
varDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
no_invisible_vars == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
600 VSETATTR (var, att_invisible);
executed 5 times by 1 test: ((var)->attributes |= (0x0001000));
Executed by:
  • Self test
5
601 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
602 else if (var->context != 0)
var->context != 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2572 times by 1 test
Evaluated by:
  • Self test
8-2572
603 VSETATTR (var, att_propagate);
executed 8 times by 1 test: ((var)->attributes |= (0x0200000));
Executed by:
  • Self test
8
604 }
executed 2585 times by 1 test: end of block
Executed by:
  • Self test
2585
605 }-
606-
607 if (var)
varDescription
TRUEevaluated 2597 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2597
608 SETVARATTR (var, attribute, undo);
executed 2597 times by 1 test: ((undo == 0) ? ((var)->attributes |= (attribute)) : ((var)->attributes &= ~(attribute)));
Executed by:
  • Self test
2597
609-
610 if (var && (exported_p (var) || (attribute & att_exported)))
varDescription
TRUEevaluated 2597 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((((var)->attr... (0x0000001)))Description
TRUEevaluated 2519 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 78 times by 1 test
Evaluated by:
  • Self test
(attribute & 0x0000001)Description
TRUEnever evaluated
FALSEevaluated 78 times by 1 test
Evaluated by:
  • Self test
0-2597
611 array_needs_making++; /* XXX */
executed 2519 times by 1 test: array_needs_making++;
Executed by:
  • Self test
2519
612}
executed 2597 times by 1 test: end of block
Executed by:
  • Self test
2597
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2