OpenCoverage

getopts.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/getopts.def
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16static int getopts_unbind_variable (char *);-
17static int getopts_bind_variable (char *, char *);-
18static int dogetopts (int, char **);-
19-
20-
21-
22void-
23getopts_reset (newind)-
24 int newind;-
25{-
26 sh_optind = newind;-
27 sh_badopt = 0;-
28}
executed 5455 times by 1 test: end of block
Executed by:
  • Self test
5455
29-
30static int-
31getopts_unbind_variable (name)-
32 char *name;-
33{-
34-
35-
36-
37 return
executed 28 times by 1 test: return (unbind_variable_noref (name));
Executed by:
  • Self test
(unbind_variable_noref (name));
executed 28 times by 1 test: return (unbind_variable_noref (name));
Executed by:
  • Self test
28
38-
39}-
40-
41static int-
42getopts_bind_variable (name, value)-
43 char *name, *value;-
44{-
45 SHELL_VAR *v;-
46-
47 if (legal_identifier (name)
legal_identifier (name)Description
TRUEevaluated 75 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
)
1-75
48 {-
49 v = bind_variable (name, value, 0);-
50 if (v
vDescription
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
&& (((((
((((v)->attrib... (0x0000002)))Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
v)->attributes) & (0x0000002)))
((((v)->attrib... (0x0000002)))Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
|| ((((
((((v)->attrib... (0x0004000)))Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
v)->attributes) & (0x0004000)))
((((v)->attrib... (0x0004000)))Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
))
0-70
51 return
never executed: return (2);
(2);
never executed: return (2);
0
52 return
executed 75 times by 1 test: return (v ? 0 : 1);
Executed by:
  • Self test
(v ? 0 : 1);
executed 75 times by 1 test: return (v ? 0 : 1);
Executed by:
  • Self test
75
53 }-
54 else-
55 {-
56 sh_invalidid (name);-
57 return
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
(1);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
58 }-
59}-
60static int-
61dogetopts (argc, argv)-
62 int argc;-
63 char **argv;-
64{-
65 int ret, special_error, old_opterr, i, n;-
66 char strval[2], numval[16];-
67 char *optstr;-
68 char *name;-
69 char *t;-
70-
71 if (argc < 3
argc < 3Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 76 times by 1 test
Evaluated by:
  • Self test
)
1-76
72 {-
73 builtin_usage ();-
74 return
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
(258);
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
1
75 }-
76-
77-
78-
79 optstr = argv[1];-
80 name = argv[2];-
81 argc -= 2;-
82 argv += 2;-
83-
84 special_error = optstr[0] == ':';-
85-
86 if (special_error
special_errorDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
)
29-47
87 {-
88 old_opterr = sh_opterr;-
89 optstr++;-
90 sh_opterr = 0;-
91 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
92-
93 if (argc > 1
argc > 1Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
)
27-49
94 {-
95 sh_getopt_restore_state (argv);-
96 t = argv[0];-
97 argv[0] = dollar_vars[0];-
98 ret = sh_getopt (argc, argv, optstr);-
99 argv[0] = t;-
100 }
executed 49 times by 1 test: end of block
Executed by:
  • Self test
49
101 else if (rest_of_args == (WORD_LIST *)
rest_of_args =...*) ((void *)0)Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-24
102 ((void *)0)
rest_of_args =...*) ((void *)0)Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-24
103 )-
104 {-
105 for (i = 0; i < 10
i < 10Description
TRUEevaluated 94 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
&& dollar_vars[i]
dollar_vars[i]Description
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
; i++)
0-94
106 ;
executed 70 times by 1 test: ;
Executed by:
  • Self test
70
107-
108 sh_getopt_restore_state (dollar_vars);-
109 ret = sh_getopt (i, dollar_vars, optstr);-
110 }
executed 24 times by 1 test: end of block
Executed by:
  • Self test
24
111 else-
112 {-
113 register WORD_LIST *words;-
114 char **v;-
115-
116 for (i = 0; i < 10
i < 10Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
&& dollar_vars[i]
dollar_vars[i]Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
; i++)
0-30
117 ;
executed 30 times by 1 test: ;
Executed by:
  • Self test
30
118 for (words = rest_of_args; words
wordsDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
; words = words->next, i++)
3-18
119 ;
executed 18 times by 1 test: ;
Executed by:
  • Self test
18
120 v = strvec_create (i + 1);-
121 for (i = 0; i < 10
i < 10Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
&& dollar_vars[i]
dollar_vars[i]Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
; i++)
0-30
122 v[i] = dollar_vars[i];
executed 30 times by 1 test: v[i] = dollar_vars[i];
Executed by:
  • Self test
30
123 for (words = rest_of_args; words
wordsDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
; words = words->next, i++)
3-18
124 v[i] = words->word->word;
executed 18 times by 1 test: v[i] = words->word->word;
Executed by:
  • Self test
18
125 v[i] = (char *)-
126 ((void *)0)-
127 ;-
128 sh_getopt_restore_state (v);-
129 ret = sh_getopt (i, v, optstr);-
130 sh_xfree((v), "./getopts.def", 227);-
131 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
132-
133 if (special_error
special_errorDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
)
29-47
134 sh_opterr = old_opterr;
executed 29 times by 1 test: sh_opterr = old_opterr;
Executed by:
  • Self test
29
135-
136-
137-
138 if (sh_optind < 10
sh_optind < 10Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
)
3-73
139 {-
140 numval[14] = sh_optind + '0';-
141 numval[15] = '\0';-
142 i = 14;-
143 }
executed 73 times by 1 test: end of block
Executed by:
  • Self test
73
144 else-
145 {-
146 numval[i = 15] = '\0';-
147 n = sh_optind;-
148 do-
149 {-
150 numval[--i] = (n % 10) + '0';-
151 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
152 while (n /= 10
n /= 10Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
);
3
153 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
154 bind_variable ("OPTIND", numval + i, 0);-
155-
156-
157-
158-
159-
160-
161 if (ret == '?'
ret == '?'Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test
)
13-63
162 {-
163 if (sh_optarg ==
sh_optarg == ((void *)0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-11
164 ((void *)0)
sh_optarg == ((void *)0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-11
165 )-
166 ret = -2;
executed 11 times by 1 test: ret = -2;
Executed by:
  • Self test
11
167 else if (sh_optarg[0] == '\0'
sh_optarg[0] == '\0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
)
0-2
168 ret = -3;
executed 2 times by 1 test: ret = -3;
Executed by:
  • Self test
2
169 }
executed 13 times by 1 test: end of block
Executed by:
  • Self test
13
170-
171 if (ret == -1
ret == -1Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
)
18-58
172 {-
173 getopts_unbind_variable ("OPTARG");-
174 getopts_bind_variable (name, "?");-
175 return
executed 18 times by 1 test: return (1);
Executed by:
  • Self test
(1);
executed 18 times by 1 test: return (1);
Executed by:
  • Self test
18
176 }-
177-
178 if (ret == -2
ret == -2Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
)
11-47
179 {-
180-
181 ret = getopts_bind_variable (name, "?");-
182-
183 if (special_error
special_errorDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
)
2-9
184 {-
185 strval[0] = (char)sh_optopt;-
186 strval[1] = '\0';-
187 bind_variable ("OPTARG", strval, 0);-
188 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
189 else-
190 getopts_unbind_variable ("OPTARG");
executed 9 times by 1 test: getopts_unbind_variable ("OPTARG");
Executed by:
  • Self test
9
191-
192 return
executed 11 times by 1 test: return (ret);
Executed by:
  • Self test
(ret);
executed 11 times by 1 test: return (ret);
Executed by:
  • Self test
11
193 }-
194-
195 if (ret == -3
ret == -3Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • Self test
)
2-45
196 {-
197-
198 if (special_error
special_errorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
)
1
199 {-
200 ret = getopts_bind_variable (name, ":");-
201-
202 strval[0] = (char)sh_optopt;-
203 strval[1] = '\0';-
204 bind_variable ("OPTARG", strval, 0);-
205 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
206 else-
207 {-
208 ret = getopts_bind_variable (name, "?");-
209 getopts_unbind_variable ("OPTARG");-
210 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
211 return
executed 2 times by 1 test: return (ret);
Executed by:
  • Self test
(ret);
executed 2 times by 1 test: return (ret);
Executed by:
  • Self test
2
212 }-
213-
214 bind_variable ("OPTARG", sh_optarg, 0);-
215-
216 strval[0] = (char) ret;-
217 strval[1] = '\0';-
218 return
executed 45 times by 1 test: return (getopts_bind_variable (name, strval));
Executed by:
  • Self test
(getopts_bind_variable (name, strval));
executed 45 times by 1 test: return (getopts_bind_variable (name, strval));
Executed by:
  • Self test
45
219}-
220-
221-
222int-
223getopts_builtin (list)-
224 WORD_LIST *list;-
225{-
226 char **av;-
227 int ac, ret;-
228-
229 if (list == 0
list == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 78 times by 1 test
Evaluated by:
  • Self test
)
1-78
230 {-
231 builtin_usage ();-
232 return
executed 1 time by 1 test: return 258;
Executed by:
  • Self test
258;
executed 1 time by 1 test: return 258;
Executed by:
  • Self test
1
233 }-
234-
235 reset_internal_getopt ();-
236 if ((
(ret = interna...st, "")) != -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 77 times by 1 test
Evaluated by:
  • Self test
ret = internal_getopt (list, "")) != -1
(ret = interna...st, "")) != -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 77 times by 1 test
Evaluated by:
  • Self test
)
1-77
237 {-
238 if (ret == -99
ret == -99Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
)
0-1
239 builtin_help ();
never executed: builtin_help ();
0
240 else-
241 builtin_usage ();
executed 1 time by 1 test: builtin_usage ();
Executed by:
  • Self test
1
242 return
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
(258);
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
1
243 }-
244 list = loptend;-
245-
246 av = make_builtin_argv (list, &ac);-
247 ret = dogetopts (ac, av);-
248 sh_xfree(((char *)av), "./getopts.def", 343);-
249-
250 return
executed 77 times by 1 test: return (ret);
Executed by:
  • Self test
(ret);
executed 77 times by 1 test: return (ret);
Executed by:
  • Self test
77
251}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2