qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Wayne Xia <xiawenc@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3] Sort the help info shown in monitor at runtime
Date: Tue, 01 Nov 2011 17:21:13 -0500	[thread overview]
Message-ID: <4EB070D9.6050907@codemonkey.ws> (raw)
In-Reply-To: <1318390361-583-1-git-send-email-xiawenc@linux.vnet.ibm.com>

On 10/11/2011 10:32 PM, Wayne Xia wrote:
> 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<xiawenc@linux.vnet.ibm.com>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
>   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)

      parent reply	other threads:[~2011-11-01 22:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12  3:32 [Qemu-devel] [PATCH v3] Sort the help info shown in monitor at runtime Wayne Xia
2011-10-12  6:39 ` Wenyi Gao
2011-11-01 22:21 ` Anthony Liguori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EB070D9.6050907@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    --cc=xiawenc@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).