[PATCH xfree86] Signed-off-by: Oleh Nykyforchyn <oleh.nyk at gmail.com>

Peter Hutterer peter.hutterer at who-t.net
Mon May 16 23:14:03 PDT 2011


On Mon, May 16, 2011 at 09:15:51PM +0300, Oleh R. Nykyforchyn wrote:
> xfree86: allow negative conditions in "Match*" statements
> 
> Match statement syntax is extended to allow strings like:
> "aaa,!a,bbb,!b,ccc,!c"
> Match succeedes if an attribute matches aaa, bbb, or ccc, or
> does not match neither a, b, or c.
> 
> Signed-off-by: Oleh Nykyforchyn <oleh.nyk at gmail.com>

this needs an entry in the man page. I also wonder how long it will take us
until we need full regex support...

> ---
>  hw/xfree86/common/xf86Xinput.c |   28 ++++++++++++++++++++++------
>  1 files changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
> index e7e1ce1..9462bad 100644
> --- a/hw/xfree86/common/xf86Xinput.c
> +++ b/hw/xfree86/common/xf86Xinput.c
> @@ -495,13 +495,29 @@ MatchAttrToken(const char *attr, struct list *patterns,
>          char * const *cur;
>          Bool match = FALSE;
>  
> -        for (cur = group->values; *cur; cur++)
> -            if ((*compare)(attr, *cur) == 0) {
> -                match = TRUE;
> -                break;
> +        for (cur = group->values; *cur; cur++) {
> +            if (**cur == '!') {
> +            /*
> +             * A condition starting with '!' is NEGATIVE
> +             * If it is matched, the match is rejected
> +             */
> +                if ((*compare)(attr, *cur+1) == 0)

do all handlers handle NULL as pattern argument? if not, we need an extra
condition here.

> +                    return FALSE;

break instead?

> +                else
> +                    match = TRUE;
> +                }
> +            else {
> +                if ((*compare)(attr, *cur) == 0) {

else if ...  on one line please


> +                    match = TRUE;
> +                    break;
> +                    }
> +                }
>              }
> -        if (!match)
> -            return FALSE;
> +        /*
> +         * Either a positive condition or all
> +         * negative conditions succeeded
> +         */
> +        if (!match) return FALSE;

two lines please

I wonder if this flow could be made simpler with a few temporary variables.

Bool positive_match = TRUE;
Bool match_result = FALSE;

match_result = (*compare)(...)

return (positive_match) ?  match_result : !match_result;

something like that, anyway :)

Cheers,
  Peter

>      }
>  
>      /* All the entries in the list matched the attribute */
> -- 
> 1.7.4.4
> 
> 


More information about the xorg-devel mailing list