From 14268964e8fdc1956a4d2013fe5a020e89746a95 Mon Sep 17 00:00:00 2001 Message-Id: <14268964e8fdc1956a4d2013fe5a020e89746a95.1422637807.git.jen@redhat.com> In-Reply-To: References: From: Max Reitz Date: Mon, 19 Jan 2015 14:52:04 -0500 Subject: [CHANGE 03/10] rename parse_enum_option to qapi_enum_parse and make it public To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Max Reitz Message-id: <1421679130-22714-4-git-send-email-mreitz@redhat.com> Patchwork-id: 63363 O-Subject: [RHEL-6.7 qemu-kvm PATCH 3/9] rename parse_enum_option to qapi_enum_parse and make it public Bugzilla: 1040220 RH-Acked-by: Fam Zheng RH-Acked-by: Laszlo Ersek RH-Acked-by: Stefan Hajnoczi From: Peter Lieven BZ: 1040220 relaxing the license to LGPLv2+ is intentional. Suggested-by: Markus Armbruster Signed-off-by: Hu Tao Signed-off-by: Peter Lieven Reviewed-by: Eric Blake Reviewed-by: Benoit Canet Signed-off-by: Stefan Hajnoczi (cherry picked from commit 9e7dac7c6c6003ad9d4aca0125f0278233fcf761) Signed-off-by: Jeff E. Nelson Conflicts: qapi/Makefile.objs Makefile.objs blockdev.c qapi/qapi-util.c There is no qapi/Makefile.objs downstream, instead all QAPI files are described by the main Makefile.objs file. Downstream, there is no parse_enum_option(), which results in no changes being necessary in blockdev.c. qapi/error.h is just error.h downstream which requires a change to qapi/qapi-util.c from upstream. Signee-off-by: Max Reitz --- Makefile.objs | 1 + include/qapi/util.h | 17 +++++++++++++++++ qapi/qapi-util.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 include/qapi/util.h create mode 100644 qapi/qapi-util.c Signed-off-by: Jeff E. Nelson --- Makefile.objs | 1 + include/qapi/util.h | 17 +++++++++++++++++ qapi/qapi-util.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 include/qapi/util.h create mode 100644 qapi/qapi-util.c diff --git a/Makefile.objs b/Makefile.objs index f2f9106..10a9d7b 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -201,6 +201,7 @@ hw-obj-$(CONFIG_QDEV_ADDR) += qdev-addr.o qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-dealloc-visitor.o qapi-nested-y += qmp-registry.o qmp-dispatch.o string-input-visitor.o string-output-visitor.o +qapi-nested-y += qapi-util.o ifeq ($(CONFIG_LIVE_SNAPSHOTS),y) qapi-generated-y += rhev-qapi-visit.o rhev-qapi-types.o rhev-qmp-marshal.o diff --git a/include/qapi/util.h b/include/qapi/util.h new file mode 100644 index 0000000..de9238b --- /dev/null +++ b/include/qapi/util.h @@ -0,0 +1,17 @@ +/* + * QAPI util functions + * + * Copyright Fujitsu, Inc. 2014 + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef QAPI_UTIL_H +#define QAPI_UTIL_H + +int qapi_enum_parse(const char *lookup[], const char *buf, + int max, int def, Error **errp); + +#endif diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c new file mode 100644 index 0000000..4d7332d --- /dev/null +++ b/qapi/qapi-util.c @@ -0,0 +1,34 @@ +/* + * QAPI util functions + * + * Authors: + * Hu Tao + * Peter Lieven + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include "qemu-common.h" +#include "error.h" +#include "qapi/util.h" + +int qapi_enum_parse(const char *lookup[], const char *buf, + int max, int def, Error **errp) +{ + int i; + + if (!buf) { + return def; + } + + for (i = 0; i < max; i++) { + if (!strcmp(buf, lookup[i])) { + return i; + } + } + + error_setg(errp, "invalid parameter value: %s", buf); + return def; +} -- 2.1.0