summaryrefslogtreecommitdiff
path: root/qemu-config.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-10-14 10:39:25 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-09 08:43:12 -0600
commitddc978550db144aa44098cd00c87d1436a78dd1b (patch)
treecaffb6142fd341d3a722f7fec1a3a9e19e8d89eb /qemu-config.c
parent3e03236438b5015dda8bebf9c247b978565f0211 (diff)
QemuOpts: add find_list()
Factor out the QemuOptsList search code for upcoming users. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-config.c')
-rw-r--r--qemu-config.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/qemu-config.c b/qemu-config.c
index d83d2a697c..cb2c213a7d 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -212,11 +212,26 @@ static QemuOptsList *lists[] = {
NULL,
};
+static QemuOptsList *find_list(const char *group)
+{
+ int i;
+
+ for (i = 0; lists[i] != NULL; i++) {
+ if (strcmp(lists[i]->name, group) == 0)
+ break;
+ }
+ if (lists[i] == NULL) {
+ qemu_error("there is no option group \"%s\"\n", group);
+ }
+ return lists[i];
+}
+
int qemu_set_option(const char *str)
{
char group[64], id[64], arg[64];
+ QemuOptsList *list;
QemuOpts *opts;
- int i, rc, offset;
+ int rc, offset;
rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
if (rc < 3 || str[offset] != '=') {
@@ -224,19 +239,15 @@ int qemu_set_option(const char *str)
return -1;
}
- for (i = 0; lists[i] != NULL; i++) {
- if (strcmp(lists[i]->name, group) == 0)
- break;
- }
- if (lists[i] == NULL) {
- qemu_error("there is no option group \"%s\"\n", group);
+ list = find_list(group);
+ if (list == NULL) {
return -1;
}
- opts = qemu_opts_find(lists[i], id);
+ opts = qemu_opts_find(list, id);
if (!opts) {
qemu_error("there is no %s \"%s\" defined\n",
- lists[i]->name, id);
+ list->name, id);
return -1;
}