rules: fix parsing of multiple options
authorRan Benita <ran234@gmail.com>
Wed, 11 Jul 2012 11:08:28 +0000 (14:08 +0300)
committerDaniel Stone <daniel@fooishbar.org>
Thu, 12 Jul 2012 08:42:08 +0000 (09:42 +0100)
This was broken by commit 18d331b86b4942ba54fe087ca07e47c9383d768b
(where only the first option out of a comma-separated string was
matched). Do it correctly this time and add a test.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/rules.c
test/data/rules/multiple-options [new file with mode: 0644]
test/rules-file.c

index 6c7f4fd..5cd4e31 100644 (file)
@@ -680,19 +680,16 @@ match_group_member(struct rules *rules, const char *group_name,
 static bool
 match_one_of(const char *haystack, const char *needle, char sep)
 {
-    const char *s = strstr(haystack, needle);
+    const char *s = haystack;
+    const size_t len = strlen(needle);
 
-    if (s == NULL)
-        return false;
-
-    if (s != haystack && *s != sep)
-        return false;
+    do {
+        if (strncmp(s, needle, len) == 0 && (s[len] == '\0' || s[len] == sep))
+            return true;
+        s = strchr(s, sep);
+    } while (s++);
 
-    s += strlen(needle);
-    if (*s != '\0' && *s != sep)
-        return false;
-
-    return true;
+    return false;
 }
 
 static int
diff --git a/test/data/rules/multiple-options b/test/data/rules/multiple-options
new file mode 100644 (file)
index 0000000..afbdc9f
--- /dev/null
@@ -0,0 +1,27 @@
+! model         = keycodes
+  my_model      = my_keycodes
+  *             = default_keycodes
+
+! layout        variant    = symbols
+  my_layout     my_variant = my_symbols+extra_variant
+
+! layout        = symbols
+  my_layout     = my_symbols
+  *             = default_symbols
+
+! model         = types
+  my_model      = my_types
+  *             = default_types
+
+! model         = compat
+  my_model      = my_compat
+  *             = default_compat
+
+! option        = compat
+  option111     = +substring
+  option1       = +some:compat
+  option11      = +group(bla)
+
+! option        = symbols
+  option3       = +compose(foo)+keypad(bar)
+  colon:opt     = +altwin(menu)
index 8e301b2..6d4c508 100644 (file)
@@ -176,6 +176,18 @@ main(void)
     };
     assert(test_rules(ctx, &test6));
 
+    struct test_data test7 = {
+        .rules = "multiple-options",
+
+        .model = "my_model", .layout = "my_layout", .variant = "my_variant",
+        .options = "option3,option1,colon:opt,option11",
+
+        .keycodes = "my_keycodes", .types = "my_types",
+        .compat = "my_compat+some:compat+group(bla)",
+        .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
+    };
+    assert(test_rules(ctx, &test7));
+
     xkb_context_unref(ctx);
     return 0;
 }