summaryrefslogtreecommitdiff
path: root/dix/atom.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-03-21 12:55:09 -0700
committerKeith Packard <keithp@keithp.com>2012-03-21 13:54:42 -0700
commit9838b7032ea9792bec21af424c53c07078636d21 (patch)
treeb72d0827dac50f0f3b8eab29b3b7639546d735d7 /dix/atom.c
parent75199129c603fc8567185ac31866c9518193cb78 (diff)
Introduce a consistent coding style
This is strictly the application of the script 'x-indent-all.sh' from util/modular. Compared to the patch that Daniel posted in January, I've added a few indent flags: -bap -psl -T PrivatePtr -T pmWait -T _XFUNCPROTOBEGIN -T _XFUNCPROTOEND -T _X_EXPORT The typedefs were needed to make the output of sdksyms.sh match the previous output, otherwise, the code is formatted badly enough that sdksyms.sh generates incorrect output. The generated code was compared with the previous version and found to be essentially identical -- "assert" line numbers and BUILD_TIME were the only differences found. The comparison was done with this script: dir1=$1 dir2=$2 for dir in $dir1 $dir2; do (cd $dir && find . -name '*.o' | while read file; do dir=`dirname $file` base=`basename $file .o` dump=$dir/$base.dump objdump -d $file > $dump done) done find $dir1 -name '*.dump' | while read dump; do otherdump=`echo $dump | sed "s;$dir1;$dir2;"` diff -u $dump $otherdump done Signed-off-by: Keith Packard <keithp@keithp.com> Acked-by: Daniel Stone <daniel@fooishbar.org> Acked-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'dix/atom.c')
-rw-r--r--dix/atom.c143
1 files changed, 69 insertions, 74 deletions
diff --git a/dix/atom.c b/dix/atom.c
index 83ff71a7d..6f85968cd 100644
--- a/dix/atom.c
+++ b/dix/atom.c
@@ -22,7 +22,6 @@ Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
-
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
@@ -45,7 +44,6 @@ SOFTWARE.
******************************************************************/
-
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
@@ -61,10 +59,10 @@ SOFTWARE.
#define InitialTableSize 100
typedef struct _Node {
- struct _Node *left, *right;
+ struct _Node *left, *right;
Atom a;
unsigned int fingerPrint;
- const char *string;
+ const char *string;
} NodeRec, *NodePtr;
static Atom lastAtom = None;
@@ -77,77 +75,71 @@ void FreeAtom(NodePtr patom);
Atom
MakeAtom(const char *string, unsigned len, Bool makeit)
{
- NodePtr * np;
+ NodePtr *np;
unsigned i;
int comp;
unsigned int fp = 0;
np = &atomRoot;
- for (i = 0; i < (len+1)/2; i++)
- {
- fp = fp * 27 + string[i];
- fp = fp * 27 + string[len - 1 - i];
+ for (i = 0; i < (len + 1) / 2; i++) {
+ fp = fp * 27 + string[i];
+ fp = fp * 27 + string[len - 1 - i];
}
- while (*np != NULL)
- {
- if (fp < (*np)->fingerPrint)
- np = &((*np)->left);
- else if (fp > (*np)->fingerPrint)
- np = &((*np)->right);
- else
- { /* now start testing the strings */
- comp = strncmp(string, (*np)->string, (int)len);
- if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
- np = &((*np)->left);
- else if (comp > 0)
- np = &((*np)->right);
- else
- return(*np)->a;
- }
+ while (*np != NULL) {
+ if (fp < (*np)->fingerPrint)
+ np = &((*np)->left);
+ else if (fp > (*np)->fingerPrint)
+ np = &((*np)->right);
+ else { /* now start testing the strings */
+ comp = strncmp(string, (*np)->string, (int) len);
+ if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
+ np = &((*np)->left);
+ else if (comp > 0)
+ np = &((*np)->right);
+ else
+ return (*np)->a;
+ }
}
- if (makeit)
- {
- NodePtr nd;
-
- nd = malloc(sizeof(NodeRec));
- if (!nd)
- return BAD_RESOURCE;
- if (lastAtom < XA_LAST_PREDEFINED)
- {
- nd->string = string;
- }
- else
- {
- nd->string = strndup(string, len);
- if (!nd->string) {
- free(nd);
- return BAD_RESOURCE;
- }
- }
- if ((lastAtom + 1) >= tableLength) {
- NodePtr *table;
-
- table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr)));
- if (!table) {
- if (nd->string != string) {
+ if (makeit) {
+ NodePtr nd;
+
+ nd = malloc(sizeof(NodeRec));
+ if (!nd)
+ return BAD_RESOURCE;
+ if (lastAtom < XA_LAST_PREDEFINED) {
+ nd->string = string;
+ }
+ else {
+ nd->string = strndup(string, len);
+ if (!nd->string) {
+ free(nd);
+ return BAD_RESOURCE;
+ }
+ }
+ if ((lastAtom + 1) >= tableLength) {
+ NodePtr *table;
+
+ table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr)));
+ if (!table) {
+ if (nd->string != string) {
/* nd->string has been strdup'ed */
- free((char *)nd->string);
+ free((char *) nd->string);
}
- free(nd);
- return BAD_RESOURCE;
- }
- tableLength <<= 1;
- nodeTable = table;
- }
- *np = nd;
- nd->left = nd->right = NULL;
- nd->fingerPrint = fp;
- nd->a = ++lastAtom;
- nodeTable[lastAtom] = nd;
- return nd->a;
+ free(nd);
+ return BAD_RESOURCE;
+ }
+ tableLength <<= 1;
+ nodeTable = table;
+ }
+ *np = nd;
+ nd->left = nd->right = NULL;
+ nd->fingerPrint = fp;
+ nd->a = ++lastAtom;
+ nodeTable[lastAtom] = nd;
+ return nd->a;
}
else
- return None;
+ return None;
}
Bool
@@ -160,8 +152,11 @@ const char *
NameForAtom(Atom atom)
{
NodePtr node;
- if (atom > lastAtom) return 0;
- if ((node = nodeTable[atom]) == NULL) return 0;
+
+ if (atom > lastAtom)
+ return 0;
+ if ((node = nodeTable[atom]) == NULL)
+ return 0;
return node->string;
}
@@ -174,16 +169,16 @@ AtomError(void)
void
FreeAtom(NodePtr patom)
{
- if(patom->left)
- FreeAtom(patom->left);
- if(patom->right)
- FreeAtom(patom->right);
+ if (patom->left)
+ FreeAtom(patom->left);
+ if (patom->right)
+ FreeAtom(patom->right);
if (patom->a > XA_LAST_PREDEFINED) {
/*
* All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to
* cast here
*/
- free((char *)patom->string);
+ free((char *) patom->string);
}
free(patom);
}
@@ -192,7 +187,7 @@ void
FreeAllAtoms(void)
{
if (atomRoot == NULL)
- return;
+ return;
FreeAtom(atomRoot);
atomRoot = NULL;
free(nodeTable);
@@ -207,9 +202,9 @@ InitAtoms(void)
tableLength = InitialTableSize;
nodeTable = malloc(InitialTableSize * sizeof(NodePtr));
if (!nodeTable)
- AtomError();
+ AtomError();
nodeTable[None] = NULL;
MakePredeclaredAtoms();
if (lastAtom != XA_LAST_PREDEFINED)
- AtomError();
+ AtomError();
}