1 |
commit: a0c3ddab026e271b3eb2e66e64b9e9a24eb6f708 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Nov 27 23:26:17 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Nov 27 23:26:17 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a0c3ddab |
7 |
|
8 |
qgrep/quse: add multiple overlay support |
9 |
|
10 |
This is a pretty straight forward extension. The code hasn't seen |
11 |
any clean ups in the process (although it probably should). |
12 |
|
13 |
URL: https://bugs.gentoo.org/553260 |
14 |
|
15 |
qgrep.c | 366 +++++++++++++++++++++++++++++++++------------------------------- |
16 |
quse.c | 268 ++++++++++++++++++++++++----------------------- |
17 |
2 files changed, 329 insertions(+), 305 deletions(-) |
18 |
|
19 |
diff --git a/qgrep.c b/qgrep.c |
20 |
index de018ea..e7c2c10 100644 |
21 |
--- a/qgrep.c |
22 |
+++ b/qgrep.c |
23 |
@@ -259,7 +259,7 @@ int qgrep_main(int argc, char **argv) |
24 |
int need_separator = 0; |
25 |
char status = 1; |
26 |
|
27 |
- QGREP_STR_FUNC strfunc = (QGREP_STR_FUNC) strstr; |
28 |
+ QGREP_STR_FUNC strfunc = strstr; |
29 |
|
30 |
DBG("argc=%d argv[0]=%s argv[1]=%s", |
31 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
32 |
@@ -271,7 +271,7 @@ int qgrep_main(int argc, char **argv) |
33 |
switch (i) { |
34 |
case 'I': invert_match = 1; break; |
35 |
case 'i': |
36 |
- strfunc = (QGREP_STR_FUNC) strcasestr; |
37 |
+ strfunc = strcasestr; |
38 |
reflags |= REG_ICASE; |
39 |
break; |
40 |
case 'c': do_count = 1; break; |
41 |
@@ -369,203 +369,216 @@ int qgrep_main(int argc, char **argv) |
42 |
xregcomp(&skip_preg, skip_pattern, reflags); |
43 |
} |
44 |
|
45 |
- /* go look either in ebuilds or eclasses or VDB */ |
46 |
- if (!do_eclass && !do_installed) { |
47 |
- if ((fp = fopen(initialize_ebuild_flat(), "r")) == NULL) |
48 |
- return 1; |
49 |
- xchdir(portdir); |
50 |
- } else if (do_eclass) { |
51 |
- xchdir(portdir); |
52 |
- if ((eclass_dir = opendir("eclass")) == NULL) |
53 |
- errp("opendir(\"%s/eclass\") failed", portdir); |
54 |
- } else { /* if (do_install) */ |
55 |
- char buf[_Q_PATH_MAX]; |
56 |
- snprintf(buf, sizeof(buf), "%s/%s", portroot, portvdb); |
57 |
- xchdir(buf); |
58 |
- if ((vdb_dir = opendir(".")) == NULL) |
59 |
- errp("could not opendir(%s/%s) for ROOT/VDB", portroot, portvdb); |
60 |
- } |
61 |
- |
62 |
/* allocate a circular buffers list for --before */ |
63 |
buf_list = qgrep_buf_list_alloc(num_lines_before + 1); |
64 |
|
65 |
- /* iteration is either over ebuilds or eclasses */ |
66 |
- while (do_eclass |
67 |
- ? ((dentry = readdir(eclass_dir)) |
68 |
- && snprintf(ebuild, sizeof(ebuild), "eclass/%s", dentry->d_name)) |
69 |
- : (do_installed |
70 |
- ? (get_next_installed_ebuild(ebuild, vdb_dir, &dentry, &cat_dir) != NULL) |
71 |
- : (fgets(ebuild, sizeof(ebuild), fp) != NULL))) { |
72 |
- FILE *newfp; |
73 |
- |
74 |
- /* filter badly named files, prepare eclass or package name, etc. */ |
75 |
- if (do_eclass) { |
76 |
- if ((p = strrchr(ebuild, '.')) == NULL) |
77 |
+ size_t n; |
78 |
+ char *overlay; |
79 |
+ array_for_each(overlays, n, overlay) { |
80 |
+ |
81 |
+ /* go look either in ebuilds or eclasses or VDB */ |
82 |
+ if (!do_eclass && !do_installed) { |
83 |
+ fp = fopen(initialize_flat(overlay, CACHE_EBUILD, false), "re"); |
84 |
+ if (fp == NULL) |
85 |
continue; |
86 |
- if (strcmp(p, ".eclass")) |
87 |
+ xchdir(overlay); |
88 |
+ } else if (do_eclass) { |
89 |
+ xchdir(overlay); |
90 |
+ if ((eclass_dir = opendir("eclass")) == NULL) { |
91 |
+ if (errno != ENOENT) |
92 |
+ warnp("opendir(\"%s/eclass\") failed", overlay); |
93 |
continue; |
94 |
- if (show_name || (include_atoms != NULL)) { |
95 |
- /* cut ".eclass" */ |
96 |
- *p = '\0'; |
97 |
- /* and skip "eclass/" */ |
98 |
- snprintf(name, sizeof(name), "%s", ebuild + 7); |
99 |
- /* restore the filepath */ |
100 |
- *p = '.'; |
101 |
} |
102 |
- } else { |
103 |
- if ((p = strchr(ebuild, '\n')) != NULL) |
104 |
- *p = '\0'; |
105 |
- if (show_name || (include_atoms != NULL)) { |
106 |
- /* cut ".ebuild" */ |
107 |
- if (p == NULL) |
108 |
- p = ebuild + strlen(ebuild); |
109 |
- *(p-7) = '\0'; |
110 |
- /* cut "/foo/" from "cat/foo/foo-x.y" */ |
111 |
- if ((p = strchr(ebuild, '/')) == NULL) |
112 |
+ } else { /* if (do_install) */ |
113 |
+ char buf[_Q_PATH_MAX]; |
114 |
+ snprintf(buf, sizeof(buf), "%s/%s", portroot, portvdb); |
115 |
+ xchdir(buf); |
116 |
+ if ((vdb_dir = opendir(".")) == NULL) |
117 |
+ errp("could not opendir(%s/%s) for ROOT/VDB", portroot, portvdb); |
118 |
+ } |
119 |
+ |
120 |
+ /* iteration is either over ebuilds or eclasses */ |
121 |
+ while (do_eclass |
122 |
+ ? ((dentry = readdir(eclass_dir)) |
123 |
+ && snprintf(ebuild, sizeof(ebuild), "eclass/%s", dentry->d_name)) |
124 |
+ : (do_installed |
125 |
+ ? (get_next_installed_ebuild(ebuild, vdb_dir, &dentry, &cat_dir) != NULL) |
126 |
+ : (fgets(ebuild, sizeof(ebuild), fp) != NULL))) { |
127 |
+ FILE *newfp; |
128 |
+ |
129 |
+ /* filter badly named files, prepare eclass or package name, etc. */ |
130 |
+ if (do_eclass) { |
131 |
+ if ((p = strrchr(ebuild, '.')) == NULL) |
132 |
continue; |
133 |
- *(p++) = '\0'; |
134 |
- /* find head of the ebuild basename */ |
135 |
- if ((p = strchr(p, '/')) == NULL) |
136 |
+ if (strcmp(p, ".eclass")) |
137 |
continue; |
138 |
- /* find start of the pkg name */ |
139 |
- snprintf(name, sizeof(name), "%s/%s", ebuild, (p+1)); |
140 |
- /* restore the filepath */ |
141 |
- *p = '/'; |
142 |
- *(p + strlen(p)) = '.'; |
143 |
- ebuild[strlen(ebuild)] = '/'; |
144 |
+ if (show_name || (include_atoms != NULL)) { |
145 |
+ /* cut ".eclass" */ |
146 |
+ *p = '\0'; |
147 |
+ /* and skip "eclass/" */ |
148 |
+ snprintf(name, sizeof(name), "%s", ebuild + 7); |
149 |
+ /* restore the filepath */ |
150 |
+ *p = '.'; |
151 |
+ } |
152 |
+ } else { |
153 |
+ if ((p = strchr(ebuild, '\n')) != NULL) |
154 |
+ *p = '\0'; |
155 |
+ if (show_name || (include_atoms != NULL)) { |
156 |
+ /* cut ".ebuild" */ |
157 |
+ if (p == NULL) |
158 |
+ p = ebuild + strlen(ebuild); |
159 |
+ *(p-7) = '\0'; |
160 |
+ /* cut "/foo/" from "cat/foo/foo-x.y" */ |
161 |
+ if ((p = strchr(ebuild, '/')) == NULL) |
162 |
+ continue; |
163 |
+ *(p++) = '\0'; |
164 |
+ /* find head of the ebuild basename */ |
165 |
+ if ((p = strchr(p, '/')) == NULL) |
166 |
+ continue; |
167 |
+ /* find start of the pkg name */ |
168 |
+ snprintf(name, sizeof(name), "%s/%s", ebuild, (p+1)); |
169 |
+ /* restore the filepath */ |
170 |
+ *p = '/'; |
171 |
+ *(p + strlen(p)) = '.'; |
172 |
+ ebuild[strlen(ebuild)] = '/'; |
173 |
+ } |
174 |
} |
175 |
- } |
176 |
|
177 |
- /* filter the files we grep when there are extra args */ |
178 |
- if (include_atoms != NULL) |
179 |
- if (!qgrep_name_match(name, (argc - optind - 1), include_atoms)) |
180 |
- continue; |
181 |
- |
182 |
- if ((newfp = fopen(ebuild, "r")) != NULL) { |
183 |
- int lineno = 0; |
184 |
- char remaining_after_context = 0; |
185 |
- count = 0; |
186 |
- /* if there have been some matches already, then a separator will be needed */ |
187 |
- need_separator = (!status) && (num_lines_before || num_lines_after); |
188 |
- /* whatever is in the circular buffers list is no more a valid context */ |
189 |
- qgrep_buf_list_invalidate(buf_list); |
190 |
- |
191 |
- /* reading a new line always happen in the next buffer of the list */ |
192 |
- while ((buf_list = buf_list->next) |
193 |
- && (fgets(buf_list->buf, sizeof(buf_list->buf), newfp)) != NULL) { |
194 |
- lineno++; |
195 |
- buf_list->valid = 1; |
196 |
- |
197 |
- /* cleanup EOL */ |
198 |
- if ((p = strrchr(buf_list->buf, '\n')) != NULL) |
199 |
- *p = 0; |
200 |
- if ((p = strrchr(buf_list->buf, '\r')) != NULL) |
201 |
- *p = 0; |
202 |
- |
203 |
- if (skip_comments) { |
204 |
- /* reject comments line ("^[ \t]*#") */ |
205 |
- p = buf_list->buf; |
206 |
- while (*p == ' ' || *p == '\t') p++; |
207 |
- if (*p == '#') |
208 |
- goto print_after_context; |
209 |
- } |
210 |
+ /* filter the files we grep when there are extra args */ |
211 |
+ if (include_atoms != NULL) |
212 |
+ if (!qgrep_name_match(name, (argc - optind - 1), include_atoms)) |
213 |
+ continue; |
214 |
|
215 |
- if (skip_pattern) { |
216 |
- /* reject some other lines which match an optional pattern */ |
217 |
- if (!do_regex) { |
218 |
- if (strfunc(buf_list->buf, skip_pattern) != NULL) |
219 |
- goto print_after_context; |
220 |
- } else { |
221 |
- if (regexec(&skip_preg, buf_list->buf, 0, NULL, 0) == 0) |
222 |
+ if ((newfp = fopen(ebuild, "r")) != NULL) { |
223 |
+ int lineno = 0; |
224 |
+ char remaining_after_context = 0; |
225 |
+ count = 0; |
226 |
+ /* if there have been some matches already, then a separator will be needed */ |
227 |
+ need_separator = (!status) && (num_lines_before || num_lines_after); |
228 |
+ /* whatever is in the circular buffers list is no more a valid context */ |
229 |
+ qgrep_buf_list_invalidate(buf_list); |
230 |
+ |
231 |
+ /* reading a new line always happen in the next buffer of the list */ |
232 |
+ while ((buf_list = buf_list->next) |
233 |
+ && (fgets(buf_list->buf, sizeof(buf_list->buf), newfp)) != NULL) { |
234 |
+ lineno++; |
235 |
+ buf_list->valid = 1; |
236 |
+ |
237 |
+ /* cleanup EOL */ |
238 |
+ if ((p = strrchr(buf_list->buf, '\n')) != NULL) |
239 |
+ *p = 0; |
240 |
+ if ((p = strrchr(buf_list->buf, '\r')) != NULL) |
241 |
+ *p = 0; |
242 |
+ |
243 |
+ if (skip_comments) { |
244 |
+ /* reject comments line ("^[ \t]*#") */ |
245 |
+ p = buf_list->buf; |
246 |
+ while (*p == ' ' || *p == '\t') p++; |
247 |
+ if (*p == '#') |
248 |
goto print_after_context; |
249 |
} |
250 |
- } |
251 |
|
252 |
- /* four ways to match a line (with/without inversion and regexp) */ |
253 |
- if (!invert_match) { |
254 |
- if (do_regex == 0) { |
255 |
- if (strfunc(buf_list->buf, argv[optind]) == NULL) |
256 |
- goto print_after_context; |
257 |
- } else { |
258 |
- if (regexec(&preg, buf_list->buf, 0, NULL, 0) != 0) |
259 |
- goto print_after_context; |
260 |
+ if (skip_pattern) { |
261 |
+ /* reject some other lines which match an optional pattern */ |
262 |
+ if (!do_regex) { |
263 |
+ if (strfunc(buf_list->buf, skip_pattern) != NULL) |
264 |
+ goto print_after_context; |
265 |
+ } else { |
266 |
+ if (regexec(&skip_preg, buf_list->buf, 0, NULL, 0) == 0) |
267 |
+ goto print_after_context; |
268 |
+ } |
269 |
} |
270 |
- } else { |
271 |
- if (do_regex == 0) { |
272 |
- if (strfunc(buf_list->buf, argv[optind]) != NULL) |
273 |
- goto print_after_context; |
274 |
+ |
275 |
+ /* four ways to match a line (with/without inversion and regexp) */ |
276 |
+ if (!invert_match) { |
277 |
+ if (do_regex == 0) { |
278 |
+ if (strfunc(buf_list->buf, argv[optind]) == NULL) |
279 |
+ goto print_after_context; |
280 |
+ } else { |
281 |
+ if (regexec(&preg, buf_list->buf, 0, NULL, 0) != 0) |
282 |
+ goto print_after_context; |
283 |
+ } |
284 |
} else { |
285 |
- if (regexec(&preg, buf_list->buf, 0, NULL, 0) == 0) |
286 |
- goto print_after_context; |
287 |
+ if (do_regex == 0) { |
288 |
+ if (strfunc(buf_list->buf, argv[optind]) != NULL) |
289 |
+ goto print_after_context; |
290 |
+ } else { |
291 |
+ if (regexec(&preg, buf_list->buf, 0, NULL, 0) == 0) |
292 |
+ goto print_after_context; |
293 |
+ } |
294 |
} |
295 |
- } |
296 |
|
297 |
- count++; |
298 |
- status = 0; /* got a match, exit status should be 0 */ |
299 |
- if (per_file_output) |
300 |
- continue; /* matching files are listed out of this loop */ |
301 |
- |
302 |
- if ((need_separator > 0) |
303 |
- && (num_lines_before || num_lines_after)) |
304 |
- printf("--\n"); |
305 |
- /* "need_separator" is not a flag, but a counter, so that |
306 |
- * adjacent contextes are not separated */ |
307 |
- need_separator = 0 - num_lines_before; |
308 |
- if (!do_list) { |
309 |
- /* print the leading context */ |
310 |
- qgrep_print_before_context(buf_list, num_lines_before, label, |
311 |
- ((verbose > 1) ? lineno : -1)); |
312 |
- /* print matching line */ |
313 |
- if (invert_match || *RED == '\0') |
314 |
- qgrep_print_matching_line_nocolor(buf_list, label, |
315 |
- ((verbose > 1) ? lineno : -1)); |
316 |
- else if (do_regex) |
317 |
- qgrep_print_matching_line_regcolor(buf_list, label, |
318 |
- ((verbose > 1) ? lineno : -1), &preg); |
319 |
- else |
320 |
- qgrep_print_matching_line_strcolor(buf_list, label, |
321 |
- ((verbose > 1) ? lineno : -1), strfunc, argv[optind]); |
322 |
- } else { |
323 |
- /* in verbose do_list mode, list the file once per match */ |
324 |
- printf("%s", label); |
325 |
- if (verbose > 1) |
326 |
- printf(":%d", lineno); |
327 |
- putchar('\n'); |
328 |
- } |
329 |
- /* init count down of trailing context lines */ |
330 |
- remaining_after_context = num_lines_after; |
331 |
- continue; |
332 |
+ count++; |
333 |
+ status = 0; /* got a match, exit status should be 0 */ |
334 |
+ if (per_file_output) |
335 |
+ continue; /* matching files are listed out of this loop */ |
336 |
+ |
337 |
+ if ((need_separator > 0) |
338 |
+ && (num_lines_before || num_lines_after)) |
339 |
+ printf("--\n"); |
340 |
+ /* "need_separator" is not a flag, but a counter, so that |
341 |
+ * adjacent contextes are not separated */ |
342 |
+ need_separator = 0 - num_lines_before; |
343 |
+ if (!do_list) { |
344 |
+ /* print the leading context */ |
345 |
+ qgrep_print_before_context(buf_list, num_lines_before, label, |
346 |
+ ((verbose > 1) ? lineno : -1)); |
347 |
+ /* print matching line */ |
348 |
+ if (invert_match || *RED == '\0') |
349 |
+ qgrep_print_matching_line_nocolor(buf_list, label, |
350 |
+ ((verbose > 1) ? lineno : -1)); |
351 |
+ else if (do_regex) |
352 |
+ qgrep_print_matching_line_regcolor(buf_list, label, |
353 |
+ ((verbose > 1) ? lineno : -1), &preg); |
354 |
+ else |
355 |
+ qgrep_print_matching_line_strcolor(buf_list, label, |
356 |
+ ((verbose > 1) ? lineno : -1), strfunc, argv[optind]); |
357 |
+ } else { |
358 |
+ /* in verbose do_list mode, list the file once per match */ |
359 |
+ printf("%s", label); |
360 |
+ if (verbose > 1) |
361 |
+ printf(":%d", lineno); |
362 |
+ putchar('\n'); |
363 |
+ } |
364 |
+ /* init count down of trailing context lines */ |
365 |
+ remaining_after_context = num_lines_after; |
366 |
+ continue; |
367 |
|
368 |
-print_after_context: |
369 |
- /* print some trailing context lines when needed */ |
370 |
- if (!remaining_after_context) { |
371 |
- if (!status) |
372 |
- /* we're getting closer to the need of a separator between |
373 |
- * current match block and the next one */ |
374 |
- ++need_separator; |
375 |
- } else { |
376 |
- qgrep_print_context_line(buf_list, label, |
377 |
- ((verbose > 1) ? lineno : -1)); |
378 |
- --remaining_after_context; |
379 |
+ print_after_context: |
380 |
+ /* print some trailing context lines when needed */ |
381 |
+ if (!remaining_after_context) { |
382 |
+ if (!status) |
383 |
+ /* we're getting closer to the need of a separator between |
384 |
+ * current match block and the next one */ |
385 |
+ ++need_separator; |
386 |
+ } else { |
387 |
+ qgrep_print_context_line(buf_list, label, |
388 |
+ ((verbose > 1) ? lineno : -1)); |
389 |
+ --remaining_after_context; |
390 |
+ } |
391 |
} |
392 |
+ fclose(newfp); |
393 |
+ if (!per_file_output) |
394 |
+ continue; /* matches were already displayed, line per line */ |
395 |
+ if (do_count && count) { |
396 |
+ if (label != NULL) |
397 |
+ /* -c without -v/-N/-H only outputs |
398 |
+ * the matches count of the file */ |
399 |
+ printf("%s:", label); |
400 |
+ printf("%d\n", count); |
401 |
+ } else if ((count && !invert_list) || (!count && invert_list)) |
402 |
+ printf("%s\n", label); /* do_list == 1, or we wouldn't be here */ |
403 |
} |
404 |
- fclose(newfp); |
405 |
- if (!per_file_output) |
406 |
- continue; /* matches were already displayed, line per line */ |
407 |
- if (do_count && count) { |
408 |
- if (label != NULL) |
409 |
- /* -c without -v/-N/-H only outputs |
410 |
- * the matches count of the file */ |
411 |
- printf("%s:", label); |
412 |
- printf("%d\n", count); |
413 |
- } else if ((count && !invert_list) || (!count && invert_list)) |
414 |
- printf("%s\n", label); /* do_list == 1, or we wouldn't be here */ |
415 |
} |
416 |
+ if (do_eclass) |
417 |
+ closedir(eclass_dir); |
418 |
+ else if (!do_installed) |
419 |
+ fclose(fp); |
420 |
+ |
421 |
+ if (do_installed) |
422 |
+ break; |
423 |
} |
424 |
- if (do_eclass) |
425 |
- closedir(eclass_dir); |
426 |
- else if (!do_installed) |
427 |
- fclose(fp); |
428 |
+ |
429 |
if (do_regex) |
430 |
regfree(&preg); |
431 |
if (do_regex && skip_pattern) |
432 |
@@ -577,6 +590,7 @@ print_after_context: |
433 |
free(include_atoms); |
434 |
} |
435 |
qgrep_buf_list_free(buf_list); |
436 |
+ |
437 |
return status; |
438 |
} |
439 |
|
440 |
|
441 |
diff --git a/quse.c b/quse.c |
442 |
index 8ba0be1..2ac6cad 100644 |
443 |
--- a/quse.c |
444 |
+++ b/quse.c |
445 |
@@ -239,6 +239,8 @@ int quse_main(int argc, char **argv) |
446 |
short quse_all = 0; |
447 |
int regexp_matching = 1, i, idx = 0; |
448 |
size_t search_len; |
449 |
+ size_t n; |
450 |
+ const char *overlay; |
451 |
|
452 |
DBG("argc=%d argv[0]=%s argv[1]=%s", |
453 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
454 |
@@ -259,179 +261,187 @@ int quse_main(int argc, char **argv) |
455 |
quse_usage(EXIT_FAILURE); |
456 |
|
457 |
if (idx == -1) { |
458 |
- size_t n; |
459 |
- const char *overlay; |
460 |
array_for_each(overlays, n, overlay) |
461 |
quse_describe_flag(overlay, optind, argc, argv); |
462 |
return 0; |
463 |
} |
464 |
|
465 |
if (quse_all) optind = argc; |
466 |
- cache_file = initialize_ebuild_flat(); |
467 |
|
468 |
search_len = strlen(search_vars[idx]); |
469 |
assert(search_len < sizeof(buf0)); |
470 |
|
471 |
- if ((fp = fopen(cache_file, "r")) == NULL) { |
472 |
- warnp("could not read cache: %s", cache_file); |
473 |
- return 1; |
474 |
- } |
475 |
+ array_for_each(overlays, n, overlay) { |
476 |
+ cache_file = initialize_flat(overlay, CACHE_EBUILD, false); |
477 |
|
478 |
- int portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH); |
479 |
+ if ((fp = fopen(cache_file, "re")) == NULL) { |
480 |
+ warnp("could not read cache: %s", cache_file); |
481 |
+ continue; |
482 |
+ } |
483 |
|
484 |
- ebuild = NULL; |
485 |
- while ((linelen = getline(&ebuild, &ebuildlen, fp)) != -1) { |
486 |
- FILE *newfp; |
487 |
- int fd; |
488 |
+ int overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH); |
489 |
|
490 |
- rmspace_len(ebuild, linelen); |
491 |
+ ebuild = NULL; |
492 |
+ while ((linelen = getline(&ebuild, &ebuildlen, fp)) != -1) { |
493 |
+ FILE *newfp; |
494 |
+ int fd; |
495 |
|
496 |
- fd = openat(portdir_fd, ebuild, O_RDONLY|O_CLOEXEC); |
497 |
- if (fd < 0) |
498 |
- continue; |
499 |
- newfp = fdopen(fd, "r"); |
500 |
- if (newfp != NULL) { |
501 |
- unsigned int lineno = 0; |
502 |
- char revision[sizeof(buf0)]; |
503 |
- char date[sizeof(buf0)]; |
504 |
- char user[sizeof(buf0)]; |
505 |
- |
506 |
- revision[0] = 0; |
507 |
- user[0] = 0; |
508 |
- date[0] = 0; |
509 |
- while (fgets(buf0, sizeof(buf0), newfp) != NULL) { |
510 |
- int ok = 0; |
511 |
- char warned = 0; |
512 |
- lineno++; |
513 |
- |
514 |
- if (*buf0 == '#') { |
515 |
- if (strncmp(buf0, "# $Header: /", 12) == 0) |
516 |
- sscanf(buf0, "%*s %*s %*s %s %s %*s %s %*s %*s", (char *) &revision, (char *) &date, (char *) &user); |
517 |
- continue; |
518 |
- } |
519 |
- if (strncmp(buf0, search_vars[idx], search_len) != 0) |
520 |
- continue; |
521 |
+ rmspace_len(ebuild, linelen); |
522 |
+ |
523 |
+ fd = openat(overlay_fd, ebuild, O_RDONLY|O_CLOEXEC); |
524 |
+ if (fd < 0) |
525 |
+ continue; |
526 |
+ newfp = fdopen(fd, "r"); |
527 |
+ if (newfp != NULL) { |
528 |
+ unsigned int lineno = 0; |
529 |
+ char revision[sizeof(buf0)]; |
530 |
+ char date[sizeof(buf0)]; |
531 |
+ char user[sizeof(buf0)]; |
532 |
+ |
533 |
+ revision[0] = 0; |
534 |
+ user[0] = 0; |
535 |
+ date[0] = 0; |
536 |
+ while (fgets(buf0, sizeof(buf0), newfp) != NULL) { |
537 |
+ int ok = 0; |
538 |
+ char warned = 0; |
539 |
+ lineno++; |
540 |
+ |
541 |
+ if (*buf0 == '#') { |
542 |
+ if (strncmp(buf0, "# $Header: /", 12) == 0) |
543 |
+ sscanf(buf0, "%*s %*s %*s %s %s %*s %s %*s %*s", |
544 |
+ revision, date, user); |
545 |
+ continue; |
546 |
+ } |
547 |
+ if (strncmp(buf0, search_vars[idx], search_len) != 0) |
548 |
+ continue; |
549 |
|
550 |
- if ((p = strchr(buf0, '\n')) != NULL) |
551 |
- *p = 0; |
552 |
- if ((p = strchr(buf0, '#')) != NULL) { |
553 |
- if (buf0 != p && p[-1] == ' ') |
554 |
- p[-1] = 0; |
555 |
- else |
556 |
+ if ((p = strchr(buf0, '\n')) != NULL) |
557 |
*p = 0; |
558 |
- } |
559 |
- if (verbose > 1) { |
560 |
- if ((strchr(buf0, '\t') != NULL) |
561 |
- || (strchr(buf0, '$') != NULL) |
562 |
- || (strchr(buf0, '\\') != NULL) |
563 |
- || (strchr(buf0, '\'') != NULL) |
564 |
- || (strstr(buf0, " ") != NULL)) { |
565 |
- warned = 1; |
566 |
- warn("# Line %d of %s has an annoying %s", lineno, ebuild, buf0); |
567 |
+ if ((p = strchr(buf0, '#')) != NULL) { |
568 |
+ if (buf0 != p && p[-1] == ' ') |
569 |
+ p[-1] = 0; |
570 |
+ else |
571 |
+ *p = 0; |
572 |
+ } |
573 |
+ if (verbose > 1) { |
574 |
+ if ((strchr(buf0, '\t') != NULL) |
575 |
+ || (strchr(buf0, '$') != NULL) |
576 |
+ || (strchr(buf0, '\\') != NULL) |
577 |
+ || (strchr(buf0, '\'') != NULL) |
578 |
+ || (strstr(buf0, " ") != NULL)) { |
579 |
+ warned = 1; |
580 |
+ warn("# Line %d of %s has an annoying %s", |
581 |
+ lineno, ebuild, buf0); |
582 |
+ } |
583 |
} |
584 |
- } |
585 |
#ifdef THIS_SUCKS |
586 |
- if ((p = strrchr(&buf0[search_len + 1], '\\')) != NULL) { |
587 |
+ if ((p = strrchr(&buf0[search_len + 1], '\\')) != NULL) { |
588 |
|
589 |
- multiline: |
590 |
- *p = ' '; |
591 |
+ multiline: |
592 |
+ *p = ' '; |
593 |
|
594 |
- if (fgets(buf1, sizeof(buf1), newfp) == NULL) |
595 |
- continue; |
596 |
- lineno++; |
597 |
+ if (fgets(buf1, sizeof(buf1), newfp) == NULL) |
598 |
+ continue; |
599 |
+ lineno++; |
600 |
|
601 |
- if ((p = strchr(buf1, '\n')) != NULL) |
602 |
- *p = 0; |
603 |
- snprintf(buf2, sizeof(buf2), "%s %s", buf0, buf1); |
604 |
- remove_extra_space(buf2); |
605 |
- strcpy(buf0, buf2); |
606 |
- if ((p = strrchr(buf1, '\\')) != NULL) |
607 |
- goto multiline; |
608 |
- } |
609 |
+ if ((p = strchr(buf1, '\n')) != NULL) |
610 |
+ *p = 0; |
611 |
+ snprintf(buf2, sizeof(buf2), "%s %s", buf0, buf1); |
612 |
+ remove_extra_space(buf2); |
613 |
+ strcpy(buf0, buf2); |
614 |
+ if ((p = strrchr(buf1, '\\')) != NULL) |
615 |
+ goto multiline; |
616 |
+ } |
617 |
#else |
618 |
- remove_extra_space(buf0); |
619 |
+ remove_extra_space(buf0); |
620 |
#endif |
621 |
- while ((p = strrchr(&buf0[search_len + 1], '"')) != NULL) *p = 0; |
622 |
- while ((p = strrchr(&buf0[search_len + 1], '\'')) != NULL) *p = 0; |
623 |
- while ((p = strrchr(&buf0[search_len + 1], '\\')) != NULL) *p = ' '; |
624 |
- |
625 |
- if (verbose && warned == 0) { |
626 |
- if ((strchr(buf0, '$') != NULL) || (strchr(buf0, '\\') != NULL)) { |
627 |
- warned = 1; |
628 |
- warn("# Line %d of %s has an annoying %s", lineno, ebuild, buf0); |
629 |
+ while ((p = strrchr(&buf0[search_len + 1], '"')) != NULL) *p = 0; |
630 |
+ while ((p = strrchr(&buf0[search_len + 1], '\'')) != NULL) *p = 0; |
631 |
+ while ((p = strrchr(&buf0[search_len + 1], '\\')) != NULL) *p = ' '; |
632 |
+ |
633 |
+ if (verbose && warned == 0) { |
634 |
+ if ((strchr(buf0, '$') != NULL) || (strchr(buf0, '\\') != NULL)) { |
635 |
+ warned = 1; |
636 |
+ warn("# Line %d of %s has an annoying %s", |
637 |
+ lineno, ebuild, buf0); |
638 |
+ } |
639 |
} |
640 |
- } |
641 |
|
642 |
- if (strlen(buf0) < search_len + 1) { |
643 |
- /* warnf("err '%s'/%zu <= %zu; line %u\n", buf0, strlen(buf0), search_len + 1, lineno); */ |
644 |
- continue; |
645 |
- } |
646 |
+ if (strlen(buf0) < search_len + 1) { |
647 |
+ /* warnf("err '%s'/%zu <= %zu; line %u\n", buf0, strlen(buf0), search_len + 1, lineno); */ |
648 |
+ continue; |
649 |
+ } |
650 |
|
651 |
- if ((argc == optind) || (quse_all)) { |
652 |
- ok = 1; |
653 |
- } else { |
654 |
- ok = 0; |
655 |
- if (regexp_matching) { |
656 |
- for (i = optind; i < argc; ++i) { |
657 |
- if (rematch(argv[i], &buf0[search_len + 1], REG_NOSUB) == 0) { |
658 |
- ok = 1; |
659 |
- break; |
660 |
- } |
661 |
- } |
662 |
+ if ((argc == optind) || (quse_all)) { |
663 |
+ ok = 1; |
664 |
} else { |
665 |
- remove_extra_space(buf0); |
666 |
- strcpy(buf1, &buf0[search_len + 1]); |
667 |
- |
668 |
- for (i = (size_t) optind; i < argc && argv[i] != NULL; i++) { |
669 |
- if (strcmp(buf1, argv[i]) == 0) { |
670 |
- ok = 1; |
671 |
- break; |
672 |
+ ok = 0; |
673 |
+ if (regexp_matching) { |
674 |
+ for (i = optind; i < argc; ++i) { |
675 |
+ if (rematch(argv[i], &buf0[search_len + 1], REG_NOSUB) == 0) { |
676 |
+ ok = 1; |
677 |
+ break; |
678 |
+ } |
679 |
} |
680 |
- } |
681 |
- if (ok == 0) while ((p = strchr(buf1, ' ')) != NULL) { |
682 |
- *p = 0; |
683 |
+ } else { |
684 |
+ remove_extra_space(buf0); |
685 |
+ strcpy(buf1, &buf0[search_len + 1]); |
686 |
+ |
687 |
for (i = (size_t) optind; i < argc && argv[i] != NULL; i++) { |
688 |
if (strcmp(buf1, argv[i]) == 0) { |
689 |
ok = 1; |
690 |
break; |
691 |
} |
692 |
} |
693 |
- strcpy(buf2, p + 1); |
694 |
- strcpy(buf1, buf2); |
695 |
- if (strchr(buf1, ' ') == NULL) |
696 |
+ if (ok == 0) while ((p = strchr(buf1, ' ')) != NULL) { |
697 |
+ *p = 0; |
698 |
for (i = (size_t) optind; i < argc && argv[i] != NULL; i++) { |
699 |
- if (strcmp(buf1, argv[i]) == 0) |
700 |
+ if (strcmp(buf1, argv[i]) == 0) { |
701 |
ok = 1; |
702 |
+ break; |
703 |
+ } |
704 |
} |
705 |
+ strcpy(buf2, p + 1); |
706 |
+ strcpy(buf1, buf2); |
707 |
+ if (strchr(buf1, ' ') == NULL) |
708 |
+ for (i = (size_t) optind; i < argc && argv[i] != NULL; i++) { |
709 |
+ if (strcmp(buf1, argv[i]) == 0) |
710 |
+ ok = 1; |
711 |
+ } |
712 |
+ } |
713 |
} |
714 |
} |
715 |
- } |
716 |
- if (ok) { |
717 |
- if (verbose > 3) |
718 |
- printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING"); |
719 |
- |
720 |
- printf("%s%s%s ", CYAN, ebuild, NORM); |
721 |
- print_highlighted_use_flags(&buf0[search_len + 1], optind, argc, argv); |
722 |
- puts(NORM); |
723 |
- if (verbose > 1) { |
724 |
- char **ARGV; |
725 |
- int ARGC; |
726 |
- makeargv(&buf0[search_len + 1], &ARGC, &ARGV); |
727 |
- quse_describe_flag(portdir, 1, ARGC, ARGV); |
728 |
- freeargv(ARGC, ARGV); |
729 |
+ if (ok) { |
730 |
+ if (verbose > 3) |
731 |
+ printf("%s %s %s ", |
732 |
+ *user ? user : "MISSING", |
733 |
+ *revision ? revision : "MISSING", |
734 |
+ *date ? date : "MISSING"); |
735 |
+ |
736 |
+ printf("%s%s%s ", CYAN, ebuild, NORM); |
737 |
+ print_highlighted_use_flags(&buf0[search_len + 1], optind, argc, argv); |
738 |
+ puts(NORM); |
739 |
+ if (verbose > 1) { |
740 |
+ char **ARGV; |
741 |
+ int ARGC; |
742 |
+ makeargv(&buf0[search_len + 1], &ARGC, &ARGV); |
743 |
+ quse_describe_flag(overlay, 1, ARGC, ARGV); |
744 |
+ freeargv(ARGC, ARGV); |
745 |
+ } |
746 |
} |
747 |
+ break; |
748 |
} |
749 |
- break; |
750 |
+ fclose(newfp); |
751 |
+ } else { |
752 |
+ if (!reinitialize) |
753 |
+ warnfp("(cache update pending) %s", ebuild); |
754 |
+ reinitialize = 1; |
755 |
} |
756 |
- fclose(newfp); |
757 |
- } else { |
758 |
- if (!reinitialize) |
759 |
- warnfp("(cache update pending) %s", ebuild); |
760 |
- reinitialize = 1; |
761 |
} |
762 |
+ fclose(fp); |
763 |
+ close(overlay_fd); |
764 |
} |
765 |
- fclose(fp); |
766 |
- close(portdir_fd); |
767 |
+ |
768 |
return EXIT_SUCCESS; |
769 |
} |