From patchwork Thu Nov 1 09:12:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 196106 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 7478E2C00BA for ; Thu, 1 Nov 2012 20:38:53 +1100 (EST) Received: from localhost ([::1]:50191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTqqC-000087-TF for incoming@patchwork.ozlabs.org; Thu, 01 Nov 2012 05:13:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTqpk-0007Ya-Ub for qemu-devel@nongnu.org; Thu, 01 Nov 2012 05:13:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTqpj-0000Zr-D8 for qemu-devel@nongnu.org; Thu, 01 Nov 2012 05:13:04 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:46990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTqpi-0000Uq-Rw for qemu-devel@nongnu.org; Thu, 01 Nov 2012 05:13:03 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so1555663pbb.4 for ; Thu, 01 Nov 2012 02:13:02 -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:x-mailer:in-reply-to :references; bh=z4/CVmSWsI0H9o8Irfl91x+zVwBs7e6mrrYU03LP6yA=; b=prMHCnBGL65RbSp3RHV+CfoiEy500I8dVcea+yyImao/lc7AW39IUsggo4zs8n7u0K oBfKtpdiO7v1hTHqQhnegw7qfYw5tte0YayJpSV3sq680X5KnRjsso+AMvR0jhKqSzG9 dYXNwUo3akn50Vd8IW7+JZJehL9skjzC8VQUhRH0z0PxKG+H89/+4KE35UWPJJh6a8Bs Py1FTvtZkhN/AOk3GyzAzR0fgGtoqodxqdeim2riTM5fTDW5/2L8PvFKuCR82wtK1ieT nUzqjmiTjXT+g+3oO42eerUqyFtpGMofG+E/f7yz+PRXxVyAZXL9JvHCoUE2m9MLgf6Y 3E1w== Received: by 10.69.1.73 with SMTP id be9mr39986488pbd.116.1351761182592; Thu, 01 Nov 2012 02:13:02 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id o11sm3751238pby.8.2012.11.01.02.13.00 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Nov 2012 02:13:01 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 1 Nov 2012 17:12:27 +0800 Message-Id: <1351761150-20705-8-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1351761150-20705-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1351761150-20705-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 V5 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 --- v4->v5: 1) Rewrite qemu_opts_print. 2) Do not use def_value, but def_print_str. 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 {