From patchwork Thu Dec 6 06:47:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 204171 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 E83D02C01C2 for ; Thu, 6 Dec 2012 18:46:13 +1100 (EST) Received: from localhost ([::1]:33586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVHN-0001z9-Rv for incoming@patchwork.ozlabs.org; Thu, 06 Dec 2012 01:49:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFd-0006bY-J8 for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:48:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgVFb-0005Lo-W5 for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:48:05 -0500 Received: from mail-ie0-f179.google.com ([209.85.223.179]:45906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFb-0005Lh-Ma for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:48:03 -0500 Received: by mail-ie0-f179.google.com with SMTP id k14so9216325iea.38 for ; Wed, 05 Dec 2012 22:48:02 -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=nhEkU0fflY37Axg1FqbAfXN9SHaFh8iYfDmfR0pBfOg=; b=0zbY99P9RarTvusg5qnVaL0D3LhOJzR/a5l8GJMxcK+1VRKZAZlVIrUxrRi0Gt38Hb y1n/JoFTT8t3FPpr848HJf4SnITSkTbz5FT0rziGjH6ssnAUSV7nrBahSYsPj4UusT7U wL7eHUyZdrxaRdDdVFbj29S+FAkG3fJE1aBBmCfGQSpiQ96l1jQPjW8mZ1dkn5hZYyz6 n36gktRj8yn2lpKp8m7Q0wrHcEgQYZgFo9bmiZh5KX1qKw9WQosfV9yJQJawTyUaaqb5 Mh71rJOsWbZm3+EdOWbm0IaYMg9NM2kqTlP23qexjVxtWGMX/qKyGunntJewmMNVVJaY YGoQ== Received: by 10.50.179.100 with SMTP id df4mr4755769igc.60.1354776482646; Wed, 05 Dec 2012 22:48:02 -0800 (PST) Received: from localhost.localdomain ([202.108.130.153]) by mx.google.com with ESMTPS id kp4sm6494017igc.1.2012.12.05.22.48.00 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Dec 2012 22:48:01 -0800 (PST) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2012 14:47:24 +0800 Message-Id: <1354776447-12041-8-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1354776447-12041-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1354776447-12041-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.223.179 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V7 07/10] 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 --- qemu-option.c | 27 ++++++++++++++++++++------- qemu-option.h | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 94557cf..e0628da 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -862,15 +862,28 @@ 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); + for (desc = opts->list->desc; desc && desc->name; desc++) { + const char *value = desc->def_print_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); + } } - fprintf(stderr, "\n"); - return 0; + return 0; } static int opts_do_parse(QemuOpts *opts, const char *params, diff --git a/qemu-option.h b/qemu-option.h index 002dd07..ab02023 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_print_str; } QemuOptDesc; struct QemuOptsList {