diff mbox

[1/4] QemuOpts: add find_list()

Message ID 1255509568-10635-2-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Oct. 14, 2009, 8:39 a.m. UTC
Factor out the QemuOptsList search code for upcoming users.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qemu-config.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
diff mbox

Patch

diff --git a/qemu-config.c b/qemu-config.c
index bafaea2..f02dd42 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -193,11 +193,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] != '=') {
@@ -205,19 +220,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;
     }