Commit 8a5c1d3d authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Atoms.c: some code cleanup

add else clauses, improve debugging, add comments
parent 2594ca99
...@@ -610,17 +610,14 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length) ...@@ -610,17 +610,14 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length)
* really asking to X-server and caching them. * really asking to X-server and caching them.
* FIXME: I don't really know if is better to allocate * FIXME: I don't really know if is better to allocate
* an automatic variable like ret_value and write it, instead of make all * an automatic variable like ret_value and write it, instead of make all
* these return!, perhaps this way the code is a little bit easyer to read. * these return!, perhaps this way the code is a little bit easier to read.
* I think this and the 2 .*Find.* are the only functions to look for performances. * I think this and the 2 .*Find.* are the only functions to look for performances.
*/ */
XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
{ {
AtomMap *current;
/* /*
* Surely MakeAtom is faster than * Surely MakeAtom is faster than our nxagentFindAtomByName.
* our nxagentFindAtomByName.
*/ */
Atom local = MakeAtom(string, length, Makeit); Atom local = MakeAtom(string, length, Makeit);
...@@ -635,6 +632,8 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -635,6 +632,8 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return local; return local;
} }
AtomMap *current;
if ((current = nxagentFindAtomByLocalValue(local))) if ((current = nxagentFindAtomByLocalValue(local)))
{ {
/* /*
...@@ -643,8 +642,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -643,8 +642,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return current->remote; return current->remote;
} }
else if ((current = nxagentFindAtomByName(string, length)))
if ((current = nxagentFindAtomByName(string, length)))
{ {
/* /*
* Found cached by name. * Found cached by name.
...@@ -656,26 +654,29 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -656,26 +654,29 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return current->remote; return current->remote;
} }
else
/*
* We really have to ask the Xserver for it.
*/
{ {
/*
* We really have to ask the Xserver for it.
*/
/* FIXME: why is Makeit inverted here? */
XlibAtom remote = XInternAtom(nxagentDisplay, string, !Makeit); XlibAtom remote = XInternAtom(nxagentDisplay, string, !Makeit);
if (remote == None) if (remote == None)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentMakeAtom: WARNING XInternAtom failed.\n"); fprintf(stderr, "nxagentMakeAtom: WARNING XInternAtom(.., %s, ..) failed.\n", string);
#endif #endif
return None; return None;
} }
else
{
nxagentWriteAtom(local, remote, string, True);
nxagentWriteAtom(local, remote, string, True); return remote;
}
return remote;
} }
} }
...@@ -693,6 +694,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local) ...@@ -693,6 +694,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
return None; return None;
} }
/* no mapping required for built-in atoms */
if (local <= XA_LAST_PREDEFINED) if (local <= XA_LAST_PREDEFINED)
{ {
#ifdef DEBUG #ifdef DEBUG
...@@ -705,32 +707,39 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local) ...@@ -705,32 +707,39 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
if (current) if (current)
{ {
#ifdef TEST #ifdef DEBUG
fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote); if (current->string)
fprintf(stderr, "%s: local [%d] -> remote [%d (%s)]\n", __func__, local, current->remote, current->string);
else
fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote);
#endif #endif
return current->remote; return current->remote;
} }
else
{
const char *string = NameForAtom(local);
const char *string = NameForAtom(local); /* FIXME: why False? */
XlibAtom remote = XInternAtom(nxagentDisplay, string, False);
XlibAtom remote = XInternAtom(nxagentDisplay, string, False);
if (remote == None) if (remote == None)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentLocalToRemoteAtom: WARNING XInternAtom failed.\n"); fprintf(stderr, "nxagentLocalToRemoteAtom: WARNING XInternAtom failed.\n");
#endif #endif
return None; return None;
} }
nxagentWriteAtom(local, remote, string, True); nxagentWriteAtom(local, remote, string, True);
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: local [%d] -> remote [%d (%s)]\n", __func__, local, remote, string); fprintf(stderr, "%s: local [%d (%s)] -> remote [%d]\n", __func__, local, string, remote);
#endif #endif
return remote; return remote;
}
} }
Atom nxagentRemoteToLocalAtom(XlibAtom remote) Atom nxagentRemoteToLocalAtom(XlibAtom remote)
...@@ -743,6 +752,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote) ...@@ -743,6 +752,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
return None; return None;
} }
/* no mapping required for built-in atoms */
if (remote <= XA_LAST_PREDEFINED) if (remote <= XA_LAST_PREDEFINED)
{ {
#ifdef DEBUG #ifdef DEBUG
...@@ -774,41 +784,47 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote) ...@@ -774,41 +784,47 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: remote [%d] -> local [%d]\n", __func__, remote, current->local); if (current->string)
fprintf(stderr, "%s: remote [%d] -> local [%d (%s)]\n", __func__, remote, current->local, current->string);
else
fprintf(stderr, "%s: remote [%d] -> local [%d]\n", __func__, remote, current->local);
#endif #endif
return current->local; return current->local;
} }
else
char *string = XGetAtomName(nxagentDisplay, remote);
if (string)
{ {
Atom local = MakeAtom(string, strlen(string), True); char *string = XGetAtomName(nxagentDisplay, remote);
if (!ValidAtom(local)) if (string)
{ {
#ifdef WARNING Atom local = MakeAtom(string, strlen(string), True);
fprintf(stderr, "%s: WARNING MakeAtom failed.\n", __func__);
if (!ValidAtom(local))
{
#ifdef WARNING
fprintf(stderr, "%s: WARNING MakeAtom failed.\n", __func__);
#endif
local = None;
}
nxagentWriteAtom(local, remote, string, True);
#ifdef TEST
fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local);
#endif #endif
SAFE_XFree(string);
local = None; return local;
} }
nxagentWriteAtom(local, remote, string, True); #ifdef WARNING
fprintf(stderr, "%s: WARNING failed to get name from remote atom.\n", __func__);
#ifdef TEST
fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local);
#endif #endif
SAFE_XFree(string);
return local; return None;
} }
#ifdef WARNING
fprintf(stderr, "%s: WARNING failed to get name from remote atom.\n", __func__);
#endif
return None;
} }
#ifdef DEBUG #ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment