Add XkbNameMatchesPattern implementation from xkbfile The xkbcomp listing code matches a glob type pattern against installed xkb files. This adds a Xkbc implementation of the pattern matching code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
diff --git a/src/misc.c b/src/misc.c
index 744c588..e49921a 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -259,3 +259,38 @@ _XkbcKSCheckCase(KeySym ks)
return rtrn;
}
+
+#define UNMATCHABLE(c) ((c) == '(' || (c) == ')' || (c) == '/')
+
+Bool
+XkbcNameMatchesPattern(char *name, char *ptrn)
+{
+ while (ptrn[0] != '\0') {
+ if (name[0] == '\0') {
+ if (ptrn[0] == '*') {
+ ptrn++;
+ continue;
+ }
+ return False;
+ }
+
+ if (ptrn[0] == '?') {
+ if (UNMATCHABLE(name[0]))
+ return False;
+ }
+ else if (ptrn[0] == '*') {
+ if (!UNMATCHABLE(name[0]) &&
+ XkbcNameMatchesPattern(name + 1, ptrn))
+ return True;
+ return XkbcNameMatchesPattern(name, ptrn + 1);
+ }
+ else if (ptrn[0] != name[0])
+ return False;
+
+ name++;
+ ptrn++;
+ }
+
+ /* if we get here, the pattern is exhausted (-:just like me:-) */
+ return (name[0] == '\0');
+}
diff --git a/src/xkbcomp/listing.c b/src/xkbcomp/listing.c
index 2845032..e509b96 100644
--- a/src/xkbcomp/listing.c
+++ b/src/xkbcomp/listing.c
@@ -117,6 +117,7 @@ SOFTWARE.
# define FileName(file) file->d_name
#endif
+#include "xkbmisc.h"
#include "xkbpath.h"
#include "parseutils.h"
#include "misc.h"
@@ -306,7 +307,7 @@ AddDirectory(char *head, char *ptrn, char *rest, char *map)
filename = FileName(file);
if (!filename || filename[0] == '.')
continue;
- if (ptrn && (!XkbNameMatchesPattern(filename, ptrn)))
+ if (ptrn && (!XkbcNameMatchesPattern(filename, ptrn)))
continue;
tmp =
(char *) uAlloc((head ? strlen(head) : 0) + strlen(filename) + 2);
@@ -401,12 +402,12 @@ MapMatches(char *mapToConsider, char *ptrn)
int i;
if (ptrn != NULL)
- return XkbNameMatchesPattern(mapToConsider, ptrn);
+ return XkbcNameMatchesPattern(mapToConsider, ptrn);
if (nMapOnly < 1)
return True;
for (i = 0; i < nMapOnly; i++)
{
- if (XkbNameMatchesPattern(mapToConsider, mapOnly[i]))
+ if (XkbcNameMatchesPattern(mapToConsider, mapOnly[i]))
return True;
}
return False;
diff --git a/src/xkbmisc.h b/src/xkbmisc.h
index 16747a1..61e94e6 100644
--- a/src/xkbmisc.h
+++ b/src/xkbmisc.h
@@ -63,6 +63,9 @@ _XkbcKSCheckCase(KeySym sym);
#define XkbcKSIsLower(k) (_XkbcKSCheckCase(k) & _XkbKSLower)
#define XkbcKSIsUpper(k) (_XkbcKSCheckCase(k) & _XkbKSUpper)
+extern Bool
+XkbcNameMatchesPattern(char *name, char *ptrn);
+
/***====================================================================***/
extern char *