]> git.sur5r.net Git - cc65/blobdiff - src/ca65/listing.c
New module strstack
[cc65] / src / ca65 / listing.c
index 8177c6e15779fbd71e97194b1fdc048367df0939..f18ac5910994aff6499e37dc65f2c9b57779feda 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-2003 Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #include <string.h>
 #include <errno.h>
 
-#include "../common/segdefs.h"
-#include "../common/version.h"
+/* common */
+#include "check.h"
+#include "fname.h"
+#include "fragdefs.h"
+#include "version.h"
+#include "xmalloc.h"
 
+/* ca65 */
 #include "error.h"
-#include "fname.h"
+#include "filetab.h"
 #include "global.h"
-#include "mem.h"
-#include "objcode.h"
 #include "listing.h"
+#include "segment.h"
 
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                  Data                                    */
 /*****************************************************************************/
 
 
@@ -63,7 +67,7 @@ ListLine*       LineLast = 0;         /* Last (current) listing line */
 /* Page and other formatting */
 int                    PageLength = -1;        /* Length of a listing page */
 static unsigned        PageNumber = 1;         /* Current listing page number */
-static unsigned PageLines  = 0;                /* Current line on page */
+static int      PageLines  = 0;                /* Current line on page */
 static unsigned ListBytes  = 12;       /* Number of bytes to list for one line */
 
 /* Switch the listing on/off */
@@ -94,7 +98,7 @@ void NewListingLine (const char* Line, unsigned char File, unsigned char Depth)
        }
 
        /* Allocate memory */
-       L = Xmalloc (sizeof (ListLine) + Len);
+       L = xmalloc (sizeof (ListLine) + Len);
 
        /* Initialize the fields. */
        L->Next         = 0;
@@ -142,7 +146,7 @@ void DisableListing (void)
     if (Listing) {
        if (ListingEnabled == 0) {
            /* Cannot switch the listing off once more */
-           Error (ERR_COUNTER_UNDERFLOW);
+           Error ("Counter underflow");
        } else {
            --ListingEnabled;
        }
@@ -167,13 +171,28 @@ void InitListingLine (void)
 {
     if (Listing) {
        /* Make the last loaded line the current line */
-       LineCur = LineLast;
+       /* ###### This code is a hack! We really need to do it right
+        * as soon as we know, how:-(
+        */
+               if (LineCur && LineCur->Next && LineCur->Next != LineLast) {
+           ListLine* L = LineCur;
+           do {
+               L = L->Next;
+               /* Set the values for this line */
+               CHECK (L != 0);
+               L->PC            = GetPC ();
+               L->Reloc         = RelocMode;
+               L->Output        = (ListingEnabled > 0);
+               L->ListBytes = (unsigned char) ListBytes;
+           } while (L->Next != LineLast);
+       }
+       LineCur = LineLast;
 
-       /* Set the values for this line */
-       CHECK (LineCur != 0);
-       LineCur->PC         = GetPC ();
-       LineCur->Reloc      = RelocMode;
-       LineCur->Output     = (ListingEnabled > 0);
+       /* Set the values for this line */
+       CHECK (LineCur != 0);
+       LineCur->PC         = GetPC ();
+       LineCur->Reloc      = RelocMode;
+       LineCur->Output     = (ListingEnabled > 0);
                LineCur->ListBytes  = (unsigned char) ListBytes;
     }
 }
@@ -201,12 +220,13 @@ static void PrintPageHeader (FILE* F, const ListLine* L)
  */
 {
     /* Print the header on the new page */
-    fprintf (F, 
-            "ca65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n"
+    fprintf (F,
+            "ca65 V%u.%u.%u - %s\n"
             "Main file   : %s\n"
             "Current file: %s\n"
             "\n",
             VER_MAJOR, VER_MINOR, VER_PATCH,
+             Copyright,
             InFile,
             GetFileName (L->File));
 
@@ -286,7 +306,7 @@ void CreateListing (void)
     /* Open the real listing file */
     F = fopen (ListFile, "w");
     if (F == 0) {
-       Fatal (FAT_CANNOT_OPEN_LISTING, strerror (errno));
+       Fatal ("Cannot open listing file: %s", strerror (errno));
     }
 
     /* Reset variables, print the header for the first page */
@@ -328,7 +348,7 @@ void CreateListing (void)
        }
 
        /* Allocate memory for the given number of bytes */
-       Buf = Xmalloc (Count*2+1);
+       Buf = xmalloc (Count*2+1);
 
        /* Copy an ASCII representation of the bytes into the buffer */
        B = Buf;
@@ -345,7 +365,7 @@ void CreateListing (void)
                    break;
 
                case FRAG_EXPR:
-               case FRAG_SEXPR:
+               case FRAG_SEXPR:
                    B = AddMult (B, 'r', Frag->Len*2);
                    break;
 
@@ -422,7 +442,7 @@ void CreateListing (void)
        }
 
        /* Delete the temporary buffer */
-       Xfree (Buf);
+       xfree (Buf);
 
        /* Next line */
        L = L->Next;