From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGvKh-0004yk-8K for qemu-devel@nongnu.org; Thu, 20 Oct 2011 12:19:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGvKe-0003My-KA for qemu-devel@nongnu.org; Thu, 20 Oct 2011 12:19:03 -0400 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:52196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGvKd-0003LA-Nt for qemu-devel@nongnu.org; Thu, 20 Oct 2011 12:19:00 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp02.au.ibm.com (8.14.4/8.13.1) with ESMTP id p9KGC7mx030346 for ; Fri, 21 Oct 2011 03:12:07 +1100 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9KGGHRU2297916 for ; Fri, 21 Oct 2011 03:16:17 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9KGIn7P022636 for ; Fri, 21 Oct 2011 03:18:49 +1100 From: "Aneesh Kumar K.V" Date: Thu, 20 Oct 2011 21:47:35 +0530 Message-Id: <1319127460-5181-4-git-send-email-aneesh.kumar@linux.vnet.ibm.com> In-Reply-To: <1319127460-5181-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1319127460-5181-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 3/8] qemu: Add opt_set_bool functionality List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, "M. Mohan Kumar" , "Aneesh Kumar K.V" From: "M. Mohan Kumar" Signed-off-by: M. Mohan Kumar Signed-off-by: Aneesh Kumar K.V --- qemu-option.c | 43 +++++++++++++++++++++++++++++++++++++++---- qemu-option.h | 3 ++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 105d760..1fd2755 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -168,7 +168,7 @@ QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list, return NULL; } -static int parse_option_bool(const char *name, const char *value, int *ret) +static int parse_option_bool(const char *name, const char *value, bool *ret) { if (value != NULL) { if (!strcmp(value, "on")) { @@ -258,7 +258,7 @@ static int parse_option_size(const char *name, const char *value, uint64_t *ret) int set_option_parameter(QEMUOptionParameter *list, const char *name, const char *value) { - int flag; + bool flag; // Find a matching parameter list = get_option_parameter(list, name); @@ -508,7 +508,7 @@ struct QemuOpt { const QemuOptDesc *desc; union { - int boolean; + bool boolean; uint64_t uint; } value; @@ -542,7 +542,7 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name) return opt ? opt->str : NULL; } -int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval) +bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) { QemuOpt *opt = qemu_opt_find(opts, name); @@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) return 0; } +int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val) +{ + QemuOpt *opt; + const QemuOptDesc *desc = opts->list->desc; + int i; + + for (i = 0; desc[i].name != NULL; i++) { + if (strcmp(desc[i].name, name) == 0) { + break; + } + } + if (desc[i].name == NULL) { + if (i == 0) { + /* empty list -> allow any */; + } else { + qerror_report(QERR_INVALID_PARAMETER, name); + return -1; + } + } + + opt = g_malloc0(sizeof(*opt)); + opt->name = g_strdup(name); + opt->opts = opts; + QTAILQ_INSERT_TAIL(&opts->head, opt, next); + if (desc[i].name != NULL) { + opt->desc = desc+i; + } + opt->value.boolean = !!val; + if (qemu_opt_parse(opt) < 0) { + qemu_opt_del(opt); + return -1; + } + return 0; +} + int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, int abort_on_failure) { diff --git a/qemu-option.h b/qemu-option.h index b515813..07958e4 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -105,10 +105,11 @@ struct QemuOptsList { }; const char *qemu_opt_get(QemuOpts *opts, const char *name); -int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval); +bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); +int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val); typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, int abort_on_failure); -- 1.7.5.4