]> git.sur5r.net Git - cc65/blobdiff - src/ar65/objdata.c
Merge remote-tracking branch 'upstream/master' into creativision
[cc65] / src / ar65 / objdata.c
index 6b42f33a809c7ccb77dda5818051bf406199e5e6..5a8f0c5fb1bf8ab9e157d84b0abf892b2da6683b 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                objdata.c                                 */
+/*                                 objdata.c                                 */
 /*                                                                           */
-/*             Handling object file data for the ar65 archiver              */
+/*              Handling object file data for the ar65 archiver              */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 /* ar65 */
 #include "error.h"
+#include "library.h"
 #include "objdata.h"
 
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 
-/* Object data list management */
-unsigned       ObjCount = 0;   /* Count of object files in the list */
-ObjData*       ObjRoot  = 0;   /* List of object files */
-ObjData*       ObjLast  = 0;   /* Last entry in list */
-ObjData**              ObjPool  = 0;   /* Object files as array */
+/* Collection with object files */
+Collection       ObjPool        = STATIC_COLLECTION_INITIALIZER;
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -72,29 +70,18 @@ ObjData* NewObjData (void)
     ObjData* O = xmalloc (sizeof (ObjData));
 
     /* Initialize the data */
-    O->Next       = 0;
-    O->Name      = 0;
-    O->Index     = ~0;
-    O->Flags             = 0;
-    O->MTime     = 0;
-    O->Start     = 0;
-    O->Size      = 0;
-    O->ImportSize = 0;
-    O->Imports    = 0;
-    O->ExportSize = 0;
-    O->Exports    = 0;
-
-    /* Link it into the list */
-    if (ObjLast) {
-       ObjLast->Next = O;
-       ObjLast       = O;
-    } else {
-       /* First entry */
-       ObjRoot = ObjLast = O;
-    }
+    O->Name        = 0;
+
+    O->Flags       = 0;
+    O->MTime       = 0;
+    O->Start       = 0;
+    O->Size        = 0;
 
-    /* One object file more now */
-    ++ObjCount;
+    O->Strings     = EmptyCollection;
+    O->Exports     = EmptyCollection;
+
+    /* Add it to the list */
+    CollAppend (&ObjPool, O);
 
     /* Return the new entry */
     return O;
@@ -105,107 +92,78 @@ ObjData* NewObjData (void)
 void FreeObjData (ObjData* O)
 /* Free a complete struct */
 {
-    xfree (O->Name);
-    xfree (O->Imports);
-    xfree (O->Exports);
-    xfree (O);
-}
-
-
+    unsigned I;
 
-ObjData* FindObjData (const char* Module)
-/* Search for the module with the given name and return it. Return NULL if the
- * module is not in the list.
- */
-{
-    /* Hmm. Maybe we should hash the module names? */
-    ObjData* O = ObjRoot;
-    while (O) {
-       if (strcmp (O->Name, Module) == 0) {
-           return O;
-       }
-       O = O->Next;
+    xfree (O->Name);
+    for (I = 0; I < CollCount (&O->Strings); ++I) {
+        xfree (CollAt (&O->Strings, I));
     }
-    return 0;
+    DoneCollection (&O->Strings);
+    DoneCollection (&O->Exports);
+    xfree (O);
 }
 
 
 
-void DelObjData (const char* Module)
-/* Delete the object module from the list */
+void ClearObjData (ObjData* O)
+/* Remove any data stored in O */
 {
-    ObjData* O = ObjRoot;
-    ObjData* Last = 0;
-    while (O) {
-       if (strcmp (O->Name, Module) == 0) {
-           /* Found the module, remove it from the list */
-           if (Last == 0) {
-               /* This was the first entry in the list */
-               ObjRoot = O->Next;
-           } else {
-               Last->Next = O->Next;
-           }
-           if (ObjLast == O) {
-               /* O was the last object in the list */
-               ObjLast = Last;
-           }
-           --ObjCount;
-
-           /* Free the entry */
-           FreeObjData (O);
-
-           /* Done */
-           return;
-       }
-       Last = O;
-       O = O->Next;
+    unsigned I;
+    xfree (O->Name);
+    O->Name = 0;
+    for (I = 0; I < CollCount (&O->Strings); ++I) {
+        xfree (CollAt (&O->Strings, I));
     }
-
-    /* Not found! */
-    Warning ("Module `%s' not found in library", Module);
+    CollDeleteAll (&O->Strings);
+    CollDeleteAll (&O->Exports);
 }
 
 
 
-void MakeObjPool (void)
-/* Allocate memory, index the entries and make the ObjPool valid */
+ObjData* FindObjData (const char* Module)
+/* Search for the module with the given name and return it. Return NULL if the
+** module is not in the list.
+*/
 {
-    ObjData* O;
-    unsigned Index;
-
-    /* Allocate memory for the pool */
-    ObjPool = xmalloc (ObjCount * sizeof (ObjData*));
-
-    /* Setup the pointers and index the objects */
-    Index = 0;
-    O = ObjRoot;
-    while (O) {
+    unsigned I;
 
-       /* Safety */
-       CHECK (Index < ObjCount);
+    /* Hmm. Maybe we should hash the module names? */
+    for (I = 0; I < CollCount (&ObjPool); ++I) {
 
-       /* Set the Index */
-       O->Index = Index;
+        /* Get this object file */
+        ObjData* O = CollAtUnchecked (&ObjPool, I);
 
-       /* Set the pool pointer */
-       ObjPool [Index] = O;
-                                                                            
-       /* Next object */
-       ++Index;
-       O = O->Next;
+        /* Did we find it? */
+        if (strcmp (O->Name, Module) == 0) {
+            return O;
+        }
     }
+    return 0;
 }
 
 
 
-const char* GetObjName (unsigned Index)
-/* Get the name of a module by index */
+void DelObjData (const char* Module)
+/* Delete the object module from the list */
 {
-    PRECONDITION (ObjPool != 0 && Index < ObjCount && ObjPool [Index] != 0);
-    return ObjPool [Index]->Name;
-}
+    unsigned I;
+    for (I = 0; I < CollCount (&ObjPool); ++I) {
 
+        /* Get this object file */
+        ObjData* O = CollAtUnchecked (&ObjPool, I);
 
+        /* Did we find it? */
+        if (strcmp (O->Name, Module) == 0) {
 
+            /* Free the entry */
+            CollDelete (&ObjPool, I);
+            FreeObjData (O);
 
+            /* Done */
+            return;
+        }
+    }
 
+    /* Not found! */
+    Warning ("Module `%s' not found in library `%s'", Module, LibName);
+}