OpenCoverage

make_cmd.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/make_cmd.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* make_cmd.c -- Functions for making instances of the various-
2 parser constructs. */-
3-
4/* Copyright (C) 1989-2018 Free Software Foundation, Inc.-
5-
6 This file is part of GNU Bash, the Bourne Again SHell.-
7-
8 Bash is free software: you can redistribute it and/or modify-
9 it under the terms of the GNU General Public License as published by-
10 the Free Software Foundation, either version 3 of the License, or-
11 (at your option) any later version.-
12-
13 Bash is distributed in the hope that it will be useful,-
14 but WITHOUT ANY WARRANTY; without even the implied warranty of-
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16 GNU General Public License for more details.-
17-
18 You should have received a copy of the GNU General Public License-
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20*/-
21-
22#include "config.h"-
23-
24#include <stdio.h>-
25#include "bashtypes.h"-
26#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)-
27# include <sys/file.h>-
28#endif-
29#include "filecntl.h"-
30#include "bashansi.h"-
31#if defined (HAVE_UNISTD_H)-
32# include <unistd.h>-
33#endif-
34-
35#include "bashintl.h"-
36-
37#include "shell.h"-
38#include "execute_cmd.h"-
39#include "parser.h"-
40#include "flags.h"-
41#include "input.h"-
42-
43#if defined (JOB_CONTROL)-
44#include "jobs.h"-
45#endif-
46-
47#include "shmbutil.h"-
48-
49int here_doc_first_line = 0;-
50-
51/* Object caching */-
52sh_obj_cache_t wdcache = {0, 0, 0};-
53sh_obj_cache_t wlcache = {0, 0, 0};-
54-
55#define WDCACHESIZE 128-
56#define WLCACHESIZE 128-
57-
58static COMMAND *make_for_or_select __P((enum command_type, WORD_DESC *, WORD_LIST *, COMMAND *, int));-
59#if defined (ARITH_FOR_COMMAND)-
60static WORD_LIST *make_arith_for_expr __P((char *));-
61#endif-
62static COMMAND *make_until_or_while __P((enum command_type, COMMAND *, COMMAND *));-
63-
64void-
65cmd_init ()-
66{-
67 ocache_create (wdcache, WORD_DESC, WDCACHESIZE);-
68 ocache_create (wlcache, WORD_LIST, WLCACHESIZE);-
69}
executed 5446 times by 1 test: end of block
Executed by:
  • Self test
5446
70-
71WORD_DESC *-
72alloc_word_desc ()-
73{-
74 WORD_DESC *temp;-
75-
76 ocache_alloc (wdcache, WORD_DESC, temp);
executed 637154073 times by 1 test: end of block
Executed by:
  • Self test
executed 38743462 times by 1 test: (temp) = (WORD_DESC *)sh_xmalloc((sizeof (WORD_DESC)), "make_cmd.c", 76);
Executed by:
  • Self test
(wdcache).nc > 0Description
TRUEevaluated 637154073 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38743462 times by 1 test
Evaluated by:
  • Self test
38743462-637154073
77 temp->flags = 0;-
78 temp->word = 0;-
79 return temp;
executed 675897535 times by 1 test: return temp;
Executed by:
  • Self test
675897535
80}-
81-
82WORD_DESC *-
83make_bare_word (string)-
84 const char *string;-
85{-
86 WORD_DESC *temp;-
87-
88 temp = alloc_word_desc ();-
89-
90 if (*string)
*stringDescription
TRUEevaluated 324499458 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 799 times by 1 test
Evaluated by:
  • Self test
799-324499458
91 temp->word = savestring (string);
executed 324499458 times by 1 test: temp->word = (char *)strcpy (sh_xmalloc((1 + strlen (string)), "make_cmd.c", 91), (string));
Executed by:
  • Self test
324499458
92 else-
93 {-
94 temp->word = (char *)xmalloc (1);-
95 temp->word[0] = '\0';-
96 }
executed 799 times by 1 test: end of block
Executed by:
  • Self test
799
97-
98 return (temp);
executed 324500257 times by 1 test: return (temp);
Executed by:
  • Self test
324500257
99}-
100-
101WORD_DESC *-
102make_word_flags (w, string)-
103 WORD_DESC *w;-
104 const char *string;-
105{-
106 register int i;-
107 size_t slen;-
108 DECLARE_MBSTATE;-
109-
110 i = 0;-
111 slen = strlen (string);-
112 while (i < slen)
i < slenDescription
TRUEevaluated 5505273 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4640662 times by 1 test
Evaluated by:
  • Self test
4640662-5505273
113 {-
114 switch (string[i])-
115 {-
116 case '$':
executed 1032 times by 1 test: case '$':
Executed by:
  • Self test
1032
117 w->flags |= W_HASDOLLAR;-
118 break;
executed 1032 times by 1 test: break;
Executed by:
  • Self test
1032
119 case '\\':
executed 800 times by 1 test: case '\\':
Executed by:
  • Self test
800
120 break; /* continue the loop */
executed 800 times by 1 test: break;
Executed by:
  • Self test
800
121 case '\'':
executed 804 times by 1 test: case '\'':
Executed by:
  • Self test
804
122 case '`':
executed 43 times by 1 test: case '`':
Executed by:
  • Self test
43
123 case '"':
executed 1817 times by 1 test: case '"':
Executed by:
  • Self test
1817
124 w->flags |= W_QUOTED;-
125 break;
executed 2664 times by 1 test: break;
Executed by:
  • Self test
2664
126 }-
127-
128 ADVANCE_CHAR (string, slen, i);
executed 4957037 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 142935 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 90 times by 1 test: end of block
Executed by:
  • Self test
executed 9 times by 1 test: end of block
Executed by:
  • Self test
never executed: (i)++;
executed 5100053 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 405211 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 5100062 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 405211 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 4957037 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 143025 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 5100053 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 143025 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 142935 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 5100062 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5100053 times by 1 test
Evaluated by:
  • Self test
0-5100062
129 }
executed 5505273 times by 1 test: end of block
Executed by:
  • Self test
5505273
130-
131 return (w);
executed 4640662 times by 1 test: return (w);
Executed by:
  • Self test
4640662
132}-
133-
134WORD_DESC *-
135make_word (string)-
136 const char *string;-
137{-
138 WORD_DESC *temp;-
139-
140 temp = make_bare_word (string);-
141 return (make_word_flags (temp, string));
executed 4630111 times by 1 test: return (make_word_flags (temp, string));
Executed by:
  • Self test
4630111
142}-
143-
144WORD_DESC *-
145make_word_from_token (token)-
146 int token;-
147{-
148 char tokenizer[2];-
149-
150 tokenizer[0] = token;-
151 tokenizer[1] = '\0';-
152-
153 return (make_word (tokenizer));
executed 2 times by 1 test: return (make_word (tokenizer));
Executed by:
  • Self test
2
154}-
155-
156WORD_LIST *-
157make_word_list (word, wlink)-
158 WORD_DESC *word;-
159 WORD_LIST *wlink;-
160{-
161 WORD_LIST *temp;-
162-
163 ocache_alloc (wlcache, WORD_LIST, temp);
executed 494987269 times by 1 test: end of block
Executed by:
  • Self test
executed 4702745 times by 1 test: (temp) = (WORD_LIST *)sh_xmalloc((sizeof (WORD_LIST)), "make_cmd.c", 163);
Executed by:
  • Self test
(wlcache).nc > 0Description
TRUEevaluated 494987269 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4702745 times by 1 test
Evaluated by:
  • Self test
4702745-494987269
164-
165 temp->word = word;-
166 temp->next = wlink;-
167 return (temp);
executed 499690014 times by 1 test: return (temp);
Executed by:
  • Self test
499690014
168}-
169-
170COMMAND *-
171make_command (type, pointer)-
172 enum command_type type;-
173 SIMPLE_COM *pointer;-
174{-
175 COMMAND *temp;-
176-
177 temp = (COMMAND *)xmalloc (sizeof (COMMAND));-
178 temp->type = type;-
179 temp->value.Simple = pointer;-
180 temp->value.Simple->flags = temp->flags = 0;-
181 temp->redirects = (REDIRECT *)NULL;-
182 return (temp);
executed 337203 times by 1 test: return (temp);
Executed by:
  • Self test
337203
183}-
184-
185COMMAND *-
186command_connect (com1, com2, connector)-
187 COMMAND *com1, *com2;-
188 int connector;-
189{-
190 CONNECTION *temp;-
191-
192 temp = (CONNECTION *)xmalloc (sizeof (CONNECTION));-
193 temp->connector = connector;-
194 temp->first = com1;-
195 temp->second = com2;-
196 return (make_command (cm_connection, (SIMPLE_COM *)temp));
executed 194753 times by 1 test: return (make_command (cm_connection, (SIMPLE_COM *)temp));
Executed by:
  • Self test
194753
197}-
198-
199static COMMAND *-
200make_for_or_select (type, name, map_list, action, lineno)-
201 enum command_type type;-
202 WORD_DESC *name;-
203 WORD_LIST *map_list;-
204 COMMAND *action;-
205 int lineno;-
206{-
207 FOR_COM *temp;-
208-
209 temp = (FOR_COM *)xmalloc (sizeof (FOR_COM));-
210 temp->flags = 0;-
211 temp->name = name;-
212 temp->line = lineno;-
213 temp->map_list = map_list;-
214 temp->action = action;-
215 return (make_command (type, (SIMPLE_COM *)temp));
executed 25661 times by 1 test: return (make_command (type, (SIMPLE_COM *)temp));
Executed by:
  • Self test
25661
216}-
217-
218COMMAND *-
219make_for_command (name, map_list, action, lineno)-
220 WORD_DESC *name;-
221 WORD_LIST *map_list;-
222 COMMAND *action;-
223 int lineno;-
224{-
225 return (make_for_or_select (cm_for, name, map_list, action, lineno));
executed 25652 times by 1 test: return (make_for_or_select (cm_for, name, map_list, action, lineno));
Executed by:
  • Self test
25652
226}-
227-
228COMMAND *-
229make_select_command (name, map_list, action, lineno)-
230 WORD_DESC *name;-
231 WORD_LIST *map_list;-
232 COMMAND *action;-
233 int lineno;-
234{-
235#if defined (SELECT_COMMAND)-
236 return (make_for_or_select (cm_select, name, map_list, action, lineno));
executed 9 times by 1 test: return (make_for_or_select (cm_select, name, map_list, action, lineno));
Executed by:
  • Self test
9
237#else-
238 last_command_exit_value = 2;-
239 return ((COMMAND *)NULL);-
240#endif-
241}-
242-
243#if defined (ARITH_FOR_COMMAND)-
244static WORD_LIST *-
245make_arith_for_expr (s)-
246 char *s;-
247{-
248 WORD_LIST *result;-
249 WORD_DESC *wd;-
250-
251 if (s == 0 || *s == '\0')
s == 0Description
TRUEevaluated 2428 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7922 times by 1 test
Evaluated by:
  • Self test
*s == '\0'Description
TRUEnever evaluated
FALSEevaluated 7922 times by 1 test
Evaluated by:
  • Self test
0-7922
252 return ((WORD_LIST *)NULL);
executed 2428 times by 1 test: return ((WORD_LIST *) ((void *)0) );
Executed by:
  • Self test
2428
253 wd = make_word (s);-
254 wd->flags |= W_NOGLOB|W_NOSPLIT|W_QUOTED|W_DQUOTE; /* no word splitting or globbing */-
255#if defined (PROCESS_SUBSTITUTION)-
256 wd->flags |= W_NOPROCSUB; /* no process substitution */-
257#endif-
258 result = make_word_list (wd, (WORD_LIST *)NULL);-
259 return result;
executed 7922 times by 1 test: return result;
Executed by:
  • Self test
7922
260}-
261#endif-
262-
263/* Note that this function calls dispose_words on EXPRS, since it doesn't-
264 use the word list directly. We free it here rather than at the caller-
265 because no other function in this file requires that the caller free-
266 any arguments. */-
267COMMAND *-
268make_arith_for_command (exprs, action, lineno)-
269 WORD_LIST *exprs;-
270 COMMAND *action;-
271 int lineno;-
272{-
273#if defined (ARITH_FOR_COMMAND)-
274 ARITH_FOR_COM *temp;-
275 WORD_LIST *init, *test, *step;-
276 char *s, *t, *start;-
277 int nsemi, i;-
278-
279 init = test = step = (WORD_LIST *)NULL;-
280 /* Parse the string into the three component sub-expressions. */-
281 start = t = s = exprs->word->word;-
282 for (nsemi = 0; ;)-
283 {-
284 /* skip whitespace at the start of each sub-expression. */-
285 while (whitespace (*s))
((*s) == ' ')Description
TRUEevaluated 6506 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7923 times by 1 test
Evaluated by:
  • Self test
((*s) == '\t')Description
TRUEnever evaluated
FALSEevaluated 7923 times by 1 test
Evaluated by:
  • Self test
0-7923
286 s++;
executed 6506 times by 1 test: s++;
Executed by:
  • Self test
6506
287 start = s;-
288 /* skip to the semicolon or EOS */-
289 i = skip_to_delim (start, 0, ";", SD_NOJMP|SD_NOPROCSUB);-
290 s = start + i;-
291-
292 t = (i > 0) ? substring (start, 0, i) : (char *)NULL;
(i > 0)Description
TRUEevaluated 5495 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2428 times by 1 test
Evaluated by:
  • Self test
2428-5495
293-
294 nsemi++;-
295 switch (nsemi)-
296 {-
297 case 1:
executed 2641 times by 1 test: case 1:
Executed by:
  • Self test
2641
298 init = make_arith_for_expr (t);-
299 break;
executed 2641 times by 1 test: break;
Executed by:
  • Self test
2641
300 case 2:
executed 2641 times by 1 test: case 2:
Executed by:
  • Self test
2641
301 test = make_arith_for_expr (t);-
302 break;
executed 2641 times by 1 test: break;
Executed by:
  • Self test
2641
303 case 3:
executed 2640 times by 1 test: case 3:
Executed by:
  • Self test
2640
304 step = make_arith_for_expr (t);-
305 break;
executed 2640 times by 1 test: break;
Executed by:
  • Self test
2640
306 }-
307-
308 FREE (t);
executed 5495 times by 1 test: sh_xfree((t), "make_cmd.c", 308);
Executed by:
  • Self test
tDescription
TRUEevaluated 5495 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2428 times by 1 test
Evaluated by:
  • Self test
2428-5495
309 if (*s == '\0')
*s == '\0'Description
TRUEevaluated 2641 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5282 times by 1 test
Evaluated by:
  • Self test
2641-5282
310 break;
executed 2641 times by 1 test: break;
Executed by:
  • Self test
2641
311 s++; /* skip over semicolon */-
312 }
executed 5282 times by 1 test: end of block
Executed by:
  • Self test
5282
313-
314 if (nsemi != 3)
nsemi != 3Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2639 times by 1 test
Evaluated by:
  • Self test
2-2639
315 {-
316 if (nsemi < 3)
nsemi < 3Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1
317 parser_error (lineno, _("syntax error: arithmetic expression required"));
executed 1 time by 1 test: parser_error (lineno, dcgettext (((void *)0), "syntax error: arithmetic expression required" , 5) );
Executed by:
  • Self test
1
318 else-
319 parser_error (lineno, _("syntax error: `;' unexpected"));
executed 1 time by 1 test: parser_error (lineno, dcgettext (((void *)0), "syntax error: `;' unexpected" , 5) );
Executed by:
  • Self test
1
320 parser_error (lineno, _("syntax error: `((%s))'"), exprs->word->word);-
321 free (init);-
322 free (test);-
323 free (step);-
324 last_command_exit_value = 2;-
325 return ((COMMAND *)NULL);
executed 2 times by 1 test: return ((COMMAND *) ((void *)0) );
Executed by:
  • Self test
2
326 }-
327-
328 temp = (ARITH_FOR_COM *)xmalloc (sizeof (ARITH_FOR_COM));-
329 temp->flags = 0;-
330 temp->line = lineno;-
331 temp->init = init ? init : make_arith_for_expr ("1");
initDescription
TRUEevaluated 1831 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 808 times by 1 test
Evaluated by:
  • Self test
808-1831
332 temp->test = test ? test : make_arith_for_expr ("1");
testDescription
TRUEevaluated 1627 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1012 times by 1 test
Evaluated by:
  • Self test
1012-1627
333 temp->step = step ? step : make_arith_for_expr ("1");
stepDescription
TRUEevaluated 2031 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 608 times by 1 test
Evaluated by:
  • Self test
608-2031
334 temp->action = action;-
335-
336 dispose_words (exprs);-
337 return (make_command (cm_arith_for, (SIMPLE_COM *)temp));
executed 2639 times by 1 test: return (make_command (cm_arith_for, (SIMPLE_COM *)temp));
Executed by:
  • Self test
2639
338#else-
339 dispose_words (exprs);-
340 last_command_exit_value = 2;-
341 return ((COMMAND *)NULL);-
342#endif /* ARITH_FOR_COMMAND */-
343}-
344-
345COMMAND *-
346make_group_command (command)-
347 COMMAND *command;-
348{-
349 GROUP_COM *temp;-
350-
351 temp = (GROUP_COM *)xmalloc (sizeof (GROUP_COM));-
352 temp->command = command;-
353 return (make_command (cm_group, (SIMPLE_COM *)temp));
executed 12022 times by 1 test: return (make_command (cm_group, (SIMPLE_COM *)temp));
Executed by:
  • Self test
12022
354}-
355-
356COMMAND *-
357make_case_command (word, clauses, lineno)-
358 WORD_DESC *word;-
359 PATTERN_LIST *clauses;-
360 int lineno;-
361{-
362 CASE_COM *temp;-
363-
364 temp = (CASE_COM *)xmalloc (sizeof (CASE_COM));-
365 temp->flags = 0;-
366 temp->line = lineno;-
367 temp->word = word;-
368 temp->clauses = REVERSE_LIST (clauses, PATTERN_LIST *);
clausesDescription
TRUEevaluated 78108 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
clauses->nextDescription
TRUEevaluated 50301 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27807 times by 1 test
Evaluated by:
  • Self test
2-78108
369 return (make_command (cm_case, (SIMPLE_COM *)temp));
executed 78110 times by 1 test: return (make_command (cm_case, (SIMPLE_COM *)temp));
Executed by:
  • Self test
78110
370}-
371-
372PATTERN_LIST *-
373make_pattern_list (patterns, action)-
374 WORD_LIST *patterns;-
375 COMMAND *action;-
376{-
377 PATTERN_LIST *temp;-
378-
379 temp = (PATTERN_LIST *)xmalloc (sizeof (PATTERN_LIST));-
380 temp->patterns = REVERSE_LIST (patterns, WORD_LIST *);
patternsDescription
TRUEevaluated 158270 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
patterns->nextDescription
TRUEevaluated 6820 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 151450 times by 1 test
Evaluated by:
  • Self test
0-158270
381 temp->action = action;-
382 temp->next = NULL;-
383 temp->flags = 0;-
384 return (temp);
executed 158270 times by 1 test: return (temp);
Executed by:
  • Self test
158270
385}-
386-
387COMMAND *-
388make_if_command (test, true_case, false_case)-
389 COMMAND *test, *true_case, *false_case;-
390{-
391 IF_COM *temp;-
392-
393 temp = (IF_COM *)xmalloc (sizeof (IF_COM));-
394 temp->flags = 0;-
395 temp->test = test;-
396 temp->true_case = true_case;-
397 temp->false_case = false_case;-
398 return (make_command (cm_if, (SIMPLE_COM *)temp));
executed 1621 times by 1 test: return (make_command (cm_if, (SIMPLE_COM *)temp));
Executed by:
  • Self test
1621
399}-
400-
401static COMMAND *-
402make_until_or_while (which, test, action)-
403 enum command_type which;-
404 COMMAND *test, *action;-
405{-
406 WHILE_COM *temp;-
407-
408 temp = (WHILE_COM *)xmalloc (sizeof (WHILE_COM));-
409 temp->flags = 0;-
410 temp->test = test;-
411 temp->action = action;-
412 return (make_command (which, (SIMPLE_COM *)temp));
executed 5172 times by 1 test: return (make_command (which, (SIMPLE_COM *)temp));
Executed by:
  • Self test
5172
413}-
414-
415COMMAND *-
416make_while_command (test, action)-
417 COMMAND *test, *action;-
418{-
419 return (make_until_or_while (cm_while, test, action));
executed 5156 times by 1 test: return (make_until_or_while (cm_while, test, action));
Executed by:
  • Self test
5156
420}-
421-
422COMMAND *-
423make_until_command (test, action)-
424 COMMAND *test, *action;-
425{-
426 return (make_until_or_while (cm_until, test, action));
executed 16 times by 1 test: return (make_until_or_while (cm_until, test, action));
Executed by:
  • Self test
16
427}-
428-
429COMMAND *-
430make_arith_command (exp)-
431 WORD_LIST *exp;-
432{-
433#if defined (DPAREN_ARITHMETIC)-
434 COMMAND *command;-
435 ARITH_COM *temp;-
436-
437 command = (COMMAND *)xmalloc (sizeof (COMMAND));-
438 command->value.Arith = temp = (ARITH_COM *)xmalloc (sizeof (ARITH_COM));-
439-
440 temp->flags = 0;-
441 temp->line = line_number;-
442 temp->exp = exp;-
443-
444 command->type = cm_arith;-
445 command->redirects = (REDIRECT *)NULL;-
446 command->flags = 0;-
447-
448 return (command);
executed 47077 times by 1 test: return (command);
Executed by:
  • Self test
47077
449#else-
450 last_command_exit_value = 2;-
451 return ((COMMAND *)NULL);-
452#endif-
453}-
454-
455#if defined (COND_COMMAND)-
456struct cond_com *-
457make_cond_node (type, op, left, right)-
458 int type;-
459 WORD_DESC *op;-
460 struct cond_com *left, *right;-
461{-
462 COND_COM *temp;-
463-
464 temp = (COND_COM *)xmalloc (sizeof (COND_COM));-
465 temp->flags = 0;-
466 temp->line = line_number;-
467 temp->type = type;-
468 temp->op = op;-
469 temp->left = left;-
470 temp->right = right;-
471-
472 return (temp);
executed 1926 times by 1 test: return (temp);
Executed by:
  • Self test
1926
473}-
474#endif-
475-
476COMMAND *-
477make_cond_command (cond_node)-
478 COND_COM *cond_node;-
479{-
480#if defined (COND_COMMAND)-
481 COMMAND *command;-
482-
483 command = (COMMAND *)xmalloc (sizeof (COMMAND));-
484 command->value.Cond = cond_node;-
485-
486 command->type = cm_cond;-
487 command->redirects = (REDIRECT *)NULL;-
488 command->flags = 0;-
489 command->line = cond_node ? cond_node->line : 0;
cond_nodeDescription
TRUEevaluated 574 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-574
490-
491 return (command);
executed 574 times by 1 test: return (command);
Executed by:
  • Self test
574
492#else-
493 last_command_exit_value = 2;-
494 return ((COMMAND *)NULL);-
495#endif-
496}-
497-
498COMMAND *-
499make_bare_simple_command ()-
500{-
501 COMMAND *command;-
502 SIMPLE_COM *temp;-
503-
504 command = (COMMAND *)xmalloc (sizeof (COMMAND));-
505 command->value.Simple = temp = (SIMPLE_COM *)xmalloc (sizeof (SIMPLE_COM));-
506-
507 temp->flags = 0;-
508 temp->line = line_number;-
509 temp->words = (WORD_LIST *)NULL;-
510 temp->redirects = (REDIRECT *)NULL;-
511-
512 command->type = cm_simple;-
513 command->redirects = (REDIRECT *)NULL;-
514 command->flags = 0;-
515-
516 return (command);
executed 1038411 times by 1 test: return (command);
Executed by:
  • Self test
1038411
517}-
518-
519/* Return a command which is the connection of the word or redirection-
520 in ELEMENT, and the command * or NULL in COMMAND. */-
521COMMAND *-
522make_simple_command (element, command)-
523 ELEMENT element;-
524 COMMAND *command;-
525{-
526 /* If we are starting from scratch, then make the initial command-
527 structure. Also note that we have to fill in all the slots, since-
528 malloc doesn't return zeroed space. */-
529 if (command == 0)
command == 0Description
TRUEevaluated 1038344 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1023618 times by 1 test
Evaluated by:
  • Self test
1023618-1038344
530 {-
531 command = make_bare_simple_command ();-
532 parser_state |= PST_REDIRLIST;-
533 }
executed 1038344 times by 1 test: end of block
Executed by:
  • Self test
1038344
534-
535 if (element.word)
element.wordDescription
TRUEevaluated 2026542 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35420 times by 1 test
Evaluated by:
  • Self test
35420-2026542
536 {-
537 command->value.Simple->words = make_word_list (element.word, command->value.Simple->words);-
538 parser_state &= ~PST_REDIRLIST;-
539 }
executed 2026542 times by 1 test: end of block
Executed by:
  • Self test
2026542
540 else if (element.redirect)
element.redirectDescription
TRUEevaluated 35415 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-35415
541 {-
542 REDIRECT *r = element.redirect;-
543 /* Due to the way <> is implemented, there may be more than a single-
544 redirection in element.redirect. We just follow the chain as far-
545 as it goes, and hook onto the end. */-
546 while (r->next)
r->nextDescription
TRUEnever evaluated
FALSEevaluated 35415 times by 1 test
Evaluated by:
  • Self test
0-35415
547 r = r->next;
never executed: r = r->next;
0
548 r->next = command->value.Simple->redirects;-
549 command->value.Simple->redirects = element.redirect;-
550 }
executed 35415 times by 1 test: end of block
Executed by:
  • Self test
35415
551-
552 return (command);
executed 2061962 times by 1 test: return (command);
Executed by:
  • Self test
2061962
553}-
554-
555/* Because we are Bourne compatible, we read the input for this-
556 << or <<- redirection now, from wherever input is coming from.-
557 We store the input read into a WORD_DESC. Replace the text of-
558 the redirectee.word with the new input text. If <<- is on,-
559 then remove leading TABS from each line. */-
560void-
561make_here_document (temp, lineno)-
562 REDIRECT *temp;-
563 int lineno;-
564{-
565 int kill_leading, redir_len;-
566 char *redir_word, *document, *full_line;-
567 int document_index, document_size, delim_unquoted;-
568-
569 if (temp->instruction != r_deblank_reading_until &&
temp->instruct..._reading_untilDescription
TRUEevaluated 1696 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
38-1696
570 temp->instruction != r_reading_until)
temp->instruct..._reading_untilDescription
TRUEnever evaluated
FALSEevaluated 1696 times by 1 test
Evaluated by:
  • Self test
0-1696
571 {-
572 internal_error (_("make_here_document: bad instruction type %d"), temp->instruction);-
573 return;
never executed: return;
0
574 }-
575-
576 kill_leading = temp->instruction == r_deblank_reading_until;-
577-
578 document = (char *)NULL;-
579 document_index = document_size = 0;-
580-
581 /* Quote removal is the only expansion performed on the delimiter-
582 for here documents, making it an extremely special case. */-
583 redir_word = string_quote_removal (temp->redirectee.filename->word, 0);-
584-
585 /* redirection_expand will return NULL if the expansion results in-
586 multiple words or no words. Check for that here, and just abort-
587 this here document if it does. */-
588 if (redir_word)
redir_wordDescription
TRUEevaluated 1734 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1734
589 redir_len = strlen (redir_word);
executed 1734 times by 1 test: redir_len = strlen (redir_word);
Executed by:
  • Self test
1734
590 else-
591 {-
592 temp->here_doc_eof = (char *)xmalloc (1);-
593 temp->here_doc_eof[0] = '\0';-
594 goto document_done;
never executed: goto document_done;
0
595 }-
596-
597 free (temp->redirectee.filename->word);-
598 temp->here_doc_eof = redir_word;-
599-
600 /* Read lines from wherever lines are coming from.-
601 For each line read, if kill_leading, then kill the-
602 leading tab characters.-
603 If the line matches redir_word exactly, then we have-
604 manufactured the document. Otherwise, add the line to the-
605 list of lines in the document. */-
606-
607 /* If the here-document delimiter was quoted, the lines should-
608 be read verbatim from the input. If it was not quoted, we-
609 need to perform backslash-quoted newline removal. */-
610 delim_unquoted = (temp->redirectee.filename->flags & W_QUOTED) == 0;-
611 while (full_line = read_secondary_line (delim_unquoted))
full_line = re...elim_unquoted)Description
TRUEevaluated 5241 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
17-5241
612 {-
613 register char *line;-
614 int len;-
615-
616 here_doc_first_line = 0;-
617 line = full_line;-
618 line_number++;-
619-
620 /* If set -v is in effect, echo the line read. read_secondary_line/-
621 read_a_line leaves the newline at the end, so don't print another. */-
622 if (echo_input_at_read)
echo_input_at_readDescription
TRUEnever evaluated
FALSEevaluated 5241 times by 1 test
Evaluated by:
  • Self test
0-5241
623 fprintf (stderr, "%s", line);
never executed: fprintf ( stderr , "%s", line);
0
624-
625 if (kill_leading && *line)
kill_leadingDescription
TRUEevaluated 80 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5161 times by 1 test
Evaluated by:
  • Self test
*lineDescription
TRUEevaluated 80 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5161
626 {-
627 /* Hack: To be compatible with some Bourne shells, we-
628 check the word before stripping the whitespace. This-
629 is a hack, though. */-
630 if (STREQN (line, redir_word, redir_len) && line[redir_len] == '\n')
never executed: __result = (((const unsigned char *) (const char *) ( line ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( redir_word ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(redir_len == 0)Description
TRUEnever evaluated
FALSEevaluated 80 times by 1 test
Evaluated by:
  • Self test
((redir_len ==...len ))) == 0))Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 78 times by 1 test
Evaluated by:
  • Self test
(line)[0] == (redir_word)[0]Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 77 times by 1 test
Evaluated by:
  • Self test
(__extension__...r_len ))) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
__builtin_cons... ( redir_len )Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( line )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( line ...( redir_len ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...( redir_word )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( redir...( redir_len ))Description
TRUEnever evaluated
FALSEnever evaluated
__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
line[redir_len] == '\n'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-80
631 goto document_done;
executed 2 times by 1 test: goto document_done;
Executed by:
  • Self test
2
632-
633 while (*line == '\t')
*line == '\t'Description
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 78 times by 1 test
Evaluated by:
  • Self test
46-78
634 line++;
executed 46 times by 1 test: line++;
Executed by:
  • Self test
46
635 }
executed 78 times by 1 test: end of block
Executed by:
  • Self test
78
636-
637 if (*line == 0)
*line == 0Description
TRUEnever evaluated
FALSEevaluated 5239 times by 1 test
Evaluated by:
  • Self test
0-5239
638 continue;
never executed: continue;
0
639-
640 if (STREQN (line, redir_word, redir_len) && line[redir_len] == '\n')
never executed: __result = (((const unsigned char *) (const char *) ( line ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( redir_word ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(redir_len == 0)Description
TRUEnever evaluated
FALSEevaluated 5239 times by 1 test
Evaluated by:
  • Self test
((redir_len ==...len ))) == 0))Description
TRUEevaluated 1728 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3511 times by 1 test
Evaluated by:
  • Self test
(line)[0] == (redir_word)[0]Description
TRUEevaluated 1731 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3508 times by 1 test
Evaluated by:
  • Self test
(__extension__...r_len ))) == 0Description
TRUEevaluated 1728 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
__builtin_cons... ( redir_len )Description
TRUEnever evaluated
FALSEevaluated 1731 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( line )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( line ...( redir_len ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...( redir_word )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( redir...( redir_len ))Description
TRUEnever evaluated
FALSEnever evaluated
__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
line[redir_len] == '\n'Description
TRUEevaluated 1715 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
0-5239
641 goto document_done;
executed 1715 times by 1 test: goto document_done;
Executed by:
  • Self test
1715
642-
643 len = strlen (line);-
644 if (len + document_index >= document_size)
len + document... document_sizeDescription
TRUEevaluated 3088 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 436 times by 1 test
Evaluated by:
  • Self test
436-3088
645 {-
646 document_size = document_size ? 2 * (document_size + len) : len + 2;
document_sizeDescription
TRUEevaluated 1357 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1731 times by 1 test
Evaluated by:
  • Self test
1357-1731
647 document = (char *)xrealloc (document, document_size);-
648 }
executed 3088 times by 1 test: end of block
Executed by:
  • Self test
3088
649-
650 /* len is guaranteed to be > 0 because of the check for line-
651 being an empty string before the call to strlen. */-
652 FASTCOPY (line, document + document_index, len);-
653 document_index += len;-
654 }
executed 3524 times by 1 test: end of block
Executed by:
  • Self test
3524
655-
656 if (full_line == 0)
full_line == 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-17
657 internal_warning (_("here-document at line %d delimited by end-of-file (wanted `%s')"), lineno, redir_word);
executed 17 times by 1 test: internal_warning ( dcgettext (((void *)0), "here-document at line %d delimited by end-of-file (wanted `%s')" , 5) , lineno, redir_word);
Executed by:
  • Self test
17
658-
659document_done:
code before this statement executed 17 times by 1 test: document_done:
Executed by:
  • Self test
17
660 if (document)
documentDescription
TRUEevaluated 1731 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-1731
661 document[document_index] = '\0';
executed 1731 times by 1 test: document[document_index] = '\0';
Executed by:
  • Self test
1731
662 else-
663 {-
664 document = (char *)xmalloc (1);-
665 document[0] = '\0';-
666 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
667 temp->redirectee.filename->word = document;-
668 here_doc_first_line = 0;-
669}
executed 1734 times by 1 test: end of block
Executed by:
  • Self test
1734
670-
671/* Generate a REDIRECT from SOURCE, DEST, and INSTRUCTION.-
672 INSTRUCTION is the instruction type, SOURCE is a file descriptor,-
673 and DEST is a file descriptor or a WORD_DESC *. */-
674REDIRECT *-
675make_redirection (source, instruction, dest_and_filename, flags)-
676 REDIRECTEE source;-
677 enum r_instruction instruction;-
678 REDIRECTEE dest_and_filename;-
679 int flags;-
680{-
681 REDIRECT *temp;-
682 WORD_DESC *w;-
683 int wlen;-
684 intmax_t lfd;-
685-
686 temp = (REDIRECT *)xmalloc (sizeof (REDIRECT));-
687-
688 /* First do the common cases. */-
689 temp->redirector = source;-
690 temp->redirectee = dest_and_filename;-
691 temp->here_doc_eof = 0;-
692 temp->instruction = instruction;-
693 temp->flags = 0;-
694 temp->rflags = flags;-
695 temp->next = (REDIRECT *)NULL;-
696-
697 switch (instruction)-
698 {-
699-
700 case r_output_direction: /* >foo */
executed 11271 times by 1 test: case r_output_direction:
Executed by:
  • Self test
11271
701 case r_output_force: /* >| foo */
executed 19 times by 1 test: case r_output_force:
Executed by:
  • Self test
19
702 case r_err_and_out: /* &>filename */
executed 20 times by 1 test: case r_err_and_out:
Executed by:
  • Self test
20
703 temp->flags = O_TRUNC | O_WRONLY | O_CREAT;-
704 break;
executed 11310 times by 1 test: break;
Executed by:
  • Self test
11310
705-
706 case r_appending_to: /* >>foo */
executed 33 times by 1 test: case r_appending_to:
Executed by:
  • Self test
33
707 case r_append_err_and_out: /* &>> filename */
executed 4 times by 1 test: case r_append_err_and_out:
Executed by:
  • Self test
4
708 temp->flags = O_APPEND | O_WRONLY | O_CREAT;-
709 break;
executed 37 times by 1 test: break;
Executed by:
  • Self test
37
710-
711 case r_input_direction: /* <foo */
executed 2893 times by 1 test: case r_input_direction:
Executed by:
  • Self test
2893
712 case r_inputa_direction: /* foo & makes this. */
never executed: case r_inputa_direction:
0
713 temp->flags = O_RDONLY;-
714 break;
executed 2893 times by 1 test: break;
Executed by:
  • Self test
2893
715-
716 case r_input_output: /* <>foo */
executed 18 times by 1 test: case r_input_output:
Executed by:
  • Self test
18
717 temp->flags = O_RDWR | O_CREAT;-
718 break;
executed 18 times by 1 test: break;
Executed by:
  • Self test
18
719-
720 case r_deblank_reading_until: /* <<-foo */
executed 38 times by 1 test: case r_deblank_reading_until:
Executed by:
  • Self test
38
721 case r_reading_until: /* << foo */
executed 1713 times by 1 test: case r_reading_until:
Executed by:
  • Self test
1713
722 case r_reading_string: /* <<< foo */
executed 65 times by 1 test: case r_reading_string:
Executed by:
  • Self test
65
723 case r_close_this: /* <&- */
executed 667544 times by 1 test: case r_close_this:
Executed by:
  • Self test
667544
724 case r_duplicating_input: /* 1<&2 */
executed 1439 times by 1 test: case r_duplicating_input:
Executed by:
  • Self test
1439
725 case r_duplicating_output: /* 1>&2 */
executed 51836 times by 1 test: case r_duplicating_output:
Executed by:
  • Self test
51836
726 break;
executed 722635 times by 1 test: break;
Executed by:
  • Self test
722635
727-
728 /* the parser doesn't pass these. */-
729 case r_move_input: /* 1<&2- */
executed 3 times by 1 test: case r_move_input:
Executed by:
  • Self test
3
730 case r_move_output: /* 1>&2- */
executed 3 times by 1 test: case r_move_output:
Executed by:
  • Self test
3
731 case r_move_input_word: /* 1<&$foo- */
never executed: case r_move_input_word:
0
732 case r_move_output_word: /* 1>&$foo- */
never executed: case r_move_output_word:
0
733 break;
executed 6 times by 1 test: break;
Executed by:
  • Self test
6
734-
735 /* The way the lexer works we have to do this here. */-
736 case r_duplicating_input_word: /* 1<&$foo */
executed 20 times by 1 test: case r_duplicating_input_word:
Executed by:
  • Self test
20
737 case r_duplicating_output_word: /* 1>&$foo */
executed 117 times by 1 test: case r_duplicating_output_word:
Executed by:
  • Self test
117
738 w = dest_and_filename.filename;-
739 wlen = strlen (w->word) - 1;-
740 if (w->word[wlen] == '-') /* Yuck */
w->word[wlen] == '-'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 129 times by 1 test
Evaluated by:
  • Self test
8-129
741 {-
742 w->word[wlen] = '\0';-
743 if (all_digits (w->word) && legal_number (w->word, &lfd) && lfd == (int)lfd)
all_digits (w->word)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
legal_number (w->word, &lfd)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lfd == (int)lfdDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
744 {-
745 dispose_word (w);-
746 temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input : r_move_output;
(instruction =...ng_input_word)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
747 temp->redirectee.dest = lfd;-
748 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
749 else-
750 temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input_word : r_move_output_word;
executed 6 times by 1 test: temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input_word : r_move_output_word;
Executed by:
  • Self test
(instruction =...ng_input_word)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-6
751 }-
752 -
753 break;
executed 137 times by 1 test: break;
Executed by:
  • Self test
137
754-
755 default:
never executed: default:
0
756 programming_error (_("make_redirection: redirection instruction `%d' out of range"), instruction);-
757 abort ();
never executed: abort ();
0
758 break;
never executed: break;
0
759 }-
760 return (temp);
executed 737036 times by 1 test: return (temp);
Executed by:
  • Self test
737036
761}-
762-
763COMMAND *-
764make_function_def (name, command, lineno, lstart)-
765 WORD_DESC *name;-
766 COMMAND *command;-
767 int lineno, lstart;-
768{-
769 FUNCTION_DEF *temp;-
770#if defined (ARRAY_VARS)-
771 SHELL_VAR *bash_source_v;-
772 ARRAY *bash_source_a;-
773#endif-
774-
775 temp = (FUNCTION_DEF *)xmalloc (sizeof (FUNCTION_DEF));-
776 temp->command = command;-
777 temp->name = name;-
778 temp->line = lineno;-
779 temp->flags = 0;-
780 command->line = lstart;-
781-
782 /* Information used primarily for debugging. */-
783 temp->source_file = 0;-
784#if defined (ARRAY_VARS)-
785 GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);-
786 if (bash_source_a && array_num_elements (bash_source_a) > 0)
bash_source_aDescription
TRUEevaluated 11147 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64 times by 1 test
Evaluated by:
  • Self test
((bash_source_..._elements) > 0Description
TRUEevaluated 11140 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
7-11147
787 temp->source_file = array_reference (bash_source_a, 0);
executed 11140 times by 1 test: temp->source_file = array_reference (bash_source_a, 0);
Executed by:
  • Self test
11140
788#endif-
789 /* Assume that shell functions without a source file before the shell is-
790 initialized come from the environment. Otherwise default to "main"-
791 (usually functions being defined interactively) */-
792 if (temp->source_file == 0)
temp->source_file == 0Description
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11140 times by 1 test
Evaluated by:
  • Self test
71-11140
793 temp->source_file = shell_initialized ? "main" : "environment";
executed 71 times by 1 test: temp->source_file = shell_initialized ? "main" : "environment";
Executed by:
  • Self test
shell_initializedDescription
TRUEnever evaluated
FALSEevaluated 71 times by 1 test
Evaluated by:
  • Self test
0-71
794-
795#if defined (DEBUGGER)-
796 bind_function_def (name->word, temp, 0);-
797#endif-
798-
799 temp->source_file = temp->source_file ? savestring (temp->source_file) : 0;
temp->source_fileDescription
TRUEevaluated 11211 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-11211
800-
801 return (make_command (cm_function_def, (SIMPLE_COM *)temp));
executed 11211 times by 1 test: return (make_command (cm_function_def, (SIMPLE_COM *)temp));
Executed by:
  • Self test
11211
802}-
803-
804COMMAND *-
805make_subshell_command (command)-
806 COMMAND *command;-
807{-
808 SUBSHELL_COM *temp;-
809-
810 temp = (SUBSHELL_COM *)xmalloc (sizeof (SUBSHELL_COM));-
811 temp->command = command;-
812 temp->flags = CMD_WANT_SUBSHELL;-
813 temp->line = line_number;-
814 return (make_command (cm_subshell, (SIMPLE_COM *)temp));
executed 5977 times by 1 test: return (make_command (cm_subshell, (SIMPLE_COM *)temp));
Executed by:
  • Self test
5977
815}-
816-
817COMMAND *-
818make_coproc_command (name, command)-
819 char *name;-
820 COMMAND *command;-
821{-
822 COPROC_COM *temp;-
823-
824 temp = (COPROC_COM *)xmalloc (sizeof (COPROC_COM));-
825 temp->name = savestring (name);-
826 temp->command = command;-
827 temp->flags = CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL;-
828 return (make_command (cm_coproc, (SIMPLE_COM *)temp));
executed 37 times by 1 test: return (make_command (cm_coproc, (SIMPLE_COM *)temp));
Executed by:
  • Self test
37
829}-
830-
831/* Reverse the word list and redirection list in the simple command-
832 has just been parsed. It seems simpler to do this here the one-
833 time then by any other method that I can think of. */-
834COMMAND *-
835clean_simple_command (command)-
836 COMMAND *command;-
837{-
838 if (command->type != cm_simple)
command->type != cm_simpleDescription
TRUEnever evaluated
FALSEevaluated 1038338 times by 1 test
Evaluated by:
  • Self test
0-1038338
839 command_error ("clean_simple_command", CMDERR_BADTYPE, command->type, 0);
never executed: command_error ("clean_simple_command", 1, command->type, 0);
0
840 else-
841 {-
842 command->value.Simple->words =-
843 REVERSE_LIST (command->value.Simple->words, WORD_LIST *);
command->value.Simple->wordsDescription
TRUEevaluated 1038219 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 119 times by 1 test
Evaluated by:
  • Self test
command->value...e->words->nextDescription
TRUEevaluated 880682 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 157537 times by 1 test
Evaluated by:
  • Self test
119-1038219
844 command->value.Simple->redirects =-
845 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
command->value...ple->redirectsDescription
TRUEevaluated 34031 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1004307 times by 1 test
Evaluated by:
  • Self test
command->value...edirects->nextDescription
TRUEevaluated 1337 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32694 times by 1 test
Evaluated by:
  • Self test
1337-1004307
846 }
executed 1038338 times by 1 test: end of block
Executed by:
  • Self test
1038338
847-
848 parser_state &= ~PST_REDIRLIST;-
849 return (command);
executed 1038338 times by 1 test: return (command);
Executed by:
  • Self test
1038338
850}-
851-
852/* The Yacc grammar productions have a problem, in that they take a-
853 list followed by an ampersand (`&') and do a simple command connection,-
854 making the entire list effectively asynchronous, instead of just-
855 the last command. This means that when the list is executed, all-
856 the commands have stdin set to /dev/null when job control is not-
857 active, instead of just the last. This is wrong, and needs fixing-
858 up. This function takes the `&' and applies it to the last command-
859 in the list. This is done only for lists connected by `;'; it makes-
860 `;' bind `tighter' than `&'. */-
861COMMAND *-
862connect_async_list (command, command2, connector)-
863 COMMAND *command, *command2;-
864 int connector;-
865{-
866 COMMAND *t, *t1, *t2;-
867-
868 t1 = command;-
869 t = command->value.Connection->second;-
870-
871 if (!t || (command->flags & CMD_WANT_SUBSHELL) ||
!tDescription
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test
(command->flags & 0x01)Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test
0-63
872 command->value.Connection->connector != ';')
command->value...nnector != ';'Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
26-37
873 {-
874 t = command_connect (command, command2, connector);-
875 return t;
executed 26 times by 1 test: return t;
Executed by:
  • Self test
26
876 }-
877-
878 /* This is just defensive programming. The Yacc precedence rules-
879 will generally hand this function a command where t points directly-
880 to the command we want (e.g. given a ; b ; c ; d &, t1 will point-
881 to the `a ; b ; c' list and t will be the `d'). We only want to do-
882 this if the list is not being executed as a unit in the background-
883 with `( ... )', so we have to check for CMD_WANT_SUBSHELL. That's-
884 the only way to tell. */-
885 while (((t->flags & CMD_WANT_SUBSHELL) == 0) && t->type == cm_connection &&
((t->flags & 0x01) == 0)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
t->type == cm_connectionDescription
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
0-28
886 t->value.Connection->connector == ';')
t->value.Conne...nnector == ';'Description
TRUEnever evaluated
FALSEnever evaluated
0
887 {-
888 t1 = t;-
889 t = t->value.Connection->second;-
890 }
never executed: end of block
0
891 /* Now we have t pointing to the last command in the list, and-
892 t1->value.Connection->second == t. */-
893 t2 = command_connect (t, command2, connector);-
894 t1->value.Connection->second = t2;-
895 return command;
executed 37 times by 1 test: return command;
Executed by:
  • Self test
37
896}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2