From: Dan Nicholson Date: Sun, 12 Apr 2009 19:30:12 +0000 (-0700) Subject: Add XkbNameMatchesPattern implementation from xkbfile X-Git-Tag: xkbcommon-0.2.0~902 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9520ea0eb3794228fc78844feb1f28f23b076432;p=platform%2Fupstream%2Flibxkbcommon.git 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. --- 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 *