From patchwork Mon Jan 7 05:26:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 209856 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 2FA282C007C for ; Mon, 7 Jan 2013 16:27:12 +1100 (EST) Received: from localhost ([::1]:35653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts5Es-0001C3-5Y for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 00:27:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts5Ed-000126-Ek for qemu-devel@nongnu.org; Mon, 07 Jan 2013 00:26:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ts5Ec-0001Zm-5y for qemu-devel@nongnu.org; Mon, 07 Jan 2013 00:26:55 -0500 Received: from mail-da0-f50.google.com ([209.85.210.50]:33630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts5Ec-0001Zg-0b for qemu-devel@nongnu.org; Mon, 07 Jan 2013 00:26:54 -0500 Received: by mail-da0-f50.google.com with SMTP id h15so8509473dan.23 for ; Sun, 06 Jan 2013 21:26:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=nAAkrBYzCS+138sI7tQrnDPU/KojYFbeVSqsmdWdA5o=; b=skg5t7L1a9vg4LaY+WNnc/VdH+3QFwTT2jainwaQB6Rh+aN2If2JuBTSoNfv6RMn0v pnvT+eSGIe7BDpmjCOpRUxVPVkFMAt7XYUaUjnFcwgAfXUhVe8etwnB0VO31FX01oqrp yErtlDQ3vIlFqzx3vJ4THg+FdZR0TqWonATgBRVKyUH7gFbz1UR0sQ88AmajSN6VQE6i NwdICu8ixgNd+S3q3qU4FIG9GSiE/kTBiE+m8qq7DOkupoQtpAzxyoZgk188HWJE0SDK ZDKszxgN7mnC5ya7okC9JGSvh6f/kJuD0zmgS1bevbY1mVSH0b4O8JXNwxNk7CB1tHmW UhJg== X-Received: by 10.68.235.1 with SMTP id ui1mr16355042pbc.138.1357536413330; Sun, 06 Jan 2013 21:26:53 -0800 (PST) Received: from localhost.localdomain ([202.108.130.194]) by mx.google.com with ESMTPS id x6sm38033607pav.29.2013.01.06.21.26.49 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 06 Jan 2013 21:26:52 -0800 (PST) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2013 13:26:20 +0800 Message-Id: <1357536383-7299-2-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1357536383-7299-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1357536383-7299-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.210.50 Cc: kwolf@redhat.com, Dong Xu Wang , stefanha@redhat.com Subject: [Qemu-devel] [PATCH V10 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. Signed-off-by: Dong Xu Wang --- 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. include/qemu/option.h | 1 + qemu-option.c | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index ba197cd..394170a 100644 --- a/include/qemu/option.h +++ b/include/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 { diff --git a/qemu-option.c b/qemu-option.c index f532b76..6f19fd3 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,