]> git.sur5r.net Git - cc65/blobdiff - src/ca65/objfile.c
The line counter got confused for lines with more than 256 chars. Removed the
[cc65] / src / ca65 / objfile.c
index c8859f5fc61dc95d8645d1b53fef064b489d8767..f9fba1521141de0c06e30920ad7acf52e4217392 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2001 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
@@ -63,9 +63,29 @@ static FILE* F = 0;
 
 /* Header structure */
 static ObjHeader Header = {
-    OBJ_MAGIC,
-    OBJ_VERSION,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+    OBJ_MAGIC,          /* 32: Magic number */
+    OBJ_VERSION,        /* 16: Version number */
+    0,                  /* 16: flags */
+    0,                  /* 32: Offset to option table */
+    0,                  /* 32: Size of options */
+    0,                  /* 32: Offset to file table */
+    0,                  /* 32: Size of files */
+    0,                  /* 32: Offset to segment table */
+    0,                  /* 32: Size of segment table */
+    0,                  /* 32: Offset to import list */
+    0,                  /* 32: Size of import list */
+    0,                  /* 32: Offset to export list */
+    0,                  /* 32: Size of export list */
+    0,                  /* 32: Offset to list of debug symbols */
+    0,                  /* 32: Size of debug symbols */
+    0,                  /* 32: Offset to list of line infos */
+    0,                  /* 32: Size of line infos */
+    0,                  /* 32: Offset to string pool */
+    0,                  /* 32: Size of string pool */
+    0,                  /* 32: Offset to assertion table */
+    0,                  /* 32: Size of assertion table */
+    0,                  /* 32: Offset into scope table */
+    0,                  /* 32: Size of scope table */
 };
 
 
@@ -91,7 +111,7 @@ static void ObjWriteError (void)
     remove (OutFile);
 
     /* Now abort with a fatal error */
-    Fatal (FAT_CANNOT_WRITE_OUTPUT, OutFile, strerror (Error));
+    Fatal ("Cannot write to output file `%s': %s", OutFile, strerror (Error));
 }
 
 
@@ -116,6 +136,12 @@ static void ObjWriteHeader (void)
     ObjWrite32 (Header.DbgSymSize);
     ObjWrite32 (Header.LineInfoOffs);
     ObjWrite32 (Header.LineInfoSize);
+    ObjWrite32 (Header.StrPoolOffs);
+    ObjWrite32 (Header.StrPoolSize);
+    ObjWrite32 (Header.AssertOffs);
+    ObjWrite32 (Header.AssertSize);
+    ObjWrite32 (Header.ScopeOffs);
+    ObjWrite32 (Header.ScopeSize);
 }
 
 
@@ -140,7 +166,7 @@ void ObjOpen (void)
     /* Create the output file */
     F = fopen (OutFile, "w+b");
     if (F == 0) {
-       Fatal (FAT_CANNOT_OPEN_OUTPUT, OutFile, strerror (errno));
+       Fatal ("Cannot open output file `%s': %s", OutFile, strerror (errno));
     }
 
     /* Write a dummy header */
@@ -173,6 +199,28 @@ void ObjClose (void)
 
 
 
+unsigned long ObjGetFilePos (void)
+/* Get the current file position */
+{
+    long Pos = ftell (F);
+    if (Pos < 0) {
+        ObjWriteError ();
+    }
+    return Pos;
+}
+
+
+
+void ObjSetFilePos (unsigned long Pos)
+/* Set the file position */
+{
+    if (fseek (F, Pos, SEEK_SET) != 0) {
+        ObjWriteError ();
+    }
+}
+
+
+
 void ObjWrite8 (unsigned V)
 /* Write an 8 bit value to the file */
 {
@@ -248,6 +296,19 @@ void ObjWriteStr (const char* S)
 
 
 
+void ObjWriteBuf (const StrBuf* S)
+/* Write a string to the object file */
+{
+    /* Write the string with the length preceeded (this is easier for
+     * the reading routine than the C format since the length is known in
+     * advance).
+     */
+    ObjWriteVar (SB_GetLen (S));
+    ObjWriteData (SB_GetConstBuf (S), SB_GetLen (S));    
+}
+
+
+
 void ObjWriteData (const void* Data, unsigned Size)
 /* Write literal data to the file */
 {
@@ -386,3 +447,51 @@ void ObjEndLineInfos (void)
 
 
 
+void ObjStartStrPool (void)
+/* Mark the start of the string pool section */
+{
+    Header.StrPoolOffs = ftell (F);
+}
+
+
+
+void ObjEndStrPool (void)
+/* Mark the end of the string pool section */
+{
+    Header.StrPoolSize = ftell (F) - Header.StrPoolOffs;
+}
+
+
+
+void ObjStartAssertions (void)
+/* Mark the start of the assertion table */
+{
+    Header.AssertOffs = ftell (F);
+}
+
+
+
+void ObjEndAssertions (void)
+/* Mark the end of the assertion table */
+{
+    Header.AssertSize = ftell (F) - Header.AssertOffs;
+}
+
+
+
+void ObjStartScopes (void)
+/* Mark the start of the scope table */
+{
+    Header.ScopeOffs = ftell (F);
+}
+
+
+
+void ObjEndScopes (void)
+/* Mark the end of the scope table */
+{
+    Header.ScopeSize = ftell (F) - Header.ScopeOffs;
+}
+
+
+