]> git.sur5r.net Git - cc65/blob - ar65/exports.c
Fixed _textcolor definition.
[cc65] / ar65 / exports.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 exports.c                                 */
4 /*                                                                           */
5 /*              Duplicate export checking for the ar65 archiver              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <string.h>
37
38 #include "../common/hashstr.h"
39
40 #include "mem.h"
41 #include "error.h"
42 #include "objdata.h"
43 #include "exports.h"
44
45
46
47 /*****************************************************************************/
48 /*                                   Data                                    */
49 /*****************************************************************************/
50
51
52
53 /* A hash table entry */
54 typedef struct HashEntry_ HashEntry;
55 struct HashEntry_ {
56     HashEntry*          Next;           /* Next in list */
57     unsigned            Module;         /* Module index */
58     char                Name [1];       /* Name of identifier */
59 };
60
61 /* Hash table */
62 #define HASHTAB_SIZE    4783
63 static HashEntry*       HashTab [HASHTAB_SIZE];
64
65
66
67 /*****************************************************************************/
68 /*                                   Code                                    */
69 /*****************************************************************************/
70
71
72
73 static HashEntry* NewHashEntry (const char* Name, unsigned Module)
74 /* Create and return a new hash entry */
75 {
76     /* Get the length of the name */
77     unsigned Len = strlen (Name);
78
79     /* Get memory for the struct */
80     HashEntry* H = Xmalloc (sizeof (HashEntry) + Len);
81
82     /* Initialize the fields and return it */
83     H->Next     = 0;
84     H->Module   = Module;
85     memcpy (H->Name, Name, Len);
86     H->Name [Len] = '\0';
87     return H;
88 }
89
90
91
92 void ExpInsert (const char* Name, unsigned Module)
93 /* Insert an exported identifier and check if it's already in the list */
94 {
95     HashEntry* L;
96
97     /* Create a hash value for the given name */
98     unsigned HashVal = HashStr (Name) % HASHTAB_SIZE;
99
100     /* Create a new hash entry */
101     HashEntry* H = NewHashEntry (Name, Module);
102
103     /* Search through the list in that slot and print matching duplicates */
104     if (HashTab [HashVal] == 0) {
105         /* The slot is empty */
106         HashTab [HashVal] = H;
107         return;
108     }
109     L = HashTab [HashVal];
110     while (1) {
111         if (strcmp (L->Name, Name) == 0) {
112             /* Duplicate entry */
113             Warning ("External symbol `%s' in module `%s' is duplicated in "
114                      "module `%s'",
115                      Name, GetObjName (L->Module), GetObjName (Module));
116         }
117         if (L->Next == 0) {
118             break;
119         } else {
120             L = L->Next;
121         }
122     }
123     L->Next = H;
124 }
125
126
127
128 int ExpFind (const char* Name)
129 /* Check for an identifier in the list. Return -1 if not found, otherwise
130  * return the number of the module, that exports the identifer.
131  */
132 {
133     /* Get a pointer to the list with the symbols hash value */
134     HashEntry* L = HashTab [HashStr (Name) % HASHTAB_SIZE];
135     while (L) {
136         /* Search through the list in that slot */
137         if (strcmp (L->Name, Name) == 0) {
138             /* Entry found */
139             return L->Module;
140         }
141         L = L->Next;
142     }
143
144     /* Not found */
145     return -1;
146 }
147
148
149