1 /* $XConsortium: atom.c,v 1.4 94/04/17 20:17:31 gildea Exp $ */
5 Copyright (c) 1990, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
31 * Author: Keith Packard, MIT X Consortium
34 /* lame atom replacement routines for font applications */
38 typedef struct _AtomList {
43 } AtomListRec, *AtomListPtr;
45 static AtomListPtr *hashTable;
47 static int hashSize, hashUsed;
51 static AtomListPtr *reverseMap;
52 static int reverseMapSize;
63 h = (h << 3) ^ *string++;
74 AtomListPtr *newHashTable;
83 newHashSize = hashSize * 2;
84 newHashTable = (AtomListPtr *) xalloc (newHashSize * sizeof (AtomListPtr));
87 bzero ((char *) newHashTable, newHashSize * sizeof (AtomListPtr));
88 newHashMask = newHashSize - 1;
89 newRehash = (newHashMask - 2);
90 for (i = 0; i < hashSize; i++)
94 h = (hashTable[i]->hash) & newHashMask;
97 r = hashTable[i]->hash % newRehash | 1;
100 if (h >= newHashSize)
102 } while (newHashTable[h]);
104 newHashTable[h] = hashTable[i];
108 hashTable = newHashTable;
109 hashSize = newHashSize;
110 hashMask = newHashMask;
118 if (reverseMapSize == 0)
119 reverseMapSize = 1000;
122 reverseMap = (AtomListPtr *) xrealloc (reverseMap, reverseMapSize * sizeof (AtomListPtr));
138 MakeAtom(string, len, makeit)
148 hash = Hash (string, len);
154 if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
155 NameEqual (hashTable[h]->name, string, len))
157 return hashTable[h]->atom;
159 r = (hash % rehash) | 1;
167 if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
168 NameEqual (hashTable[h]->name, string, len))
170 return hashTable[h]->atom;
177 a = (AtomListPtr) xalloc (sizeof (AtomListRec) + len + 1);
178 a->name = (char *) (a + 1);
180 strncpy (a->name, string, len);
182 a->atom = ++lastAtom;
184 if (hashUsed >= hashSize / 2)
190 r = (hash % rehash) | 1;
195 } while (hashTable[h]);
200 if (reverseMapSize <= a->atom)
202 reverseMap[a->atom] = a;
209 return (atom != None) && (atom <= lastAtom);
216 if (atom != None && atom <= lastAtom)
217 return reverseMap[atom]->name;