[RESEND] [PATCH] weston: Add support for "--foo bar" style options

Eric Engestrom eric at engestrom.ch
Mon May 8 01:22:17 UTC 2017


On Friday, 2017-05-05 14:20:33 -0400, Lyude wrote:
> A little earlier today I ended up spending a lot of time trying to
> figure out why weston wasn't managing to launch over SSH and telling me
> that I did not have a --tty option specified, despite me passing the
> option strings ["--tty", "3"]. Turns out weston just doesn't support
> that.
> 
> So, add support for this kind of format in addition to "--foo=bar" to
> save others from making the same mistake I did.
> 
> Signed-off-by: Lyude <lyude at redhat.com>
> ---
> Resending since I realized I was no longer subscribed to this mailing list
> after the first time I sent this, whoops.
> 
>  shared/option-parser.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/shared/option-parser.c b/shared/option-parser.c
> index eee7546..82f2f31 100644
> --- a/shared/option-parser.c
> +++ b/shared/option-parser.c
> @@ -87,6 +87,28 @@ long_option(const struct weston_option *options, int count, char *arg)
>  }
>  
>  static int
> +long_option_with_arg(const struct weston_option *options, int count, char *arg, char *param)
> +{
> +	int k, len;
> +
> +	for (k = 0; k < count; k++) {
> +		if (!options[k].name)
> +			continue;
> +
> +		len = strlen(options[k].name);
> +		if (strncmp(options[k].name, arg + 2, len) != 0)
> +			continue;
> +
> +		if (options[k].type == WESTON_OPTION_BOOLEAN)
> +			continue;

Am I understanding this right, that you're skipping this here because it
is already be handled by long_option()?
I think this is actually unreachable, in which case an assert might
better document this, or you can add a small comment.

With either of these, the patch is
Reviewed-by: Eric Engestrom <eric at engestrom.ch>

Thanks!

> +
> +		return handle_option(options + k, param);
> +	}
> +
> +	return 0;
> +}
> +
> +static int
>  short_option(const struct weston_option *options, int count, char *arg)
>  {
>  	int k;
> @@ -148,6 +170,12 @@ parse_options(const struct weston_option *options,
>  				if (long_option(options, count, argv[i]))
>  					continue;
>  
> +				/* ...also handle --foo bar */
> +				if (i + 1 < *argc &&
> +				    long_option_with_arg(options, count, argv[i], argv[i+1])) {
> +					i++;
> +					continue;
> +				}
>  			} else {
>  				/* Short option, e.g -f or -f42 */
>  				if (short_option(options, count, argv[i]))
> -- 
> 2.9.3
> 


More information about the wayland-devel mailing list