lib: Use NULLSTR family of macros more

There is a family of convenient macros: NULLSTR, NULLSTR_EMPTY,
NULLSTR_STAR, NULLSTR_MINUS which hides ternary operator.

Generated using the following spatch (and its obvious variants):

  @@
  expression s;
  @@
    <+...
  - s ? s : "<null>"
  + NULLSTR(s)
    ...+>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik
2024-08-19 12:26:27 +02:00
parent 3780522968
commit ab7f877f27
8 changed files with 16 additions and 16 deletions

View File

@@ -455,7 +455,7 @@ cmdCheckpointInfo(vshControl *ctl,
_("unexpected problem querying checkpoint state"));
return false;
}
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-");
vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_MINUS(parent));
/* Children, Descendants. */
flags = 0;

View File

@@ -712,11 +712,11 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
mac = virXPathString("string(./mac/@address)", ctxt);
if (vshTableRowAppend(table,
target ? target : "-",
NULLSTR_MINUS(target),
type,
source ? source : "-",
model ? model : "-",
mac ? mac : "-",
NULLSTR_MINUS(source),
NULLSTR_MINUS(model),
NULLSTR_MINUS(mac),
NULL) < 0)
return false;
}

View File

@@ -1233,7 +1233,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
parent = virNodeDeviceGetParent(device);
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device));
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "");
vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_EMPTY(parent));
vshPrint(ctl, "%-15s %s\n", _("Active:"), virNodeDeviceIsActive(device) ?
_("yes") : _("no"));
vshPrint(ctl, "%-15s %s\n", _("Persistent:"),