OpenCoverage

set.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/set.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is set.def, from which is created set.c.-
2It implements the "set" and "unset" builtins 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 set.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-
34#include "../bashansi.h"-
35#include "../bashintl.h"-
36-
37#include "../shell.h"-
38#include "../parser.h"-
39#include "../flags.h"-
40#include "common.h"-
41#include "bashgetopt.h"-
42-
43#if defined (READLINE)-
44# include "../input.h"-
45# include "../bashline.h"-
46# include <readline/readline.h>-
47#endif-
48-
49#if defined (HISTORY)-
50# include "../bashhist.h"-
51#endif-
52-
53$BUILTIN set-
54$FUNCTION set_builtin-
55$SHORT_DOC set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]-
56Set or unset values of shell options and positional parameters.-
57-
58Change the value of shell attributes and positional parameters, or-
59display the names and values of shell variables.-
60-
61Options:-
62 -a Mark variables which are modified or created for export.-
63 -b Notify of job termination immediately.-
64 -e Exit immediately if a command exits with a non-zero status.-
65 -f Disable file name generation (globbing).-
66 -h Remember the location of commands as they are looked up.-
67 -k All assignment arguments are placed in the environment for a-
68 command, not just those that precede the command name.-
69 -m Job control is enabled.-
70 -n Read commands but do not execute them.-
71 -o option-name-
72 Set the variable corresponding to option-name:-
73 allexport same as -a-
74 braceexpand same as -B-
75#if defined (READLINE)-
76 emacs use an emacs-style line editing interface-
77#endif /* READLINE */-
78 errexit same as -e-
79 errtrace same as -E-
80 functrace same as -T-
81 hashall same as -h-
82#if defined (BANG_HISTORY)-
83 histexpand same as -H-
84#endif /* BANG_HISTORY */-
85#if defined (HISTORY)-
86 history enable command history-
87#endif-
88 ignoreeof the shell will not exit upon reading EOF-
89 interactive-comments-
90 allow comments to appear in interactive commands-
91 keyword same as -k-
92#if defined (JOB_CONTROL)-
93 monitor same as -m-
94#endif-
95 noclobber same as -C-
96 noexec same as -n-
97 noglob same as -f-
98 nolog currently accepted but ignored-
99#if defined (JOB_CONTROL)-
100 notify same as -b-
101#endif-
102 nounset same as -u-
103 onecmd same as -t-
104 physical same as -P-
105 pipefail the return value of a pipeline is the status of-
106 the last command to exit with a non-zero status,-
107 or zero if no command exited with a non-zero status-
108 posix change the behavior of bash where the default-
109 operation differs from the Posix standard to-
110 match the standard-
111 privileged same as -p-
112 verbose same as -v-
113#if defined (READLINE)-
114 vi use a vi-style line editing interface-
115#endif /* READLINE */-
116 xtrace same as -x-
117 -p Turned on whenever the real and effective user ids do not match.-
118 Disables processing of the $ENV file and importing of shell-
119 functions. Turning this option off causes the effective uid and-
120 gid to be set to the real uid and gid.-
121 -t Exit after reading and executing one command.-
122 -u Treat unset variables as an error when substituting.-
123 -v Print shell input lines as they are read.-
124 -x Print commands and their arguments as they are executed.-
125#if defined (BRACE_EXPANSION)-
126 -B the shell will perform brace expansion-
127#endif /* BRACE_EXPANSION */-
128 -C If set, disallow existing regular files to be overwritten-
129 by redirection of output.-
130 -E If set, the ERR trap is inherited by shell functions.-
131#if defined (BANG_HISTORY)-
132 -H Enable ! style history substitution. This flag is on-
133 by default when the shell is interactive.-
134#endif /* BANG_HISTORY */-
135 -P If set, do not resolve symbolic links when executing commands-
136 such as cd which change the current directory.-
137 -T If set, the DEBUG and RETURN traps are inherited by shell functions.-
138 -- Assign any remaining arguments to the positional parameters.-
139 If there are no remaining arguments, the positional parameters-
140 are unset.-
141 - Assign any remaining arguments to the positional parameters.-
142 The -x and -v options are turned off.-
143-
144Using + rather than - causes these flags to be turned off. The-
145flags can also be used upon invocation of the shell. The current-
146set of flags may be found in $-. The remaining n ARGs are positional-
147parameters and are assigned, in order, to $1, $2, .. $n. If no-
148ARGs are given, all shell variables are printed.-
149-
150Exit Status:-
151Returns success unless an invalid option is given.-
152$END-
153-
154typedef int setopt_set_func_t __P((int, char *));-
155typedef int setopt_get_func_t __P((char *));-
156-
157static void print_minus_o_option __P((char *, int, int));-
158static void print_all_shell_variables __P((void));-
159-
160static int set_ignoreeof __P((int, char *));-
161static int set_posix_mode __P((int, char *));-
162-
163#if defined (READLINE)-
164static int set_edit_mode __P((int, char *));-
165static int get_edit_mode __P((char *));-
166#endif-
167-
168#if defined (HISTORY)-
169static int bash_set_history __P((int, char *));-
170#endif-
171-
172static const char * const on = "on";-
173static const char * const off = "off";-
174-
175static int previous_option_value;-
176-
177/* A struct used to match long options for set -o to the corresponding-
178 option letter or internal variable. The functions can be called to-
179 dynamically generate values. If you add a new variable name here-
180 that doesn't have a corresponding single-character option letter, make-
181 sure to set the value appropriately in reset_shell_options. */-
182const struct {-
183 char *name;-
184 int letter;-
185 int *variable;-
186 setopt_set_func_t *set_func;-
187 setopt_get_func_t *get_func;-
188} o_options[] = {-
189 { "allexport", 'a', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
190#if defined (BRACE_EXPANSION)-
191 { "braceexpand",'B', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
192#endif-
193#if defined (READLINE)-
194 { "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode },-
195#endif-
196 { "errexit", 'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
197 { "errtrace", 'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
198 { "functrace", 'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
199 { "hashall", 'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
200#if defined (BANG_HISTORY)-
201 { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
202#endif /* BANG_HISTORY */-
203#if defined (HISTORY)-
204 { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL },-
205#endif-
206 { "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },-
207 { "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
208 { "keyword", 'k', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
209#if defined (JOB_CONTROL)-
210 { "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
211#endif-
212 { "noclobber", 'C', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
213 { "noexec", 'n', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
214 { "noglob", 'f', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
215#if defined (HISTORY)-
216 { "nolog", '\0', &dont_save_function_defs, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
217#endif-
218#if defined (JOB_CONTROL)-
219 { "notify", 'b', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
220#endif /* JOB_CONTROL */-
221 { "nounset", 'u', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
222 { "onecmd", 't', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
223 { "physical", 'P', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
224 { "pipefail", '\0', &pipefail_opt, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
225 { "posix", '\0', &posixly_correct, set_posix_mode, (setopt_get_func_t *)NULL },-
226 { "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
227 { "verbose", 'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
228#if defined (READLINE)-
229 { "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode },-
230#endif-
231 { "xtrace", 'x', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
232 {(char *)NULL, 0 , (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },-
233};-
234-
235#define N_O_OPTIONS (sizeof (o_options) / sizeof (o_options[0]))-
236-
237#define GET_BINARY_O_OPTION_VALUE(i, name) \-
238 ((o_options[i].get_func) ? (*o_options[i].get_func) (name) \-
239 : (*o_options[i].variable))-
240-
241#define SET_BINARY_O_OPTION_VALUE(i, onoff, name) \-
242 ((o_options[i].set_func) ? (*o_options[i].set_func) (onoff, name) \-
243 : (*o_options[i].variable = (onoff == FLAG_ON)))-
244-
245int-
246minus_o_option_value (name)-
247 char *name;-
248{-
249 register int i;-
250 int *on_or_off;-
251-
252 for (i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEevaluated 117 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-117
253 {-
254 if (STREQ (name, o_options[i].name))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( o_options[i].name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(name)[0] == (...ns[i].name)[0]Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-102
255 {-
256 if (o_options[i].letter)
o_options[i].letterDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
2-4
257 {-
258 on_or_off = find_flag (o_options[i].letter);-
259 return ((on_or_off == FLAG_UNKNOWN) ? -1 : *on_or_off);
executed 2 times by 1 test: return ((on_or_off == (int *)0) ? -1 : *on_or_off);
Executed by:
  • Self test
2
260 }-
261 else-
262 return (GET_BINARY_O_OPTION_VALUE (i, name));
executed 4 times by 1 test: return (((o_options[i].get_func) ? (*o_options[i].get_func) (name) : (*o_options[i].variable)));
Executed by:
  • Self test
4
263 }-
264 }
executed 111 times by 1 test: end of block
Executed by:
  • Self test
111
265-
266 return (-1);
executed 1 time by 1 test: return (-1);
Executed by:
  • Self test
1
267}-
268-
269#define MINUS_O_FORMAT "%-15s\t%s\n"-
270-
271static void-
272print_minus_o_option (name, value, pflag)-
273 char *name;-
274 int value, pflag;-
275{-
276 if (pflag == 0)
pflag == 0Description
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 81 times by 1 test
Evaluated by:
  • Self test
46-81
277 printf (MINUS_O_FORMAT, name, value ? on : off);
executed 46 times by 1 test: printf ("%-15s\t%s\n", name, value ? on : off);
Executed by:
  • Self test
46
278 else-
279 printf ("set %co %s\n", value ? '-' : '+', name);
executed 81 times by 1 test: printf ("set %co %s\n", value ? '-' : '+', name);
Executed by:
  • Self test
81
280}-
281-
282void-
283list_minus_o_opts (mode, reusable)-
284 int mode, reusable;-
285{-
286 register int i;-
287 int *on_or_off, value;-
288-
289 for (i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEevaluated 162 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-162
290 {-
291 if (o_options[i].letter)
o_options[i].letterDescription
TRUEevaluated 114 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
48-114
292 {-
293 value = 0;-
294 on_or_off = find_flag (o_options[i].letter);-
295 if (on_or_off == FLAG_UNKNOWN)
on_or_off == (int *)0Description
TRUEnever evaluated
FALSEevaluated 114 times by 1 test
Evaluated by:
  • Self test
0-114
296 on_or_off = &value;
never executed: on_or_off = &value;
0
297 if (mode == -1 || mode == *on_or_off)
mode == -1Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 57 times by 1 test
Evaluated by:
  • Self test
mode == *on_or_offDescription
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
24-57
298 print_minus_o_option (o_options[i].name, *on_or_off, reusable);
executed 90 times by 1 test: print_minus_o_option (o_options[i].name, *on_or_off, reusable);
Executed by:
  • Self test
90
299 }
executed 114 times by 1 test: end of block
Executed by:
  • Self test
114
300 else-
301 {-
302 value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name);
(o_options[i].get_func)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 36 times by 1 test
Evaluated by:
  • Self test
12-36
303 if (mode == -1 || mode == value)
mode == -1Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
mode == valueDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-24
304 print_minus_o_option (o_options[i].name, value, reusable);
executed 37 times by 1 test: print_minus_o_option (o_options[i].name, value, reusable);
Executed by:
  • Self test
37
305 }
executed 48 times by 1 test: end of block
Executed by:
  • Self test
48
306 }-
307}
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
308-
309char **-
310get_minus_o_opts ()-
311{-
312 char **ret;-
313 int i;-
314-
315 ret = strvec_create (N_O_OPTIONS + 1);-
316 for (i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEnever evaluated
FALSEnever evaluated
0
317 ret[i] = o_options[i].name;
never executed: ret[i] = o_options[i].name;
0
318 ret[i] = (char *)NULL;-
319 return ret;
never executed: return ret;
0
320}-
321-
322char *-
323get_current_options ()-
324{-
325 char *temp;-
326 int i;-
327-
328 temp = (char *)xmalloc (1 + N_O_OPTIONS);-
329 for (i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEnever evaluated
FALSEnever evaluated
0
330 {-
331 if (o_options[i].letter)
o_options[i].letterDescription
TRUEnever evaluated
FALSEnever evaluated
0
332 temp[i] = *(find_flag (o_options[i].letter));
never executed: temp[i] = *(find_flag (o_options[i].letter));
0
333 else-
334 temp[i] = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name);
never executed: temp[i] = ((o_options[i].get_func) ? (*o_options[i].get_func) (o_options[i].name) : (*o_options[i].variable));
(o_options[i].get_func)Description
TRUEnever evaluated
FALSEnever evaluated
0
335 }-
336 temp[i] = '\0';-
337 return (temp);
never executed: return (temp);
0
338}-
339-
340void-
341set_current_options (bitmap)-
342 const char *bitmap;-
343{-
344 int i;-
345-
346 if (bitmap == 0)
bitmap == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
347 return;
never executed: return;
0
348 for (i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEnever evaluated
FALSEnever evaluated
0
349 {-
350 if (o_options[i].letter)
o_options[i].letterDescription
TRUEnever evaluated
FALSEnever evaluated
0
351 change_flag (o_options[i].letter, bitmap[i] ? FLAG_ON : FLAG_OFF);
never executed: change_flag (o_options[i].letter, bitmap[i] ? '-' : '+');
0
352 else-
353 SET_BINARY_O_OPTION_VALUE (i, bitmap[i] ? FLAG_ON : FLAG_OFF, o_options[i].name);
never executed: ((o_options[i].set_func) ? (*o_options[i].set_func) (bitmap[i] ? '-' : '+', o_options[i].name) : (*o_options[i].variable = (bitmap[i] ? '-' : '+' == '-')));
0
354 }-
355}
never executed: end of block
0
356-
357static int-
358set_ignoreeof (on_or_off, option_name)-
359 int on_or_off;-
360 char *option_name;-
361{-
362 ignoreeof = on_or_off == FLAG_ON;-
363 unbind_variable_noref ("ignoreeof");-
364 if (ignoreeof)
ignoreeofDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
3-9
365 bind_variable ("IGNOREEOF", "10", 0);
executed 3 times by 1 test: bind_variable ("IGNOREEOF", "10", 0);
Executed by:
  • Self test
3
366 else-
367 unbind_variable_noref ("IGNOREEOF");
executed 9 times by 1 test: unbind_variable_noref ("IGNOREEOF");
Executed by:
  • Self test
9
368 sv_ignoreeof ("IGNOREEOF");-
369 return 0;
executed 12 times by 1 test: return 0;
Executed by:
  • Self test
12
370}-
371-
372static int-
373set_posix_mode (on_or_off, option_name)-
374 int on_or_off;-
375 char *option_name;-
376{-
377 posixly_correct = on_or_off == FLAG_ON;-
378 if (posixly_correct == 0)
posixly_correct == 0Description
TRUEevaluated 108 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 106 times by 1 test
Evaluated by:
  • Self test
106-108
379 unbind_variable_noref ("POSIXLY_CORRECT");
executed 108 times by 1 test: unbind_variable_noref ("POSIXLY_CORRECT");
Executed by:
  • Self test
108
380 else-
381 bind_variable ("POSIXLY_CORRECT", "y", 0);
executed 106 times by 1 test: bind_variable ("POSIXLY_CORRECT", "y", 0);
Executed by:
  • Self test
106
382 sv_strict_posix ("POSIXLY_CORRECT");-
383 return (0);
executed 214 times by 1 test: return (0);
Executed by:
  • Self test
214
384}-
385-
386#if defined (READLINE)-
387/* Magic. This code `knows' how readline handles rl_editing_mode. */-
388static int-
389set_edit_mode (on_or_off, option_name)-
390 int on_or_off;-
391 char *option_name;-
392{-
393 int isemacs;-
394-
395 if (on_or_off == FLAG_ON)
on_or_off == '-'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1
396 {-
397 rl_variable_bind ("editing-mode", option_name);-
398-
399 if (interactive)
interactiveDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
400 with_input_from_stdin ();
never executed: with_input_from_stdin ();
0
401 no_line_editing = 0;-
402 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
403 else-
404 {-
405 isemacs = rl_editing_mode == 1;-
406 if ((isemacs && *option_name == 'e') || (!isemacs && *option_name == 'v'))
isemacsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*option_name == 'e'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
!isemacsDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
*option_name == 'v'Description
TRUEnever evaluated
FALSEnever evaluated
0-1
407 {-
408 if (interactive)
interactiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
409 with_input_from_stream (stdin, "stdin");
never executed: with_input_from_stream ( stdin , "stdin");
0
410 no_line_editing = 1;-
411 }
never executed: end of block
0
412 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
413 return 1-no_line_editing;
executed 2 times by 1 test: return 1-no_line_editing;
Executed by:
  • Self test
2
414}-
415-
416static int-
417get_edit_mode (name)-
418 char *name;-
419{-
420 return (*name == 'e' ? no_line_editing == 0 && rl_editing_mode == 1
executed 19606 times by 1 test: return (*name == 'e' ? no_line_editing == 0 && rl_editing_mode == 1 : no_line_editing == 0 && rl_editing_mode == 0);
Executed by:
  • Self test
19606
421 : no_line_editing == 0 && rl_editing_mode == 0);
executed 19606 times by 1 test: return (*name == 'e' ? no_line_editing == 0 && rl_editing_mode == 1 : no_line_editing == 0 && rl_editing_mode == 0);
Executed by:
  • Self test
19606
422}-
423#endif /* READLINE */-
424-
425#if defined (HISTORY)-
426static int-
427bash_set_history (on_or_off, option_name)-
428 int on_or_off;-
429 char *option_name;-
430{-
431 if (on_or_off == FLAG_ON)
on_or_off == '-'Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-33
432 {-
433 enable_history_list = 1;-
434 bash_history_enable ();-
435 if (history_lines_this_session == 0)
history_lines_...s_session == 0Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-32
436 load_history ();
executed 32 times by 1 test: load_history ();
Executed by:
  • Self test
32
437 }
executed 33 times by 1 test: end of block
Executed by:
  • Self test
33
438 else-
439 {-
440 enable_history_list = 0;-
441 bash_history_disable ();-
442 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
443 return (1 - enable_history_list);
executed 36 times by 1 test: return (1 - enable_history_list);
Executed by:
  • Self test
36
444}-
445#endif-
446-
447int-
448set_minus_o_option (on_or_off, option_name)-
449 int on_or_off;-
450 char *option_name;-
451{-
452 register int i;-
453-
454 for (i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEevaluated 13926 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-13926
455 {-
456 if (STREQ (option_name, o_options[i].name))
never executed: __result = (((const unsigned char *) (const char *) ( option_name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( o_options[i].name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(option_name)[...ns[i].name)[0]Description
TRUEevaluated 2110 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11816 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEevaluated 887 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1223 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-11816
457 {-
458 if (o_options[i].letter == 0)
o_options[i].letter == 0Description
TRUEevaluated 441 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 446 times by 1 test
Evaluated by:
  • Self test
441-446
459 {-
460 previous_option_value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name);
(o_options[i].get_func)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 439 times by 1 test
Evaluated by:
  • Self test
2-439
461 SET_BINARY_O_OPTION_VALUE (i, on_or_off, option_name);-
462 return (EXECUTION_SUCCESS);
executed 441 times by 1 test: return (0);
Executed by:
  • Self test
441
463 }-
464 else-
465 {-
466 if ((previous_option_value = change_flag (o_options[i].letter, on_or_off)) == FLAG_ERROR)
(previous_opti...or_off)) == -1Description
TRUEnever evaluated
FALSEevaluated 446 times by 1 test
Evaluated by:
  • Self test
0-446
467 {-
468 sh_invalidoptname (option_name);-
469 return (EXECUTION_FAILURE);
never executed: return (1);
0
470 }-
471 else-
472 return (EXECUTION_SUCCESS);
executed 446 times by 1 test: return (0);
Executed by:
  • Self test
446
473 }-
474-
475 }-
476 }
executed 13039 times by 1 test: end of block
Executed by:
  • Self test
13039
477-
478 sh_invalidoptname (option_name);-
479 return (EX_USAGE);
executed 2 times by 1 test: return (258);
Executed by:
  • Self test
2
480}-
481-
482static void-
483print_all_shell_variables ()-
484{-
485 SHELL_VAR **vars;-
486-
487 vars = all_shell_variables ();-
488 if (vars)
varsDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
489 {-
490 print_var_list (vars);-
491 free (vars);-
492 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
493-
494 /* POSIX.2 does not allow function names and definitions to be output when-
495 `set' is invoked without options (PASC Interp #202). */-
496 if (posixly_correct == 0)
posixly_correct == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
497 {-
498 vars = all_shell_functions ();-
499 if (vars)
varsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-4
500 {-
501 print_func_list (vars);-
502 free (vars);-
503 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
504 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
505}
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
506-
507void-
508set_shellopts ()-
509{-
510 char *value;-
511 char tflag[N_O_OPTIONS];-
512 int vsize, i, vptr, *ip, exported;-
513 SHELL_VAR *v;-
514-
515 for (vsize = i = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEevaluated 264492 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9796 times by 1 test
Evaluated by:
  • Self test
9796-264492
516 {-
517 tflag[i] = 0;-
518 if (o_options[i].letter)
o_options[i].letterDescription
TRUEevaluated 186124 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 78368 times by 1 test
Evaluated by:
  • Self test
78368-186124
519 {-
520 ip = find_flag (o_options[i].letter);-
521 if (ip && *ip)
ipDescription
TRUEevaluated 186124 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*ipDescription
TRUEevaluated 20894 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 165230 times by 1 test
Evaluated by:
  • Self test
0-186124
522 {-
523 vsize += strlen (o_options[i].name) + 1;-
524 tflag[i] = 1;-
525 }
executed 20894 times by 1 test: end of block
Executed by:
  • Self test
20894
526 }
executed 186124 times by 1 test: end of block
Executed by:
  • Self test
186124
527 else if (GET_BINARY_O_OPTION_VALUE (i, o_options[i].name))
((o_options[i]...[i].variable))Description
TRUEevaluated 10454 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 67914 times by 1 test
Evaluated by:
  • Self test
(o_options[i].get_func)Description
TRUEevaluated 19592 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 58776 times by 1 test
Evaluated by:
  • Self test
10454-67914
528 {-
529 vsize += strlen (o_options[i].name) + 1;-
530 tflag[i] = 1;-
531 }
executed 10454 times by 1 test: end of block
Executed by:
  • Self test
10454
532 }
executed 264492 times by 1 test: end of block
Executed by:
  • Self test
264492
533-
534 value = (char *)xmalloc (vsize + 1);-
535-
536 for (i = vptr = 0; o_options[i].name; i++)
o_options[i].nameDescription
TRUEevaluated 264492 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9796 times by 1 test
Evaluated by:
  • Self test
9796-264492
537 {-
538 if (tflag[i])
tflag[i]Description
TRUEevaluated 31348 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 233144 times by 1 test
Evaluated by:
  • Self test
31348-233144
539 {-
540 strcpy (value + vptr, o_options[i].name);-
541 vptr += strlen (o_options[i].name);-
542 value[vptr++] = ':';-
543 }
executed 31348 times by 1 test: end of block
Executed by:
  • Self test
31348
544 }
executed 264492 times by 1 test: end of block
Executed by:
  • Self test
264492
545-
546 if (vptr)
vptrDescription
TRUEevaluated 9796 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9796
547 vptr--; /* cut off trailing colon */
executed 9796 times by 1 test: vptr--;
Executed by:
  • Self test
9796
548 value[vptr] = '\0';-
549-
550 v = find_variable ("SHELLOPTS");-
551-
552 /* Turn off the read-only attribute so we can bind the new value, and-
553 note whether or not the variable was exported. */-
554 if (v)
vDescription
TRUEevaluated 4349 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
4349-5447
555 {-
556 VUNSETATTR (v, att_readonly);-
557 exported = exported_p (v);-
558 }
executed 4349 times by 1 test: end of block
Executed by:
  • Self test
4349
559 else-
560 exported = 0;
executed 5447 times by 1 test: exported = 0;
Executed by:
  • Self test
5447
561-
562 v = bind_variable ("SHELLOPTS", value, 0);-
563-
564 /* Turn the read-only attribute back on, and turn off the export attribute-
565 if it was set implicitly by mark_modified_vars and SHELLOPTS was not-
566 exported before we bound the new value. */-
567 VSETATTR (v, att_readonly);-
568 if (mark_modified_vars && exported == 0 && exported_p (v))
mark_modified_varsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9795 times by 1 test
Evaluated by:
  • Self test
exported == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((((v)->attrib... (0x0000001)))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9795
569 VUNSETATTR (v, att_exported);
executed 1 time by 1 test: ((v)->attributes &= ~(0x0000001));
Executed by:
  • Self test
1
570-
571 free (value);-
572}
executed 9796 times by 1 test: end of block
Executed by:
  • Self test
9796
573-
574void-
575parse_shellopts (value)-
576 char *value;-
577{-
578 char *vname;-
579 int vptr;-
580-
581 vptr = 0;-
582 while (vname = extract_colon_unit (value, &vptr))
vname = extrac...(value, &vptr)Description
TRUEnever evaluated
FALSEnever evaluated
0
583 {-
584 set_minus_o_option (FLAG_ON, vname);-
585 free (vname);-
586 }
never executed: end of block
0
587}
never executed: end of block
0
588-
589void-
590initialize_shell_options (no_shellopts)-
591 int no_shellopts;-
592{-
593 char *temp;-
594 SHELL_VAR *var;-
595-
596 if (no_shellopts == 0)
no_shellopts == 0Description
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5447
597 {-
598 var = find_variable ("SHELLOPTS");-
599 /* set up any shell options we may have inherited. */-
600 if (var && imported_p (var))
varDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5430 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0008000)))Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-5430
601 {-
602 temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var));
((((var)->attr... (0x0000004)))Description
TRUEnever evaluated
FALSEnever evaluated
((((var)->attr... (0x0000040)))Description
TRUEnever evaluated
FALSEnever evaluated
0
603 if (temp)
tempDescription
TRUEnever evaluated
FALSEnever evaluated
0
604 {-
605 parse_shellopts (temp);-
606 free (temp);-
607 }
never executed: end of block
0
608 }
never executed: end of block
0
609 }
executed 5447 times by 1 test: end of block
Executed by:
  • Self test
5447
610-
611 /* Set up the $SHELLOPTS variable. */-
612 set_shellopts ();-
613}
executed 5447 times by 1 test: end of block
Executed by:
  • Self test
5447
614-
615/* Reset the values of the -o options that are not also shell flags. This is-
616 called from execute_cmd.c:initialize_subshell() when setting up a subshell-
617 to run an executable shell script without a leading `#!'. */-
618void-
619reset_shell_options ()-
620{-
621 pipefail_opt = 0;-
622 ignoreeof = 0;-
623-
624#if defined (STRICT_POSIX)-
625 posixly_correct = 1;-
626#else-
627 posixly_correct = 0;-
628#endif-
629#if defined (HISTORY)-
630 dont_save_function_defs = 0;-
631 remember_on_history = enable_history_list = 1;-
632#endif-
633}
executed 15 times by 1 test: end of block
Executed by:
  • Self test
15
634-
635/* Set some flags from the word values in the input list. If LIST is empty,-
636 then print out the values of the variables instead. If LIST contains-
637 non-flags, then set $1 - $9 to the successive words of LIST. */-
638int-
639set_builtin (list)-
640 WORD_LIST *list;-
641{-
642 int on_or_off, flag_name, force_assignment, opts_changed, rv, r;-
643 register char *arg;-
644 char s[3];-
645-
646 if (list == 0)
list == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3259648 times by 1 test
Evaluated by:
  • Self test
6-3259648
647 {-
648 print_all_shell_variables ();-
649 return (sh_chkwrite (EXECUTION_SUCCESS));
executed 6 times by 1 test: return (sh_chkwrite (0));
Executed by:
  • Self test
6
650 }-
651-
652 /* Check validity of flag arguments. */-
653 rv = EXECUTION_SUCCESS;-
654 reset_internal_getopt ();-
655 while ((flag_name = internal_getopt (list, optflags)) != -1)
(flag_name = i...tflags)) != -1Description
TRUEevaluated 1230 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3259647 times by 1 test
Evaluated by:
  • Self test
1230-3259647
656 {-
657 switch (flag_name)-
658 {-
659 case 'i': /* don't allow set -i */
never executed: case 'i':
0
660 s[0] = list_opttype;-
661 s[1] = 'i';-
662 s[2] = '\0';-
663 sh_invalidopt (s);-
664 builtin_usage ();-
665 return (EX_USAGE);
never executed: return (258);
0
666 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
667 case '?':
executed 1 time by 1 test: case '?':
Executed by:
  • Self test
1
668 builtin_usage ();-
669 return (list_optopt == '?' ? EXECUTION_SUCCESS : EX_USAGE);
executed 1 time by 1 test: return (list_optopt == '?' ? 0 : 258);
Executed by:
  • Self test
1
670 default:
executed 1229 times by 1 test: default:
Executed by:
  • Self test
1229
671 break;
executed 1229 times by 1 test: break;
Executed by:
  • Self test
1229
672 }-
673 }-
674 -
675 /* Do the set command. While the list consists of words starting with-
676 '-' or '+' treat them as flags, otherwise, start assigning them to-
677 $1 ... $n. */-
678 for (force_assignment = opts_changed = 0; list; )
listDescription
TRUEevaluated 3259820 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1053 times by 1 test
Evaluated by:
  • Self test
1053-3259820
679 {-
680 arg = list->word->word;-
681-
682 /* If the argument is `--' or `-' then signal the end of the list-
683 and remember the remaining arguments. */-
684 if (arg[0] == '-' && (!arg[1] || (arg[1] == '-' && !arg[2])))
arg[0] == '-'Description
TRUEevaluated 11204 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3248616 times by 1 test
Evaluated by:
  • Self test
!arg[1]Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11200 times by 1 test
Evaluated by:
  • Self test
arg[1] == '-'Description
TRUEevaluated 10290 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 910 times by 1 test
Evaluated by:
  • Self test
!arg[2]Description
TRUEevaluated 10290 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3248616
685 {-
686 list = list->next;-
687-
688 /* `set --' unsets the positional parameters. */-
689 if (arg[1] == '-')
arg[1] == '-'Description
TRUEevaluated 10290 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-10290
690 force_assignment = 1;
executed 10290 times by 1 test: force_assignment = 1;
Executed by:
  • Self test
10290
691-
692 /* Until told differently, the old shell behaviour of-
693 `set - [arg ...]' being equivalent to `set +xv [arg ...]'-
694 stands. Posix.2 says the behaviour is marked as obsolescent. */-
695 else-
696 {-
697 change_flag ('x', '+');-
698 change_flag ('v', '+');-
699 opts_changed = 1;-
700 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
701-
702 break;
executed 10294 times by 1 test: break;
Executed by:
  • Self test
10294
703 }-
704-
705 if ((on_or_off = *arg) && (on_or_off == '-' || on_or_off == '+'))
(on_or_off = *arg)Description
TRUEevaluated 3249497 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
on_or_off == '-'Description
TRUEevaluated 910 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3248587 times by 1 test
Evaluated by:
  • Self test
on_or_off == '+'Description
TRUEevaluated 319 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3248268 times by 1 test
Evaluated by:
  • Self test
29-3249497
706 {-
707 while (flag_name = *++arg)
flag_name = *++argDescription
TRUEevaluated 1229 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1226 times by 1 test
Evaluated by:
  • Self test
1226-1229
708 {-
709 if (flag_name == '?')
flag_name == '?'Description
TRUEnever evaluated
FALSEevaluated 1229 times by 1 test
Evaluated by:
  • Self test
0-1229
710 {-
711 builtin_usage ();-
712 return (EXECUTION_SUCCESS);
never executed: return (0);
0
713 }-
714 else if (flag_name == 'o') /* -+o option-name */
flag_name == 'o'Description
TRUEevaluated 871 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 358 times by 1 test
Evaluated by:
  • Self test
358-871
715 {-
716 char *option_name;-
717 WORD_LIST *opt;-
718-
719 opt = list->next;-
720-
721 if (opt == 0)
opt == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 869 times by 1 test
Evaluated by:
  • Self test
2-869
722 {-
723 list_minus_o_opts (-1, (on_or_off == '+'));-
724 rv = sh_chkwrite (rv);-
725 continue;
executed 2 times by 1 test: continue;
Executed by:
  • Self test
2
726 }-
727-
728 option_name = opt->word->word;-
729-
730 if (option_name == 0 || *option_name == '\0' ||
option_name == 0Description
TRUEnever evaluated
FALSEevaluated 869 times by 1 test
Evaluated by:
  • Self test
*option_name == '\0'Description
TRUEnever evaluated
FALSEevaluated 869 times by 1 test
Evaluated by:
  • Self test
0-869
731 *option_name == '-' || *option_name == '+')
*option_name == '-'Description
TRUEnever evaluated
FALSEevaluated 869 times by 1 test
Evaluated by:
  • Self test
*option_name == '+'Description
TRUEnever evaluated
FALSEevaluated 869 times by 1 test
Evaluated by:
  • Self test
0-869
732 {-
733 list_minus_o_opts (-1, (on_or_off == '+'));-
734 continue;
never executed: continue;
0
735 }-
736 list = list->next; /* Skip over option name. */-
737-
738 opts_changed = 1;-
739 if ((r = set_minus_o_option (on_or_off, option_name)) != EXECUTION_SUCCESS)
(r = set_minus...on_name)) != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 867 times by 1 test
Evaluated by:
  • Self test
2-867
740 {-
741 set_shellopts ();-
742 return (r);
executed 2 times by 1 test: return (r);
Executed by:
  • Self test
2
743 }-
744 }
executed 867 times by 1 test: end of block
Executed by:
  • Self test
867
745 else if (change_flag (flag_name, on_or_off) == FLAG_ERROR)
change_flag (f..._or_off) == -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 357 times by 1 test
Evaluated by:
  • Self test
1-357
746 {-
747 s[0] = on_or_off;-
748 s[1] = flag_name;-
749 s[2] = '\0';-
750 sh_invalidopt (s);-
751 builtin_usage ();-
752 set_shellopts ();-
753 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
754 }-
755 opts_changed = 1;-
756 }
executed 1224 times by 1 test: end of block
Executed by:
  • Self test
1224
757 }
executed 1226 times by 1 test: end of block
Executed by:
  • Self test
1226
758 else-
759 {-
760 break;
executed 3248297 times by 1 test: break;
Executed by:
  • Self test
3248297
761 }-
762 list = list->next;-
763 }
executed 1226 times by 1 test: end of block
Executed by:
  • Self test
1226
764-
765 /* Assigning $1 ... $n */-
766 if (list || force_assignment)
listDescription
TRUEevaluated 3258566 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1078 times by 1 test
Evaluated by:
  • Self test
force_assignmentDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1053 times by 1 test
Evaluated by:
  • Self test
25-3258566
767 remember_args (list, 1);
executed 3258591 times by 1 test: remember_args (list, 1);
Executed by:
  • Self test
3258591
768 /* Set up new value of $SHELLOPTS */-
769 if (opts_changed)
opts_changedDescription
TRUEevaluated 1057 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3258587 times by 1 test
Evaluated by:
  • Self test
1057-3258587
770 set_shellopts ();
executed 1057 times by 1 test: set_shellopts ();
Executed by:
  • Self test
1057
771 return (rv);
executed 3259644 times by 1 test: return (rv);
Executed by:
  • Self test
3259644
772}-
773-
774$BUILTIN unset-
775$FUNCTION unset_builtin-
776$SHORT_DOC unset [-f] [-v] [-n] [name ...]-
777Unset values and attributes of shell variables and functions.-
778-
779For each NAME, remove the corresponding variable or function.-
780-
781Options:-
782 -f treat each NAME as a shell function-
783 -v treat each NAME as a shell variable-
784 -n treat each NAME as a name reference and unset the variable itself-
785 rather than the variable it references-
786-
787Without options, unset first tries to unset a variable, and if that fails,-
788tries to unset a function.-
789-
790Some variables cannot be unset; also see `readonly'.-
791-
792Exit Status:-
793Returns success unless an invalid option is given or a NAME is read-only.-
794$END-
795-
796#define NEXT_VARIABLE() any_failed++; list = list->next; continue;-
797-
798int-
799unset_builtin (list)-
800 WORD_LIST *list;-
801{-
802 int unset_function, unset_variable, unset_array, opt, nameref, any_failed;-
803 int global_unset_func, global_unset_var;-
804 char *name, *tname;-
805-
806 unset_function = unset_variable = unset_array = nameref = any_failed = 0;-
807 global_unset_func = global_unset_var = 0;-
808-
809 reset_internal_getopt ();-
810 while ((opt = internal_getopt (list, "fnv")) != -1)
(opt = interna... "fnv")) != -1Description
TRUEevaluated 6589 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12384 times by 1 test
Evaluated by:
  • Self test
6589-12384
811 {-
812 switch (opt)-
813 {-
814 case 'f':
executed 3529 times by 1 test: case 'f':
Executed by:
  • Self test
3529
815 global_unset_func = 1;-
816 break;
executed 3529 times by 1 test: break;
Executed by:
  • Self test
3529
817 case 'v':
executed 2884 times by 1 test: case 'v':
Executed by:
  • Self test
2884
818 global_unset_var = 1;-
819 break;
executed 2884 times by 1 test: break;
Executed by:
  • Self test
2884
820 case 'n':
executed 171 times by 1 test: case 'n':
Executed by:
  • Self test
171
821 nameref = 1;-
822 break;
executed 171 times by 1 test: break;
Executed by:
  • Self test
171
823 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
824 default:
executed 5 times by 1 test: default:
Executed by:
  • Self test
5
825 builtin_usage ();-
826 return (EX_USAGE);
executed 5 times by 1 test: return (258);
Executed by:
  • Self test
5
827 }-
828 }-
829-
830 list = loptend;-
831-
832 if (global_unset_func && global_unset_var)
global_unset_funcDescription
TRUEevaluated 3529 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8855 times by 1 test
Evaluated by:
  • Self test
global_unset_varDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3524 times by 1 test
Evaluated by:
  • Self test
5-8855
833 {-
834 builtin_error (_("cannot simultaneously unset a function and a variable"));-
835 return (EXECUTION_FAILURE);
executed 5 times by 1 test: return (1);
Executed by:
  • Self test
5
836 }-
837 else if (unset_function && nameref)
unset_functionDescription
TRUEnever evaluated
FALSEevaluated 12379 times by 1 test
Evaluated by:
  • Self test
namerefDescription
TRUEnever evaluated
FALSEnever evaluated
0-12379
838 nameref = 0;
never executed: nameref = 0;
0
839-
840 while (list)
listDescription
TRUEevaluated 13977 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12379 times by 1 test
Evaluated by:
  • Self test
12379-13977
841 {-
842 SHELL_VAR *var;-
843 int tem;-
844#if defined (ARRAY_VARS)-
845 char *t;-
846#endif-
847-
848 name = list->word->word;-
849-
850 unset_function = global_unset_func;-
851 unset_variable = global_unset_var;-
852-
853#if defined (ARRAY_VARS)-
854 unset_array = 0;-
855 if (!unset_function && nameref == 0 && valid_array_reference (name, assoc_expand_once)) /* XXX valid array reference second arg was 0 */
!unset_functionDescription
TRUEevaluated 9316 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4661 times by 1 test
Evaluated by:
  • Self test
nameref == 0Description
TRUEevaluated 9134 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 182 times by 1 test
Evaluated by:
  • Self test
valid_array_re...c_expand_once)Description
TRUEevaluated 139 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8995 times by 1 test
Evaluated by:
  • Self test
139-9316
856 {-
857 t = strchr (name, '[');
__builtin_constant_p ( '[' )Description
TRUEevaluated 139 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
!__builtin_constant_p ( name )Description
TRUEevaluated 139 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( '[' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 139 times by 1 test
Evaluated by:
  • Self test
0-139
858 *t++ = '\0';-
859 unset_array++;-
860 }
executed 139 times by 1 test: end of block
Executed by:
  • Self test
139
861#endif-
862 /* Get error checking out of the way first. The low-level functions-
863 just perform the unset, relying on the caller to verify. */-
864-
865 /* Bash allows functions with names which are not valid identifiers-
866 to be created when not in posix mode, so check only when in posix-
867 mode when unsetting a function. */-
868 if (((unset_function && posixly_correct) || !unset_function) && legal_identifier (name) == 0)
unset_functionDescription
TRUEevaluated 4661 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9316 times by 1 test
Evaluated by:
  • Self test
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 4661 times by 1 test
Evaluated by:
  • Self test
!unset_functionDescription
TRUEevaluated 9316 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4661 times by 1 test
Evaluated by:
  • Self test
legal_identifier (name) == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9307 times by 1 test
Evaluated by:
  • Self test
0-9316
869 {-
870 sh_invalidid (name);-
871 NEXT_VARIABLE ();
executed 9 times by 1 test: continue;
Executed by:
  • Self test
9
872 }-
873-
874 /* Only search for functions here if -f supplied. */-
875 var = unset_function ? find_function (name)
unset_functionDescription
TRUEevaluated 4661 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9307 times by 1 test
Evaluated by:
  • Self test
4661-9307
876 : (nameref ? find_variable_last_nameref (name, 0) : find_variable (name));
namerefDescription
TRUEevaluated 182 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9125 times by 1 test
Evaluated by:
  • Self test
182-9125
877-
878 /* Some variables (but not functions yet) cannot be unset, period. */-
879 if (var && unset_function == 0 && non_unsettable_p (var))
varDescription
TRUEevaluated 11941 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2027 times by 1 test
Evaluated by:
  • Self test
unset_function == 0Description
TRUEevaluated 7291 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4650 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0002000)))Description
TRUEnever evaluated
FALSEevaluated 7291 times by 1 test
Evaluated by:
  • Self test
0-11941
880 {-
881 builtin_error (_("%s: cannot unset"), name);-
882 NEXT_VARIABLE ();
never executed: continue;
0
883 }-
884-
885 /* if we have a nameref we want to use it */-
886 if (var && unset_function == 0 && nameref == 0 && STREQ (name, name_cell(var)) == 0)
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ((var)->name) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
varDescription
TRUEevaluated 11941 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2027 times by 1 test
Evaluated by:
  • Self test
unset_function == 0Description
TRUEevaluated 7291 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4650 times by 1 test
Evaluated by:
  • Self test
nameref == 0Description
TRUEevaluated 7211 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 80 times by 1 test
Evaluated by:
  • Self test
((name)[0] == ... }) == 0) == 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7192 times by 1 test
Evaluated by:
  • Self test
(name)[0] == (...ar)->name))[0]Description
TRUEevaluated 7195 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEevaluated 7192 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-11941
887 name = name_cell (var);
executed 19 times by 1 test: name = ((var)->name);
Executed by:
  • Self test
19
888-
889 /* Posix.2 says try variables first, then functions. If we would-
890 find a function after unsuccessfully searching for a variable,-
891 note that we're acting on a function now as if -f were-
892 supplied. The readonly check below takes care of it. */-
893 if (var == 0 && nameref == 0 && unset_variable == 0 && unset_function == 0)
var == 0Description
TRUEevaluated 2027 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11941 times by 1 test
Evaluated by:
  • Self test
nameref == 0Description
TRUEevaluated 1925 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
unset_variable == 0Description
TRUEevaluated 1743 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 182 times by 1 test
Evaluated by:
  • Self test
unset_function == 0Description
TRUEevaluated 1732 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-11941
894 {-
895 if (var = find_function (name))
var = find_function (name)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1728 times by 1 test
Evaluated by:
  • Self test
4-1728
896 unset_function = 1;
executed 4 times by 1 test: unset_function = 1;
Executed by:
  • Self test
4
897 }
executed 1732 times by 1 test: end of block
Executed by:
  • Self test
1732
898-
899 /* Posix.2 says that unsetting readonly variables is an error. */-
900 if (var && readonly_p (var))
varDescription
TRUEevaluated 11945 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2023 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0000002)))Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11925 times by 1 test
Evaluated by:
  • Self test
20-11945
901 {-
902 builtin_error (_("%s: cannot unset: readonly %s"),-
903 var->name, unset_function ? "function" : "variable");-
904 NEXT_VARIABLE ();
executed 20 times by 1 test: continue;
Executed by:
  • Self test
20
905 }-
906-
907 /* Unless the -f option is supplied, the name refers to a variable. */-
908#if defined (ARRAY_VARS)-
909 if (var && unset_array)
varDescription
TRUEevaluated 11925 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2023 times by 1 test
Evaluated by:
  • Self test
unset_arrayDescription
TRUEevaluated 109 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11816 times by 1 test
Evaluated by:
  • Self test
109-11925
910 {-
911 /* Let unbind_array_element decide what to do with non-array vars */-
912 tem = unbind_array_element (var, t, assoc_expand_once); /* XXX new third arg */-
913 if (tem == -2 && array_p (var) == 0 && assoc_p (var) == 0)
tem == -2Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 100 times by 1 test
Evaluated by:
  • Self test
((((var)->attr...000004))) == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((((var)->attr...000040))) == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-100
914 {-
915 builtin_error (_("%s: not an array variable"), var->name);-
916 NEXT_VARIABLE ();
executed 9 times by 1 test: continue;
Executed by:
  • Self test
9
917 }-
918 else if (tem < 0)
tem < 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 94 times by 1 test
Evaluated by:
  • Self test
6-94
919 any_failed++;
executed 6 times by 1 test: any_failed++;
Executed by:
  • Self test
6
920 }
executed 100 times by 1 test: end of block
Executed by:
  • Self test
100
921 else-
922#endif /* ARRAY_VARS */-
923 /* If we're trying to unset a nameref variable whose value isn't a set-
924 variable, make sure we still try to unset the nameref's value */-
925 if (var == 0 && nameref == 0 && unset_function == 0)
var == 0Description
TRUEevaluated 2023 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11816 times by 1 test
Evaluated by:
  • Self test
nameref == 0Description
TRUEevaluated 1921 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
unset_function == 0Description
TRUEevaluated 1910 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-11816
926 {-
927 var = find_variable_last_nameref (name, 0);-
928 if (var && nameref_p (var))
varDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1903 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0000800)))Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1903
929 {-
930#if defined (ARRAY_VARS)-
931 if (valid_array_reference (nameref_cell (var), 0))
valid_array_re...r)->value), 0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-6
932 {-
933 tname = savestring (nameref_cell (var));-
934 if (var = array_variable_part (tname, 0, &t, (int *)0))
var = array_va... &t, (int *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3
935 tem = unbind_array_element (var, t, assoc_expand_once); /* XXX new third arg */
executed 3 times by 1 test: tem = unbind_array_element (var, t, assoc_expand_once);
Executed by:
  • Self test
3
936 free (tname);-
937 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
938 else-
939#endif-
940 tem = unbind_variable (nameref_cell (var));
executed 1 time by 1 test: tem = unbind_variable (((var)->value));
Executed by:
  • Self test
1
941 }-
942 else-
943 tem = unbind_variable (name);
executed 1903 times by 1 test: tem = unbind_variable (name);
Executed by:
  • Self test
1903
944 }-
945 else-
946 tem = unset_function ? unbind_func (name) : (nameref ? unbind_nameref (name) : unbind_variable (name));
executed 11929 times by 1 test: tem = unset_function ? unbind_func (name) : (nameref ? unbind_nameref (name) : unbind_variable (name));
Executed by:
  • Self test
unset_functionDescription
TRUEevaluated 4660 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7269 times by 1 test
Evaluated by:
  • Self test
namerefDescription
TRUEevaluated 180 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7089 times by 1 test
Evaluated by:
  • Self test
180-11929
947-
948 /* This is what Posix.2 says: ``If neither -f nor -v-
949 is specified, the name refers to a variable; if a variable by-
950 that name does not exist, a function by that name, if any,-
951 shall be unset.'' */-
952 if (tem == -1 && nameref == 0 && unset_function == 0 && unset_variable == 0)
tem == -1Description
TRUEevaluated 1916 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12023 times by 1 test
Evaluated by:
  • Self test
nameref == 0Description
TRUEevaluated 1916 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
unset_function == 0Description
TRUEevaluated 1905 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
unset_variable == 0Description
TRUEevaluated 1723 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 182 times by 1 test
Evaluated by:
  • Self test
0-12023
953 tem = unbind_func (name);
executed 1723 times by 1 test: tem = unbind_func (name);
Executed by:
  • Self test
1723
954-
955 name = list->word->word; /* reset above for namerefs */-
956-
957 /* SUSv3, POSIX.1-2001 say: ``Unsetting a variable or function that-
958 was not previously set shall not be considered an error.'' */-
959-
960 if (unset_function == 0)
unset_function == 0Description
TRUEevaluated 9279 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4660 times by 1 test
Evaluated by:
  • Self test
4660-9279
961 stupidly_hack_special_variables (name);
executed 9279 times by 1 test: stupidly_hack_special_variables (name);
Executed by:
  • Self test
9279
962-
963 list = list->next;-
964 }
executed 13939 times by 1 test: end of block
Executed by:
  • Self test
13939
965-
966 return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
executed 12379 times by 1 test: return (any_failed ? 1 : 0);
Executed by:
  • Self test
12379
967}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2