diff mbox

[v23,07/32] add qemu_opts_print_help to replace print_option_help

Message ID 1395396763-26081-8-git-send-email-cyliu@suse.com
State New
Headers show

Commit Message

Chunyan Liu March 21, 2014, 10:12 a.m. UTC
print_option_help takes QEMUOptionParameter as parameter, add
qemu_opts_print_help to take QemuOptsList as parameter for later
replace work.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
 include/qemu/option.h |  1 +
 util/qemu-option.c    | 11 +++++++++++
 2 files changed, 12 insertions(+)

Comments

Leandro Dorileo March 25, 2014, 7:07 p.m. UTC | #1
On Fri, Mar 21, 2014 at 06:12:18PM +0800, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>


Reviewed-by: Leandro Dorileo <l@dorileo.org>


> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c    | 11 +++++++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 6653e43..fbf5dc2 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -166,5 +166,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
>  void qemu_opts_print(QemuOpts *opts);
>  int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
>                        int abort_on_failure);
> +void qemu_opts_print_help(QemuOptsList *list);
>  
>  #endif
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 02a7602..315a7bb 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -553,6 +553,17 @@ void print_option_help(QEMUOptionParameter *list)
>      }
>  }
>  
> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> +    int i;
> +
> +    printf("Supported options:\n");
> +    for (i = 0; list && list->desc[i].name; i++) {
> +        printf("%-16s %s\n", list->desc[i].name,
> +               list->desc[i].help ?
> +               list->desc[i].help : "No description available");
> +    }
> +}
>  /* ------------------------------------------------------------------ */
>  
>  static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
> -- 
> 1.7.12.4
> 
>
Eric Blake March 25, 2014, 8:43 p.m. UTC | #2
On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> print_option_help takes QEMUOptionParameter as parameter, add
> qemu_opts_print_help to take QemuOptsList as parameter for later
> replace work.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c    | 11 +++++++++++
>  2 files changed, 12 insertions(+)
> 

> +void qemu_opts_print_help(QemuOptsList *list)
> +{
> +    int i;
> +
> +    printf("Supported options:\n");
> +    for (i = 0; list && list->desc[i].name; i++) {

Similar to print_option_help(), this prints "Supported options:\n" on a
line by itself if list is NULL.  But do any of the drivers/protocols
actually lack options?  Is it worth guaranteeing that this is only used
on non-empty lists?  What would happen if you wrote this as:

assert(list);
for (i = 0; list->desc[i].name; i++) { ...

or even

QemuOptDesc *desc;
assert(list);
desc = list->desc;
while (desc->name) {
    ...
    desc++;
}
Chunyan Liu March 26, 2014, 2:58 a.m. UTC | #3
2014-03-26 4:43 GMT+08:00 Eric Blake <eblake@redhat.com>:

> On 03/21/2014 04:12 AM, Chunyan Liu wrote:
> > print_option_help takes QEMUOptionParameter as parameter, add
> > qemu_opts_print_help to take QemuOptsList as parameter for later
> > replace work.
> >
> > Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> > Signed-off-by: Chunyan Liu <cyliu@suse.com>
> > ---
> >  include/qemu/option.h |  1 +
> >  util/qemu-option.c    | 11 +++++++++++
> >  2 files changed, 12 insertions(+)
> >
>
> > +void qemu_opts_print_help(QemuOptsList *list)
> > +{
> > +    int i;
> > +
> > +    printf("Supported options:\n");
> > +    for (i = 0; list && list->desc[i].name; i++) {
>
> Similar to print_option_help(), this prints "Supported options:\n" on a
> line by itself if list is NULL.  But do any of the drivers/protocols
> actually lack options?


Yes, vvfat has no .create_options. Will update.


>  Is it worth guaranteeing that this is only used
> on non-empty lists?  What would happen if you wrote this as:
>
> assert(list);
> for (i = 0; list->desc[i].name; i++) { ...
>
> or even
>
> QemuOptDesc *desc;
> assert(list);
> desc = list->desc;
> while (desc->name) {
>     ...
>     desc++;
> }
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>
diff mbox

Patch

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 6653e43..fbf5dc2 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -166,5 +166,6 @@  typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
 void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
                       int abort_on_failure);
+void qemu_opts_print_help(QemuOptsList *list);
 
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 02a7602..315a7bb 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -553,6 +553,17 @@  void print_option_help(QEMUOptionParameter *list)
     }
 }
 
+void qemu_opts_print_help(QemuOptsList *list)
+{
+    int i;
+
+    printf("Supported options:\n");
+    for (i = 0; list && list->desc[i].name; i++) {
+        printf("%-16s %s\n", list->desc[i].name,
+               list->desc[i].help ?
+               list->desc[i].help : "No description available");
+    }
+}
 /* ------------------------------------------------------------------ */
 
 static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)