[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 2/2] pkg:arch handling for dpkg -l



Output pkg:arch in dpkg -l output for non-native packages, and parse pkg:arch
syntax in input arguments to dpkg -l
---
 src/query.c |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/query.c b/src/query.c
index 552f56e..50b5e9e 100644
--- a/src/query.c
+++ b/src/query.c
@@ -79,6 +79,7 @@ list1package(struct pkginfo *pkg, int *head, struct pkg_array *array)
   int i,l,w;
   static int nw,vw,dw;
   const char *pdesc;
+  char *pname;
   static char format[80]   = "";
     
   if (format[0] == '\0') {
@@ -93,6 +94,9 @@ list1package(struct pkginfo *pkg, int *head, struct pkg_array *array)
 	if (!pdesc) pdesc= _("(no description available)");
 
 	plen = strlen(array->pkgs[i]->name);
+	if (strcmp(ARCHITECTURE, array->pkgs[i]->installed.architecture) != 0 &&
+	    strcmp("all", array->pkgs[i]->installed.architecture) != 0)
+		plen += strlen(array->pkgs[i]->installed.architecture) + 1;
 	vlen = strlen(versiondescribe(&array->pkgs[i]->installed.version,
 	                              vdew_nonambig));
 	dlen= strcspn(pdesc, "\n");
@@ -124,13 +128,22 @@ Desired=Unknown/Install/Remove/Purge/Hold\n\
     printf("\n");
     *head= 1;
   }
+  if (pkg->installed.architecture &&
+      strcmp(ARCHITECTURE, pkg->installed.architecture) != 0 &&
+      strcmp("all", pkg->installed.architecture) != 0)
+  {
+    pname = m_malloc(strlen(pkg->installed.architecture) + strlen(pkg->name) + 2);
+    sprintf(pname, "%s:%s", pkg->name, pkg->installed.architecture);
+  } else {
+    pname = (char *)pkg->name;
+  }    
   if (!pkg->installed.valid) blankpackageperfile(&pkg->installed);
   limiteddescription(pkg,dw,&pdesc,&l);
   printf(format,
          "uihrp"[pkg->want],
          "ncHUFWti"[pkg->status],
          " R"[pkg->eflag],
-         pkg->name,
+         pname,
          versiondescribe(&pkg->installed.version, vdew_nonambig),
          l, pdesc);
 }
@@ -161,9 +174,21 @@ void listpackages(const char *const *argv) {
     memset(found, 0, sizeof(int) * argc);
 
     for (i = 0; i < array.n_pkgs; i++) {
+      char *arch, *pkgname;
       pkg = array.pkgs[i];
       for (ip = 0; ip < argc; ip++) {
-        if (!fnmatch(argv[ip], pkg->name, 0)) {
+        pkgname = m_strdup(argv[ip]);
+        arch = strchr(pkgname, ':');
+	if (arch) {
+		*arch = '\0';
+		arch++;
+	}
+        if (!fnmatch(pkgname, pkg->name, 0) &&
+            (!pkg->installed.architecture ||
+             (arch && fnmatch(arch, pkg->installed.architecture, 0) == 0) ||
+             (!arch && (strcmp(ARCHITECTURE, pkg->installed.architecture) == 0 ||
+                        strcmp("all", pkg->installed.architecture) == 0))))
+        {
           list1package(pkg, &head, &array);
           found[ip]++;
           break;
-- 
1.7.1


Reply to: