diff mbox

[v2,1/4] qemu-option.c: Add qemu_opt functions that step over arguments

Message ID 4f4de465fc0d1cc73fb47bf51743896d21e4128f.1397197001.git.alistair.francis@xilinx.com
State New
Headers show

Commit Message

Alistair Francis April 11, 2014, 6:34 a.m. UTC
This adds two functions, qemu_opt_step() and qemu_opt_name_step()
which iterate over the comma separated stings in the QemuOpts*
argument. This allows accessing multiple arguments with the
same name by iterating over all of the arguments

Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---

 include/qemu/option.h |    2 ++
 util/qemu-option.c    |   30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..ad20cd4 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -110,6 +110,8 @@  struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+const char *qemu_opt_name_step(QemuOpts *opts, int num);
+const char *qemu_opt_step(QemuOpts *opts, int num);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9d898af..4192c13 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -541,6 +541,36 @@  void print_option_help(QEMUOptionParameter *list)
 
 /* ------------------------------------------------------------------ */
 
+const char *qemu_opt_name_step(QemuOpts *opts, int num)
+{
+    QemuOpt *opt;
+    int i = 0;
+
+    QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
+        if (i < num) {
+            i++;
+            continue;
+        }
+        return opt->name;
+    }
+    return NULL;
+}
+
+const char *qemu_opt_step(QemuOpts *opts, int num)
+{
+    QemuOpt *opt;
+    int i = 0;
+
+    QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
+        if (i < num) {
+            i++;
+            continue;
+        }
+        return opt->str;
+    }
+    return NULL;
+}
+
 static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
 {
     QemuOpt *opt;