1 /*****************************************************************************/
5 /* Duplicate export checking for the ar65 archiver */
9 /* (C) 1998-2003 Ullrich von Bassewitz */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
49 /*****************************************************************************/
51 /*****************************************************************************/
55 /* A hash table entry */
56 typedef struct HashEntry HashEntry;
58 HashEntry* Next; /* Next in list */
59 unsigned Module; /* Module index */
60 char Name [1]; /* Name of identifier */
64 #define HASHTAB_SIZE 4783
65 static HashEntry* HashTab [HASHTAB_SIZE];
69 /*****************************************************************************/
71 /*****************************************************************************/
75 static HashEntry* NewHashEntry (const char* Name, unsigned Module)
76 /* Create and return a new hash entry */
78 /* Get the length of the name */
79 unsigned Len = strlen (Name);
81 /* Get memory for the struct */
82 HashEntry* H = xmalloc (sizeof (HashEntry) + Len);
84 /* Initialize the fields and return it */
87 memcpy (H->Name, Name, Len);
94 void ExpInsert (const char* Name, unsigned Module)
95 /* Insert an exported identifier and check if it's already in the list */
99 /* Create a hash value for the given name */
100 unsigned HashVal = HashStr (Name) % HASHTAB_SIZE;
102 /* Create a new hash entry */
103 HashEntry* H = NewHashEntry (Name, Module);
105 /* Search through the list in that slot and print matching duplicates */
106 if (HashTab [HashVal] == 0) {
107 /* The slot is empty */
108 HashTab [HashVal] = H;
111 L = HashTab [HashVal];
113 if (strcmp (L->Name, Name) == 0) {
114 /* Duplicate entry */
115 Warning ("External symbol `%s' in module `%s' is duplicated in "
117 Name, GetObjName (L->Module), GetObjName (Module));
130 int ExpFind (const char* Name)
131 /* Check for an identifier in the list. Return -1 if not found, otherwise
132 * return the number of the module, that exports the identifer.
135 /* Get a pointer to the list with the symbols hash value */
136 HashEntry* L = HashTab [HashStr (Name) % HASHTAB_SIZE];
138 /* Search through the list in that slot */
139 if (strcmp (L->Name, Name) == 0) {