Prechádzať zdrojové kódy

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 rokov pred
rodič
commit
3d98111bd4
2 zmenil súbory, kde vykonal 30 pridanie a 12 odobranie
  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>.
   * Do not use undefined values returned form deps_parse() in dpkg-shlibdeps.
     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 ]
   * Swedish (Peter Krefting).

+ 28 - 12
src/querycmd.c

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