Allow external atom databases

Allow people to plug in an external atom database (e.g. the X server's),
so we don't have to migrate our own atoms over later.  We are a bit
over-keen on atoms at the moment, so it does pollute the atom database a
bit though.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
master
Daniel Stone 2010-06-21 14:22:26 +01:00
parent 15b0db5492
commit 2c4a045aca
6 changed files with 40 additions and 21 deletions

View File

@ -191,8 +191,11 @@ typedef struct _XkbcDesc {
_XFUNCPROTOBEGIN
typedef uint32_t (*InternAtomFuncPtr)(const char *val);
typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
extern void
XkbcInitAtoms(void);
XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
extern XkbcDescPtr
XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);

View File

@ -81,21 +81,31 @@ SOFTWARE.
typedef struct _Node {
struct _Node *left, *right;
Atom a;
CARD32 a;
unsigned int fingerPrint;
char *string;
} NodeRec, *NodePtr;
#define BAD_RESOURCE 0xe0000000
static Atom lastAtom = None;
static CARD32 lastAtom = None;
static NodePtr atomRoot = NULL;
static unsigned long tableLength;
static NodePtr *nodeTable = NULL;
InternAtomFuncPtr do_intern_atom = NULL;
GetAtomValueFuncPtr do_get_atom_value = NULL;
void
XkbcInitAtoms(void)
XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value)
{
if (intern && get_atom_value) {
if (do_intern_atom && do_get_atom_value)
return;
do_intern_atom = intern;
do_get_atom_value = get_atom_value;
return;
}
if (nodeTable)
return;
@ -104,11 +114,14 @@ XkbcInitAtoms(void)
nodeTable[None] = NULL;
}
static char *
_XkbcAtomGetString(Atom atom)
static const char *
_XkbcAtomGetString(CARD32 atom)
{
NodePtr node;
if (do_get_atom_value)
return do_get_atom_value(atom);
if ((atom == None) || (atom > lastAtom))
return NULL;
if (!(node = nodeTable[atom]))
@ -117,16 +130,17 @@ _XkbcAtomGetString(Atom atom)
}
char *
XkbcAtomGetString(Atom atom)
XkbcAtomGetString(CARD32 atom)
{
char *ret = _XkbcAtomGetString(atom);
const char *ret = _XkbcAtomGetString(atom);
return ret ? strdup(ret) : NULL;
}
char *
XkbcAtomText(Atom atom)
XkbcAtomText(CARD32 atom)
{
char *tmp, *ret;
const char *tmp;
char *ret;
tmp = _XkbcAtomGetString(atom);
if (!tmp)
@ -140,8 +154,8 @@ XkbcAtomText(Atom atom)
return ret;
}
static Atom
_XkbcMakeAtom(char *string, unsigned len, Bool makeit)
static CARD32
_XkbcMakeAtom(const char *string, unsigned len, Bool makeit)
{
NodePtr *np;
unsigned i;
@ -214,10 +228,12 @@ _XkbcMakeAtom(char *string, unsigned len, Bool makeit)
return None;
}
Atom
XkbcInternAtom(char *name, Bool onlyIfExists)
CARD32
XkbcInternAtom(const char *name, Bool onlyIfExists)
{
if (!name)
return None;
if (do_intern_atom)
return do_intern_atom(name);
return _XkbcMakeAtom(name, strlen(name), !onlyIfExists);
}

View File

@ -63,15 +63,15 @@ XkbcNameMatchesPattern(char *name, char *ptrn);
/***====================================================================***/
extern char *
XkbcAtomGetString(Atom atom);
XkbcAtomGetString(uint32_t atom);
extern Atom
XkbcInternAtom(char *name, Bool onlyIfExists);
extern uint32_t
XkbcInternAtom(const char *name, Bool onlyIfExists);
/***====================================================================***/
extern char *
XkbcAtomText(Atom atm);
XkbcAtomText(uint32_t atm);
extern char *
XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx);

View File

@ -60,7 +60,7 @@ int main(int argc, char *argv[])
}
uSetErrorFile(NULL);
XkbcInitAtoms();
XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromFile(file, name);
fclose(file);

View File

@ -54,7 +54,7 @@ int main(int argc, char *argv[])
ktcsg.geometry = argv[5];
uSetErrorFile(NULL);
XkbcInitAtoms();
XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromComponents(&ktcsg);

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[])
rmlvo.options = argv[5];
uSetErrorFile(NULL);
XkbcInitAtoms();
XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromRules(&rmlvo);