From patchwork Wed Oct 14 08:39:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 35931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 94476B7B9D for ; Wed, 14 Oct 2009 19:47:33 +1100 (EST) Received: from localhost ([127.0.0.1]:37714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxzW6-0001KS-HL for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 04:47:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxzOY-0006ew-0Y for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxzOT-0006cu-E7 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:41 -0400 Received: from [199.232.76.173] (port=40704 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxzOT-0006cr-8T for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11523) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxzOS-00048v-Oi for qemu-devel@nongnu.org; Wed, 14 Oct 2009 04:39:37 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9E8dX5e006349 for ; Wed, 14 Oct 2009 04:39:33 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-6.ams2.redhat.com [10.36.5.6]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9E8dVw8005423; Wed, 14 Oct 2009 04:39:31 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id B4EF1700E5; Wed, 14 Oct 2009 10:39:28 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 14 Oct 2009 10:39:26 +0200 Message-Id: <1255509568-10635-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1255509568-10635-1-git-send-email-kraxel@redhat.com> References: <1255509568-10635-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 2/4] QemuOpts: dump config. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a function to write the QemuOpts configuration to a git-style config file. Signed-off-by: Gerd Hoffmann --- qemu-config.c | 39 +++++++++++++++++++++++++++++++++++++++ qemu-config.h | 2 ++ 2 files changed, 41 insertions(+), 0 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index f02dd42..fa236e9 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -238,3 +238,42 @@ int qemu_set_option(const char *str) return 0; } +struct ConfigWriteData { + QemuOptsList *list; + FILE *fp; +}; + +static int config_write_opt(const char *name, const char *value, void *opaque) +{ + struct ConfigWriteData *data = opaque; + + fprintf(data->fp, " %s = \"%s\"\n", name, value); + return 0; +} + +static int config_write_opts(QemuOpts *opts, void *opaque) +{ + struct ConfigWriteData *data = opaque; + const char *id = qemu_opts_id(opts); + + if (id) { + fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id); + } else { + fprintf(data->fp, "[%s]\n", data->list->name); + } + qemu_opt_foreach(opts, config_write_opt, data, 0); + fprintf(data->fp, "\n"); + return 0; +} + +void qemu_config_write(FILE *fp) +{ + struct ConfigWriteData data = { .fp = fp }; + int i; + + fprintf(fp, "# qemu config file\n\n"); + for (i = 0; lists[i] != NULL; i++) { + data.list = lists[i]; + qemu_opts_foreach(data.list, config_write_opts, &data, 0); + } +} diff --git a/qemu-config.h b/qemu-config.h index cdad5ac..33fce7e 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -9,4 +9,6 @@ extern QemuOptsList qemu_rtc_opts; int qemu_set_option(const char *str); +void qemu_config_write(FILE *fp); + #endif /* QEMU_CONFIG_H */