Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/getopt.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | char *sh_optarg = 0; | - | ||||||||||||||||||
13 | int sh_optind = 0; | - | ||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | static int sh_curopt; | - | ||||||||||||||||||
17 | static char *nextchar; | - | ||||||||||||||||||
18 | static int sh_charindex; | - | ||||||||||||||||||
19 | - | |||||||||||||||||||
20 | - | |||||||||||||||||||
21 | - | |||||||||||||||||||
22 | - | |||||||||||||||||||
23 | int sh_opterr = 1; | - | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | - | |||||||||||||||||||
26 | - | |||||||||||||||||||
27 | - | |||||||||||||||||||
28 | - | |||||||||||||||||||
29 | int sh_optopt = '?'; | - | ||||||||||||||||||
30 | - | |||||||||||||||||||
31 | - | |||||||||||||||||||
32 | int sh_badopt = 0; | - | ||||||||||||||||||
33 | int | - | ||||||||||||||||||
34 | sh_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
| 0-68 | ||||||||||||||||||
44 | { | - | ||||||||||||||||||
45 | sh_optind = argc; | - | ||||||||||||||||||
46 | return executed 8 times by 1 test: (return ( (-1) ); Executed by:
executed 8 times by 1 test: return ( (-1) ); Executed by:
| 8 | ||||||||||||||||||
47 | (-1) executed 8 times by 1 test: return ( (-1) ); Executed by:
| 8 | ||||||||||||||||||
48 | ); executed 8 times by 1 test: return ( (-1) ); Executed by:
| 8 | ||||||||||||||||||
49 | } | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | - | |||||||||||||||||||
52 | - | |||||||||||||||||||
53 | - | |||||||||||||||||||
54 | - | |||||||||||||||||||
55 | - | |||||||||||||||||||
56 | if (sh_optind == 0
| 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:
| 34 | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | if (nextchar == 0
| 0-63 | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | if (sh_optind >= argc
| 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] == '-'
| 0-54 | ||||||||||||||||||
77 | { | - | ||||||||||||||||||
78 | sh_optind++; | - | ||||||||||||||||||
79 | return executed 1 time by 1 test: return (-1) ; Executed by:
executed 1 time by 1 test: return (-1) ; Executed by:
| 1 | ||||||||||||||||||
80 | (-1) executed 1 time by 1 test: return (-1) ; Executed by:
| 1 | ||||||||||||||||||
81 | ; executed 1 time by 1 test: return (-1) ; Executed by:
| 1 | ||||||||||||||||||
82 | } | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | - | |||||||||||||||||||
85 | - | |||||||||||||||||||
86 | - | |||||||||||||||||||
87 | if (temp[0] != '-'
| 0-53 | ||||||||||||||||||
88 | return executed 9 times by 1 test: return (-1) ; Executed by:
executed 9 times by 1 test: return (-1) ; Executed by:
| 9 | ||||||||||||||||||
89 | (-1) executed 9 times by 1 test: return (-1) ; Executed by:
| 9 | ||||||||||||||||||
90 | ; executed 9 times by 1 test: return (-1) ; Executed by:
| 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:
| 53 | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | - | |||||||||||||||||||
99 | - | |||||||||||||||||||
100 | c = *nextchar++; sh_charindex++; | - | ||||||||||||||||||
101 | temp = | - | ||||||||||||||||||
102 | (__extension__ (__builtin_constant_p (
| 0-58 | ||||||||||||||||||
103 | c
| 0-58 | ||||||||||||||||||
104 | )
| 0-58 | ||||||||||||||||||
105 | optstring
| 0 | ||||||||||||||||||
106 | )
| 0 | ||||||||||||||||||
107 | c
| 0 | ||||||||||||||||||
108 | ) == '\0'
| 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
| 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:
| 50 | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | if (sh_badopt = (temp ==
| 11-47 | ||||||||||||||||||
131 | ((void *)0)
| 11-47 | ||||||||||||||||||
132 | || c == ':'
| 0-47 | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | if (sh_opterr
| 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:
| 8 | ||||||||||||||||||
136 | stderr executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
| 8 | ||||||||||||||||||
137 | , executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
| 8 | ||||||||||||||||||
138 | dcgettext (((void *)0), executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
| 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:
| 8 | ||||||||||||||||||
140 | , executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
executed 8 times by 1 test: 5)fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
| 8 | ||||||||||||||||||
141 | , executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
executed 8 times by 1 test: argv[0], c);fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
executed 8 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: illegal option -- %c\n" , 5) , argv[0], c); Executed by:
| 8 | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | return executed 11 times by 1 test: '?';return '?'; Executed by:
executed 11 times by 1 test: return '?'; Executed by:
| 11 | ||||||||||||||||||
144 | } | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | if (temp[1] == ':'
| 19-28 | ||||||||||||||||||
147 | { | - | ||||||||||||||||||
148 | if (nextchar
| 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:
| 1 | ||||||||||||||||||
156 | else if (sh_optind == argc
| 2-16 | ||||||||||||||||||
157 | { | - | ||||||||||||||||||
158 | if (sh_opterr
| 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:
| 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:
| 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:
| 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:
| 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:
| 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:
| 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:
| 1 | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | sh_optopt = c; | - | ||||||||||||||||||
168 | sh_optarg = ""; | - | ||||||||||||||||||
169 | c = (
| 0-2 | ||||||||||||||||||
170 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
171 | else | - | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | - | |||||||||||||||||||
174 | sh_optarg = argv[sh_optind++]; executed 16 times by 1 test: sh_optarg = argv[sh_optind++]; Executed by:
| 16 | ||||||||||||||||||
175 | nextchar = (char *) | - | ||||||||||||||||||
176 | ((void *)0) | - | ||||||||||||||||||
177 | ; | - | ||||||||||||||||||
178 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||||||||
179 | return executed 47 times by 1 test: c;return c; Executed by:
executed 47 times by 1 test: return c; Executed by:
| 47 | ||||||||||||||||||
180 | } | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | void | - | ||||||||||||||||||
183 | sh_getopt_restore_state (argv) | - | ||||||||||||||||||
184 | char **argv; | - | ||||||||||||||||||
185 | { | - | ||||||||||||||||||
186 | if (nextchar
| 8-68 | ||||||||||||||||||
187 | nextchar = argv[sh_curopt] + sh_charindex; executed 8 times by 1 test: nextchar = argv[sh_curopt] + sh_charindex; Executed by:
| 8 | ||||||||||||||||||
188 | } executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | sh_getopt_state_t * | - | ||||||||||||||||||
191 | sh_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: ret;return ret; Executed by:
executed 1640471 times by 1 test: return ret; Executed by:
| 1640471 | ||||||||||||||||||
197 | } | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | void | - | ||||||||||||||||||
200 | sh_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:
| 3 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | sh_getopt_state_t * | - | ||||||||||||||||||
207 | sh_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: ret;return ret; Executed by:
executed 1640471 times by 1 test: return ret; Executed by:
| 1640471 | ||||||||||||||||||
221 | } | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | void | - | ||||||||||||||||||
224 | sh_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:
| 3 | ||||||||||||||||||
Switch to Source code | Preprocessed file |