1 /*****************************************************************************/
5 /* Data segment structure */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 FreeDataSeg (DataSeg* S)
71 /* Free a data segment including all line entries */
73 Internal ("Not implemented");
78 void AppendDataSeg (DataSeg* Target, const DataSeg* Source)
79 /* Append the data from Source to Target */
83 /* Append all lines from Source to Target */
84 unsigned Count = CollCount (&Source->Lines);
85 for (I = 0; I < Count; ++I) {
86 CollAppend (&Target->Lines, xstrdup (CollConstAt (&Source->Lines, I)));
92 void AddDataEntry (DataSeg* S, const char* Format, va_list ap)
93 /* Add a line to the given data segment */
97 xvsprintf (Buf, sizeof (Buf), Format, ap);
99 /* Add a copy to the data segment */
100 CollAppend (&S->Lines, xstrdup (Buf));
105 void OutputDataSeg (const DataSeg* S, FILE* F)
106 /* Output the data segment data to a file */
110 /* Get the number of entries in this segment */
111 unsigned Count = CollCount (&S->Lines);
113 /* If the segment is actually empty, bail out */
118 /* Output the segment directive */
119 fprintf (F, ".segment\t\"%s\"\n\n", S->SegName);
121 /* Output all entries */
122 for (I = 0; I < Count; ++I) {
123 fprintf (F, "%s\n", (const char*) CollConstAt (&S->Lines, I));
126 /* Add an additional newline after the segment output */