Commit 1f71a75f authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Atoms.c: code cleanup

no functional change
parent a61102b6
...@@ -179,8 +179,6 @@ void nxagentWMDetect() ...@@ -179,8 +179,6 @@ void nxagentWMDetect()
int nxagentInitAtoms(WindowPtr pWin) int nxagentInitAtoms(WindowPtr pWin)
{ {
Atom atom;
/* /*
* Value of nxagentAtoms[8] is "NX_AGENT_SIGNATURE". * Value of nxagentAtoms[8] is "NX_AGENT_SIGNATURE".
* *
...@@ -189,39 +187,43 @@ int nxagentInitAtoms(WindowPtr pWin) ...@@ -189,39 +187,43 @@ int nxagentInitAtoms(WindowPtr pWin)
* run nested. * run nested.
*/ */
atom = MakeAtom(nxagentAtomNames[8], strlen(nxagentAtomNames[8]), 1); Atom atom = MakeAtom(nxagentAtomNames[8], strlen(nxagentAtomNames[8]), 1);
if (atom == None) if (atom == None)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentInitAtoms: PANIC! Could not create [%s] atom.\n", fprintf(stderr, "%s: PANIC! Could not create [%s] atom.\n", __func__,
nxagentAtomNames[8]); nxagentAtomNames[8]);
#endif #endif
return -1; return -1;
} }
else
return 1; {
#ifdef TEST
fprintf(stderr, "nxagentInitAtoms: atom [%s] created with value [%d].\n",
nxagentAtomNames[8], atom);
#endif
return 1;
}
} }
int nxagentQueryAtoms(ScreenPtr pScreen) int nxagentQueryAtoms(ScreenPtr pScreen)
{ {
int i;
static unsigned long atomGeneration = 1; static unsigned long atomGeneration = 1;
int num_of_atoms = NXAGENT_NUMBER_OF_ATOMS; int num_of_atoms = NXAGENT_NUMBER_OF_ATOMS;
char *names[NXAGENT_NUMBER_OF_ATOMS]; char *names[NXAGENT_NUMBER_OF_ATOMS];
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentQueryAtoms: Going to create the intern atoms on real display.\n"); fprintf(stderr, "%s: Going to create the intern atoms on real display.\n", __func__);
#endif #endif
nxagentPrintAtomMapInfo("nxagentQueryAtoms: Entering"); nxagentPrintAtomMapInfo("nxagentQueryAtoms: Entering");
for (i = 0; i < num_of_atoms; i++) for (int i = 0; i < num_of_atoms; i++)
{ {
names[i] = nxagentAtomNames[i]; names[i] = nxagentAtomNames[i];
nxagentAtoms[i] = None; nxagentAtoms[i] = None;
} }
...@@ -248,10 +250,10 @@ int nxagentQueryAtoms(ScreenPtr pScreen) ...@@ -248,10 +250,10 @@ int nxagentQueryAtoms(ScreenPtr pScreen)
if (atomGeneration != serverGeneration) if (atomGeneration != serverGeneration)
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentQueryAtoms: The nxagent has been reset with server %ld atom %ld.\n", fprintf(stderr, "%s: The nxagent has been reset with server %ld atom %ld.\n", __func__,
serverGeneration, atomGeneration); serverGeneration, atomGeneration);
fprintf(stderr, "nxagentQueryAtoms: Forcing a sync to detect the window manager.\n"); fprintf(stderr, "%s: Forcing a sync to detect the window manager.\n", __func__);
#endif #endif
atomGeneration = serverGeneration; atomGeneration = serverGeneration;
...@@ -309,9 +311,9 @@ int nxagentQueryAtoms(ScreenPtr pScreen) ...@@ -309,9 +311,9 @@ int nxagentQueryAtoms(ScreenPtr pScreen)
#ifdef TEST #ifdef TEST
for (i = 0; i < num_of_atoms; i++) for (int i = 0; i < num_of_atoms; i++)
{ {
fprintf(stderr, "nxagentQueryAtoms: Created intern atom [%s] with id [%ld].\n", fprintf(stderr, "%s: Created intern atom [%s] with id [%ld].\n", __func__,
names[i], nxagentAtoms[i]); names[i], nxagentAtoms[i]);
} }
#endif #endif
...@@ -353,9 +355,8 @@ static void nxagentExpandCache(void) ...@@ -353,9 +355,8 @@ static void nxagentExpandCache(void)
} }
/* /*
* Check if there is space left on the map * Check if there is space left on the map and manage the possible
* and manage the possible consequent allocation, * consequent allocation, then cache the atom-couple.
* then cache the atom-couple.
*/ */
static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool duplicate) static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool duplicate)
...@@ -363,10 +364,9 @@ static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool d ...@@ -363,10 +364,9 @@ static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool d
const char *s; const char *s;
/* /*
* We could remove this string duplication if * We could remove this string duplication if we knew for sure that
* we know for sure that the server will not * the server will not reset, since only at reset the dix layer
* reset, since only at reset the dix layer * frees all the atom names.
* free all the atom names.
*/ */
if (duplicate) if (duplicate)
...@@ -399,19 +399,16 @@ static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool d ...@@ -399,19 +399,16 @@ static void nxagentWriteAtom(Atom local, Atom remote, const char *string, Bool d
} }
/* /*
* FIXME: We should clean up the atom map * FIXME: We should clean up the atom map at nxagent reset, in order
* at nxagent reset, in order to cancel * to cancel all the local atoms but still maintaining the Xserver
* all the local atoms but still maintaining * values and the atom names.
* the Xserver values and the atom names.
*/ */
void nxagentResetAtomMap(void) void nxagentResetAtomMap(void)
{ {
unsigned i;
nxagentPrintAtomMapInfo("nxagentResetAtomMap: Entering"); nxagentPrintAtomMapInfo("nxagentResetAtomMap: Entering");
for (i = 0; i < privLastAtom; i++) for (unsigned int i = 0; i < privLastAtom; i++)
{ {
privAtomMap[i].local = None; privAtomMap[i].local = None;
} }
...@@ -426,16 +423,13 @@ void nxagentResetAtomMap(void) ...@@ -426,16 +423,13 @@ void nxagentResetAtomMap(void)
static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet) static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet)
{ {
XlibAtom *atom_list;
char **name_list;
unsigned int i; unsigned int i;
int ret_value = 0;
int list_size = count + privLastAtom; int list_size = count + privLastAtom;
nxagentPrintAtomMapInfo("nxagentInitAtomMap: Entering"); nxagentPrintAtomMapInfo("nxagentInitAtomMap: Entering");
atom_list = malloc((list_size) * sizeof(*atom_list)); XlibAtom *atom_list = malloc((list_size) * sizeof(*atom_list));
name_list = malloc((list_size) * sizeof(char*)); char **name_list = malloc((list_size) * sizeof(char*));
if ((atom_list == NULL) || (name_list == NULL)) if ((atom_list == NULL) || (name_list == NULL))
{ {
...@@ -459,7 +453,7 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet) ...@@ -459,7 +453,7 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet)
* ... if successful cache them too. * ... if successful cache them too.
*/ */
ret_value = XInternAtoms(nxagentDisplay, name_list, list_size, False, atom_list); int ret_value = XInternAtoms(nxagentDisplay, name_list, list_size, False, atom_list);
if (ret_value == 0) if (ret_value == 0)
{ {
...@@ -517,22 +511,19 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet) ...@@ -517,22 +511,19 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet)
} }
/* /*
* If the nxagent has been reset, * If the nxagent has been reset, the local value of the atoms stored
* the local value of the atoms stored * in cache could have the value None, do not call this function with
* in cache could have the value None, * None.
* do not call this function with None.
*/ */
static AtomMap* nxagentFindAtomByLocalValue(Atom local) static AtomMap* nxagentFindAtomByLocalValue(Atom local)
{ {
unsigned i;
if (!ValidAtom(local)) if (!ValidAtom(local))
{ {
return NULL; return NULL;
} }
for (i = 0; i < privLastAtom; i++) for (unsigned int i = 0; i < privLastAtom; i++)
{ {
if (local == privAtomMap[i].local) if (local == privAtomMap[i].local)
{ {
...@@ -545,14 +536,12 @@ static AtomMap* nxagentFindAtomByLocalValue(Atom local) ...@@ -545,14 +536,12 @@ static AtomMap* nxagentFindAtomByLocalValue(Atom local)
static AtomMap* nxagentFindAtomByRemoteValue(Atom remote) static AtomMap* nxagentFindAtomByRemoteValue(Atom remote)
{ {
unsigned i;
if (remote == None || remote == BAD_RESOURCE) if (remote == None || remote == BAD_RESOURCE)
{ {
return NULL; return NULL;
} }
for (i = 0; i < privLastAtom; i++) for (unsigned int i = 0; i < privLastAtom; i++)
{ {
if (remote == privAtomMap[i].remote) if (remote == privAtomMap[i].remote)
{ {
...@@ -565,9 +554,7 @@ static AtomMap* nxagentFindAtomByRemoteValue(Atom remote) ...@@ -565,9 +554,7 @@ static AtomMap* nxagentFindAtomByRemoteValue(Atom remote)
static AtomMap* nxagentFindAtomByName(char *string, unsigned int length) static AtomMap* nxagentFindAtomByName(char *string, unsigned int length)
{ {
unsigned i; for (unsigned int i = 0; i < privLastAtom; i++)
for (i = 0; i < privLastAtom; i++)
{ {
if ((length == privAtomMap[i].length) && if ((length == privAtomMap[i].length) &&
(strcmp(string, privAtomMap[i].string) == 0)) (strcmp(string, privAtomMap[i].string) == 0))
...@@ -591,7 +578,6 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length) ...@@ -591,7 +578,6 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length)
Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
{ {
Atom local;
AtomMap *current; AtomMap *current;
/* /*
...@@ -599,7 +585,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -599,7 +585,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
* our nxagentFindAtomByName. * our nxagentFindAtomByName.
*/ */
local = MakeAtom(string, length, Makeit); Atom local = MakeAtom(string, length, Makeit);
if (!ValidAtom(local)) if (!ValidAtom(local))
{ {
...@@ -623,7 +609,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -623,7 +609,7 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
if ((current = nxagentFindAtomByName(string, length))) if ((current = nxagentFindAtomByName(string, length)))
{ {
/* /*
* Found Cached by name. * Found cached by name.
* It means that nxagent has been reset, * It means that nxagent has been reset,
* but not the xserver so we still have cached its atoms. * but not the xserver so we still have cached its atoms.
*/ */
...@@ -634,13 +620,11 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -634,13 +620,11 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
} }
/* /*
* We really have to ask Xserver for it. * We really have to ask the Xserver for it.
*/ */
{ {
Atom remote; Atom remote = XInternAtom(nxagentDisplay, string, !Makeit);
remote = XInternAtom(nxagentDisplay, string, !Makeit);
if (remote == None) if (remote == None)
{ {
...@@ -659,10 +643,6 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -659,10 +643,6 @@ Atom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
Atom nxagentLocalToRemoteAtom(Atom local) Atom nxagentLocalToRemoteAtom(Atom local)
{ {
AtomMap *current;
const char *string;
Atom remote;
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: entering\n", __func__); fprintf(stderr, "%s: entering\n", __func__);
#endif #endif
...@@ -683,7 +663,9 @@ Atom nxagentLocalToRemoteAtom(Atom local) ...@@ -683,7 +663,9 @@ Atom nxagentLocalToRemoteAtom(Atom local)
return local; return local;
} }
if ((current = nxagentFindAtomByLocalValue(local))) AtomMap *current = nxagentFindAtomByLocalValue(local);
if (current)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote); fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote);
...@@ -691,9 +673,9 @@ Atom nxagentLocalToRemoteAtom(Atom local) ...@@ -691,9 +673,9 @@ Atom nxagentLocalToRemoteAtom(Atom local)
return current->remote; return current->remote;
} }
string = NameForAtom(local); const char *string = NameForAtom(local);
remote = XInternAtom(nxagentDisplay, string, False); Atom remote = XInternAtom(nxagentDisplay, string, False);
if (remote == None) if (remote == None)
{ {
...@@ -715,10 +697,6 @@ Atom nxagentLocalToRemoteAtom(Atom local) ...@@ -715,10 +697,6 @@ Atom nxagentLocalToRemoteAtom(Atom local)
Atom nxagentRemoteToLocalAtom(Atom remote) Atom nxagentRemoteToLocalAtom(Atom remote)
{ {
AtomMap *current;
char *string;
Atom local;
if (remote == None || remote == BAD_RESOURCE) if (remote == None || remote == BAD_RESOURCE)
{ {
#ifdef DEBUG #ifdef DEBUG
...@@ -735,11 +713,13 @@ Atom nxagentRemoteToLocalAtom(Atom remote) ...@@ -735,11 +713,13 @@ Atom nxagentRemoteToLocalAtom(Atom remote)
return remote; return remote;
} }
if ((current = nxagentFindAtomByRemoteValue(remote))) AtomMap *current = nxagentFindAtomByRemoteValue(remote);
if (current)
{ {
if (!ValidAtom(current->local)) if (!ValidAtom(current->local))
{ {
local = MakeAtom(current->string, current->length, True); Atom local = MakeAtom(current->string, current->length, True);
if (ValidAtom(local)) if (ValidAtom(local))
{ {
...@@ -761,14 +741,16 @@ Atom nxagentRemoteToLocalAtom(Atom remote) ...@@ -761,14 +741,16 @@ Atom nxagentRemoteToLocalAtom(Atom remote)
return current->local; return current->local;
} }
if ((string = XGetAtomName(nxagentDisplay, remote))) char *string = XGetAtomName(nxagentDisplay, remote);
if (string)
{ {
local = MakeAtom(string, strlen(string), True); Atom local = MakeAtom(string, strlen(string), True);
if (!ValidAtom(local)) if (!ValidAtom(local))
{ {
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentRemoteToLocalAtom: WARNING MakeAtom failed.\n"); fprintf(stderr, "%s: WARNING MakeAtom failed.\n", __func__);
#endif #endif
local = None; local = None;
...@@ -785,7 +767,7 @@ Atom nxagentRemoteToLocalAtom(Atom remote) ...@@ -785,7 +767,7 @@ Atom nxagentRemoteToLocalAtom(Atom remote)
} }
#ifdef WARNING #ifdef WARNING
fprintf(stderr, "nxagentRemoteToLocalAtom: WARNING failed to get name from remote atom.\n"); fprintf(stderr, "%s: WARNING failed to get name from remote atom.\n", __func__);
#endif #endif
return None; return None;
...@@ -795,13 +777,11 @@ Atom nxagentRemoteToLocalAtom(Atom remote) ...@@ -795,13 +777,11 @@ Atom nxagentRemoteToLocalAtom(Atom remote)
static void nxagentPrintAtomMapInfo(char *message) static void nxagentPrintAtomMapInfo(char *message)
{ {
unsigned i;
fprintf(stderr, "--------------- Atom map in context [%s] ----------------------\n", message); fprintf(stderr, "--------------- Atom map in context [%s] ----------------------\n", message);
fprintf(stderr, "nxagentPrintAtomMapInfo: Map at [%p] size [%d] number of entry [%d] auto increment [%d].\n", fprintf(stderr, "nxagentPrintAtomMapInfo: Map at [%p] size [%d] number of entry [%d] auto increment [%d].\n",
(void*) privAtomMap, privLastAtom, privAtomMapSize, NXAGENT_ATOM_MAP_SIZE_INCREMENT); (void*) privAtomMap, privLastAtom, privAtomMapSize, NXAGENT_ATOM_MAP_SIZE_INCREMENT);
for (i = 0; i < privLastAtom; i++) for (unsigned int i = 0; i < privLastAtom; i++)
{ {
fprintf(stderr, "[%5.1d] local: %6.1u - remote: %6.1u - [%p] %s\n", i, fprintf(stderr, "[%5.1d] local: %6.1u - remote: %6.1u - [%p] %s\n", i,
privAtomMap[i].local, privAtomMap[i].local,
......
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