mirror of https://github.com/xqemu/xqemu.git
qemu-option: opt_set(): split it up into more functions
The new functions are opts_accepts_any() and find_desc_by_name(), which are also going to be used by qemu_opts_validate() (see next commit). This also makes opt_set() slightly more readable. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
fbcad04d6b
commit
c474ced8fe
|
@ -602,26 +602,36 @@ static void qemu_opt_del(QemuOpt *opt)
|
||||||
g_free(opt);
|
g_free(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void opt_set(QemuOpts *opts, const char *name, const char *value,
|
static bool opts_accepts_any(const QemuOpts *opts)
|
||||||
bool prepend, Error **errp)
|
{
|
||||||
|
return opts->list->desc[0].name == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
QemuOpt *opt;
|
|
||||||
const QemuOptDesc *desc = opts->list->desc;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; desc[i].name != NULL; i++) {
|
for (i = 0; desc[i].name != NULL; i++) {
|
||||||
if (strcmp(desc[i].name, name) == 0) {
|
if (strcmp(desc[i].name, name) == 0) {
|
||||||
break;
|
return &desc[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desc[i].name == NULL) {
|
|
||||||
if (i == 0) {
|
return NULL;
|
||||||
/* empty list -> allow any */;
|
}
|
||||||
} else {
|
|
||||||
error_set(errp, QERR_INVALID_PARAMETER, name);
|
static void opt_set(QemuOpts *opts, const char *name, const char *value,
|
||||||
return;
|
bool prepend, Error **errp)
|
||||||
}
|
{
|
||||||
|
QemuOpt *opt;
|
||||||
|
const QemuOptDesc *desc;
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
|
desc = find_desc_by_name(opts->list->desc, name);
|
||||||
|
if (!desc && !opts_accepts_any(opts)) {
|
||||||
|
error_set(errp, QERR_INVALID_PARAMETER, name);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
opt = g_malloc0(sizeof(*opt));
|
opt = g_malloc0(sizeof(*opt));
|
||||||
|
@ -632,9 +642,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
|
||||||
} else {
|
} else {
|
||||||
QTAILQ_INSERT_TAIL(&opts->head, opt, next);
|
QTAILQ_INSERT_TAIL(&opts->head, opt, next);
|
||||||
}
|
}
|
||||||
if (desc[i].name != NULL) {
|
opt->desc = desc;
|
||||||
opt->desc = desc+i;
|
|
||||||
}
|
|
||||||
if (value) {
|
if (value) {
|
||||||
opt->str = g_strdup(value);
|
opt->str = g_strdup(value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue