OpenCoverage

getopt.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/getopt.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12char *sh_optarg = 0;-
13int sh_optind = 0;-
14-
15-
16static int sh_curopt;-
17static char *nextchar;-
18static int sh_charindex;-
19-
20-
21-
22-
23int sh_opterr = 1;-
24-
25-
26-
27-
28-
29int sh_optopt = '?';-
30-
31-
32int sh_badopt = 0;-
33int-
34sh_getopt (argc, argv, optstring)-
35 int argc;-
36 char *const *argv;-
37 const char *optstring;-
38{-
39 char c, *temp;-
40-
41 sh_optarg = 0;-
42-
43 if (sh_optind >= argc
sh_optind >= argcDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 68 times by 1 test
Evaluated by:
  • Self test
|| sh_optind < 0
sh_optind < 0Description
TRUEnever evaluated
FALSEevaluated 68 times by 1 test
Evaluated by:
  • Self test
)
0-68
44 {-
45 sh_optind = argc;-
46 return
executed 8 times by 1 test: return ( (-1) );
Executed by:
  • Self test
(
executed 8 times by 1 test: return ( (-1) );
Executed by:
  • Self test
8
47 (-1)
executed 8 times by 1 test: return ( (-1) );
Executed by:
  • Self test
8
48 );
executed 8 times by 1 test: return ( (-1) );
Executed by:
  • Self test
8
49 }-
50-
51-
52-
53-
54-
55-
56 if (sh_optind == 0
sh_optind == 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
)
34
57 {-
58 sh_optind = 1;-
59 nextchar = (char *)-
60 ((void *)0)-
61 ;-
62 }
executed 34 times by 1 test: end of block
Executed by:
  • Self test
34
63-
64 if (nextchar == 0
nextchar == 0Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
|| *
*nextchar == '\0'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
nextchar == '\0'
*nextchar == '\0'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
)
0-63
65 {-
66-
67 if (sh_optind >= argc
sh_optind >= argcDescription
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test
)
0-63
68 return
never executed: return (-1) ;
never executed: return (-1) ;
0
69 (-1)
never executed: return (-1) ;
0
70 ;
never executed: return (-1) ;
0
71-
72 temp = argv[sh_optind];-
73-
74-
75-
76 if (temp[0] == '-'
temp[0] == '-'Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
&& temp[1] == '-'
temp[1] == '-'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
&& temp[2] == '\0'
temp[2] == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
)
0-54
77 {-
78 sh_optind++;-
79 return
executed 1 time by 1 test: return (-1) ;
Executed by:
  • Self test
executed 1 time by 1 test: return (-1) ;
Executed by:
  • Self test
1
80 (-1)
executed 1 time by 1 test: return (-1) ;
Executed by:
  • Self test
1
81 ;
executed 1 time by 1 test: return (-1) ;
Executed by:
  • Self test
1
82 }-
83-
84-
85-
86-
87 if (temp[0] != '-'
temp[0] != '-'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
|| temp[1] == '\0'
temp[1] == '\0'Description
TRUEnever evaluated
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
)
0-53
88 return
executed 9 times by 1 test: return (-1) ;
Executed by:
  • Self test
executed 9 times by 1 test: return (-1) ;
Executed by:
  • Self test
9
89 (-1)
executed 9 times by 1 test: return (-1) ;
Executed by:
  • Self test
9
90 ;
executed 9 times by 1 test: return (-1) ;
Executed by:
  • Self test
9
91-
92-
93-
94 nextchar = argv[sh_curopt = sh_optind] + 1;-
95 sh_charindex = 1;-
96 }
executed 53 times by 1 test: end of block
Executed by:
  • Self test
53
97-
98-
99-
100 c = *nextchar++; sh_charindex++;-
101 temp = -
102 (__extension__ (__builtin_constant_p (
__builtin_constant_p ( c )Description
TRUEnever evaluated
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
0-58
103 c
__builtin_constant_p ( c )Description
TRUEnever evaluated
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
0-58
104 )
__builtin_constant_p ( c )Description
TRUEnever evaluated
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
&& !__builtin_constant_p (
!__builtin_con... ( optstring )Description
TRUEnever evaluated
FALSEnever evaluated
0-58
105 optstring
!__builtin_con... ( optstring )Description
TRUEnever evaluated
FALSEnever evaluated
0
106 )
!__builtin_con... ( optstring )Description
TRUEnever evaluated
FALSEnever evaluated
&& (
( c ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
107 c
( c ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
108 ) == '\0'
( c ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
? (char *) __rawmemchr (
0
109 optstring-
110 , -
111 c-
112 ) : __builtin_strchr (-
113 optstring-
114 , -
115 c-
116 )))-
117 ;-
118-
119 sh_optopt = c;-
120-
121-
122 if (nextchar == 0
nextchar == 0Description
TRUEnever evaluated
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
|| *
*nextchar == '\0'Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
nextchar == '\0'
*nextchar == '\0'Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
)
0-58
123 {-
124 sh_optind++;-
125 nextchar = (char *)-
126 ((void *)0)-
127 ;-
128 }
executed 50 times by 1 test: end of block
Executed by:
  • Self test
50
129-
130 if (sh_badopt = (temp ==
temp == ((void *)0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
11-47
131 ((void *)0)
temp == ((void *)0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
11-47
132 || c == ':'
c == ':'Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
))
0-47
133 {-
134 if (sh_opterr
sh_opterrDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
)
3-8
135 fprintf (
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
136stderr
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
137,
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
138dcgettext (((void *)0),
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
139"%s: illegal option -- %c\n"
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
140,
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
5)
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
141,
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
argv[0], c);
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
8
142-
143 return
executed 11 times by 1 test: return '?';
Executed by:
  • Self test
'?';
executed 11 times by 1 test: return '?';
Executed by:
  • Self test
11
144 }-
145-
146 if (temp[1] == ':'
temp[1] == ':'Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
19-28
147 {-
148 if (nextchar
nextcharDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
&& *
*nextcharDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
nextchar
*nextcharDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
)
0-18
149 {-
150-
151 sh_optarg = nextchar;-
152-
153-
154 sh_optind++;-
155 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
156 else if (sh_optind == argc
sh_optind == argcDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
)
2-16
157 {-
158 if (sh_opterr
sh_opterrDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
)
1
159 fprintf (
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
160 stderr
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
161 ,
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
162 dcgettext (((void *)0),
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
163 "%s: option requires an argument -- %c\n"
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
164 , 5)
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
165 , argv[0], c);
executed 1 time by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: option requires an argument -- %c\n" , 5) , argv[0], c);
Executed by:
  • Self test
1
166-
167 sh_optopt = c;-
168 sh_optarg = "";-
169 c = (
(optstring[0] == ':')Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
optstring[0] == ':')
(optstring[0] == ':')Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
? ':' : '?';
0-2
170 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
171 else-
172-
173-
174 sh_optarg = argv[sh_optind++];
executed 16 times by 1 test: sh_optarg = argv[sh_optind++];
Executed by:
  • Self test
16
175 nextchar = (char *)-
176 ((void *)0)-
177 ;-
178 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test
19
179 return
executed 47 times by 1 test: return c;
Executed by:
  • Self test
c;
executed 47 times by 1 test: return c;
Executed by:
  • Self test
47
180}-
181-
182void-
183sh_getopt_restore_state (argv)-
184 char **argv;-
185{-
186 if (nextchar
nextcharDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 68 times by 1 test
Evaluated by:
  • Self test
)
8-68
187 nextchar = argv[sh_curopt] + sh_charindex;
executed 8 times by 1 test: nextchar = argv[sh_curopt] + sh_charindex;
Executed by:
  • Self test
8
188}
executed 76 times by 1 test: end of block
Executed by:
  • Self test
76
189-
190sh_getopt_state_t *-
191sh_getopt_alloc_istate ()-
192{-
193 sh_getopt_state_t *ret;-
194-
195 ret = (sh_getopt_state_t *)sh_xmalloc((sizeof (sh_getopt_state_t)), "getopt.c", 231);-
196 return
executed 1640471 times by 1 test: return ret;
Executed by:
  • Self test
ret;
executed 1640471 times by 1 test: return ret;
Executed by:
  • Self test
1640471
197}-
198-
199void-
200sh_getopt_dispose_istate (gs)-
201 sh_getopt_state_t *gs;-
202{-
203 sh_xfree((gs), "getopt.c", 239);-
204}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
205-
206sh_getopt_state_t *-
207sh_getopt_save_istate ()-
208{-
209 sh_getopt_state_t *ret;-
210-
211 ret = sh_getopt_alloc_istate ();-
212-
213 ret->gs_optarg = sh_optarg;-
214 ret->gs_optind = sh_optind;-
215 ret->gs_curopt = sh_curopt;-
216 ret->gs_nextchar = nextchar;-
217 ret->gs_charindex = sh_charindex;-
218 ret->gs_flags = 0;-
219-
220 return
executed 1640471 times by 1 test: return ret;
Executed by:
  • Self test
ret;
executed 1640471 times by 1 test: return ret;
Executed by:
  • Self test
1640471
221}-
222-
223void-
224sh_getopt_restore_istate (state)-
225 sh_getopt_state_t *state;-
226{-
227 sh_optarg = state->gs_optarg;-
228 sh_optind = state->gs_optind;-
229 sh_curopt = state->gs_curopt;-
230 nextchar = state->gs_nextchar;-
231 sh_charindex = state->gs_charindex;-
232-
233 sh_getopt_dispose_istate (state);-
234}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2