From patchwork Wed May 9 05:57:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10388155 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 22EC160153 for ; Wed, 9 May 2018 06:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12F0828DA5 for ; Wed, 9 May 2018 06:02:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07ABE28DBA; Wed, 9 May 2018 06:02:31 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 8FBE028DA5 for ; Wed, 9 May 2018 06:02:30 +0000 (UTC) Received: from localhost ([::1]:54672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIBJ-0000G5-RD for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 May 2018 02:02:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGI7M-0005iV-UV for qemu-devel@nongnu.org; Wed, 09 May 2018 01:58:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGI7J-0000ok-Uu for qemu-devel@nongnu.org; Wed, 09 May 2018 01:58:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40250 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGI7F-0000fQ-DL; Wed, 09 May 2018 01:58:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5E35818F6EC; Wed, 9 May 2018 05:58:16 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-170.pek2.redhat.com [10.72.12.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99CC910F1BF7; Wed, 9 May 2018 05:58:13 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 13:57:58 +0800 Message-Id: <20180509055802.28423-2-famz@redhat.com> In-Reply-To: <20180509055802.28423-1-famz@redhat.com> References: <20180509055802.28423-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 05:58:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 05:58:16 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/5] qapi: Add qapi_enum_parse_full 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: Kevin Wolf , Fam Zheng , Michael Roth , qemu-block@nongnu.org, Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This variant of qapi_enum_parse can do case insensitive compare. Signed-off-by: Fam Zheng --- include/qapi/util.h | 2 ++ qapi/qapi-util.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index a7c3c64148..2cec231919 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -19,6 +19,8 @@ typedef struct QEnumLookup { const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, int def, Error **errp); +int qapi_enum_parse_full(const QEnumLookup *lookup, const char *buf, + int def, bool ignore_case, Error **errp); int parse_qapi_name(const char *name, bool complete); diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c index e9b266bb70..6180957edb 100644 --- a/qapi/qapi-util.c +++ b/qapi/qapi-util.c @@ -21,8 +21,8 @@ const char *qapi_enum_lookup(const QEnumLookup *lookup, int val) return lookup->array[val]; } -int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, - int def, Error **errp) +int qapi_enum_parse_full(const QEnumLookup *lookup, const char *buf, + int def, bool ignore_case, Error **errp) { int i; @@ -31,8 +31,14 @@ int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, } for (i = 0; i < lookup->size; i++) { - if (!strcmp(buf, lookup->array[i])) { - return i; + if (ignore_case) { + if (!strcasecmp(buf, lookup->array[i])) { + return i; + } + } else { + if (!strcmp(buf, lookup->array[i])) { + return i; + } } } @@ -40,6 +46,12 @@ int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, return def; } +int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, + int def, Error **errp) +{ + return qapi_enum_parse_full(lookup, buf, def, false, errp); +} + /* * Parse a valid QAPI name from @str. * A valid name consists of letters, digits, hyphen and underscore.