blob: 8afb12eb43e97f2c8484115befa50559a32b38f8 [file] [log] [blame]
Peter Lieven9e7dac72014-08-13 19:20:17 +02001/*
2 * QAPI util functions
3 *
4 * Authors:
5 * Hu Tao <hutao@cn.fujitsu.com>
6 * Peter Lieven <pl@kamp.de>
7 *
8 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
9 * See the COPYING.LIB file in the top-level directory.
10 *
11 */
12
Peter Maydellcbf21152016-01-29 17:49:57 +000013#include "qemu/osdep.h"
Peter Lieven9e7dac72014-08-13 19:20:17 +020014#include "qemu-common.h"
Peter Lieven9e7dac72014-08-13 19:20:17 +020015#include "qapi/util.h"
16
Daniel P. Berrange2e4450f2015-05-13 17:14:07 +010017int qapi_enum_parse(const char * const lookup[], const char *buf,
Peter Lieven9e7dac72014-08-13 19:20:17 +020018 int max, int def, Error **errp)
19{
20 int i;
21
22 if (!buf) {
23 return def;
24 }
25
26 for (i = 0; i < max; i++) {
27 if (!strcmp(buf, lookup[i])) {
28 return i;
29 }
30 }
31
32 error_setg(errp, "invalid parameter value: %s", buf);
33 return def;
34}