From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7zlK-0000U0-NK for qemu-devel@nongnu.org; Mon, 27 Jan 2014 22:55:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7zlE-00065L-Ju for qemu-devel@nongnu.org; Mon, 27 Jan 2014 22:54:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56365) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7zlE-000652-Cp for qemu-devel@nongnu.org; Mon, 27 Jan 2014 22:54:52 -0500 From: Amos Kong Date: Tue, 28 Jan 2014 11:53:48 +0800 Message-Id: <1390881230-14033-4-git-send-email-akong@redhat.com> In-Reply-To: <1390881230-14033-1-git-send-email-akong@redhat.com> References: <1390881230-14033-1-git-send-email-akong@redhat.com> Subject: [Qemu-devel] [PATCH 3/5] query-command-line-options: query all the options in qemu-options.hx List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: jyang@redhat.com, laine@redhat.com, libvir-list@redhat.com, armbru@redhat.com, rjones@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com, lcapitulino@redhat.com vm_config_groups[] contain the options which have parameter, but some legcy options haven't been added to vm_config_groups[]. All the options can be found in qemu-options.hx, this patch used two new marcos to generate two tables, we can check if the option name is valid and if the option has arguments. This patch also try to visit all the options in option_names[], then we won't lost the legacy options that weren't added to vm_config_groups[]. The options have no arguments will also be returned (eg: -enable-fips) Signed-off-by: Amos Kong --- util/qemu-config.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/util/qemu-config.c b/util/qemu-config.c index d624d92..de233d8 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -78,6 +78,17 @@ static CommandLineParameterInfoList *get_param_infolist(const QemuOptDesc *desc) return param_list; } +static int get_group_index(const char *name) +{ + int i; + + for (i = 0; vm_config_groups[i] != NULL; i++) { + if (!strcmp(vm_config_groups[i]->name, name)) { + return i; + } + } + return -1; +} /* remove repeated entry from the info list */ static void cleanup_infolist(CommandLineParameterInfoList *head) { @@ -139,16 +150,34 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option, CommandLineOptionInfo *info; int i; - for (i = 0; vm_config_groups[i] != NULL; i++) { - if (!has_option || !strcmp(option, vm_config_groups[i]->name)) { + char const *option_names[] = { +#define QEMU_OPTIONS_GENERATE_NAME +#include "qemu-options-wrapper.h" + }; + + char const *option_hasargs[] = { +#define QEMU_OPTIONS_GENERATE_HASARG +#include "qemu-options-wrapper.h" + }; + + for (i = 0; i < sizeof(option_names) / sizeof(char *); i++) { + if (!has_option || !strcmp(option, option_names[i])) { info = g_malloc0(sizeof(*info)); - info->option = g_strdup(vm_config_groups[i]->name); - if (!strcmp("drive", vm_config_groups[i]->name)) { + info->option = g_strdup(option_names[i]); + + int idx = get_group_index(option_names[i]); + + if (!strcmp("HAS_ARG", option_hasargs[i])) { + info->has_parameters = true; + } + + if (!strcmp("drive", option_names[i])) { info->parameters = get_drive_infolist(); - } else { + } else if (idx >= 0) { info->parameters = - get_param_infolist(vm_config_groups[i]->desc); + get_param_infolist(vm_config_groups[idx]->desc); } + entry = g_malloc0(sizeof(*entry)); entry->value = info; entry->next = conf_list; -- 1.8.4.2