X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fdataseg.c;h=78b10eb7e340b37cc0667162e09beacc65cdb57c;hb=9ce1e413e4d5a9f48a57b3ce357e71d62281c7c8;hp=72f7828532db504d7154e8b72a6556f3a2edd97f;hpb=cd956115fab586d5a76e4f72a0064a040c3f6fa4;p=cc65 diff --git a/src/cc65/dataseg.c b/src/cc65/dataseg.c index 72f782853..78b10eb7e 100644 --- a/src/cc65/dataseg.c +++ b/src/cc65/dataseg.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -39,36 +39,26 @@ #include "xsprintf.h" /* cc65 */ +#include "error.h" #include "dataseg.h" -/*****************************************************************************/ -/* Data */ -/*****************************************************************************/ - - - -/* Pointer to current data segment */ -DataSeg* DS = 0; - - - /*****************************************************************************/ /* Code */ /*****************************************************************************/ -DataSeg* NewDataSeg (const char* Name) +DataSeg* NewDataSeg (const char* Name, SymEntry* Func) /* Create a new data segment, initialize and return it */ { /* Allocate memory */ - DataSeg* S = xmalloc (sizeof (DataSeg)); + DataSeg* S = xmalloc (sizeof (DataSeg)); /* Initialize the fields */ - S->Next = 0; - S->Name = xstrdup (Name); + S->SegName = xstrdup (Name); + S->Func = Func; InitCollection (&S->Lines); /* Return the new struct */ @@ -77,57 +67,6 @@ DataSeg* NewDataSeg (const char* Name) -void FreeDataSeg (DataSeg* S) -/* Free a data segment including all line entries */ -{ - unsigned I, Count; - - /* Free the name */ - xfree (S->Name); - - /* Free the lines */ - Count = CollCount (&S->Lines); - for (I = 0; I < Count; ++I) { - xfree (CollAt (&S->Lines, I)); - } - - /* Free the collection */ - DoneCollection (&S->Lines); - - /* Free the struct */ - xfree (S); -} - - - -void PushDataSeg (DataSeg* S) -/* Push the given data segment onto the stack */ -{ - /* Push */ - S->Next = DS; - DS = S; -} - - - -DataSeg* PopDataSeg (void) -/* Remove the current data segment from the stack and return it */ -{ - /* Remember the current data segment */ - DataSeg* S = DS; - - /* Cannot pop on empty stack */ - PRECONDITION (S != 0); - - /* Pop */ - DS = S->Next; - - /* Return the popped data segment */ - return S; -} - - - void AppendDataSeg (DataSeg* Target, const DataSeg* Source) /* Append the data from Source to Target */ { @@ -142,16 +81,12 @@ void AppendDataSeg (DataSeg* Target, const DataSeg* Source) -void AddDataSegLine (DataSeg* S, const char* Format, ...) +void AddDataEntry (DataSeg* S, const char* Format, va_list ap) /* Add a line to the given data segment */ { - va_list ap; - char Buf [256]; - /* Format the line */ - va_start (ap, Format); + char Buf [256]; xvsprintf (Buf, sizeof (Buf), Format, ap); - va_end (ap); /* Add a copy to the data segment */ CollAppend (&S->Lines, xstrdup (Buf)); @@ -159,7 +94,7 @@ void AddDataSegLine (DataSeg* S, const char* Format, ...) -void OutputDataSeg (FILE* F, const DataSeg* S) +void OutputDataSeg (const DataSeg* S, FILE* F) /* Output the data segment data to a file */ { unsigned I; @@ -167,10 +102,21 @@ void OutputDataSeg (FILE* F, const DataSeg* S) /* Get the number of entries in this segment */ unsigned Count = CollCount (&S->Lines); + /* If the segment is actually empty, bail out */ + if (Count == 0) { + return; + } + + /* Output the segment directive */ + fprintf (F, ".segment\t\"%s\"\n\n", S->SegName); + /* Output all entries */ for (I = 0; I < Count; ++I) { fprintf (F, "%s\n", (const char*) CollConstAt (&S->Lines, I)); } + + /* Add an additional newline after the segment output */ + fprintf (F, "\n"); }