Przeglądaj źródła

dpkg-query: Add an Architecture column to --list output

Even if the output format is designed to be human readable, and for
machine parseable output «dpkg-query -W» should be used instead, there's
probably scripts in the wild parsing «dpkg-query -l». Thus, the new
column is inserted before the Description column which is unreliable
to parse anyway as its value will always contain spaces, which are the
column separators, and as such should be pretty safe.

The arch-qualified package names will still be printed, as that
allows to copy-and-paste package names as input to dpkg commands w/o
any possibility of ambiguity.

Closes: #673190

Suggested-by: Jonathan Nieder <jnieder@gmail.com>
Guillem Jover 14 lat temu
rodzic
commit
3d98111bd4
2 zmienionych plików z 30 dodań i 12 usunięć
  1. 2 0
      debian/changelog
  2. 28 12
      src/querycmd.c

+ 2 - 0
debian/changelog

@@ -46,6 +46,8 @@ dpkg (1.16.5) UNRELEASED; urgency=low
     Thanks to Thibaut Girka <thib@sitedethib.com>.
     Thanks to Thibaut Girka <thib@sitedethib.com>.
   * Do not use undefined values returned form deps_parse() in dpkg-shlibdeps.
   * Do not use undefined values returned form deps_parse() in dpkg-shlibdeps.
     Closes: #640676
     Closes: #640676
+  * Add an Architecture column to «dpkg-query -l» before the Description
+    column. Suggested by Jonathan Nieder <jnieder@gmail.com>. Closes: #673190
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * Swedish (Peter Krefting).
   * Swedish (Peter Krefting).

+ 28 - 12
src/querycmd.c

@@ -86,7 +86,10 @@ static int getwidth(void) {
 
 
 struct list_format {
 struct list_format {
   bool head;
   bool head;
-  int nw, vw, dw;
+  int nw;
+  int vw;
+  int aw;
+  int dw;
 };
 };
 
 
 static void
 static void
@@ -102,21 +105,25 @@ list_format_init(struct list_format *fmt, struct pkg_array *array)
     int i;
     int i;
 
 
     fmt->nw = 14;
     fmt->nw = 14;
-    fmt->vw = 14;
-    fmt->dw = 44;
+    fmt->vw = 12;
+    fmt->aw = 12;
+    fmt->dw = 33;
 
 
     for (i = 0; i < array->n_pkgs; i++) {
     for (i = 0; i < array->n_pkgs; i++) {
-      int plen, vlen, dlen;
+      int plen, vlen, alen, dlen;
 
 
       plen = strlen(pkg_name(array->pkgs[i], pnaw_nonambig));
       plen = strlen(pkg_name(array->pkgs[i], pnaw_nonambig));
       vlen = strlen(versiondescribe(&array->pkgs[i]->installed.version,
       vlen = strlen(versiondescribe(&array->pkgs[i]->installed.version,
                                     vdew_nonambig));
                                     vdew_nonambig));
+      alen = strlen(array->pkgs[i]->installed.arch->name);
       pkg_summary(array->pkgs[i], &array->pkgs[i]->installed, &dlen);
       pkg_summary(array->pkgs[i], &array->pkgs[i]->installed, &dlen);
 
 
       if (plen > fmt->nw)
       if (plen > fmt->nw)
         fmt->nw = plen;
         fmt->nw = plen;
       if (vlen > fmt->vw)
       if (vlen > fmt->vw)
         fmt->vw = vlen;
         fmt->vw = vlen;
+      if (alen > fmt->aw)
+        fmt->aw = alen;
       if (dlen > fmt->dw)
       if (dlen > fmt->dw)
         fmt->dw = dlen;
         fmt->dw = dlen;
     }
     }
@@ -126,24 +133,27 @@ list_format_init(struct list_format *fmt, struct pkg_array *array)
     if (w < 0)
     if (w < 0)
       w = 0;
       w = 0;
     /* Halve that so we can add it to both the name and description. */
     /* Halve that so we can add it to both the name and description. */
-    w >>= 2;
+    w >>= 1;
     /* Name width. */
     /* Name width. */
-    fmt->nw = (14 + w);
+    fmt->nw = (14 + (w / 2));
     /* Version width. */
     /* Version width. */
-    fmt->vw = (14 + w);
+    fmt->vw = (12 + (w / 4));
+    /* Architecture width. */
+    fmt->aw = (12 + (w / 4));
     /* Description width. */
     /* Description width. */
-    fmt->dw = (44 + (2 * w));
+    fmt->dw = (33 + w);
   }
   }
 }
 }
 
 
 static void
 static void
 list_format_print(struct list_format *fmt,
 list_format_print(struct list_format *fmt,
                   int c_want, int c_status, int c_eflag,
                   int c_want, int c_status, int c_eflag,
-                  const char *name, const char *version,
+                  const char *name, const char *version, const char *arch,
                   const char *desc, int desc_len)
                   const char *desc, int desc_len)
 {
 {
-  printf("%c%c%c %-*.*s %-*.*s %.*s\n", c_want, c_status, c_eflag,
-         fmt->nw, fmt->nw, name, fmt->vw, fmt->vw, version, desc_len, desc);
+  printf("%c%c%c %-*.*s %-*.*s %-*.*s %.*s\n", c_want, c_status, c_eflag,
+         fmt->nw, fmt->nw, name, fmt->vw, fmt->vw, version,
+         fmt->aw, fmt->aw, arch, desc_len, desc);
 }
 }
 
 
 static void
 static void
@@ -165,7 +175,7 @@ Desired=Unknown/Install/Remove/Purge/Hold\n\
 | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n\
 | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n\
 |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n"), stdout);
 |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n"), stdout);
   list_format_print(fmt, '|', '|', '/', _("Name"), _("Version"),
   list_format_print(fmt, '|', '|', '/', _("Name"), _("Version"),
-                    _("Description"), 40);
+                    _("Architecture"), _("Description"), 33);
 
 
   /* Status */
   /* Status */
   printf("+++-");
   printf("+++-");
@@ -180,6 +190,11 @@ Desired=Unknown/Install/Remove/Purge/Hold\n\
     printf("=");
     printf("=");
   printf("-");
   printf("-");
 
 
+  /* Architecture. */
+  for (l = 0; l < fmt->aw; l++)
+    printf("=");
+  printf("-");
+
   /* Description. */
   /* Description. */
   for (l = 0; l < fmt->dw; l++)
   for (l = 0; l < fmt->dw; l++)
     printf("=");
     printf("=");
@@ -206,6 +221,7 @@ list1package(struct pkginfo *pkg, struct list_format *fmt, struct pkg_array *arr
                     pkg_abbrev_eflag(pkg),
                     pkg_abbrev_eflag(pkg),
                     pkg_name(pkg, pnaw_nonambig),
                     pkg_name(pkg, pnaw_nonambig),
                     versiondescribe(&pkg->installed.version, vdew_nonambig),
                     versiondescribe(&pkg->installed.version, vdew_nonambig),
+                    pkg->installed.arch->name,
                     pdesc, l);
                     pdesc, l);
 }
 }