Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/basename.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | static struct option const longopts[] = | - | ||||||||||||||||||||||||
9 | { | - | ||||||||||||||||||||||||
10 | {"multiple", | - | ||||||||||||||||||||||||
11 | 0 | - | ||||||||||||||||||||||||
12 | , | - | ||||||||||||||||||||||||
13 | ((void *)0) | - | ||||||||||||||||||||||||
14 | , 'a'}, | - | ||||||||||||||||||||||||
15 | {"suffix", | - | ||||||||||||||||||||||||
16 | 1 | - | ||||||||||||||||||||||||
17 | , | - | ||||||||||||||||||||||||
18 | ((void *)0) | - | ||||||||||||||||||||||||
19 | , 's'}, | - | ||||||||||||||||||||||||
20 | {"zero", | - | ||||||||||||||||||||||||
21 | 0 | - | ||||||||||||||||||||||||
22 | , | - | ||||||||||||||||||||||||
23 | ((void *)0) | - | ||||||||||||||||||||||||
24 | , 'z'}, | - | ||||||||||||||||||||||||
25 | {"help", | - | ||||||||||||||||||||||||
26 | 0 | - | ||||||||||||||||||||||||
27 | , | - | ||||||||||||||||||||||||
28 | ((void *)0) | - | ||||||||||||||||||||||||
29 | , GETOPT_HELP_CHAR}, | - | ||||||||||||||||||||||||
30 | {"version", | - | ||||||||||||||||||||||||
31 | 0 | - | ||||||||||||||||||||||||
32 | , | - | ||||||||||||||||||||||||
33 | ((void *)0) | - | ||||||||||||||||||||||||
34 | , GETOPT_VERSION_CHAR}, | - | ||||||||||||||||||||||||
35 | { | - | ||||||||||||||||||||||||
36 | ((void *)0) | - | ||||||||||||||||||||||||
37 | , 0, | - | ||||||||||||||||||||||||
38 | ((void *)0) | - | ||||||||||||||||||||||||
39 | , 0} | - | ||||||||||||||||||||||||
40 | }; | - | ||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | void | - | ||||||||||||||||||||||||
43 | usage (int status) | - | ||||||||||||||||||||||||
44 | { | - | ||||||||||||||||||||||||
45 | if (status !=
| 5-9 | ||||||||||||||||||||||||
46 | 0
| 5-9 | ||||||||||||||||||||||||
47 | ) | - | ||||||||||||||||||||||||
48 | do { fprintf ( | - | ||||||||||||||||||||||||
49 | stderr | - | ||||||||||||||||||||||||
50 | , | - | ||||||||||||||||||||||||
51 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
52 | "Try '%s --help' for more information.\n" | - | ||||||||||||||||||||||||
53 | , 5) | - | ||||||||||||||||||||||||
54 | , program_name); } executed 5 times by 1 test: while (0);end of block Executed by:
| 5 | ||||||||||||||||||||||||
55 | else | - | ||||||||||||||||||||||||
56 | { | - | ||||||||||||||||||||||||
57 | printf ( | - | ||||||||||||||||||||||||
58 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
59 | "Usage: %s NAME [SUFFIX]\n or: %s OPTION... NAME...\n" | - | ||||||||||||||||||||||||
60 | , 5) | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | , | - | ||||||||||||||||||||||||
65 | program_name, program_name); | - | ||||||||||||||||||||||||
66 | fputs_unlocked ( | - | ||||||||||||||||||||||||
67 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
68 | "Print NAME with any leading directory components removed.\nIf specified, also remove a trailing SUFFIX.\n" | - | ||||||||||||||||||||||||
69 | , 5) | - | ||||||||||||||||||||||||
70 | , | - | ||||||||||||||||||||||||
71 | stdout | - | ||||||||||||||||||||||||
72 | ) | - | ||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | ; | - | ||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||
77 | emit_mandatory_arg_note (); | - | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | fputs_unlocked ( | - | ||||||||||||||||||||||||
80 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
81 | " -a, --multiple support multiple arguments and treat each as a NAME\n -s, --suffix=SUFFIX remove a trailing SUFFIX; implies -a\n -z, --zero end each output line with NUL, not newline\n" | - | ||||||||||||||||||||||||
82 | , 5) | - | ||||||||||||||||||||||||
83 | , | - | ||||||||||||||||||||||||
84 | stdout | - | ||||||||||||||||||||||||
85 | ) | - | ||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | ; | - | ||||||||||||||||||||||||
90 | fputs_unlocked ( | - | ||||||||||||||||||||||||
91 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
92 | " --help display this help and exit\n" | - | ||||||||||||||||||||||||
93 | , 5) | - | ||||||||||||||||||||||||
94 | , | - | ||||||||||||||||||||||||
95 | stdout | - | ||||||||||||||||||||||||
96 | ); | - | ||||||||||||||||||||||||
97 | fputs_unlocked ( | - | ||||||||||||||||||||||||
98 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
99 | " --version output version information and exit\n" | - | ||||||||||||||||||||||||
100 | , 5) | - | ||||||||||||||||||||||||
101 | , | - | ||||||||||||||||||||||||
102 | stdout | - | ||||||||||||||||||||||||
103 | ); | - | ||||||||||||||||||||||||
104 | printf ( | - | ||||||||||||||||||||||||
105 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
106 | "\nExamples:\n %s /usr/bin/sort -> \"sort\"\n %s include/stdio.h .h -> \"stdio\"\n %s -s .h include/stdio.h -> \"stdio\"\n %s -a any/str1 any/str2 -> \"str1\" followed by \"str2\"\n" | - | ||||||||||||||||||||||||
107 | , 5) | - | ||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | , | - | ||||||||||||||||||||||||
116 | program_name, program_name, program_name, program_name); | - | ||||||||||||||||||||||||
117 | emit_ancillary_info ("basename"); | - | ||||||||||||||||||||||||
118 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||||||||
119 | exit (status); executed 14 times by 1 test: exit (status); Executed by:
| 14 | ||||||||||||||||||||||||
120 | } | - | ||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | static void | - | ||||||||||||||||||||||||
126 | remove_suffix (char *name, const char *suffix) | - | ||||||||||||||||||||||||
127 | { | - | ||||||||||||||||||||||||
128 | char *np; | - | ||||||||||||||||||||||||
129 | const char *sp; | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | np = name + strlen (name); | - | ||||||||||||||||||||||||
132 | sp = suffix + strlen (suffix); | - | ||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||
134 | while (np > name
| 1-31 | ||||||||||||||||||||||||
135 | if (*--
| 3-17 | ||||||||||||||||||||||||
136 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||||||||||||||
137 | if (np > name
| 1-11 | ||||||||||||||||||||||||
138 | * executed 11 times by 1 test: np = '\0';*np = '\0'; Executed by:
executed 11 times by 1 test: *np = '\0'; Executed by:
| 11 | ||||||||||||||||||||||||
139 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | static void | - | ||||||||||||||||||||||||
145 | perform_basename (const char *string, const char *suffix, | - | ||||||||||||||||||||||||
146 | _Bool | - | ||||||||||||||||||||||||
147 | use_nuls) | - | ||||||||||||||||||||||||
148 | { | - | ||||||||||||||||||||||||
149 | char *name = base_name (string); | - | ||||||||||||||||||||||||
150 | strip_trailing_slashes (name); | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | if (suffix
| 0-23 | ||||||||||||||||||||||||
159 | remove_suffix (name, suffix); executed 15 times by 1 test: remove_suffix (name, suffix); Executed by:
| 15 | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | fputs_unlocked (name, | - | ||||||||||||||||||||||||
162 | stdout | - | ||||||||||||||||||||||||
163 | ); | - | ||||||||||||||||||||||||
164 | putchar_unlocked (use_nuls ? '\0' : '\n'); | - | ||||||||||||||||||||||||
165 | free (name); | - | ||||||||||||||||||||||||
166 | } executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||
168 | int | - | ||||||||||||||||||||||||
169 | main (int argc, char **argv) | - | ||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||
172 | _Bool | - | ||||||||||||||||||||||||
173 | multiple_names = | - | ||||||||||||||||||||||||
174 | 0 | - | ||||||||||||||||||||||||
175 | ; | - | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | _Bool | - | ||||||||||||||||||||||||
178 | use_nuls = | - | ||||||||||||||||||||||||
179 | 0 | - | ||||||||||||||||||||||||
180 | ; | - | ||||||||||||||||||||||||
181 | const char *suffix = | - | ||||||||||||||||||||||||
182 | ((void *)0) | - | ||||||||||||||||||||||||
183 | ; | - | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | ; | - | ||||||||||||||||||||||||
186 | set_program_name (argv[0]); | - | ||||||||||||||||||||||||
187 | setlocale ( | - | ||||||||||||||||||||||||
188 | 6 | - | ||||||||||||||||||||||||
189 | , ""); | - | ||||||||||||||||||||||||
190 | bindtextdomain ("coreutils", "/usr/local/share/locale"); | - | ||||||||||||||||||||||||
191 | textdomain ("coreutils"); | - | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | atexit (close_stdout); | - | ||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | while ( | - | ||||||||||||||||||||||||
196 | 1 | - | ||||||||||||||||||||||||
197 | ) | - | ||||||||||||||||||||||||
198 | { | - | ||||||||||||||||||||||||
199 | int c = getopt_long (argc, argv, "+as:z", longopts, | - | ||||||||||||||||||||||||
200 | ((void *)0) | - | ||||||||||||||||||||||||
201 | ); | - | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | if (c == -1
| 31-38 | ||||||||||||||||||||||||
204 | break; executed 38 times by 1 test: break; Executed by:
| 38 | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | switch (c) | - | ||||||||||||||||||||||||
207 | { | - | ||||||||||||||||||||||||
208 | case executed 4 times by 1 test: 's':case 's': Executed by:
executed 4 times by 1 test: case 's': Executed by:
| 4 | ||||||||||||||||||||||||
209 | suffix = optarg; | - | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | ((void) 0); | - | ||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||
213 | case executed 4 times by 1 test: 'a':case 'a': Executed by:
executed 4 times by 1 test: case 'a': Executed by:
code before this statement executed 4 times by 1 test: case 'a': Executed by:
| 4 | ||||||||||||||||||||||||
214 | multiple_names = | - | ||||||||||||||||||||||||
215 | 1 | - | ||||||||||||||||||||||||
216 | ; | - | ||||||||||||||||||||||||
217 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||
219 | case executed 7 times by 1 test: 'z':case 'z': Executed by:
executed 7 times by 1 test: case 'z': Executed by:
| 7 | ||||||||||||||||||||||||
220 | use_nuls = | - | ||||||||||||||||||||||||
221 | 1 | - | ||||||||||||||||||||||||
222 | ; | - | ||||||||||||||||||||||||
223 | break; executed 7 times by 1 test: break; Executed by:
| 7 | ||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | case executed 9 times by 1 test: GETOPT_HELP_CHAR:case GETOPT_HELP_CHAR: Executed by:
executed 9 times by 1 test: usage (case GETOPT_HELP_CHAR: Executed by:
| 9 | ||||||||||||||||||||||||
226 | 0 | - | ||||||||||||||||||||||||
227 | ); break; never executed: ;break; | 0 | ||||||||||||||||||||||||
228 | case executed 4 times by 1 test: GETOPT_VERSION_CHAR:case GETOPT_VERSION_CHAR: Executed by:
executed 4 times by 1 test: version_etc (case GETOPT_VERSION_CHAR: Executed by:
| 4 | ||||||||||||||||||||||||
229 | stdout | - | ||||||||||||||||||||||||
230 | , "basename", "GNU coreutils", Version, ("David MacKenzie"), (char *) | - | ||||||||||||||||||||||||
231 | ((void *)0) | - | ||||||||||||||||||||||||
232 | ); exit ( executed 4 times by 1 test: exit ( 0 ); Executed by:
| 4 | ||||||||||||||||||||||||
233 | 0 executed 4 times by 1 test: exit ( 0 ); Executed by:
| 4 | ||||||||||||||||||||||||
234 | ); executed 4 times by 1 test: break;exit ( 0 ); Executed by:
never executed: ;break; | 0-4 | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | default executed 3 times by 1 test: :default: Executed by:
executed 3 times by 1 test: default: Executed by:
| 3 | ||||||||||||||||||||||||
237 | usage ( | - | ||||||||||||||||||||||||
238 | 1 | - | ||||||||||||||||||||||||
239 | ); | - | ||||||||||||||||||||||||
240 | } never executed: end of block | 0 | ||||||||||||||||||||||||
241 | } | - | ||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||
243 | if (argc < optind + 1
| 1-37 | ||||||||||||||||||||||||
244 | { | - | ||||||||||||||||||||||||
245 | error (0, 0, | - | ||||||||||||||||||||||||
246 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
247 | "missing operand" | - | ||||||||||||||||||||||||
248 | , 5) | - | ||||||||||||||||||||||||
249 | ); | - | ||||||||||||||||||||||||
250 | usage ( | - | ||||||||||||||||||||||||
251 | 1 | - | ||||||||||||||||||||||||
252 | ); | - | ||||||||||||||||||||||||
253 | } never executed: end of block | 0 | ||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||
255 | if (!multiple_names
| 1-33 | ||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||
257 | error (0, 0, | - | ||||||||||||||||||||||||
258 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
259 | "extra operand %s" | - | ||||||||||||||||||||||||
260 | , 5) | - | ||||||||||||||||||||||||
261 | , quote (argv[optind + 2])); | - | ||||||||||||||||||||||||
262 | usage ( | - | ||||||||||||||||||||||||
263 | 1 | - | ||||||||||||||||||||||||
264 | ); | - | ||||||||||||||||||||||||
265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | if (multiple_names
| 4-32 | ||||||||||||||||||||||||
268 | { | - | ||||||||||||||||||||||||
269 | for (; optind < argc
| 4-8 | ||||||||||||||||||||||||
270 | perform_basename (argv[optind], suffix, use_nuls); executed 8 times by 1 test: perform_basename (argv[optind], suffix, use_nuls); Executed by:
| 8 | ||||||||||||||||||||||||
271 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
272 | else | - | ||||||||||||||||||||||||
273 | perform_basename (argv[optind], executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls); Executed by:
| 32 | ||||||||||||||||||||||||
274 | optind + 2 == argc ? argv[optind + 1] : executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls); Executed by:
| 32 | ||||||||||||||||||||||||
275 | ((void *)0) executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls); Executed by:
| 32 | ||||||||||||||||||||||||
276 | , use_nuls); executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls); Executed by:
| 32 | ||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | return executed 36 times by 1 test: return 0 ; Executed by:
executed 36 times by 1 test: return 0 ; Executed by:
| 36 | ||||||||||||||||||||||||
279 | 0 executed 36 times by 1 test: return 0 ; Executed by:
| 36 | ||||||||||||||||||||||||
280 | ; executed 36 times by 1 test: return 0 ; Executed by:
| 36 | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |