On Mon, Mar 07, 2011 at 01:41:39PM -0800, Jason Gerecke wrote:
> Do some additional checking to ensure the user provides valid values
> for boolean parameters. Also, provide a helpful error if the user
> goes astray.
> 
> Signed-off-by: Jason Gerecke <[email protected]>
> ---
>  tools/xsetwacom.c |   13 +++++++++++--
>  1 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
> index fa98e3e..7544872 100644
> --- a/tools/xsetwacom.c
> +++ b/tools/xsetwacom.c
> @@ -1424,10 +1424,14 @@ static int convert_value_from_user(param_t
> *param, char *value)
>  {
>         int val;
> 
> -       if ((param->prop_flags & PROP_FLAG_BOOLEAN) && strcmp(value,
> "off") == 0)
> +       if (param->prop_flags & PROP_FLAG_BOOLEAN) {

fwiw, coding style in the driver is to have { on the next line.

> +               if (strcmp(value, "off") == 0)
>                         val = 0;
> -       else if ((param->prop_flags & PROP_FLAG_BOOLEAN) &&
> strcmp(value, "on") == 0)
> +               else if (strcmp(value, "on") == 0)
>                         val = 1;
> +               else
> +                       val = -1;
> +       }
>         else
>                 val = atoi(value);
> 
> @@ -1508,6 +1512,11 @@ static void set(Display *dpy, int argc, char **argv)
>         for (i = 0; i < nvals; i++)
>         {
>                 val = convert_value_from_user(param, values[i]);
> +               if (param->prop_flags & PROP_FLAG_BOOLEAN && (val != 0
> && val != 1)) {
> +                       fprintf(stderr, "Property '%s' is a boolean.
> Set it with 'on' or 'off'.\n",
> +                               param->name);
> +                       goto out;
> +               }

I think instead of having special-casing here, it'd be better to change
convert_to_user to a signature of 
Bool convert_value_from_user(param_t*, char*, int *return_value) and let
it return False if conversion failed.
that way any special-casing is confined to the actual conversion.

Cheers,
  Peter

> 
>                 switch(param->prop_format)
>                 {
> -- 
> 1.7.1




------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to