diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2011-06-21 18:26:39 +0100 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2011-06-21 18:26:39 +0100 |
commit | a53cb5b82d0490241ec48bd0083939823b6d39f9 (patch) | |
tree | 92c484146f5c7d0c9c3ba435ecb579d380bb713e /tools/libxl/libxl_utils.c | |
parent | dbf20f55f0c154d11153c40f2a709b8c32bb83cc (diff) | |
download | xen-a53cb5b82d0490241ec48bd0083939823b6d39f9.tar.gz xen-a53cb5b82d0490241ec48bd0083939823b6d39f9.tar.bz2 xen-a53cb5b82d0490241ec48bd0083939823b6d39f9.zip |
libxl: autogenerate to_string and from_string functions for Enumerations.
The generated strings are the lower case enum value names, with underscores.
Accepted string for parsing are the same but are case insensitive.
We provide a table of strings->value for each Enumeration as well as a
convenience function to perform a lookup.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_utils.c')
-rw-r--r-- | tools/libxl/libxl_utils.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index b23cf2550b..889d02cb7a 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -639,3 +639,17 @@ int libxl_get_max_cpus(libxl_ctx *ctx) { return xc_get_max_cpus(ctx->xch); } + +int libxl__enum_from_string(const libxl_enum_string_table *t, + const char *s, int *e) +{ + if (!t) return ERROR_INVAL; + + for( ; t->s; t++) { + if (!strcasecmp(t->s, s)) { + *e = t->v; + return 0; + } + } + return ERROR_FAIL; +} |