Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 1 | /* |
| 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 Maydell | cbf2115 | 2016-01-29 17:49:57 +0000 | [diff] [blame] | 13 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 14 | #include "qapi/error.h" |
Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 15 | #include "qemu-common.h" |
Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 16 | #include "qapi/util.h" |
| 17 | |
Daniel P. Berrange | 2e4450f | 2015-05-13 17:14:07 +0100 | [diff] [blame] | 18 | int qapi_enum_parse(const char * const lookup[], const char *buf, |
Peter Lieven | 9e7dac7 | 2014-08-13 19:20:17 +0200 | [diff] [blame] | 19 | int max, int def, Error **errp) |
| 20 | { |
| 21 | int i; |
| 22 | |
| 23 | if (!buf) { |
| 24 | return def; |
| 25 | } |
| 26 | |
| 27 | for (i = 0; i < max; i++) { |
| 28 | if (!strcmp(buf, lookup[i])) { |
| 29 | return i; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | error_setg(errp, "invalid parameter value: %s", buf); |
| 34 | return def; |
| 35 | } |