]> git.sur5r.net Git - cc65/blob - src/ar65/objdata.c
Allow to set character translations at compile time
[cc65] / src / ar65 / objdata.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 objdata.c                                 */
4 /*                                                                           */
5 /*              Handling object file data for the ar65 archiver              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2000 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 /* common */
39 #include "check.h"
40 #include "xmalloc.h"
41
42 /* ar65 */
43 #include "error.h"
44 #include "objdata.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
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 */
59
60
61
62 /*****************************************************************************/
63 /*                                   Code                                    */
64 /*****************************************************************************/
65
66
67
68 ObjData* NewObjData (void)
69 /* Allocate a new structure on the heap, insert it into the list, return it */
70 {
71     /* Allocate memory */
72     ObjData* O = xmalloc (sizeof (ObjData));
73
74     /* Initialize the data */
75     O->Next       = 0;
76     O->Name       = 0;
77     O->Index      = ~0;
78     O->Flags      = 0;
79     O->MTime      = 0;
80     O->Start      = 0;
81     O->Size       = 0;
82     O->ImportSize = 0;
83     O->Imports    = 0;
84     O->ExportSize = 0;
85     O->Exports    = 0;
86
87     /* Link it into the list */
88     if (ObjLast) {
89         ObjLast->Next = O;
90         ObjLast       = O;
91     } else {
92         /* First entry */
93         ObjRoot = ObjLast = O;
94     }
95
96     /* One object file more now */
97     ++ObjCount;
98
99     /* Return the new entry */
100     return O;
101 }
102
103
104
105 void FreeObjData (ObjData* O)
106 /* Free a complete struct */
107 {
108     xfree (O->Name);
109     xfree (O->Imports);
110     xfree (O->Exports);
111     xfree (O);
112 }
113
114
115
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.
119  */
120 {
121     /* Hmm. Maybe we should hash the module names? */
122     ObjData* O = ObjRoot;
123     while (O) {
124         if (strcmp (O->Name, Module) == 0) {
125             return O;
126         }
127         O = O->Next;
128     }
129     return 0;
130 }
131
132
133
134 void DelObjData (const char* Module)
135 /* Delete the object module from the list */
136 {
137     ObjData* O = ObjRoot;
138     ObjData* Last = 0;
139     while (O) {
140         if (strcmp (O->Name, Module) == 0) {
141             /* Found the module, remove it from the list */
142             if (Last == 0) {
143                 /* This was the first entry in the list */
144                 ObjRoot = O->Next;
145             } else {
146                 Last->Next = O->Next;
147             }
148             if (ObjLast == O) {
149                 /* O was the last object in the list */
150                 ObjLast = Last;
151             }
152             --ObjCount;
153
154             /* Free the entry */
155             FreeObjData (O);
156
157             /* Done */
158             return;
159         }
160         Last = O;
161         O = O->Next;
162     }
163
164     /* Not found! */
165     Warning ("Module `%s' not found in library", Module);
166 }
167
168
169
170 void MakeObjPool (void)
171 /* Allocate memory, index the entries and make the ObjPool valid */
172 {
173     ObjData* O;
174     unsigned Index;
175
176     /* Allocate memory for the pool */
177     ObjPool = xmalloc (ObjCount * sizeof (ObjData*));
178
179     /* Setup the pointers and index the objects */
180     Index = 0;
181     O = ObjRoot;
182     while (O) {
183
184         /* Safety */
185         CHECK (Index < ObjCount);
186
187         /* Set the Index */
188         O->Index = Index;
189
190         /* Set the pool pointer */
191         ObjPool [Index] = O;
192                                                                              
193         /* Next object */
194         ++Index;
195         O = O->Next;
196     }
197 }
198
199
200
201 const char* GetObjName (unsigned Index)
202 /* Get the name of a module by index */
203 {
204     PRECONDITION (ObjPool != 0 && Index < ObjCount && ObjPool [Index] != 0);
205     return ObjPool [Index]->Name;
206 }
207
208
209
210
211