/* */
/* */
/* */
-/* (C) 1998-2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2010, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include "exprdefs.h"
#include "filepos.h"
#include "libdefs.h"
+#include "print.h"
#include "symdefs.h"
#include "xmalloc.h"
/* The library header */
static LibHeader Header = {
LIB_MAGIC,
- LIB_VERSION
+ LIB_VERSION,
+ 0,
+ 0
};
static void ReadIndexEntry (void)
/* Read one entry in the index */
{
+ unsigned I;
+
/* Create a new entry and insert it into the list */
ObjData* O = NewObjData ();
O->Start = Read32 (Lib);
O->Size = Read32 (Lib);
- /* Exports */
- O->ExportSize = Read16 (Lib);
- O->Exports = xmalloc (O->ExportSize);
- ReadData (Lib, O->Exports, O->ExportSize);
+ /* Strings */
+ O->StringCount = ReadVar (Lib);
+ O->Strings = xmalloc (O->StringCount * sizeof (char*));
+ for (I = 0; I < O->StringCount; ++I) {
+ O->Strings[I] = ReadStr (Lib);
+ }
/* Imports */
- O->ImportSize = Read16 (Lib);
+ O->ImportSize = ReadVar (Lib);
O->Imports = xmalloc (O->ImportSize);
ReadData (Lib, O->Imports, O->ImportSize);
+
+ /* Exports */
+ O->ExportSize = ReadVar (Lib);
+ O->Exports = xmalloc (O->ExportSize);
+ ReadData (Lib, O->Exports, O->ExportSize);
}
fseek (Lib, Header.IndexOffs, SEEK_SET);
/* Read the object file count and calculate the cross ref size */
- Count = Read16 (Lib);
+ Count = ReadVar (Lib);
/* Read all entries in the index */
while (Count--) {
static void WriteIndexEntry (ObjData* O)
/* Write one index entry */
{
+ unsigned I;
+
/* Module name/flags/MTime/start/size */
WriteStr (NewLib, O->Name);
Write16 (NewLib, O->Flags & ~OBJ_HAVEDATA);
Write32 (NewLib, O->Start);
Write32 (NewLib, O->Size);
- /* Exports */
- Write16 (NewLib, O->ExportSize);
- WriteData (NewLib, O->Exports, O->ExportSize);
+ /* Strings */
+ WriteVar (NewLib, O->StringCount);
+ for (I = 0; I < O->StringCount; ++I) {
+ WriteStr (NewLib, O->Strings[I]);
+ }
/* Imports */
- Write16 (NewLib, O->ImportSize);
+ WriteVar (NewLib, O->ImportSize);
WriteData (NewLib, O->Imports, O->ImportSize);
+
+ /* Exports */
+ WriteVar (NewLib, O->ExportSize);
+ WriteData (NewLib, O->Exports, O->ExportSize);
}
Header.IndexOffs = ftell (NewLib);
/* Write the object file count */
- Write16 (NewLib, ObjCount);
+ WriteVar (NewLib, ObjCount);
/* Write the object files */
O = ObjRoot;
return;
case EXPR_SYMBOL:
- /* 16 bit symbol index */
- *Buf += 2;
+ /* Variable seized symbol index */
+ (void) GetVar (Buf);
return;
- case EXPR_SEGMENT:
+ case EXPR_SECTION:
/* 8 bit segment number */
*Buf += 1;
return;
}
/* What's left are unary and binary nodes */
- SkipExpr (Buf); /* Skip left */
- SkipExpr (Buf); /* Skip right */
+ SkipExpr (Buf); /* Skip left */
+ SkipExpr (Buf); /* Skip right */
}
unsigned Count = GetVar (&Exports);
/* Read the exports */
- if (Verbose > 1) {
- printf ("Module `%s' (%u exports):\n", O->Name, Count);
- }
+ Print (stdout, 1, "Module `%s' (%u exports):\n", O->Name, Count);
while (Count--) {
-
- unsigned char Tag;
- unsigned Len;
- char* Name;
- /* Get the export tag */
- Tag = *Exports++;
+ const char* Name;
+
+ /* Get the export tag and skip the address size */
+ unsigned Type = GetVar (&Exports);
+ ++Exports;
/* condes decls may follow */
- Exports += GET_EXP_CONDES_COUNT (Tag);
+ Exports += SYM_GET_CONDES_COUNT (Type);
- /* Next thing is name of symbol */
- Len = GetVar (&Exports);
- Name = xmalloc (Len + 1);
- memcpy (Name, Exports, Len);
- Name [Len] = '\0';
- Exports += Len;
+ /* Next thing is index of name of symbol */
+ Name = GetObjString (O, GetVar (&Exports));
/* Skip value of symbol */
- if (Tag & EXP_EXPR) {
+ if (SYM_IS_EXPR (Type)) {
/* Expression tree */
SkipExpr (&Exports);
} else {
SkipFilePos (&Exports);
/* Insert the name into the hash table */
- if (Verbose > 1) {
- printf (" %s\n", Name);
- }
+ Print (stdout, 1, " %s\n", Name);
ExpInsert (Name, O->Index);
-
- /* Free the name */
- xfree (Name);
}
}