From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmOTJ-0005jY-Rd for qemu-devel@nongnu.org; Mon, 19 May 2014 10:23:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmOTC-0004FW-VC for qemu-devel@nongnu.org; Mon, 19 May 2014 10:23:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38393) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmOTC-0004FO-H4 for qemu-devel@nongnu.org; Mon, 19 May 2014 10:23:14 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4JENEhw032021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 19 May 2014 10:23:14 -0400 From: Kevin Wolf Date: Mon, 19 May 2014 16:22:39 +0200 Message-Id: <1400509360-25470-22-git-send-email-kwolf@redhat.com> In-Reply-To: <1400509360-25470-1-git-send-email-kwolf@redhat.com> References: <1400509360-25470-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 21/22] blockdev: add a function to parse enum ids from strings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Peter Lieven this adds a generic function to recover the enum id of a parameter given as a string. Signed-off-by: Peter Lieven Signed-off-by: Kevin Wolf --- blockdev.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/blockdev.c b/blockdev.c index 7810e9f..78b927f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -288,6 +288,25 @@ static int parse_block_error_action(const char *buf, bool is_read, Error **errp) } } +static inline int parse_enum_option(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; +} + static bool check_throttle_config(ThrottleConfig *cfg, Error **errp) { if (throttle_conflicting(cfg)) { -- 1.8.3.1