Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/getopts.def |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||||||||
11 | - | |||||||||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||||||||
14 | - | |||||||||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||||||||
16 | static int getopts_unbind_variable (char *); | - | ||||||||||||||||||||||||||||||
17 | static int getopts_bind_variable (char *, char *); | - | ||||||||||||||||||||||||||||||
18 | static int dogetopts (int, char **); | - | ||||||||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||||||||
22 | void | - | ||||||||||||||||||||||||||||||
23 | getopts_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:
| 5455 | ||||||||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||||||||
30 | static int | - | ||||||||||||||||||||||||||||||
31 | getopts_unbind_variable (name) | - | ||||||||||||||||||||||||||||||
32 | char *name; | - | ||||||||||||||||||||||||||||||
33 | { | - | ||||||||||||||||||||||||||||||
34 | - | |||||||||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||||||||
37 | return executed 28 times by 1 test: (unbind_variable_noref (name));return (unbind_variable_noref (name)); Executed by:
executed 28 times by 1 test: return (unbind_variable_noref (name)); Executed by:
| 28 | ||||||||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||||||||
39 | } | - | ||||||||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||||||||
41 | static int | - | ||||||||||||||||||||||||||||||
42 | getopts_bind_variable (name, value) | - | ||||||||||||||||||||||||||||||
43 | char *name, *value; | - | ||||||||||||||||||||||||||||||
44 | { | - | ||||||||||||||||||||||||||||||
45 | SHELL_VAR *v; | - | ||||||||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||||||||
47 | if (legal_identifier (name)
| 1-75 | ||||||||||||||||||||||||||||||
48 | { | - | ||||||||||||||||||||||||||||||
49 | v = bind_variable (name, value, 0); | - | ||||||||||||||||||||||||||||||
50 | if (v
| 0-70 | ||||||||||||||||||||||||||||||
51 | return never executed: (2);return (2); never executed: return (2); | 0 | ||||||||||||||||||||||||||||||
52 | return executed 75 times by 1 test: (v ? 0 : 1);return (v ? 0 : 1); Executed by:
executed 75 times by 1 test: return (v ? 0 : 1); Executed by:
| 75 | ||||||||||||||||||||||||||||||
53 | } | - | ||||||||||||||||||||||||||||||
54 | else | - | ||||||||||||||||||||||||||||||
55 | { | - | ||||||||||||||||||||||||||||||
56 | sh_invalidid (name); | - | ||||||||||||||||||||||||||||||
57 | return executed 1 time by 1 test: (1);return (1); Executed by:
executed 1 time by 1 test: return (1); Executed by:
| 1 | ||||||||||||||||||||||||||||||
58 | } | - | ||||||||||||||||||||||||||||||
59 | } | - | ||||||||||||||||||||||||||||||
60 | static int | - | ||||||||||||||||||||||||||||||
61 | dogetopts (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
| 1-76 | ||||||||||||||||||||||||||||||
72 | { | - | ||||||||||||||||||||||||||||||
73 | builtin_usage (); | - | ||||||||||||||||||||||||||||||
74 | return executed 1 time by 1 test: (258);return (258); Executed by:
executed 1 time by 1 test: return (258); Executed by:
| 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
| 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:
| 29 | ||||||||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||||||||
93 | if (argc > 1
| 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:
| 49 | ||||||||||||||||||||||||||||||
101 | else if (rest_of_args == (WORD_LIST *)
| 3-24 | ||||||||||||||||||||||||||||||
102 | ((void *)0)
| 3-24 | ||||||||||||||||||||||||||||||
103 | ) | - | ||||||||||||||||||||||||||||||
104 | { | - | ||||||||||||||||||||||||||||||
105 | for (i = 0; i < 10
| 0-94 | ||||||||||||||||||||||||||||||
106 | ; executed 70 times by 1 test: ; Executed by:
| 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:
| 24 | ||||||||||||||||||||||||||||||
111 | else | - | ||||||||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||||||||
113 | register WORD_LIST *words; | - | ||||||||||||||||||||||||||||||
114 | char **v; | - | ||||||||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||||||||
116 | for (i = 0; i < 10
| 0-30 | ||||||||||||||||||||||||||||||
117 | ; executed 30 times by 1 test: ; Executed by:
| 30 | ||||||||||||||||||||||||||||||
118 | for (words = rest_of_args; words
| 3-18 | ||||||||||||||||||||||||||||||
119 | ; executed 18 times by 1 test: ; Executed by:
| 18 | ||||||||||||||||||||||||||||||
120 | v = strvec_create (i + 1); | - | ||||||||||||||||||||||||||||||
121 | for (i = 0; i < 10
| 0-30 | ||||||||||||||||||||||||||||||
122 | v[i] = dollar_vars[i]; executed 30 times by 1 test: v[i] = dollar_vars[i]; Executed by:
| 30 | ||||||||||||||||||||||||||||||
123 | for (words = rest_of_args; words
| 3-18 | ||||||||||||||||||||||||||||||
124 | v[i] = words->word->word; executed 18 times by 1 test: v[i] = words->word->word; Executed by:
| 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:
| 3 | ||||||||||||||||||||||||||||||
132 | - | |||||||||||||||||||||||||||||||
133 | if (special_error
| 29-47 | ||||||||||||||||||||||||||||||
134 | sh_opterr = old_opterr; executed 29 times by 1 test: sh_opterr = old_opterr; Executed by:
| 29 | ||||||||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||||||||
138 | if (sh_optind < 10
| 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:
| 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:
| 6 | ||||||||||||||||||||||||||||||
152 | while (n /= 10
| 3 | ||||||||||||||||||||||||||||||
153 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||
154 | bind_variable ("OPTIND", numval + i, 0); | - | ||||||||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||||||||
161 | if (ret == '?'
| 13-63 | ||||||||||||||||||||||||||||||
162 | { | - | ||||||||||||||||||||||||||||||
163 | if (sh_optarg ==
| 2-11 | ||||||||||||||||||||||||||||||
164 | ((void *)0)
| 2-11 | ||||||||||||||||||||||||||||||
165 | ) | - | ||||||||||||||||||||||||||||||
166 | ret = -2; executed 11 times by 1 test: ret = -2; Executed by:
| 11 | ||||||||||||||||||||||||||||||
167 | else if (sh_optarg[0] == '\0'
| 0-2 | ||||||||||||||||||||||||||||||
168 | ret = -3; executed 2 times by 1 test: ret = -3; Executed by:
| 2 | ||||||||||||||||||||||||||||||
169 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||||||||
171 | if (ret == -1
| 18-58 | ||||||||||||||||||||||||||||||
172 | { | - | ||||||||||||||||||||||||||||||
173 | getopts_unbind_variable ("OPTARG"); | - | ||||||||||||||||||||||||||||||
174 | getopts_bind_variable (name, "?"); | - | ||||||||||||||||||||||||||||||
175 | return executed 18 times by 1 test: (1);return (1); Executed by:
executed 18 times by 1 test: return (1); Executed by:
| 18 | ||||||||||||||||||||||||||||||
176 | } | - | ||||||||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||||||||
178 | if (ret == -2
| 11-47 | ||||||||||||||||||||||||||||||
179 | { | - | ||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||
181 | ret = getopts_bind_variable (name, "?"); | - | ||||||||||||||||||||||||||||||
182 | - | |||||||||||||||||||||||||||||||
183 | if (special_error
| 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:
| 2 | ||||||||||||||||||||||||||||||
189 | else | - | ||||||||||||||||||||||||||||||
190 | getopts_unbind_variable ("OPTARG"); executed 9 times by 1 test: getopts_unbind_variable ("OPTARG"); Executed by:
| 9 | ||||||||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||||||||
192 | return executed 11 times by 1 test: (ret);return (ret); Executed by:
executed 11 times by 1 test: return (ret); Executed by:
| 11 | ||||||||||||||||||||||||||||||
193 | } | - | ||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||
195 | if (ret == -3
| 2-45 | ||||||||||||||||||||||||||||||
196 | { | - | ||||||||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||||||||
198 | if (special_error
| 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:
| 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:
| 1 | ||||||||||||||||||||||||||||||
211 | return executed 2 times by 1 test: (ret);return (ret); Executed by:
executed 2 times by 1 test: return (ret); Executed by:
| 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: (getopts_bind_variable (name, strval));return (getopts_bind_variable (name, strval)); Executed by:
executed 45 times by 1 test: return (getopts_bind_variable (name, strval)); Executed by:
| 45 | ||||||||||||||||||||||||||||||
219 | } | - | ||||||||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||||||||
222 | int | - | ||||||||||||||||||||||||||||||
223 | getopts_builtin (list) | - | ||||||||||||||||||||||||||||||
224 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||
225 | { | - | ||||||||||||||||||||||||||||||
226 | char **av; | - | ||||||||||||||||||||||||||||||
227 | int ac, ret; | - | ||||||||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||||||||
229 | if (list == 0
| 1-78 | ||||||||||||||||||||||||||||||
230 | { | - | ||||||||||||||||||||||||||||||
231 | builtin_usage (); | - | ||||||||||||||||||||||||||||||
232 | return executed 1 time by 1 test: 258;return 258; Executed by:
executed 1 time by 1 test: return 258; Executed by:
| 1 | ||||||||||||||||||||||||||||||
233 | } | - | ||||||||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||||||||
235 | reset_internal_getopt (); | - | ||||||||||||||||||||||||||||||
236 | if ((
| 1-77 | ||||||||||||||||||||||||||||||
237 | { | - | ||||||||||||||||||||||||||||||
238 | if (ret == -99
| 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:
| 1 | ||||||||||||||||||||||||||||||
242 | return executed 1 time by 1 test: (258);return (258); Executed by:
executed 1 time by 1 test: return (258); Executed by:
| 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: (ret);return (ret); Executed by:
executed 77 times by 1 test: return (ret); Executed by:
| 77 | ||||||||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |