1 /*****************************************************************************/
5 /* Data segment structure */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
47 /*****************************************************************************/
49 /*****************************************************************************/
53 DataSeg* NewDataSeg (const char* Name, SymEntry* Func)
54 /* Create a new data segment, initialize and return it */
57 DataSeg* S = xmalloc (sizeof (DataSeg));
59 /* Initialize the fields */
60 S->SegName = xstrdup (Name);
62 InitCollection (&S->Lines);
64 /* Return the new struct */
70 void DS_Append (DataSeg* Target, const DataSeg* Source)
71 /* Append the data from Source to Target */
75 /* Append all lines from Source to Target */
76 unsigned Count = CollCount (&Source->Lines);
77 for (I = 0; I < Count; ++I) {
78 CollAppend (&Target->Lines, xstrdup (CollConstAt (&Source->Lines, I)));
84 void DS_AddVLine (DataSeg* S, const char* Format, va_list ap)
85 /* Add a line to the given data segment */
89 xvsprintf (Buf, sizeof (Buf), Format, ap);
91 /* Add a copy to the data segment */
92 CollAppend (&S->Lines, xstrdup (Buf));
97 void DS_AddLine (DataSeg* S, const char* Format, ...)
98 /* Add a line to the given data segment */
101 va_start (ap, Format);
102 DS_AddVLine (S, Format, ap);
108 void DS_Output (const DataSeg* S, FILE* F)
109 /* Output the data segment data to a file */
113 /* Get the number of entries in this segment */
114 unsigned Count = CollCount (&S->Lines);
116 /* If the segment is actually empty, bail out */
121 /* Output the segment directive */
122 fprintf (F, ".segment\t\"%s\"\n\n", S->SegName);
124 /* Output all entries */
125 for (I = 0; I < Count; ++I) {
126 fprintf (F, "%s\n", (const char*) CollConstAt (&S->Lines, I));
129 /* Add an additional newline after the segment output */