[PATCH 2/4] xserver: Add negation operator to Match entries

Oleh Nykyforchyn oleh.nyk at gmail.com
Sat Jun 4 22:51:15 PDT 2011


Add negation operator to Match entries

Signed-off-by: Oleh Nykyforchyn <oleh.nyk at gmail.com>
---
 hw/xfree86/common/xf86Xinput.c |   15 ++++++++++++---
 hw/xfree86/parser/InputClass.c |   10 ++++++++++
 hw/xfree86/parser/xf86Parser.h |    1 +
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 246108e..f86b021 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -516,10 +516,19 @@ MatchAttrToken(const char *attr, struct list *groups)
         Bool match = FALSE;
 
         list_for_each_entry(pattern, &group->patterns, entry) {
-            if (multi_match(attr, pattern)) {
-                match = TRUE;
-                break;
+            match = multi_match(attr, pattern);
+            if (match) {                  /* success? */
+                if (pattern->is_negated)  /* negated pattern matched */
+                    match = FALSE;        /* failure */
+                break;                    /* leave the entry */
+            }
+            else {
+                if (pattern->is_negated)  /* at least negated pattern not */
+                    match = TRUE;         /*   matched - partial success */
+                /* else non-negated pattern not matched */
+                /*  match = FALSE;         */
             }
+             /* no success yet, continue */
         }
         if (!match)
             return FALSE;
diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
index c896192..6093320 100644
--- a/hw/xfree86/parser/InputClass.c
+++ b/hw/xfree86/parser/InputClass.c
@@ -66,6 +66,8 @@ xf86ConfigSymTabRec InputClassTab[] =
 
 #define TOKEN_SEP '|'
 
+#define NEG_FLAG '!'
+
 
 static void
 add_to_group(xf86MatchGroup **group, const char *str,
@@ -89,6 +91,12 @@ add_to_group(xf86MatchGroup **group, const char *str,
         return;
     list_add(&pattern->entry, &(*group)->patterns);
 
+    /* Pattern starting with '!' should NOT be matched */
+    if (*str == NEG_FLAG) {
+        pattern->is_negated = TRUE;
+        str++;
+    }
+
     pattern->mode = pref_mode;
 
     if ((next = index(str, TOKEN_SEP)))
@@ -328,6 +336,8 @@ print_pattern(FILE * cf, const xf86MatchPattern *pattern)
     if (!pattern) return;
 
     fprintf(cf, "\"");
+    if (pattern->is_negated)
+        fprintf(cf, "%c", NEG_FLAG);
     if (pattern->mode == MATCH_IS_INVALID)
         fprintf(cf, "invalid:");
     if (pattern->str)
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 629fe5e..ea6008f 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -361,6 +361,7 @@ xf86MatchMode;
 typedef struct
 {
 	struct list entry;
+	Bool is_negated;
 	xf86MatchMode mode;
 	char *str;
 }
-- 
1.7.0.1



More information about the xorg-devel mailing list