Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
d457006274
1 değiştirilmiş dosya ile 19 ekleme ve 13 silme
  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)
 {
   bool value = PKGPFIELD(pkgbin, fip->integer, bool);
-  if (!(flags&fw_printheader)) {
-    varbuf_add_str(vb, value ? "yes" : "no");
+
+  if ((flags & fw_printheader) && !value)
     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
@@ -179,17 +184,18 @@ w_multiarch(struct varbuf *vb,
 {
   int value = PKGPFIELD(pkgbin, fip->integer, int);
 
-  if (!(flags & fw_printheader)) {
-    varbuf_add_str(vb, multiarchinfos[value].name);
+  if ((flags & fw_printheader) && !value)
     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_char(vb, '\n');
+
+  if (flags & fw_printheader)
+    varbuf_add_char(vb, '\n');
 }
 
 void