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 AppendDataSeg (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 AddDataEntry (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 OutputDataSeg (const DataSeg* S, FILE* F)
98 /* Output the data segment data to a file */
102 /* Get the number of entries in this segment */
103 unsigned Count = CollCount (&S->Lines);
105 /* If the segment is actually empty, bail out */
110 /* Output the segment directive */
111 fprintf (F, ".segment\t\"%s\"\n\n", S->SegName);
113 /* Output all entries */
114 for (I = 0; I < Count; ++I) {
115 fprintf (F, "%s\n", (const char*) CollConstAt (&S->Lines, I));
118 /* Add an additional newline after the segment output */