From patchwork Mon Sep 5 15:16:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 9314255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B7CD600CA for ; Mon, 5 Sep 2016 15:32:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CDAE28159 for ; Mon, 5 Sep 2016 15:32:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01A6F289D4; Mon, 5 Sep 2016 15:32:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C8B328159 for ; Mon, 5 Sep 2016 15:32:21 +0000 (UTC) Received: from localhost ([::1]:55387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgvsi-00028E-6P for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Sep 2016 11:32:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgvsD-000283-03 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 11:31:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgvsA-0007TJ-Lx for qemu-devel@nongnu.org; Mon, 05 Sep 2016 11:31:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgvsA-0007TE-E0 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 11:31:46 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EFE46335F84; Mon, 5 Sep 2016 15:31:45 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-221.ams2.redhat.com [10.36.6.221]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u85FVdSP021140; Mon, 5 Sep 2016 11:31:44 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 5 Sep 2016 16:16:36 +0100 Message-Id: <1473088600-17930-3-git-send-email-berrange@redhat.com> In-Reply-To: <1473088600-17930-1-git-send-email-berrange@redhat.com> References: <1473088600-17930-1-git-send-email-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 05 Sep 2016 15:31:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v11 2/6] option: make parse_option_bool/number non-static X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Max Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The opts-visitor.c opts_type_bool() method has code for parsing a string to set a bool value, as does the qemu-option.c parse_option_bool() method, except it handles fewer cases. To enable consistency across the codebase, extend parse_option_bool() to handle "yes", "no", "y" and "n", and make it non-static. Convert the opts visitor to call this method directly. Also make parse_option_number() non-static to allow for similar reuse later. Reviewed-by: Marc-André Lureau Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrange Reviewed-by: Kevin Wolf --- include/qemu/option.h | 4 ++++ qapi/opts-visitor.c | 19 +------------------ util/qemu-option.c | 27 ++++++++++++++++----------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index 1f9e3f9..2a5266f 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -37,6 +37,10 @@ int get_param_value(char *buf, int buf_size, const char *tag, const char *str); +void parse_option_bool(const char *name, const char *value, bool *ret, + Error **errp); +void parse_option_number(const char *name, const char *value, + uint64_t *ret, Error **errp); void parse_option_size(const char *name, const char *value, uint64_t *ret, Error **errp); bool has_help_option(const char *param); diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 1048bbc..084f7cc 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -334,7 +334,6 @@ opts_type_str(Visitor *v, const char *name, char **obj, Error **errp) } -/* mimics qemu-option.c::parse_option_bool() */ static void opts_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { @@ -346,23 +345,7 @@ opts_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) return; } - if (opt->str) { - if (strcmp(opt->str, "on") == 0 || - strcmp(opt->str, "yes") == 0 || - strcmp(opt->str, "y") == 0) { - *obj = true; - } else if (strcmp(opt->str, "off") == 0 || - strcmp(opt->str, "no") == 0 || - strcmp(opt->str, "n") == 0) { - *obj = false; - } else { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - "on|yes|y|off|no|n"); - return; - } - } else { - *obj = true; - } + parse_option_bool(opt->name, opt->str, obj, errp); processed(ov, name); } diff --git a/util/qemu-option.c b/util/qemu-option.c index 3467dc2..6fc9ccb 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -125,25 +125,30 @@ int get_param_value(char *buf, int buf_size, return get_next_param_value(buf, buf_size, tag, &str); } -static void parse_option_bool(const char *name, const char *value, bool *ret, - Error **errp) +void parse_option_bool(const char *name, const char *value, bool *ret, + Error **errp) { if (value != NULL) { - if (!strcmp(value, "on")) { - *ret = 1; - } else if (!strcmp(value, "off")) { - *ret = 0; + if (strcmp(value, "on") == 0 || + strcmp(value, "yes") == 0 || + strcmp(value, "y") == 0) { + *ret = true; + } else if (strcmp(value, "off") == 0 || + strcmp(value, "no") == 0 || + strcmp(value, "n") == 0) { + *ret = false; } else { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name, "'on' or 'off'"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, + "on|yes|y|off|no|n"); + return; } } else { - *ret = 1; + *ret = true; } } -static void parse_option_number(const char *name, const char *value, - uint64_t *ret, Error **errp) +void parse_option_number(const char *name, const char *value, + uint64_t *ret, Error **errp) { char *postfix; uint64_t number;