Patchwork [2/2] QMP/monitor: update do_info_version() to output broken down version string

login
register
mail settings
Submitter Miguel Di Ciurcio Filho
Date Aug. 9, 2010, 5 p.m.
Message ID <1281373256-602-3-git-send-email-miguel.filho@gmail.com>
Download mbox | patch
Permalink /patch/61295/
State New
Headers show

Comments

Miguel Di Ciurcio Filho - Aug. 9, 2010, 5 p.m.
This code was originally developed by Daniel P. Berrange <berrange@redhat.com>

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
---
 monitor.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
malc - Aug. 9, 2010, 6:09 p.m.
On Mon, 9 Aug 2010, Miguel Di Ciurcio Filho wrote:

> This code was originally developed by Daniel P. Berrange <berrange@redhat.com>
> 
> Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
> ---
>  monitor.c |   23 +++++++++++++++++++----
>  1 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index c313d5a..e82c48f 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -669,17 +669,32 @@ help:
>  static void do_info_version_print(Monitor *mon, const QObject *data)
>  {
>      QDict *qdict;
> +    QDict *qemu;
>  
>      qdict = qobject_to_qdict(data);
> +    qemu = qdict_get_qdict(qdict, "qemu");
>  
> -    monitor_printf(mon, "%s%s\n", qdict_get_str(qdict, "qemu"),
> -                                  qdict_get_str(qdict, "package"));
> +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> +		   qdict_get_int(qemu, "major"),
> +		   qdict_get_int(qemu, "minor"),
> +		   qdict_get_int(qemu, "micro"),
> +		   qdict_get_str(qdict, "package"));
>  }

Above snippet uses tab(s).

>  static void do_info_version(Monitor *mon, QObject **ret_data)
>  {
> -    *ret_data = qobject_from_jsonf("{ 'qemu': %s, 'package': %s }",
> -                                   QEMU_VERSION, QEMU_PKGVERSION);
> +    const char *version = QEMU_VERSION;
> +    int major = 0, minor = 0, micro = 0;
> +    char *tmp;
> +
> +    major = strtol(version, &tmp, 10);
> +    tmp++;
> +    minor = strtol(tmp, &tmp, 10);
> +    tmp++;
> +    micro = strtol(tmp, &tmp, 10);
> +
> +    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
> +        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
>  }
>  
>  static void do_info_name_print(Monitor *mon, const QObject *data)
>

Patch

diff --git a/monitor.c b/monitor.c
index c313d5a..e82c48f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -669,17 +669,32 @@  help:
 static void do_info_version_print(Monitor *mon, const QObject *data)
 {
     QDict *qdict;
+    QDict *qemu;
 
     qdict = qobject_to_qdict(data);
+    qemu = qdict_get_qdict(qdict, "qemu");
 
-    monitor_printf(mon, "%s%s\n", qdict_get_str(qdict, "qemu"),
-                                  qdict_get_str(qdict, "package"));
+    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
+		   qdict_get_int(qemu, "major"),
+		   qdict_get_int(qemu, "minor"),
+		   qdict_get_int(qemu, "micro"),
+		   qdict_get_str(qdict, "package"));
 }
 
 static void do_info_version(Monitor *mon, QObject **ret_data)
 {
-    *ret_data = qobject_from_jsonf("{ 'qemu': %s, 'package': %s }",
-                                   QEMU_VERSION, QEMU_PKGVERSION);
+    const char *version = QEMU_VERSION;
+    int major = 0, minor = 0, micro = 0;
+    char *tmp;
+
+    major = strtol(version, &tmp, 10);
+    tmp++;
+    minor = strtol(tmp, &tmp, 10);
+    tmp++;
+    micro = strtol(tmp, &tmp, 10);
+
+    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
+        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
 }
 
 static void do_info_name_print(Monitor *mon, const QObject *data)