[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/19] Never overwrite a QemuOpt
From: |
Mark McLoughlin |
Subject: |
[Qemu-devel] [PATCH 07/19] Never overwrite a QemuOpt |
Date: |
Thu, 10 Sep 2009 16:18:49 +0100 |
Rather than overwriting a QemuOpt, just add a new one to the tail and
always do a reverse search for parameters to preserve the same
behaviour. We use this order so that foreach() iterates over the opts
in their original order.
This will allow us handle options where multiple values for the same
parameter is allowed - e.g. -net user,hostfwd=
Signed-off-by: Mark McLoughlin <address@hidden>
---
qemu-option.c | 51 +++++++++++++++++++++++----------------------------
1 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 0f517d1..376efc1 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -483,7 +483,7 @@ struct QemuOpt {
struct QemuOpts {
const char *id;
QemuOptsList *list;
- TAILQ_HEAD(, QemuOpt) head;
+ TAILQ_HEAD(QemuOptHead, QemuOpt) head;
TAILQ_ENTRY(QemuOpts) next;
};
@@ -491,7 +491,7 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char
*name)
{
QemuOpt *opt;
- TAILQ_FOREACH(opt, &opts->head, next) {
+ TAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
if (strcmp(opt->name, name) != 0)
continue;
return opt;
@@ -565,36 +565,31 @@ static void qemu_opt_del(QemuOpt *opt)
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
{
QemuOpt *opt;
+ QemuOptDesc *desc = opts->list->desc;
+ int i;
- opt = qemu_opt_find(opts, name);
- if (!opt) {
- QemuOptDesc *desc = opts->list->desc;
- int i;
-
- for (i = 0; desc[i].name != NULL; i++) {
- if (strcmp(desc[i].name, name) == 0) {
- break;
- }
- }
- if (desc[i].name == NULL) {
- if (i == 0) {
- /* empty list -> allow any */;
- } else {
- fprintf(stderr, "option \"%s\" is not valid for %s\n",
- name, opts->list->name);
- return -1;
- }
+ for (i = 0; desc[i].name != NULL; i++) {
+ if (strcmp(desc[i].name, name) == 0) {
+ break;
}
- opt = qemu_mallocz(sizeof(*opt));
- opt->name = qemu_strdup(name);
- opt->opts = opts;
- TAILQ_INSERT_TAIL(&opts->head, opt, next);
- if (desc[i].name != NULL) {
- opt->desc = desc+i;
+ }
+ if (desc[i].name == NULL) {
+ if (i == 0) {
+ /* empty list -> allow any */;
+ } else {
+ fprintf(stderr, "option \"%s\" is not valid for %s\n",
+ name, opts->list->name);
+ return -1;
}
}
- qemu_free((/* !const */ char*)opt->str);
- opt->str = NULL;
+
+ opt = qemu_mallocz(sizeof(*opt));
+ opt->name = qemu_strdup(name);
+ opt->opts = opts;
+ TAILQ_INSERT_TAIL(&opts->head, opt, next);
+ if (desc[i].name != NULL) {
+ opt->desc = desc+i;
+ }
if (value) {
opt->str = qemu_strdup(value);
}
--
1.6.2.5
- [Qemu-devel] [PATCH 00/19] Port -net to QemuOpts, Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 11/19] Port -net tap to QemuOpts, Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 01/19] Suppress more more kraxelisms, Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 02/19] Remove bogus error message from qemu_opts_set(), Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 07/19] Never overwrite a QemuOpt,
Mark McLoughlin <=
- [Qemu-devel] [PATCH 04/19] Remove double error message for -device option parsing, Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 03/19] Remove double error message in qemu_option_set(), Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 08/19] Add qemu_net_opts, Mark McLoughlin, 2009/09/10
- [Qemu-devel] [PATCH 05/19] Make qemu_opts_parse() handle empty strings, Mark McLoughlin, 2009/09/10