1 /*****************************************************************************/
5 /* Internal assembler line structure */
9 /* (C) 2000 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 /*****************************************************************************/
38 #include "../common/xmalloc.h"
39 #include "../common/xsprintf.h"
46 /*****************************************************************************/
48 /*****************************************************************************/
52 /* Number used to index lines */
53 static unsigned long LineIndex = 0;
56 Line* FirstLine = 0; /* Pointer to first line */
57 Line* LastLine = 0; /* Pointer to last line */
61 /*****************************************************************************/
63 /*****************************************************************************/
67 static Line* NewLine (const char* Format, va_list ap)
68 /* Interal routine to create a new line from the given text */
75 /* Make a string from the given format and arguments */
76 xvsprintf (Buf, sizeof (Buf), Format, ap);
78 /* Get the length of the line */
82 L = xmalloc (sizeof (Line) + Len);
84 /* Partially initialize the struct (the remaining fields are initialized
90 memcpy (L->Line, Buf, Len+1);
92 /* Return the new line */
98 Line* NewCodeLine (const char* Format, va_list ap)
99 /* Create a new code line and return it */
101 /* Create a new line struct */
102 Line* L = NewLine (Format, ap);
104 /* Initialize struct fields */
105 L->Index = LineIndex++;
107 /* Insert the line into the list */
108 if (FirstLine == 0) {
109 /* The list is empty */
110 L->Next = L->Prev = 0;
111 FirstLine = LastLine = L;
113 /* There are entries in the list, add the new one at the end */
120 /* Return the new line */
126 Line* NewCodeLineAfter (Line* LineBefore, const char* Format, va_list ap)
127 /* Create a new line, insert it after L and return it. */
129 /* Create a new line struct */
130 Line* L = NewLine (Format, ap);
132 /* Initialize struct fields. We use the same index for the inserted line
133 * as for its predecessor, since we cannot create new numbers on the
134 * fly and the index is only used to determine sort order.
136 L->Index = LineBefore->Index;
138 /* Insert the line after its predecessor */
139 L->Next = LineBefore->Next;
140 LineBefore->Next = L;
141 L->Prev = LineBefore;
145 /* This is the last line */
149 /* Return the new line */
155 void FreeCodeLine (Line* L)
156 /* Remove a line from the list and free it */
158 /* Unlink the line */
160 /* No line before this one */
163 L->Prev->Next = L->Next;
166 /* No line after this one */
169 L->Next->Prev = L->Prev;
172 /* Free the struct */