@@ -37,6 +37,10 @@ int get_param_value(char *buf, int buf_size,
const char *tag, const char *str);
+void parse_option_bool(const char *name, const char *value, bool *ret,
+ Error **errp);
+void parse_option_number(const char *name, const char *value,
+ uint64_t *ret, Error **errp);
void parse_option_size(const char *name, const char *value,
uint64_t *ret, Error **errp);
bool has_help_option(const char *param);
@@ -334,7 +334,6 @@ opts_type_str(Visitor *v, const char *name, char **obj, Error **errp)
}
-/* mimics qemu-option.c::parse_option_bool() */
static void
opts_type_bool(Visitor *v, const char *name, bool *obj, Error **errp)
{
@@ -346,23 +345,7 @@ opts_type_bool(Visitor *v, const char *name, bool *obj, Error **errp)
return;
}
- if (opt->str) {
- if (strcmp(opt->str, "on") == 0 ||
- strcmp(opt->str, "yes") == 0 ||
- strcmp(opt->str, "y") == 0) {
- *obj = true;
- } else if (strcmp(opt->str, "off") == 0 ||
- strcmp(opt->str, "no") == 0 ||
- strcmp(opt->str, "n") == 0) {
- *obj = false;
- } else {
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
- "on|yes|y|off|no|n");
- return;
- }
- } else {
- *obj = true;
- }
+ parse_option_bool(opt->name, opt->str, obj, errp);
processed(ov, name);
}
@@ -125,25 +125,30 @@ int get_param_value(char *buf, int buf_size,
return get_next_param_value(buf, buf_size, tag, &str);
}
-static void parse_option_bool(const char *name, const char *value, bool *ret,
- Error **errp)
+void parse_option_bool(const char *name, const char *value, bool *ret,
+ Error **errp)
{
if (value != NULL) {
- if (!strcmp(value, "on")) {
- *ret = 1;
- } else if (!strcmp(value, "off")) {
- *ret = 0;
+ if (strcmp(value, "on") == 0 ||
+ strcmp(value, "yes") == 0 ||
+ strcmp(value, "y") == 0) {
+ *ret = true;
+ } else if (strcmp(value, "off") == 0 ||
+ strcmp(value, "no") == 0 ||
+ strcmp(value, "n") == 0) {
+ *ret = false;
} else {
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
- name, "'on' or 'off'");
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name,
+ "on|yes|y|off|no|n");
+ return;
}
} else {
- *ret = 1;
+ *ret = true;
}
}
-static void parse_option_number(const char *name, const char *value,
- uint64_t *ret, Error **errp)
+void parse_option_number(const char *name, const char *value,
+ uint64_t *ret, Error **errp)
{
char *postfix;
uint64_t number;