/*****************************************************************************/
/* */
-/* exports.c */
+/* exports.c */
/* */
/* Duplicate export checking for the ar65 archiver */
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/* A hash table entry */
-typedef struct HashEntry HashEntry;
+typedef struct HashEntry HashEntry;
struct HashEntry {
- HashEntry* Next; /* Next in list */
- unsigned Module; /* Module index */
+ HashEntry* Next; /* Next in list */
+ const ObjData* Module; /* Pointer to object module */
char Name [1]; /* Name of identifier */
};
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
-static HashEntry* NewHashEntry (const char* Name, unsigned Module)
+static HashEntry* NewHashEntry (const char* Name, const ObjData* Module)
/* Create and return a new hash entry */
{
/* Get the length of the name */
-void ExpInsert (const char* Name, unsigned Module)
+void ExpInsert (const char* Name, const ObjData* Module)
/* Insert an exported identifier and check if it's already in the list */
{
HashEntry* L;
/* Duplicate entry */
Warning ("External symbol `%s' in module `%s' is duplicated in "
"module `%s'",
- Name, GetObjName (L->Module), GetObjName (Module));
+ Name, L->Name, Module->Name);
}
if (L->Next == 0) {
break;
-int ExpFind (const char* Name)
-/* Check for an identifier in the list. Return -1 if not found, otherwise
- * return the number of the module, that exports the identifer.
+const ObjData* ExpFind (const char* Name)
+/* Check for an identifier in the list. Return NULL if not found, otherwise
+ * return a pointer to the module, that exports the identifer.
*/
{
/* Get a pointer to the list with the symbols hash value */
}
/* Not found */
- return -1;
+ return 0;
}
/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/*****************************************************************************/
-/* Code */
+/* Forwards */
/*****************************************************************************/
-void ExpInsert (const char* Name, unsigned Module);
+struct ObjData;
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+void ExpInsert (const char* Name, const struct ObjData* Module);
/* Insert an exported identifier and check if it's already in the list */
-int ExpFind (const char* Name);
-/* Check for an identifier in the list. Return -1 if not found, otherwise
- * return the number of the module, that exports the identifer.
+const struct ObjData* ExpFind (const char* Name);
+/* Check for an identifier in the list. Return NULL if not found, otherwise
+ * return a pointer to the module, that exports the identifer.
*/
#include <errno.h>
/* common */
-#include "bitops.h"
#include "exprdefs.h"
-#include "filepos.h"
#include "libdefs.h"
#include "print.h"
#include "symdefs.h"
-static void WriteIndexEntry (ObjData* O)
+static void WriteIndexEntry (const ObjData* O)
/* Write one index entry */
{
unsigned I;
static void WriteIndex (void)
/* Write the index of a library file */
{
- ObjData* O;
+ unsigned I;
/* Sync I/O in case the last operation was a read */
fseek (NewLib, 0, SEEK_CUR);
Header.IndexOffs = ftell (NewLib);
/* Write the object file count */
- WriteVar (NewLib, ObjCount);
+ WriteVar (NewLib, CollCount (&ObjPool));
/* Write the object files */
- O = ObjRoot;
- while (O) {
- WriteIndexEntry (O);
- O = O->Next;
+ for (I = 0; I < CollCount (&ObjPool); ++I) {
+ WriteIndexEntry (CollConstAt (&ObjPool, I));
}
}
/* Insert the name into the hash table */
Print (stdout, 1, " %s\n", Name);
- ExpInsert (Name, O->Index);
+ ExpInsert (Name, O);
}
}
unsigned char Buf [4096];
size_t Count;
- /* Index the object files and make an array containing the objects */
- MakeObjPool ();
-
/* Walk through the object file list, inserting exports into the
- * export list checking for duplicates. Copy any data that is still
- * in the old library into the new one.
- */
- for (I = 0; I < ObjCount; ++I) {
+ * export list checking for duplicates. Copy any data that is still
+ * in the old library into the new one.
+ */
+ for (I = 0; I < CollCount (&ObjPool); ++I) {
/* Get a pointer to the object */
- ObjData* O = ObjPool [I];
+ ObjData* O = CollAt (&ObjPool, I);
/* Check exports, make global export table */
LibCheckExports (O);
/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include <stdio.h>
#include <stdlib.h>
+/* ar65 */
#include "error.h"
-#include "objdata.h"
#include "library.h"
#include "list.h"
+#include "objdata.h"
void ListObjFiles (int argc, char* argv [])
/* List modules in a library */
{
- ObjData* O;
+ unsigned I;
+ const ObjData* O;
/* Check the argument count */
if (argc <= 0) {
LibOpen (argv [0], 1, 0);
/* List the modules */
- O = ObjRoot;
- while (O) {
+ for (I = 0; I < CollCount (&ObjPool); ++I) {
+
+ /* Get the entry */
+ O = CollConstAt (&ObjPool, I);
+
+ /* Print the name */
printf ("%s\n", O->Name);
- O = O->Next;
+
}
/* Create a new library file and close the old one */
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
-/* 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;
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->ExportSize = 0;
O->Exports = 0;
- /* Link it into the list */
- if (ObjLast) {
- ObjLast->Next = O;
- ObjLast = O;
- } else {
- /* First entry */
- ObjRoot = ObjLast = O;
- }
-
- /* One object file more now */
- ++ObjCount;
+ /* Add it to the list */
+ CollAppend (&ObjPool, O);
/* Return the new entry */
return O;
* module is not in the list.
*/
{
+ unsigned I;
+
/* Hmm. Maybe we should hash the module names? */
- ObjData* O = ObjRoot;
- while (O) {
+ 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) {
return O;
}
- O = O->Next;
}
return 0;
}
void DelObjData (const char* Module)
/* Delete the object module from the list */
{
- 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;
+ 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;
- }
- Last = O;
- O = O->Next;
+ }
}
/* Not found! */
-void MakeObjPool (void)
-/* Allocate memory, index the entries and make the ObjPool valid */
-{
- 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) {
-
- /* Safety */
- CHECK (Index < ObjCount);
-
- /* Set the Index */
- O->Index = Index;
-
- /* Set the pool pointer */
- ObjPool [Index] = O;
-
- /* Next object */
- ++Index;
- O = O->Next;
- }
-}
-
-
-
-const char* GetObjName (unsigned Index)
-/* Get the name of a module by index */
-{
- PRECONDITION (ObjPool != 0 && Index < ObjCount && ObjPool [Index] != 0);
- return ObjPool [Index]->Name;
-}
-
-
-
const char* GetObjString (const ObjData* O, unsigned Index)
/* Get a string from the string pool of an object file */
{
if (Index >= O->StringCount) {
Error ("Invalid string index (%u) in module `%s'",
- Index, GetObjName (O->Index));
+ Index, O->Name);
}
return O->Strings[Index];
}
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2011, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
+/* common */
+#include "coll.h"
+
+
+
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Internal structure holding object file data */
typedef struct ObjData ObjData;
struct ObjData {
- ObjData* Next; /* Linked list of all objects */
char* Name; /* Module name */
- unsigned Index; /* Module index */
unsigned Flags;
unsigned long MTime; /* Modifiation time of object file */
unsigned long Start; /* Start offset of data in library */
-/* Object data list management */
-extern unsigned ObjCount; /* Count of files in the list */
-extern ObjData* ObjRoot; /* List of object files */
-extern ObjData* ObjLast; /* Last entry in list */
-extern ObjData** ObjPool; /* Object files as array */
+/* Collection with object files */
+extern Collection ObjPool;
void DelObjData (const char* Module);
/* Delete the object module from the list */
-void MakeObjPool (void);
-/* Allocate memory, index the entries and make the ObjPool valid */
-
-const char* GetObjName (unsigned Index);
-/* Get the name of a module by index */
-
const char* GetObjString (const ObjData* O, unsigned Index);
/* Get a string from the string pool of an object file */