OpenCoverage

shift.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/shift.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is shift.def, from which is created shift.c.-
2It implements the builtin "shift" in Bash.-
3-
4Copyright (C) 1987-2009 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 shift.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 "../bashansi.h"-
33#include "../bashintl.h"-
34-
35#include "../shell.h"-
36#include "common.h"-
37-
38$BUILTIN shift-
39$FUNCTION shift_builtin-
40$SHORT_DOC shift [n]-
41Shift positional parameters.-
42-
43Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is-
44not given, it is assumed to be 1.-
45-
46Exit Status:-
47Returns success unless N is negative or greater than $#.-
48$END-
49-
50int print_shift_error;-
51-
52/* Shift the arguments ``left''. Shift DOLLAR_VARS down then take one-
53 off of REST_OF_ARGS and place it into DOLLAR_VARS[9]. If LIST has-
54 anything in it, it is a number which says where to start the-
55 shifting. Return > 0 if `times' > $#, otherwise 0. */-
56int-
57shift_builtin (list)-
58 WORD_LIST *list;-
59{-
60 intmax_t times;-
61 register int count;-
62 WORD_LIST *temp;-
63-
64 CHECK_HELPOPT (list);
never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: return (258);
(list)Description
TRUEevaluated 94 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899359 times by 1 test
Evaluated by:
  • Self test
(list)->wordDescription
TRUEevaluated 94 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 6 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-11899359
65-
66 if (get_numeric_arg (list, 0, &times) == 0)
get_numeric_ar..., &times) == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899443 times by 1 test
Evaluated by:
  • Self test
5-11899443
67 return (EXECUTION_FAILURE);
executed 5 times by 1 test: return (1);
Executed by:
  • Self test
5
68-
69 if (times == 0)
times == 0Description
TRUEnever evaluated
FALSEevaluated 11899443 times by 1 test
Evaluated by:
  • Self test
0-11899443
70 return (EXECUTION_SUCCESS);
never executed: return (0);
0
71 else if (times < 0)
times < 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899437 times by 1 test
Evaluated by:
  • Self test
6-11899437
72 {-
73 sh_erange (list ? list->word->word : NULL, _("shift count"));-
74 return (EXECUTION_FAILURE);
executed 6 times by 1 test: return (1);
Executed by:
  • Self test
6
75 }-
76 else if (times > number_of_args ())
times > number_of_args ()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899432 times by 1 test
Evaluated by:
  • Self test
5-11899432
77 {-
78 if (print_shift_error)
print_shift_errorDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
79 sh_erange (list ? list->word->word : NULL, _("shift count"));
executed 5 times by 1 test: sh_erange (list ? list->word->word : ((void *)0) , dcgettext (((void *)0), "shift count" , 5) );
Executed by:
  • Self test
5
80 return (EXECUTION_FAILURE);
executed 5 times by 1 test: return (1);
Executed by:
  • Self test
5
81 }-
82-
83 while (times-- > 0)
times-- > 0Description
TRUEevaluated 11899631 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899432 times by 1 test
Evaluated by:
  • Self test
11899432-11899631
84 {-
85 if (dollar_vars[1])
dollar_vars[1]Description
TRUEevaluated 11899631 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-11899631
86 free (dollar_vars[1]);
executed 11899631 times by 1 test: sh_xfree((dollar_vars[1]), "./shift.def", 86);
Executed by:
  • Self test
11899631
87-
88 for (count = 1; count < 9; count++)
count < 9Description
TRUEevaluated 95197048 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899631 times by 1 test
Evaluated by:
  • Self test
11899631-95197048
89 dollar_vars[count] = dollar_vars[count + 1];
executed 95197048 times by 1 test: dollar_vars[count] = dollar_vars[count + 1];
Executed by:
  • Self test
95197048
90-
91 if (rest_of_args)
rest_of_argsDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11899617 times by 1 test
Evaluated by:
  • Self test
14-11899617
92 {-
93 temp = rest_of_args;-
94 dollar_vars[9] = savestring (temp->word->word);-
95 rest_of_args = rest_of_args->next;-
96 temp->next = (WORD_LIST *)NULL;-
97 dispose_words (temp);-
98 }
executed 14 times by 1 test: end of block
Executed by:
  • Self test
14
99 else-
100 dollar_vars[9] = (char *)NULL;
executed 11899617 times by 1 test: dollar_vars[9] = (char *) ((void *)0) ;
Executed by:
  • Self test
11899617
101 }-
102-
103 invalidate_cached_quoted_dollar_at ();-
104-
105 return (EXECUTION_SUCCESS);
executed 11899432 times by 1 test: return (0);
Executed by:
  • Self test
11899432
106}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2