Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrDn8-0004M9-Dj for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:22 -0400 Received: from [199.232.76.173] (port=60311 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrDn7-0004Lk-MT for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:21 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrDn6-0005qu-AZ for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34662) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrDn5-0005qi-QX for qemu-devel@nongnu.org; Mon, 15 Mar 2010 13:09:20 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2FH9IV2017385 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Mar 2010 13:09:18 -0400 From: Kevin Wolf Date: Mon, 15 Mar 2010 18:08:30 +0100 Message-Id: <1268672915-12233-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1268672915-12233-1-git-send-email-kwolf@redhat.com> References: <1268672915-12233-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [RFC][PATCH 2/7] qemu-config: Make qemu_config_parse more generic List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com qemu_config_parse gets the option groups as a parameter now instead of hardcoding the VM configuration groups. This way it can be used for other configurations, too. Signed-off-by: Kevin Wolf --- qemu-config.c | 15 ++++++++------- qemu-config.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 8166b5e..e121f2a 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -290,7 +290,7 @@ QemuOptsList qemu_cpudef_opts = { }, }; -static QemuOptsList *lists[] = { +static QemuOptsList *vm_config_groups[] = { &qemu_drive_opts, &qemu_chardev_opts, &qemu_device_opts, @@ -303,7 +303,7 @@ static QemuOptsList *lists[] = { NULL, }; -static QemuOptsList *find_list(const char *group) +static QemuOptsList *find_list(QemuOptsList **lists, const char *group) { int i; @@ -330,7 +330,7 @@ int qemu_set_option(const char *str) return -1; } - list = find_list(group); + list = find_list(vm_config_groups, group); if (list == NULL) { return -1; } @@ -415,6 +415,7 @@ static int config_write_opts(QemuOpts *opts, void *opaque) void qemu_config_write(FILE *fp) { struct ConfigWriteData data = { .fp = fp }; + QemuOptsList **lists = vm_config_groups; int i; fprintf(fp, "# qemu config file\n\n"); @@ -424,7 +425,7 @@ void qemu_config_write(FILE *fp) } } -int qemu_config_parse(FILE *fp) +int qemu_config_parse(FILE *fp, QemuOptsList **lists) { char line[1024], group[64], id[64], arg[64], value[1024]; QemuOptsList *list = NULL; @@ -441,7 +442,7 @@ int qemu_config_parse(FILE *fp) } if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { /* group with id */ - list = find_list(group); + list = find_list(lists, group); if (list == NULL) return -1; opts = qemu_opts_create(list, id, 1); @@ -449,7 +450,7 @@ int qemu_config_parse(FILE *fp) } if (sscanf(line, "[%63[^]]]", group) == 1) { /* group without id */ - list = find_list(group); + list = find_list(lists, group); if (list == NULL) return -1; opts = qemu_opts_create(list, NULL, 0); @@ -481,7 +482,7 @@ int qemu_read_config_file(const char *filename) return -errno; } - if (qemu_config_parse(f) != 0) { + if (qemu_config_parse(f, vm_config_groups) != 0) { return -EINVAL; } fclose(f); diff --git a/qemu-config.h b/qemu-config.h index bbe9d41..086aa2a 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -16,7 +16,7 @@ int qemu_global_option(const char *str); void qemu_add_globals(void); void qemu_config_write(FILE *fp); -int qemu_config_parse(FILE *fp); +int qemu_config_parse(FILE *fp, QemuOptsList **lists); int qemu_read_config_file(const char *filename); -- 1.6.6.1