]> git.sur5r.net Git - cc65/blobdiff - src/ar65/library.c
Allow to set the ProDOS type and auxtype on creating new files in a similiar way...
[cc65] / src / ar65 / library.c
index 21b9f072e429dcdba48997453d24ccad1fbf60c5..8eb178788025b3ec051fef04844d35dc061f9c60 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (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       */
@@ -42,6 +42,7 @@
 #include "exprdefs.h"
 #include "filepos.h"
 #include "libdefs.h"
+#include "print.h"
 #include "symdefs.h"
 #include "xmalloc.h"
 
@@ -69,7 +70,9 @@ static const char*    LibName = 0;
 /* The library header */
 static LibHeader               Header = {
     LIB_MAGIC,
-    LIB_VERSION
+    LIB_VERSION,
+    0,
+    0
 };
 
 
@@ -104,6 +107,8 @@ static void ReadHeader (void)
 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 ();
 
@@ -114,15 +119,22 @@ static void ReadIndexEntry (void)
     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);
 }
 
 
@@ -136,7 +148,7 @@ static void ReadIndex (void)
     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--) {
@@ -170,6 +182,8 @@ static void WriteHeader (void)
 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);
@@ -177,13 +191,19 @@ static void WriteIndexEntry (ObjData* O)
     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);
 }
 
 
@@ -200,7 +220,7 @@ static void WriteIndex (void)
     Header.IndexOffs = ftell (NewLib);
 
     /* Write the object file count */
-    Write16 (NewLib, ObjCount);
+    WriteVar (NewLib, ObjCount);
 
     /* Write the object files */
     O = ObjRoot;
@@ -346,19 +366,19 @@ static void SkipExpr (unsigned char** Buf)
            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 */
 }
 
 
@@ -385,30 +405,23 @@ static void LibCheckExports (ObjData* O)
     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 {
@@ -420,13 +433,8 @@ static void LibCheckExports (ObjData* O)
                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);
     }
 }