Просмотр исходного кода

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
Родитель
Сommit
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)
 {
   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