From patchwork Fri Apr 11 06:34:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 338390 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7802E14008A for ; Fri, 11 Apr 2014 16:35:41 +1000 (EST) Received: from localhost ([::1]:56134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYV3p-0004No-Ss for incoming@patchwork.ozlabs.org; Fri, 11 Apr 2014 02:35:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYV39-0004Iq-Rd for qemu-devel@nongnu.org; Fri, 11 Apr 2014 02:35:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYV33-0007g6-OC for qemu-devel@nongnu.org; Fri, 11 Apr 2014 02:34:55 -0400 Received: from mail-pd0-x235.google.com ([2607:f8b0:400e:c02::235]:42277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYV33-0007fv-Ho for qemu-devel@nongnu.org; Fri, 11 Apr 2014 02:34:49 -0400 Received: by mail-pd0-f181.google.com with SMTP id p10so4824716pdj.26 for ; Thu, 10 Apr 2014 23:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=SYVN5IPNlwjLvu1INSyUsbG5ChAdJDW+52VbemopAOU=; b=oDoLDahf7jNQONePbQC4fDtK4XRXZpP4NQ4wQ3fqr8J0zmJrlK+mg96qE/cAKFosh4 yHO+2E03nz+xPsGlWQu4cZke6T2EOz6FZ2o34ZHshT9F0qjeSErW8vZH274mAy1kK1NH qxFPzf7afMBUU/Y1WLZJeHF2NcU2WTG5JoynpJeNlmFLrJEwOr1TKWhf0QxsJwoa5aQE 92Dh65uU8eI4ZCvJduIusx3WIYYJM1WdECyANfAqGnY+KGqOp/jnZU3DlVLX7VP6izOi z+vay0bb+fL8UhlZc7Ck+2LS2NaN+PwfAqhHhepzMYGcsslZIgBeram+jZ7J9TKdDJdS qSEQ== X-Received: by 10.66.254.198 with SMTP id ak6mr2434137pad.156.1397198088684; Thu, 10 Apr 2014 23:34:48 -0700 (PDT) Received: from localhost ([203.126.243.116]) by mx.google.com with ESMTPSA id de5sm13303363pbc.66.2014.04.10.23.34.47 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 10 Apr 2014 23:34:48 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org Date: Fri, 11 Apr 2014 16:34:44 +1000 Message-Id: <4f4de465fc0d1cc73fb47bf51743896d21e4128f.1397197001.git.alistair.francis@xilinx.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::235 Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, eric.auger@linaro.org, kim.phillips@linaro.org, agraf@suse.de, armbru@redhat.com, edgar.iglesias@gmail.com, alistair.francis@xilinx.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 1/4] qemu-option.c: Add qemu_opt functions that step over arguments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- include/qemu/option.h | 2 ++ util/qemu-option.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) 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;