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.
master
Dan Nicholson 2009-04-12 12:30:12 -07:00
parent fa183ce354
commit 9520ea0eb3
3 changed files with 42 additions and 3 deletions

View File

@ -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');
}

View File

@ -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;

View File

@ -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 *