Sort the help info shown in monitor at runtime
PATCH v3 1/1 Sort the help info shown in monitor at runtime
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)helpacl_addacl_policyacl_removeacl_resetacl_show
balloonblock_passwd
...
the command list is sorted.
v3: using qsort function to sort the command list.
--- monitor.c | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-)
monitor.c +26 -4
@@ -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)
Signature · 1 line
1.7.6
Quoted 80 lines · Wayne Xia
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)helpacl_addacl_policyacl_removeacl_resetacl_show
balloonblock_passwd
...
the command list is sorted.v3: using qsort function to sort the command list.
Signed-off-by Wayne Xia <[email protected]>--- monitor.c | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-)monitor.c +24
-4@@ -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:
monitor.c void monitor_init(CharDriverState *chr, int flags) · line 5137
Quoted 8 lines
monitor.c +2
-0@@ -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)
Work nice.
Wenyi Gao
Anthony Liguori
AppliedQuoted 14 lines · Wayne Xia
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)helpacl_addacl_policyacl_removeacl_resetacl_show
balloonblock_passwd
...
the command list is sorted.
Quoted 3 lines
v3: using qsort function to sort the command list.
Signed-off-by Wayne Xia<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 71 lines
--- monitor.c | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-)monitor.c +26
-4@@ -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)