1 /*****************************************************************************/
5 /* Handling object file data for the ar65 archiver */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 */
87 /* Link it into the list */
93 ObjRoot = ObjLast = O;
96 /* One object file more now */
99 /* Return the new entry */
105 void FreeObjData (ObjData* O)
106 /* Free a complete struct */
116 ObjData* FindObjData (const char* Module)
117 /* Search for the module with the given name and return it. Return NULL if the
118 * module is not in the list.
121 /* Hmm. Maybe we should hash the module names? */
122 ObjData* O = ObjRoot;
124 if (strcmp (O->Name, Module) == 0) {
134 void DelObjData (const char* Module)
135 /* Delete the object module from the list */
137 ObjData* O = ObjRoot;
140 if (strcmp (O->Name, Module) == 0) {
141 /* Found the module, remove it from the list */
143 /* This was the first entry in the list */
146 Last->Next = O->Next;
149 /* O was the last object in the list */
165 Warning ("Module `%s' not found in library", Module);
170 void MakeObjPool (void)
171 /* Allocate memory, index the entries and make the ObjPool valid */
176 /* Allocate memory for the pool */
177 ObjPool = xmalloc (ObjCount * sizeof (ObjData*));
179 /* Setup the pointers and index the objects */
185 CHECK (Index < ObjCount);
190 /* Set the pool pointer */
201 const char* GetObjName (unsigned Index)
202 /* Get the name of a module by index */
204 PRECONDITION (ObjPool != 0 && Index < ObjCount && ObjPool [Index] != 0);
205 return ObjPool [Index]->Name;