]> git.sur5r.net Git - cc65/blobdiff - src/ca65/listing.c
Reverted r5835 because of Olivers changes to the asm includes.
[cc65] / src / ca65 / listing.c
index ad97d4b509b4effd0ec89d4675aa9440b8235dc2..4994f690fc0472cd10cdf5877e739d9e3abece53 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2007 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2000-2011, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -41,6 +41,7 @@
 #include "check.h"
 #include "fname.h"
 #include "fragdefs.h"
+#include "strbuf.h"
 #include "version.h"
 #include "xmalloc.h"
 
@@ -81,19 +82,19 @@ static int          ListingEnabled = 1;     /* Enabled if > 0 */
 
 
 
-void NewListingLine (const char* Line, unsigned char File, unsigned char Depth)
+void NewListingLine (const StrBuf* Line, unsigned char File, unsigned char Depth)
 /* Create a new ListLine struct and insert it */
 {
     /* Store only if listing is enabled */
-    if (Listing) {
+    if (SB_GetLen (&ListingName) > 0) {
 
        ListLine* L;
 
        /* Get the length of the line */
-       unsigned Len = strlen (Line);
+       unsigned Len = SB_GetLen (Line);
 
        /* Ignore trailing newlines */
-       while (Len > 0 && Line[Len-1] == '\n') {
+       while (Len > 0 && SB_AtUnchecked (Line, Len-1) == '\n') {
            --Len;
        }
 
@@ -110,8 +111,8 @@ void NewListingLine (const char* Line, unsigned char File, unsigned char Depth)
        L->Depth        = Depth;
        L->Output       = (ListingEnabled > 0);
        L->ListBytes    = (unsigned char) ListBytes;
-       memcpy (L->Line, Line, Len);
-       L->Line [Len] = '\0';
+       memcpy (L->Line, SB_GetConstBuf (Line), Len);
+               L->Line[Len] = '\0';
 
        /* Insert the line into the list of lines */
        if (LineList == 0) {
@@ -128,7 +129,7 @@ void NewListingLine (const char* Line, unsigned char File, unsigned char Depth)
 void EnableListing (void)
 /* Enable output of lines to the listing */
 {
-    if (Listing) {
+    if (SB_GetLen (&ListingName) > 0) {
        /* If we're about to enable the listing, do this for the current line
         * also, so we will see the source line that did this.
         */
@@ -143,7 +144,7 @@ void EnableListing (void)
 void DisableListing (void)
 /* Disable output of lines to the listing */
 {
-    if (Listing) {
+    if (SB_GetLen (&ListingName) > 0) {
        if (ListingEnabled == 0) {
            /* Cannot switch the listing off once more */
            Error ("Counter underflow");
@@ -169,7 +170,7 @@ void SetListBytes (int Bytes)
 void InitListingLine (void)
 /* Initialize the current listing line */
 {
-    if (Listing) {
+    if (SB_GetLen (&ListingName) > 0) {
        /* Make the last loaded line the current line */
        /* ###### This code is a hack! We really need to do it right
         * as soon as we know, how:-(
@@ -219,16 +220,18 @@ static void PrintPageHeader (FILE* F, const ListLine* L)
  * last line of the previous page.
  */
 {
+    /* Gte a pointer to the current input file */
+    const StrBuf* CurFile = GetFileName (L->File);
+
     /* Print the header on the new page */
     fprintf (F,
-            "ca65 V%u.%u.%u - %s\n"
+                    "ca65 V%s - %s\n"
             "Main file   : %s\n"
-            "Current file: %s\n"
+            "Current file: %.*s\n"
             "\n",
-            VER_MAJOR, VER_MINOR, VER_PATCH,
-             Copyright,
+            GetVersionAsString (), Copyright,
             InFile,
-            GetFileName (L->File));
+            (int) SB_GetLen (CurFile), SB_GetConstBuf (CurFile));
 
     /* Count pages, reset lines */
     ++PageNumber;
@@ -298,15 +301,12 @@ void CreateListing (void)
     ListLine* L;
     char HeaderBuf [LINE_HEADER_LEN+1];
 
-    /* Create the name of the listing file if needed */
-    if (ListFile == 0) {
-       ListFile = MakeFilename (InFile, ListExt);
-    }
-
     /* Open the real listing file */
-    F = fopen (ListFile, "w");
+    F = fopen (SB_GetConstBuf (&ListingName), "w");
     if (F == 0) {
-       Fatal ("Cannot open listing file: %s", strerror (errno));
+       Fatal ("Cannot open listing file `%s': %s",
+               SB_GetConstBuf (&ListingName),
+               strerror (errno));
     }
 
     /* Reset variables, print the header for the first page */