X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fdataseg.c;h=ebb033cbc2058515dcf07ea61e7cdf88dbac7743;hb=05f72963695f843cca3fd3dac1be0175b470b179;hp=72f7828532db504d7154e8b72a6556f3a2edd97f;hpb=cd956115fab586d5a76e4f72a0064a040c3f6fa4;p=cc65 diff --git a/src/cc65/dataseg.c b/src/cc65/dataseg.c index 72f782853..ebb033cbc 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-2009, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -40,17 +40,8 @@ /* cc65 */ #include "dataseg.h" - - - -/*****************************************************************************/ -/* Data */ -/*****************************************************************************/ - - - -/* Pointer to current data segment */ -DataSeg* DS = 0; +#include "error.h" +#include "output.h" @@ -60,15 +51,15 @@ DataSeg* DS = 0; -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,58 +68,7 @@ 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) +void DS_Append (DataSeg* Target, const DataSeg* Source) /* Append the data from Source to Target */ { unsigned I; @@ -142,16 +82,12 @@ void AppendDataSeg (DataSeg* Target, const DataSeg* Source) -void AddDataSegLine (DataSeg* S, const char* Format, ...) +void DS_AddVLine (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,19 +95,42 @@ void AddDataSegLine (DataSeg* S, const char* Format, ...) -void OutputDataSeg (FILE* F, const DataSeg* S) -/* Output the data segment data to a file */ +void DS_AddLine (DataSeg* S, const char* Format, ...) +/* Add a line to the given data segment */ +{ + va_list ap; + va_start (ap, Format); + DS_AddVLine (S, Format, ap); + va_end (ap); +} + + + +void DS_Output (const DataSeg* S) +/* Output the data segment data to the output file */ { unsigned I; /* 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 */ + WriteOutput (".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)); + WriteOutput ("%s\n", (const char*) CollConstAt (&S->Lines, I)); } + + /* Add an additional newline after the segment output */ + WriteOutput ("\n"); } +