[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 1/2] virsh: use more compact VIR_ENUM_IMPL



On 21.02.2014 23:59, Eric Blake wrote:
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future.  Make this change throughout virsh.

Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.

* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.

Signed-off-by: Eric Blake <eblake redhat com>
---
  tools/virsh-domain-monitor.c | 280 +++++++++++++++-------------------
  tools/virsh-domain.c         | 347 ++++++++++++++++++-------------------------
  tools/virsh-network.c        |  36 ++---
  tools/virsh-pool.c           |  66 +++-----
  tools/virsh-volume.c         |  38 ++---
  5 files changed, 316 insertions(+), 451 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 6291ca5..c67b833 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1,7 +1,7 @@
  /*
   * virsh-domain-monitor.c: Commands to monitor domain status
   *
- * Copyright (C) 2005, 2007-2013 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2014 Red Hat, Inc.
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
@@ -40,21 +40,18 @@
  #include "virxml.h"
  #include "virstring.h"

+VIR_ENUM_DECL(vshDomainIOError)
+VIR_ENUM_IMPL(vshDomainIOError,
+              VIR_DOMAIN_DISK_ERROR_LAST,
+              N_("no error"),
+              N_("unspecified error"),
+              N_("no space"))
+
  static const char *
  vshDomainIOErrorToString(int error)
  {
-    switch ((virDomainDiskErrorCode) error) {
-    case VIR_DOMAIN_DISK_ERROR_NONE:
-        return _("no error");
-    case VIR_DOMAIN_DISK_ERROR_UNSPEC:
-        return _("unspecified error");
-    case VIR_DOMAIN_DISK_ERROR_NO_SPACE:
-        return _("no space");
-    case VIR_DOMAIN_DISK_ERROR_LAST:
-        ;
-    }
-
-    return _("unknown error");
+    const char *str = vshDomainIOErrorTypeToString(error);
+    return str ? _(str) : _("unknown error");
  }


Why _(str) if str itself already contains translated message?

Michal


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]