|
|
@@ -95,6 +95,55 @@ static int getwidth(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static int
|
|
|
+pkg_array_match_patterns(struct pkg_array *array,
|
|
|
+ pkg_array_visitor_func *pkg_visitor, void *pkg_data,
|
|
|
+ const char *const *argv)
|
|
|
+{
|
|
|
+ int argc, i, ip, *found;
|
|
|
+ int rc = 0;
|
|
|
+ struct pkg_spec *ps;
|
|
|
+
|
|
|
+ for (argc = 0; argv[argc]; argc++);
|
|
|
+ found = m_calloc(argc, sizeof(int));
|
|
|
+
|
|
|
+ ps = m_malloc(sizeof(*ps) * argc);
|
|
|
+ for (ip = 0; ip < argc; ip++) {
|
|
|
+ pkg_spec_init(&ps[ip], PKG_SPEC_PATTERNS | PKG_SPEC_ARCH_WILDCARD);
|
|
|
+ pkg_spec_parse(&ps[ip], argv[ip]);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i = 0; i < array->n_pkgs; i++) {
|
|
|
+ struct pkginfo *pkg;
|
|
|
+ bool pkg_found = false;
|
|
|
+
|
|
|
+ pkg = array->pkgs[i];
|
|
|
+ for (ip = 0; ip < argc; ip++) {
|
|
|
+ if (pkg_spec_match_pkg(&ps[ip], pkg, &pkg->installed)) {
|
|
|
+ pkg_found = true;
|
|
|
+ found[ip]++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!pkg_found)
|
|
|
+ array->pkgs[i] = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ pkg_array_foreach(array, pkg_visitor, pkg_data);
|
|
|
+
|
|
|
+ for (ip = 0; ip < argc; ip++) {
|
|
|
+ if (!found[ip]) {
|
|
|
+ notice(_("no packages found matching %s"), argv[ip]);
|
|
|
+ rc++;
|
|
|
+ }
|
|
|
+ pkg_spec_destroy(&ps[ip]);
|
|
|
+ }
|
|
|
+
|
|
|
+ free(ps);
|
|
|
+ free(found);
|
|
|
+
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
struct list_format {
|
|
|
bool head;
|
|
|
int nw;
|
|
|
@@ -255,7 +304,7 @@ listpackages(const char *const *argv)
|
|
|
struct pkg_array array;
|
|
|
struct pkginfo *pkg;
|
|
|
int i;
|
|
|
- int failures = 0;
|
|
|
+ int rc = 0;
|
|
|
struct list_format fmt;
|
|
|
|
|
|
if (!opt_loadavail)
|
|
|
@@ -277,44 +326,7 @@ listpackages(const char *const *argv)
|
|
|
|
|
|
pkg_array_foreach(&array, pkg_array_list_item, &fmt);
|
|
|
} else {
|
|
|
- int argc, ip, *found;
|
|
|
- struct pkg_spec *ps;
|
|
|
-
|
|
|
- for (argc = 0; argv[argc]; argc++);
|
|
|
- found = m_calloc(argc, sizeof(int));
|
|
|
-
|
|
|
- ps = m_malloc(sizeof(*ps) * argc);
|
|
|
- for (ip = 0; ip < argc; ip++) {
|
|
|
- pkg_spec_init(&ps[ip], PKG_SPEC_PATTERNS | PKG_SPEC_ARCH_WILDCARD);
|
|
|
- pkg_spec_parse(&ps[ip], argv[ip]);
|
|
|
- }
|
|
|
-
|
|
|
- for (i = 0; i < array.n_pkgs; i++) {
|
|
|
- bool pkg_found = false;
|
|
|
-
|
|
|
- pkg = array.pkgs[i];
|
|
|
- for (ip = 0; ip < argc; ip++) {
|
|
|
- if (pkg_spec_match_pkg(&ps[ip], pkg, &pkg->installed)) {
|
|
|
- pkg_found = true;
|
|
|
- found[ip]++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!pkg_found)
|
|
|
- array.pkgs[i] = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- pkg_array_foreach(&array, pkg_array_list_item, &fmt);
|
|
|
-
|
|
|
- for (ip = 0; ip < argc; ip++) {
|
|
|
- if (!found[ip]) {
|
|
|
- notice(_("no packages found matching %s"), argv[ip]);
|
|
|
- failures++;
|
|
|
- }
|
|
|
- pkg_spec_destroy(&ps[ip]);
|
|
|
- }
|
|
|
-
|
|
|
- free(ps);
|
|
|
- free(found);
|
|
|
+ rc = pkg_array_match_patterns(&array, pkg_array_list_item, &fmt, argv);
|
|
|
}
|
|
|
|
|
|
m_output(stdout, _("<standard output>"));
|
|
|
@@ -323,7 +335,7 @@ listpackages(const char *const *argv)
|
|
|
pkg_array_destroy(&array);
|
|
|
modstatdb_shutdown();
|
|
|
|
|
|
- return failures;
|
|
|
+ return rc;
|
|
|
}
|
|
|
|
|
|
static int searchoutput(struct filenamenode *namenode) {
|
|
|
@@ -540,14 +552,14 @@ showpackages(const char *const *argv)
|
|
|
struct pkginfo *pkg;
|
|
|
struct pkg_format_node *fmt;
|
|
|
int i;
|
|
|
- int failures = 0;
|
|
|
+ int rc = 0;
|
|
|
|
|
|
fmt = pkg_format_parse(showformat, &err);
|
|
|
if (!fmt) {
|
|
|
notice(_("error in show format: %s"), err.str);
|
|
|
dpkg_error_destroy(&err);
|
|
|
- failures++;
|
|
|
- return failures;
|
|
|
+ rc++;
|
|
|
+ return rc;
|
|
|
}
|
|
|
|
|
|
if (!opt_loadavail)
|
|
|
@@ -566,44 +578,7 @@ showpackages(const char *const *argv)
|
|
|
pkg_format_show(fmt, pkg, &pkg->installed);
|
|
|
}
|
|
|
} else {
|
|
|
- int argc, ip, *found;
|
|
|
- struct pkg_spec *ps;
|
|
|
-
|
|
|
- for (argc = 0; argv[argc]; argc++);
|
|
|
- found = m_calloc(argc, sizeof(int));
|
|
|
-
|
|
|
- ps = m_malloc(sizeof(*ps) * argc);
|
|
|
- for (ip = 0; ip < argc; ip++) {
|
|
|
- pkg_spec_init(&ps[ip], PKG_SPEC_PATTERNS | PKG_SPEC_ARCH_WILDCARD);
|
|
|
- pkg_spec_parse(&ps[ip], argv[ip]);
|
|
|
- }
|
|
|
-
|
|
|
- for (i = 0; i < array.n_pkgs; i++) {
|
|
|
- bool pkg_found = false;
|
|
|
-
|
|
|
- pkg = array.pkgs[i];
|
|
|
- for (ip = 0; ip < argc; ip++) {
|
|
|
- if (pkg_spec_match_pkg(&ps[ip], pkg, &pkg->installed)) {
|
|
|
- pkg_found = true;
|
|
|
- found[ip]++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!pkg_found)
|
|
|
- array.pkgs[i] = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- pkg_array_foreach(&array, pkg_array_show_item, fmt);
|
|
|
-
|
|
|
- for (ip = 0; ip < argc; ip++) {
|
|
|
- if (!found[ip]) {
|
|
|
- notice(_("no packages found matching %s"), argv[ip]);
|
|
|
- failures++;
|
|
|
- }
|
|
|
- pkg_spec_destroy(&ps[ip]);
|
|
|
- }
|
|
|
-
|
|
|
- free(ps);
|
|
|
- free(found);
|
|
|
+ rc = pkg_array_match_patterns(&array, pkg_array_show_item, fmt, argv);
|
|
|
}
|
|
|
|
|
|
m_output(stdout, _("<standard output>"));
|
|
|
@@ -613,7 +588,7 @@ showpackages(const char *const *argv)
|
|
|
pkg_format_free(fmt);
|
|
|
modstatdb_shutdown();
|
|
|
|
|
|
- return failures;
|
|
|
+ return rc;
|
|
|
}
|
|
|
|
|
|
static bool
|