Преглед изворни кода

libdpkg: Simplify f_booleandefno() and f_multiarch() implementations

This unifies the logic to match the rest of the dumping functions, by
printing an optional field name, the value itself and an optional
trailing newline. These two functions are somewhat special though,
and the reason for the previous code layout, because they do not
print the value if it is null and no field name has been requested.
Guillem Jover пре 14 година
родитељ
комит
d457006274
1 измењених фајлова са 19 додато и 13 уклоњено
  1. 19 13
      lib/dpkg/dump.c

+ 19 - 13
lib/dpkg/dump.c

@@ -162,14 +162,19 @@ w_booleandefno(struct varbuf *vb,
                enum fwriteflags flags, const struct fieldinfo *fip)
                enum fwriteflags flags, const struct fieldinfo *fip)
 {
 {
   bool value = PKGPFIELD(pkgbin, fip->integer, bool);
   bool value = PKGPFIELD(pkgbin, fip->integer, bool);
-  if (!(flags&fw_printheader)) {
-    varbuf_add_str(vb, value ? "yes" : "no");
+
+  if ((flags & fw_printheader) && !value)
     return;
     return;
+
+  if (flags & fw_printheader) {
+    varbuf_add_str(vb, fip->name);
+    varbuf_add_str(vb, ": ");
   }
   }
-  if (!value) return;
-  assert(value == true);
-  varbuf_add_str(vb, fip->name);
-  varbuf_add_str(vb, ": yes\n");
+
+  varbuf_add_str(vb, value ? "yes" : "no");
+
+  if (flags & fw_printheader)
+    varbuf_add_char(vb, '\n');
 }
 }
 
 
 void
 void
@@ -179,17 +184,18 @@ w_multiarch(struct varbuf *vb,
 {
 {
   int value = PKGPFIELD(pkgbin, fip->integer, int);
   int value = PKGPFIELD(pkgbin, fip->integer, int);
 
 
-  if (!(flags & fw_printheader)) {
-    varbuf_add_str(vb, multiarchinfos[value].name);
+  if ((flags & fw_printheader) && !value)
     return;
     return;
+
+  if (flags & fw_printheader) {
+    varbuf_add_str(vb, fip->name);
+    varbuf_add_str(vb, ": ");
   }
   }
-  if (!value)
-    return;
 
 
-  varbuf_add_str(vb, fip->name);
-  varbuf_add_str(vb, ": ");
   varbuf_add_str(vb, multiarchinfos[value].name);
   varbuf_add_str(vb, multiarchinfos[value].name);
-  varbuf_add_char(vb, '\n');
+
+  if (flags & fw_printheader)
+    varbuf_add_char(vb, '\n');
 }
 }
 
 
 void
 void