aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2019-12-29 10:54:28 +0100
committerFabian Groffen <grobian@gentoo.org>2019-12-29 10:54:28 +0100
commit7cdf692beb93c596b4bf4f5f7b5bb8bcc69a27ea (patch)
treeeffaefccacb9f9aa4da276b101f788b11356d816
parentqfile: make qfile_check_plibreg not trigger on an empty file (/) (diff)
downloadportage-utils-7cdf692b.tar.gz
portage-utils-7cdf692b.tar.bz2
portage-utils-7cdf692b.zip
q: improve applet searching somewhat, change warn app name
- use a single loop iteration to match an applet - set full name of applet (qlop iso lop) in argv0 for warn() to match the running command - use name of aliased applet when invoked by an alias (belongs -> qfile) Bug: https://bugs.gentoo.org/701968 Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r--applets.h1
-rw-r--r--q.c37
2 files changed, 27 insertions, 11 deletions
diff --git a/applets.h b/applets.h
index ea4eeceb..4625fde3 100644
--- a/applets.h
+++ b/applets.h
@@ -102,7 +102,6 @@ static const struct applet_t {
/*"glsa"*/
{"hasuse", quse_main, NULL, NULL},
/*"list"*/
- {"size", qsize_main, NULL, NULL},
/*"stats"*/
/*"uses"*/
/*"which"*/
diff --git a/q.c b/q.c
index 4a2fd62c..6d7eced5 100644
--- a/q.c
+++ b/q.c
@@ -48,24 +48,41 @@ APPLET lookup_applet(const char *applet)
if (strlen(applet) < 1)
return NULL;
- for (i = 0; applets[i].name; ++i) {
- if (strcmp(applets[i].name, applet) == 0) {
+ if (applet[0] == 'q')
+ applet++;
+
+ /* simple case, e.g. something like "qlop" or "q lop" both being "lop" */
+ for (i = 0; applets[i].desc != NULL; i++) {
+ if (strcmp(applets[i].name + 1, applet) == 0) {
argv0 = applets[i].name;
- if (i && applets[i].desc != NULL)
- ++argv0; /* chop the leading 'q' */
return applets[i].func;
}
}
- /* No applet found? Search by shortname then... */
- for (i = 1; applets[i].desc != NULL; ++i) {
- if (strcmp(applets[i].name + 1, applet) == 0) {
- argv0 = applets[i].name + 1;
- return applets[i].func;
+ /* this is possibly an alias like "belongs"
+ * NOTE: we continue where the previous loop left, e.g. on the first
+ * alias (desc == NULL) */
+ for ( ; applets[i].name != NULL; i++) {
+ if (strcmp(applets[i].name, applet) == 0) {
+ unsigned int j;
+
+ /* lookup the real name for this alias */
+ for (j = 1; applets[j].desc != NULL; j++) {
+ if (applets[j].func == applets[i].func) {
+ argv0 = applets[j].name;
+ return applets[j].func;
+ }
+ }
+
+ /* this shouldn't happen and means our array from applets.h
+ * is inconsistent */
+ warn("invalid applet alias '%s': target applet unknown", applet);
+ return NULL;
}
}
+
/* still nothing ? those bastards ... */
- warn("Unknown applet '%s'", applet);
+ warn("unknown applet: %s", applet);
return NULL;
}