1 |
commit: 76a1156271195be5d243f015269de35ab0ec9043 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 11 11:10:32 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 11 11:10:32 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=76a11562 |
7 |
|
8 |
qlist: simplify qlist_match somewhat reusing autom parsing |
9 |
|
10 |
qlist_match should go eventually, but this brings it into a little less |
11 |
redundant mode |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
TODO.md | 2 + |
16 |
qlist.c | 147 ++++++++++++++++++++++++++++++++-------------------------------- |
17 |
2 files changed, 75 insertions(+), 74 deletions(-) |
18 |
|
19 |
diff --git a/TODO.md b/TODO.md |
20 |
index 768c435..7df8983 100644 |
21 |
--- a/TODO.md |
22 |
+++ b/TODO.md |
23 |
@@ -29,6 +29,8 @@ |
24 |
- tree\_get\_atoms should return atoms iso string set, needs a rewrite |
25 |
to use foreach\_pkg and get\_atom |
26 |
|
27 |
+- remove odd pverbose argument to atom\_format |
28 |
+ |
29 |
# Atoms |
30 |
|
31 |
- only 32bit values are supported for revision (-r#) |
32 |
|
33 |
diff --git a/qlist.c b/qlist.c |
34 |
index 32c87b4..9219108 100644 |
35 |
--- a/qlist.c |
36 |
+++ b/qlist.c |
37 |
@@ -184,34 +184,39 @@ qlist_match( |
38 |
depend_atom **name_atom, |
39 |
bool exact) |
40 |
{ |
41 |
- const char *catname = pkg_ctx->cat_ctx->name; |
42 |
- const char *pkgname = pkg_ctx->name; |
43 |
char buf[_Q_PATH_MAX]; |
44 |
- char swap[_Q_PATH_MAX]; |
45 |
- const char *uslot; |
46 |
- size_t uslot_len = 0; |
47 |
+ char uslot[32]; |
48 |
+ char *usslot = NULL; |
49 |
const char *urepo; |
50 |
- size_t urepo_len = 0; |
51 |
+ size_t pf_len; |
52 |
depend_atom *atom; |
53 |
depend_atom *_atom = NULL; |
54 |
|
55 |
- uslot = strchr(name, ':'); |
56 |
- if (uslot != NULL) { |
57 |
- if (*++uslot == ':') |
58 |
- uslot = NULL; |
59 |
- else { |
60 |
- uslot_len = strlen(uslot); |
61 |
+ uslot[0] = '\0'; |
62 |
+ urepo = strchr(name, ':'); |
63 |
+ if (urepo != NULL) { |
64 |
+ pf_len = urepo - name; |
65 |
+ if (*++urepo == ':') { |
66 |
+ uslot[0] = '\0'; |
67 |
+ urepo++; |
68 |
+ } else { |
69 |
+ usslot = (char *)urepo; |
70 |
+ urepo = strstr(urepo, "::"); |
71 |
+ if (urepo != NULL) { |
72 |
+ snprintf(uslot, sizeof(uslot), "%.*s", |
73 |
+ (int)(urepo - usslot), usslot); |
74 |
+ urepo += 2; |
75 |
+ } else { |
76 |
+ snprintf(uslot, sizeof(uslot), "%s", usslot); |
77 |
+ } |
78 |
+ if ((usslot = strchr(uslot, '/')) != NULL) |
79 |
+ *usslot++ = '\0'; |
80 |
} |
81 |
+ } else { |
82 |
+ pf_len = strlen(name); |
83 |
} |
84 |
|
85 |
- urepo = strstr(name, "::"); |
86 |
- if (urepo != NULL) { |
87 |
- urepo += 2; |
88 |
- urepo_len = strlen(urepo); |
89 |
- |
90 |
- if (uslot_len) |
91 |
- uslot_len -= (urepo_len + 2); |
92 |
- } |
93 |
+ atom = tree_get_atom(pkg_ctx, uslot[0] != '\0' || urepo != NULL); |
94 |
|
95 |
/* maybe they're using a version range */ |
96 |
switch (name[0]) { |
97 |
@@ -219,8 +224,6 @@ qlist_match( |
98 |
case '>': |
99 |
case '<': |
100 |
case '~': |
101 |
- atom = tree_get_atom(pkg_ctx, uslot != NULL || urepo != NULL); |
102 |
- |
103 |
if (!name_atom) |
104 |
name_atom = &_atom; |
105 |
if (!*name_atom) { |
106 |
@@ -233,26 +236,36 @@ qlist_match( |
107 |
return atom_compare(atom, *name_atom) == EQUAL; |
108 |
} |
109 |
|
110 |
- if (uslot) { |
111 |
+ if (uslot[0] != '\0') { |
112 |
+ if (pkg_ctx->slot == NULL) |
113 |
+ return false; |
114 |
+ |
115 |
/* Require exact match on SLOTs. If the user didn't include a |
116 |
* subslot, then ignore it when checking the package's value. */ |
117 |
- if (strncmp(pkg_ctx->slot, uslot, uslot_len) != 0 || |
118 |
- (pkg_ctx->slot[uslot_len] != '\0' && |
119 |
- pkg_ctx->slot[uslot_len] != '/')) |
120 |
+ if (strcmp(atom->SLOT, uslot) != 0) |
121 |
+ return false; |
122 |
+ |
123 |
+ if (usslot != NULL && strcmp(atom->SUBSLOT, usslot) != 0) |
124 |
return false; |
125 |
} |
126 |
|
127 |
if (urepo) { |
128 |
/* require exact match on repositories */ |
129 |
- if (strcmp(pkg_ctx->repo, urepo) != 0) |
130 |
+ if (strcmp(atom->REPO, urepo) != 0) |
131 |
return false; |
132 |
} |
133 |
|
134 |
if (exact) { |
135 |
int i; |
136 |
|
137 |
- snprintf(buf, sizeof(buf), "%s/%s:%s::%s", |
138 |
- catname, pkgname, pkg_ctx->slot, pkg_ctx->repo); |
139 |
+ snprintf(buf, sizeof(buf), "%s/%s-%s:%s%s%s::%s", |
140 |
+ atom->CATEGORY, |
141 |
+ atom->PN, |
142 |
+ atom->PVR, |
143 |
+ atom->SLOT != NULL ? atom->SLOT : "", |
144 |
+ atom->SUBSLOT != NULL ? "/" : "", |
145 |
+ atom->SUBSLOT != NULL ? atom->SUBSLOT : "", |
146 |
+ atom->REPO != NULL ? atom->REPO : ""); |
147 |
|
148 |
/* exact match: CAT/PN-PVR[:SLOT][::REPO] */ |
149 |
if (strcmp(name, buf) == 0) |
150 |
@@ -262,37 +275,29 @@ qlist_match( |
151 |
return true; |
152 |
|
153 |
/* let's try exact matching w/out the PV */ |
154 |
- atom = tree_get_atom(pkg_ctx, uslot != NULL || urepo != NULL); |
155 |
- |
156 |
- i = snprintf(swap, sizeof(swap), "%s/%s", atom->CATEGORY, atom->PN); |
157 |
- if (uslot && i <= (int)sizeof(swap)) |
158 |
- i += snprintf(swap + i, sizeof(swap) - i, ":%s", atom->SLOT); |
159 |
- if (urepo && i <= (int)sizeof(swap)) |
160 |
- i += snprintf(swap + i, sizeof(swap) - i, "::%s", atom->REPO); |
161 |
+ i = snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN); |
162 |
+ if (uslot[0] != '\0' && i <= (int)sizeof(buf)) |
163 |
+ i += snprintf(buf + i, sizeof(buf) - i, ":%s", atom->SLOT); |
164 |
+ if (urepo && i <= (int)sizeof(buf)) |
165 |
+ i += snprintf(buf + i, sizeof(buf) - i, "::%s", atom->REPO); |
166 |
|
167 |
/* exact match: CAT/PN[:SLOT][::REPO] */ |
168 |
- if (strcmp(name, swap) == 0) |
169 |
+ if (strcmp(name, buf) == 0) |
170 |
return true; |
171 |
/* exact match: PN[:SLOT][::REPO] */ |
172 |
- if (strcmp(name, strstr(swap, "/") + 1) == 0) |
173 |
+ if (strcmp(name, strstr(buf, "/") + 1) == 0) |
174 |
return true; |
175 |
} else { |
176 |
- size_t ulen = strlen(name); |
177 |
- if (urepo) |
178 |
- ulen -= (urepo_len + 2); |
179 |
- if (uslot) |
180 |
- ulen -= (uslot_len + 1); |
181 |
- snprintf(buf, sizeof(buf), "%s/%s", catname, pkgname); |
182 |
/* partial leading match: CAT/PN-PVR */ |
183 |
- if (strncmp(name, buf, ulen) == 0) |
184 |
+ snprintf(buf, sizeof(buf), "%s/%s-%s", |
185 |
+ atom->CATEGORY, atom->PN, atom->PVR); |
186 |
+ if (strncmp(name, buf, pf_len) == 0 || |
187 |
+ rematch(name, buf, REG_EXTENDED) == 0) |
188 |
return true; |
189 |
/* partial leading match: PN-PVR */ |
190 |
- if (strncmp(name, pkgname, ulen) == 0) |
191 |
- return true; |
192 |
- /* try again but with regexps */ |
193 |
- if (rematch(name, buf, REG_EXTENDED) == 0) |
194 |
- return true; |
195 |
- if (rematch(name, pkgname, REG_EXTENDED) == 0) |
196 |
+ snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PVR); |
197 |
+ if (strncmp(name, buf, pf_len) == 0 || |
198 |
+ rematch(name, buf, REG_EXTENDED) == 0) |
199 |
return true; |
200 |
} |
201 |
|
202 |
@@ -324,8 +329,6 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
203 |
struct qlist_opt_state *state = priv; |
204 |
int i; |
205 |
FILE *fp; |
206 |
- const char *catname = pkg_ctx->cat_ctx->name; |
207 |
- const char *pkgname = pkg_ctx->name; |
208 |
depend_atom *atom; |
209 |
|
210 |
/* see if this cat/pkg is requested */ |
211 |
@@ -339,30 +342,26 @@ qlist_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
212 |
atom = tree_get_atom(pkg_ctx, false); |
213 |
if (state->just_pkgname) { |
214 |
if ((state->all + state->just_pkgname) < 2) { |
215 |
+ char qfmt[128]; |
216 |
atom = tree_get_atom(pkg_ctx, |
217 |
state->show_slots || state->show_repo); |
218 |
- if (state->show_slots && !pkg_ctx->slot) { |
219 |
- /* chop off the subslot if desired */ |
220 |
- if (state->show_slots == 1 && pkg_ctx->slot != NULL) { |
221 |
- char *s = strchr(pkg_ctx->slot, '/'); |
222 |
- if (s) |
223 |
- *s = '\0'; |
224 |
- } |
225 |
+ if (state->columns) { |
226 |
+ snprintf(qfmt, sizeof(qfmt), |
227 |
+ "%%{CATEGORY} %%{PN}%s%s%s%s", |
228 |
+ verbose ? " %{PVR}" : "", |
229 |
+ state->show_slots >= 1 ? " %{SLOT}" : "", |
230 |
+ state->show_slots >= 2 ? " %{SUBSLOT}" : "", |
231 |
+ state->show_repo ? " %{REPO}" : ""); |
232 |
+ } else { |
233 |
+ snprintf(qfmt, sizeof(qfmt), |
234 |
+ "%%[CATEGORY]%%[P%c]%s%s%s", |
235 |
+ verbose ? 'F' : 'N', |
236 |
+ state->show_slots >= 1 ? "%[SLOT]" : "", |
237 |
+ state->show_slots >= 2 ? "%[SUBSLOT]" : "", |
238 |
+ state->show_repo ? "%[REPO]" : ""); |
239 |
} |
240 |
- /* display it */ |
241 |
- printf("%s%s/%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
242 |
- BOLD, catname, BLUE, |
243 |
- (!state->columns ? (atom ? atom->PN : pkgname) : atom->PN), |
244 |
- (state->columns ? " " : ""), |
245 |
- (state->columns ? atom->PV : ""), |
246 |
- NORM, YELLOW, |
247 |
- state->show_slots ? ":" : "", |
248 |
- state->show_slots ? pkg_ctx->slot : "", |
249 |
- NORM, |
250 |
- NORM, GREEN, |
251 |
- state->show_repo ? "::" : "", |
252 |
- state->show_repo ? pkg_ctx->repo : "", |
253 |
- NORM, |
254 |
+ printf("%s%s\n", |
255 |
+ atom_format(qfmt, atom, 0), |
256 |
umapstr(state->show_umap, pkg_ctx)); |
257 |
} |