From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 3/4] QemuOpts: parse config from file.
Date: Wed, 14 Oct 2009 10:39:27 +0200 [thread overview]
Message-ID: <1255509568-10635-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1255509568-10635-1-git-send-email-kraxel@redhat.com>
Add functions to parse QemuOpts from a git-style config file.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
qemu-config.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
qemu-config.h | 1 +
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/qemu-config.c b/qemu-config.c
index fa236e9..1b24ec8 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -277,3 +277,53 @@ void qemu_config_write(FILE *fp)
qemu_opts_foreach(data.list, config_write_opts, &data, 0);
}
}
+
+int qemu_config_parse(FILE *fp)
+{
+ char line[1024], group[64], id[64], arg[64], value[1024];
+ QemuOptsList *list = NULL;
+ QemuOpts *opts = NULL;
+
+ while (fgets(line, sizeof(line), fp) != NULL) {
+ if (line[0] == '\n') {
+ /* skip empty lines */
+ continue;
+ }
+ if (line[0] == '#') {
+ /* comment */
+ continue;
+ }
+ if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
+ /* group with id */
+ list = find_list(group);
+ if (list == NULL)
+ return -1;
+ opts = qemu_opts_create(list, id, 1);
+ continue;
+ }
+ if (sscanf(line, "[%63[^]]]", group) == 1) {
+ /* group without id */
+ list = find_list(group);
+ if (list == NULL)
+ return -1;
+ opts = qemu_opts_create(list, NULL, 0);
+ continue;
+ }
+ if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
+ /* arg = value */
+ if (opts == NULL) {
+ fprintf(stderr, "no group defined\n");
+ return -1;
+ }
+ if (qemu_opt_set(opts, arg, value) != 0) {
+ fprintf(stderr, "failed to set \"%s\" for %s\n",
+ arg, group);
+ return -1;
+ }
+ continue;
+ }
+ fprintf(stderr, "parse error: %s\n", line);
+ return -1;
+ }
+ return 0;
+}
diff --git a/qemu-config.h b/qemu-config.h
index 33fce7e..0448ab4 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -10,5 +10,6 @@ extern QemuOptsList qemu_rtc_opts;
int qemu_set_option(const char *str);
void qemu_config_write(FILE *fp);
+int qemu_config_parse(FILE *fp);
#endif /* QEMU_CONFIG_H */
--
1.6.2.5
next prev parent reply other threads:[~2009-10-14 8:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-14 8:39 [Qemu-devel] [PATCH 0/4] QemuOpts: config file support Gerd Hoffmann
2009-10-14 8:39 ` [Qemu-devel] [PATCH 1/4] QemuOpts: add find_list() Gerd Hoffmann
2009-10-14 8:39 ` [Qemu-devel] [PATCH 2/4] QemuOpts: dump config Gerd Hoffmann
2009-10-14 18:56 ` Anthony Liguori
2009-10-14 8:39 ` Gerd Hoffmann [this message]
2009-10-14 18:55 ` [Qemu-devel] [PATCH 3/4] QemuOpts: parse config from file Anthony Liguori
2009-10-14 8:39 ` [Qemu-devel] [PATCH 4/4] QemuOpts: command line switches for the config file Gerd Hoffmann
2009-10-16 18:39 ` Nathan Baum
2009-10-16 19:29 ` Gerd Hoffmann
2009-10-16 18:48 ` Nathan Baum
2009-10-16 19:33 ` Gerd Hoffmann
2009-10-14 18:53 ` [Qemu-devel] [PATCH 0/4] QemuOpts: config file support Anthony Liguori
2009-10-14 19:01 ` Anthony Liguori
2009-10-16 10:16 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1255509568-10635-4-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).