diff mbox

[v2,1/6] qemu-option: Introduce has_help_option()

Message ID 1392908243-8835-2-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf Feb. 20, 2014, 2:57 p.m. UTC
This new function checks if any help option ('help' or '?') occurs
anywhere in an option string, so that things like 'cluster_size=4k,help'
are recognised.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/qemu/option.h |  1 +
 util/qemu-option.c    | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

Comments

Eric Blake Feb. 20, 2014, 3:28 p.m. UTC | #1
On 02/20/2014 07:57 AM, Kevin Wolf wrote:
> This new function checks if any help option ('help' or '?') occurs
> anywhere in an option string, so that things like 'cluster_size=4k,help'
> are recognised.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c    | 24 ++++++++++++++++++++++++
>  2 files changed, 25 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>
Jeff Cody Feb. 20, 2014, 8:21 p.m. UTC | #2
On Thu, Feb 20, 2014 at 03:57:18PM +0100, Kevin Wolf wrote:
> This new function checks if any help option ('help' or '?') occurs
> anywhere in an option string, so that things like 'cluster_size=4k,help'
> are recognised.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Reviewed-by: Jeff Cody <jcody@redhat.com>

> ---
>  include/qemu/option.h |  1 +
>  util/qemu-option.c    | 24 ++++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index 3ea871a..8d44167 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -79,6 +79,7 @@ void parse_option_size(const char *name, const char *value,
>  void free_option_parameters(QEMUOptionParameter *list);
>  void print_option_parameters(QEMUOptionParameter *list);
>  void print_option_help(QEMUOptionParameter *list);
> +bool has_help_option(const char *param);
>  
>  /* ------------------------------------------------------------------ */
>  
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 668e5d9..ce1eba8 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -450,6 +450,30 @@ fail:
>      return NULL;
>  }
>  
> +bool has_help_option(const char *param)
> +{
> +    size_t buflen = strlen(param) + 1;
> +    char *buf = g_malloc0(buflen);
> +    const char *p = param;
> +    bool result = false;
> +
> +    while (*p) {
> +        p = get_opt_value(buf, buflen, p);
> +        if (*p) {
> +            p++;
> +        }
> +
> +        if (is_help_option(buf)) {
> +            result = true;
> +            goto out;
> +        }
> +    }
> +
> +out:
> +    free(buf);
> +    return result;
> +}
> +
>  /*
>   * Prints all options of a list that have a value to stdout
>   */
> -- 
> 1.8.1.4
> 
>
diff mbox

Patch

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3ea871a..8d44167 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -79,6 +79,7 @@  void parse_option_size(const char *name, const char *value,
 void free_option_parameters(QEMUOptionParameter *list);
 void print_option_parameters(QEMUOptionParameter *list);
 void print_option_help(QEMUOptionParameter *list);
+bool has_help_option(const char *param);
 
 /* ------------------------------------------------------------------ */
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 668e5d9..ce1eba8 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -450,6 +450,30 @@  fail:
     return NULL;
 }
 
+bool has_help_option(const char *param)
+{
+    size_t buflen = strlen(param) + 1;
+    char *buf = g_malloc0(buflen);
+    const char *p = param;
+    bool result = false;
+
+    while (*p) {
+        p = get_opt_value(buf, buflen, p);
+        if (*p) {
+            p++;
+        }
+
+        if (is_help_option(buf)) {
+            result = true;
+            goto out;
+        }
+    }
+
+out:
+    free(buf);
+    return result;
+}
+
 /*
  * Prints all options of a list that have a value to stdout
  */