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 /*****************************************************************************/
49 /*****************************************************************************/
51 /*****************************************************************************/
55 /* Number used to index lines */
56 static unsigned long LineIndex = 0;
59 Line* FirstLine = 0; /* Pointer to first line */
60 Line* LastLine = 0; /* Pointer to last line */
64 /*****************************************************************************/
66 /*****************************************************************************/
70 static Line* NewLine (const char* Format, va_list ap)
71 /* Interal routine to create a new line from the given text */
78 /* Make a string from the given format and arguments */
79 xvsprintf (Buf, sizeof (Buf), Format, ap);
81 /* Get the length of the line */
85 L = xmalloc (sizeof (Line) + Len);
87 /* Partially initialize the struct (the remaining fields are initialized
93 memcpy (L->Line, Buf, Len+1);
95 /* Return the new line */
101 Line* NewCodeLine (const char* Format, va_list ap)
102 /* Create a new code line and return it */
104 /* Create a new line struct */
105 Line* L = NewLine (Format, ap);
107 /* Initialize struct fields */
108 L->Index = LineIndex++;
110 /* Insert the line into the list */
111 if (FirstLine == 0) {
112 /* The list is empty */
113 L->Next = L->Prev = 0;
114 FirstLine = LastLine = L;
116 /* There are entries in the list, add the new one at the end */
123 /* Return the new line */
129 Line* NewCodeLineAfter (Line* LineBefore, const char* Format, va_list ap)
130 /* Create a new line, insert it after L and return it. */
132 /* Create a new line struct */
133 Line* L = NewLine (Format, ap);
135 /* Initialize struct fields. We use the same index for the inserted line
136 * as for its predecessor, since we cannot create new numbers on the
137 * fly and the index is only used to determine sort order.
139 L->Index = LineBefore->Index;
141 /* Insert the line after its predecessor */
142 L->Next = LineBefore->Next;
143 LineBefore->Next = L;
144 L->Prev = LineBefore;
148 /* This is the last line */
152 /* Return the new line */
158 void FreeCodeLine (Line* L)
159 /* Remove a line from the list and free it */
161 /* Unlink the line */
163 /* No line before this one */
166 L->Prev->Next = L->Next;
169 /* No line after this one */
172 L->Next->Prev = L->Prev;
175 /* Free the struct */