1 |
commit: 967b86446d70038ccdf3d014d5554be41d981edc |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Mar 23 15:07:55 2018 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Mar 23 15:07:55 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=967b8644 |
7 |
|
8 |
qdepends_vdb_deep_cb: show atom that matched |
9 |
|
10 |
This extracts the atom that matched the regular expression. |
11 |
|
12 |
qdepends.c | 24 +++++++++++++++++++++--- |
13 |
1 file changed, 21 insertions(+), 3 deletions(-) |
14 |
|
15 |
diff --git a/qdepends.c b/qdepends.c |
16 |
index e8b2190..117ca71 100644 |
17 |
--- a/qdepends.c |
18 |
+++ b/qdepends.c |
19 |
@@ -479,6 +479,9 @@ qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) |
20 |
static char *depend, *use; |
21 |
static size_t depend_len, use_len; |
22 |
dep_node *dep_tree; |
23 |
+ int ret; |
24 |
+ regex_t preg; |
25 |
+ regmatch_t match; |
26 |
|
27 |
if (!q_vdb_pkg_eat(pkg_ctx, state->depend_file, &depend, &depend_len)) |
28 |
return 0; |
29 |
@@ -506,7 +509,14 @@ qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) |
30 |
dep_prune_use(dep_tree, use); |
31 |
|
32 |
ptr = dep_flatten_tree(dep_tree); |
33 |
- if (ptr && rematch(state->query, ptr, REG_EXTENDED) == 0) { |
34 |
+ |
35 |
+ ret = -2; |
36 |
+ if (ptr && wregcomp(&preg, state->query, REG_EXTENDED) == 0) |
37 |
+ ret = regexec(&preg, ptr, 1, &match, 0); |
38 |
+ if (ret > -2) |
39 |
+ regfree(&preg); |
40 |
+ |
41 |
+ if (ptr && ret == 0) { |
42 |
if (qdep_name_only) { |
43 |
depend_atom *atom = NULL; |
44 |
snprintf(buf, sizeof(buf), "%s/%s", catname, pkgname); |
45 |
@@ -517,8 +527,16 @@ qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) |
46 |
} else { |
47 |
printf("%s%s/%s%s%s%c", BOLD, catname, BLUE, pkgname, NORM, verbose ? ':' : '\n'); |
48 |
} |
49 |
- if (verbose) |
50 |
- printf(" %s\n", ptr); |
51 |
+ if (verbose) { |
52 |
+ /* find the boundaries for this atom */ |
53 |
+ while (match.rm_so > 0 && !isspace(ptr[match.rm_so - 1])) |
54 |
+ match.rm_so--; |
55 |
+ while (ptr[match.rm_eo] != '\0' && !isspace(ptr[match.rm_eo])) |
56 |
+ match.rm_eo++; |
57 |
+ printf(" %.*s\n", |
58 |
+ (int)(match.rm_eo - match.rm_so), |
59 |
+ ptr + match.rm_so); |
60 |
+ } |
61 |
} |
62 |
dep_burn_tree(dep_tree); |