qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v5 1/2] vl: Allow to define optional parameter w


From: Laurent Vivier
Subject: Re: [Qemu-devel] [PATCH v5 1/2] vl: Allow to define optional parameter with -arg[=params]
Date: Thu, 24 Sep 2015 18:14:35 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0

ping ?

On 14/09/2015 20:01, Laurent Vivier wrote:
> The goal is to be able to use '-help' alone, or with
> a sub-section, i.e. '-help=network,usb'.
> 
> Signed-off-by: Laurent Vivier <address@hidden>
> ---
>  vl.c | 31 ++++++++++++++++++++-----------
>  1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/vl.c b/vl.c
> index 1c8b28d..586ce55 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2703,19 +2703,28 @@ static const QEMUOption *lookup_opt(int argc, char 
> **argv,
>              error_report("invalid option");
>              exit(1);
>          }
> -        if (!strcmp(popt->name, r + 1))
> -            break;
> -        popt++;
> -    }
> -    if (popt->flags & HAS_ARG) {
> -        if (optind >= argc) {
> -            error_report("requires an argument");
> -            exit(1);
> +        /* manage arg type: -arg[=param] */
> +        optarg = strchr(r + 1, '=');
> +        if (optarg) {
> +             if (!strncmp(popt->name, r + 1, optarg - (r + 1))) {
> +                 optarg++; /* skip '=' */
> +                 break;
> +             }
> +        } else {
> +            if (!strcmp(popt->name, r + 1)) {
> +                if (popt->flags & HAS_ARG) {
> +                    if (optind >= argc) {
> +                        error_report("requires an argument");
> +                        exit(1);
> +                    }
> +                    optarg = argv[optind++];
> +                    loc_set_cmdline(argv, optind - 2, 2);
> +                }
> +                break;
> +            }
>          }
> -        optarg = argv[optind++];
> -        loc_set_cmdline(argv, optind - 2, 2);
> -    } else {
>          optarg = NULL;
> +        popt++;
>      }
>  
>      *poptarg = optarg;
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]