1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
49 /* $XConsortium: atom.c,v 1.30 94/04/17 20:26:16 dpw Exp $ */
50 /* $XFree86: xc/programs/Xserver/dix/atom.c,v 3.0 1996/04/15 11:19:31 dawes Exp $ */
58 #define InitialTableSize 100
60 typedef struct _Node {
61 struct _Node *left, *right;
63 unsigned int fingerPrint;
67 static Atom lastAtom = None;
68 static NodePtr atomRoot = (NodePtr)NULL;
69 static unsigned long tableLength;
70 static NodePtr *nodeTable;
73 MakeAtom(string, len, makeit)
78 register NodePtr * np;
81 register unsigned int fp = 0;
84 for (i = 0; i < (len+1)/2; i++)
86 fp = fp * 27 + string[i];
87 fp = fp * 27 + string[len - 1 - i];
89 while (*np != (NodePtr) NULL)
91 if (fp < (*np)->fingerPrint)
93 else if (fp > (*np)->fingerPrint)
96 { /* now start testing the strings */
97 comp = strncmp(string, (*np)->string, (int)len);
98 if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
101 np = &((*np)->right);
110 nd = (NodePtr) xalloc(sizeof(NodeRec));
113 if (lastAtom < XA_LAST_PREDEFINED)
119 nd->string = (char *) xalloc(len + 1);
124 strncpy(nd->string, string, (int)len);
127 if ((lastAtom + 1) >= tableLength) {
130 table = (NodePtr *) xrealloc(nodeTable,
131 tableLength * (2 * sizeof(NodePtr)));
133 if (nd->string != string)
142 nd->left = nd->right = (NodePtr) NULL;
143 nd->fingerPrint = fp;
144 nd->a = (++lastAtom);
145 *(nodeTable+lastAtom) = nd;
156 return (atom != None) && (atom <= lastAtom);
164 if (atom > lastAtom) return 0;
165 if ((node = nodeTable[atom]) == (NodePtr)NULL) return 0;
172 FatalError("initializing atoms");
180 FreeAtom(patom->left);
182 FreeAtom(patom->right);
183 if (patom->a > XA_LAST_PREDEFINED)
184 xfree(patom->string);
191 if(atomRoot == (NodePtr)NULL)
194 atomRoot = (NodePtr)NULL;
196 nodeTable = (NodePtr *)NULL;
204 tableLength = InitialTableSize;
205 nodeTable = (NodePtr *)xalloc(InitialTableSize*sizeof(NodePtr));
208 nodeTable[None] = (NodePtr)NULL;
209 MakePredeclaredAtoms();
210 if (lastAtom != XA_LAST_PREDEFINED)