From patchwork Fri Dec 14 14:04:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 206504 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 11E032C00B9 for ; Sat, 15 Dec 2012 01:16:21 +1100 (EST) Received: from localhost ([::1]:55328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjVtm-0002OS-Vd for incoming@patchwork.ozlabs.org; Fri, 14 Dec 2012 09:05:58 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjVtH-0000tG-BN for qemu-devel@nongnu.org; Fri, 14 Dec 2012 09:05:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjVtC-0005Jf-79 for qemu-devel@nongnu.org; Fri, 14 Dec 2012 09:05:27 -0500 Received: from mail-pb0-f45.google.com ([209.85.160.45]:56947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjVtC-0005JW-1J for qemu-devel@nongnu.org; Fri, 14 Dec 2012 09:05:22 -0500 Received: by mail-pb0-f45.google.com with SMTP id mc8so2357005pbc.4 for ; Fri, 14 Dec 2012 06:05:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=/l9eyChNBmPTECZHJe4iplgA/IXUrwUiEMLHuj4yreQ=; b=GH0BhaIZ3OXu97EuBQf8DCGeGEf7+4Ofvd8kf3zYcAb0HTlDfUWZibqgEhhmI3H4+X 55bP6BOtWIBtT7GCbzLaVceg77PTPWDAmwIf5CartsuRYqXiDBFVAANKVIpbUq7rjzau NdpZutCAsA9mpFVII8oczT/071P3tFWL4aP4qfTBBPBrA2LwZBOuKeSTV2Q1hHLJkyym 9iIOBLWFOxlnv4qqP0G8UOG4lwXc9iPqn0IjZXSl37TDg+nRLbaAdZP95QK4rytX70xM bQrj0wf28nMVwu7NmPpUMpiVjuk8UsKHUtB9pnSvhSG5v0iiGnML93oYga2tdvrt32xx HYwQ== Received: by 10.68.248.70 with SMTP id yk6mr15757431pbc.160.1355493921219; Fri, 14 Dec 2012 06:05:21 -0800 (PST) Received: from localhost.localdomain ([202.108.130.153]) by mx.google.com with ESMTPS id mt15sm2989308pbc.49.2012.12.14.06.05.17 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Dec 2012 06:05:20 -0800 (PST) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Fri, 14 Dec 2012 22:04:48 +0800 Message-Id: <1355493891-22624-2-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1355493891-22624-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1355493891-22624-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.45 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V8 1/4] add def_print_str and use it in qemu_opts_print. 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 qemu_opts_print has no user now, so can re-write the function safely. qemu_opts_print will be used while using "qemu-img create", it will produce the same output as previous code. The behavior of this function has changed: 1. Print every possible option, whether a value has been set or not. 2. Option descriptors may provide a default value. 3. Print to stdout instead of stderr. Previously the behavior was to print every option that has been set. Options that have not been set would be skipped. v7->v8: 1) print "elements => accept any params" while opts_accepts_any() == true. 2) since def_print_str is the default value if an option isn't set, so rename it to def_value_str. Signed-off-by: Dong Xu Wang --- qemu-option.c | 31 ++++++++++++++++++++++++------- qemu-option.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 94557cf..139ecd6 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -862,15 +862,32 @@ void qemu_opts_del(QemuOpts *opts) int qemu_opts_print(QemuOpts *opts, void *dummy) { - QemuOpt *opt; + QemuOptDesc *desc = opts->list->desc; - fprintf(stderr, "%s: %s:", opts->list->name, - opts->id ? opts->id : ""); - QTAILQ_FOREACH(opt, &opts->head, next) { - fprintf(stderr, " %s=\"%s\"", opt->name, opt->str); + if (desc[0].name == NULL) { + printf("no elements => accept any params"); + return 0; } - fprintf(stderr, "\n"); - return 0; + for (; desc && desc->name; desc++) { + const char *value = desc->def_value_str; + QemuOpt *opt; + + opt = qemu_opt_find(opts, desc->name); + if (opt) { + value = opt->str; + } + + if (!value) { + continue; + } + + if (desc->type == QEMU_OPT_STRING) { + printf("%s='%s' ", desc->name, value); + } else { + printf("%s=%s ", desc->name, value); + } + } + return 0; } static int opts_do_parse(QemuOpts *opts, const char *params, diff --git a/qemu-option.h b/qemu-option.h index 002dd07..2f8b9f0 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -96,6 +96,7 @@ typedef struct QemuOptDesc { const char *name; enum QemuOptType type; const char *help; + const char *def_value_str; } QemuOptDesc; struct QemuOptsList {