From patchwork Wed Oct 12 03:32:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 119143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 99DCFB6F71 for ; Wed, 12 Oct 2011 14:40:14 +1100 (EST) Received: from localhost ([::1]:48965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDpfu-0001uY-5u for incoming@patchwork.ozlabs.org; Tue, 11 Oct 2011 23:40:10 -0400 Received: from eggs.gnu.org ([140.186.70.92]:60517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDpfm-0001st-S0 for qemu-devel@nongnu.org; Tue, 11 Oct 2011 23:40:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDpfl-0005eT-DB for qemu-devel@nongnu.org; Tue, 11 Oct 2011 23:40:02 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:54325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDpfk-0005dt-NE for qemu-devel@nongnu.org; Tue, 11 Oct 2011 23:40:01 -0400 Received: from /spool/local by in.ibm.com with XMail ESMTP for from ; Wed, 12 Oct 2011 09:09:55 +0530 Received: from d28relay01.in.ibm.com ([9.184.220.58]) by in.ibm.com ([192.168.1.139]) with XMail ESMTP; Wed, 12 Oct 2011 09:09:51 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9C3dpCM3788860 for ; Wed, 12 Oct 2011 09:09:51 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9C3doiE014051 for ; Wed, 12 Oct 2011 09:09:50 +0530 Received: from FengShaoHe-PC.cn.ibm.com ([9.115.122.57]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p9C3dn5E012258; Wed, 12 Oct 2011 09:09:50 +0530 From: Wayne Xia To: qemu-devel@nongnu.org Date: Wed, 12 Oct 2011 11:32:41 +0800 Message-Id: <1318390361-583-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.6 x-cbid: 11101203-2674-0000-0000-000000D0286C X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.9 Cc: Wayne Xia Subject: [Qemu-devel] [PATCH v3] Sort the help info shown in monitor at runtime 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 This patch would try sort the command list in monitor at runtime. As a result, command help and help info would show a more friendly sorted command list. For eg: (qemu)help acl_add acl_policy acl_remove acl_reset acl_show balloon block_passwd ... the command list is sorted. v3: using qsort function to sort the command list. Signed-off-by: Wayne Xia Tested-by: Wenyi Gao --- monitor.c | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 31b212a..a172167 100644 --- a/monitor.c +++ b/monitor.c @@ -195,8 +195,8 @@ static inline int mon_print_count_get(const Monitor *mon) { return 0; } static QLIST_HEAD(mon_list, Monitor) mon_list; -static const mon_cmd_t mon_cmds[]; -static const mon_cmd_t info_cmds[]; +static mon_cmd_t mon_cmds[]; +static mon_cmd_t info_cmds[]; static const mon_cmd_t qmp_cmds[]; static const mon_cmd_t qmp_query_cmds[]; @@ -2726,13 +2726,14 @@ int monitor_get_fd(Monitor *mon, const char *fdname) return -1; } -static const mon_cmd_t mon_cmds[] = { +/* mon_cmds and info_cmds would be sorted at runtime */ +static mon_cmd_t mon_cmds[] = { #include "hmp-commands.h" { NULL, NULL, }, }; /* Please update hmp-commands.hx when adding or changing commands */ -static const mon_cmd_t info_cmds[] = { +static mon_cmd_t info_cmds[] = { { .name = "version", .args_type = "", @@ -5068,6 +5069,25 @@ static void monitor_event(void *opaque, int event) } } +static int +compare_mon_cmd(const void *a, const void *b) +{ + return strcmp(((const mon_cmd_t *)a)->name, + ((const mon_cmd_t *)b)->name); +} + +static void sortcmdlist(void) +{ + int array_num; + int elem_size = sizeof(mon_cmd_t); + + array_num = sizeof(mon_cmds)/elem_size-1; + qsort((void *)mon_cmds, array_num, elem_size, compare_mon_cmd); + + array_num = sizeof(info_cmds)/elem_size-1; + qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); +} + /* * Local variables: @@ -5110,6 +5130,8 @@ void monitor_init(CharDriverState *chr, int flags) QLIST_INSERT_HEAD(&mon_list, mon, entry); if (!default_mon || (flags & MONITOR_IS_DEFAULT)) default_mon = mon; + + sortcmdlist(); } static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)