1 /*****************************************************************************/
5 /* Handling object file data for the ar65 archiver */
9 /* (C) 1998-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
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 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
54 /* Object data list management */
55 unsigned ObjCount = 0; /* Count of object files in the list */
56 ObjData* ObjRoot = 0; /* List of object files */
57 ObjData* ObjLast = 0; /* Last entry in list */
58 ObjData** ObjPool = 0; /* Object files as array */
62 /*****************************************************************************/
64 /*****************************************************************************/
68 ObjData* NewObjData (void)
69 /* Allocate a new structure on the heap, insert it into the list, return it */
72 ObjData* O = xmalloc (sizeof (ObjData));
74 /* Initialize the data */
89 /* Link it into the list */
95 ObjRoot = ObjLast = O;
98 /* One object file more now */
101 /* Return the new entry */
107 void FreeObjData (ObjData* O)
108 /* Free a complete struct */
115 for (I = 0; I < O->StringCount; ++I) {
116 xfree (O->Strings[I]);
124 ObjData* FindObjData (const char* Module)
125 /* Search for the module with the given name and return it. Return NULL if the
126 * module is not in the list.
129 /* Hmm. Maybe we should hash the module names? */
130 ObjData* O = ObjRoot;
132 if (strcmp (O->Name, Module) == 0) {
142 void DelObjData (const char* Module)
143 /* Delete the object module from the list */
145 ObjData* O = ObjRoot;
148 if (strcmp (O->Name, Module) == 0) {
149 /* Found the module, remove it from the list */
151 /* This was the first entry in the list */
154 Last->Next = O->Next;
157 /* O was the last object in the list */
173 Warning ("Module `%s' not found in library", Module);
178 void MakeObjPool (void)
179 /* Allocate memory, index the entries and make the ObjPool valid */
184 /* Allocate memory for the pool */
185 ObjPool = xmalloc (ObjCount * sizeof (ObjData*));
187 /* Setup the pointers and index the objects */
193 CHECK (Index < ObjCount);
198 /* Set the pool pointer */
209 const char* GetObjName (unsigned Index)
210 /* Get the name of a module by index */
212 PRECONDITION (ObjPool != 0 && Index < ObjCount && ObjPool [Index] != 0);
213 return ObjPool [Index]->Name;
218 const char* GetObjString (const ObjData* O, unsigned Index)
219 /* Get a string from the string pool of an object file */
221 if (Index >= O->StringCount) {
222 Error ("Invalid string index (%u) in module `%s'",
223 Index, GetObjName (O->Index));
225 return O->Strings[Index];