/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2000 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include <string.h>
#include <errno.h>
-#include "../common/libdefs.h"
-#include "../common/symdefs.h"
-#include "../common/exprdefs.h"
-#include "../common/filepos.h"
-#include "../common/bitops.h"
+/* common */
+#include "bitops.h"
+#include "exprdefs.h"
+#include "filepos.h"
+#include "libdefs.h"
+#include "print.h"
+#include "symdefs.h"
+#include "xmalloc.h"
-#include "mem.h"
+/* ar65 */
#include "error.h"
#include "global.h"
#include "fileio.h"
/* The library header */
static LibHeader Header = {
LIB_MAGIC,
- LIB_VERSION
+ LIB_VERSION,
+ 0, 0
};
/* Exports */
O->ExportSize = Read16 (Lib);
- O->Exports = Xmalloc (O->ExportSize);
+ O->Exports = xmalloc (O->ExportSize);
ReadData (Lib, O->Exports, O->ExportSize);
/* Imports */
O->ImportSize = Read16 (Lib);
- O->Imports = Xmalloc (O->ImportSize);
+ O->Imports = xmalloc (O->ImportSize);
ReadData (Lib, O->Imports, O->ImportSize);
}
*/
{
/* Remember the name */
- LibName = StrDup (Name);
+ LibName = xstrdup (Name);
/* Open the existing library for reading */
Lib = fopen (Name, "rb");
+static unsigned long GetVar (unsigned char** Buf)
+/* Get a variable sized value from Buf */
+{
+ unsigned char C;
+ unsigned long V = 0;
+ unsigned Shift = 0;
+ do {
+ /* Read one byte */
+ C = **Buf;
+ ++(*Buf);
+ /* Add this char to the value */
+ V |= ((unsigned long)(C & 0x7F)) << Shift;
+ /* Next value */
+ Shift += 7;
+ } while (C & 0x80);
+
+ /* Return the result */
+ return V;
+}
+
+
+
static void SkipExpr (unsigned char** Buf)
/* Skip an expression in Buf */
{
*Buf += 2;
return;
- case EXPR_SEGMENT:
+ case EXPR_SECTION:
/* 8 bit segment number */
*Buf += 1;
return;
+static void SkipFilePos (unsigned char** Buf)
+/* Skip a file position in Buf */
+{
+ (void) GetVar (Buf); /* Line */
+ (void) GetVar (Buf); /* Col */
+ (void) GetVar (Buf); /* Name */
+}
+
+
+
static void LibCheckExports (ObjData* O)
/* Insert all exports from the given object file into the global list
* checking for duplicates.
*/
{
- char Name [256];
-
/* Get a pointer to the buffer */
unsigned char* Exports = O->Exports;
- /* First two bytes are export count */
- unsigned Lo = *Exports++;
- unsigned Hi = *Exports++;
- unsigned Count = (Hi << 8) + Lo;
+ /* Get the export count */
+ 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 Len;
+ unsigned char Tag;
+ unsigned Len;
+ char* Name;
/* Get the export tag */
- unsigned char Tag = *Exports++;
+ Tag = *Exports++;
+
+ /* condes decls may follow */
+ Exports += GET_EXP_CONDES_COUNT (Tag);
/* Next thing is name of symbol */
- Len = *Exports++;
+ Len = GetVar (&Exports);
+ Name = xmalloc (Len + 1);
memcpy (Name, Exports, Len);
Name [Len] = '\0';
Exports += Len;
}
/* Skip the position */
- Exports += POS_SIZE;
+ 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);
}
}