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 /*****************************************************************************/
44 /*****************************************************************************/
46 /*****************************************************************************/
50 /* Number used to index lines */
51 static unsigned long LineIndex = 0;
54 Line* FirstLine = 0; /* Pointer to first line */
55 Line* LastLine = 0; /* Pointer to last line */
59 /*****************************************************************************/
61 /*****************************************************************************/
65 static Line* NewLine (const char* Format, va_list ap)
66 /* Interal routine to create a new line from the given text */
74 /* Make a string from the given format and arguments */
75 #if defined(__WATCOMC__)
76 OVF = (_vbprintf (Buf, sizeof (Buf), Format, ap) >= sizeof (S));
78 /* Assume gcc running on a Unix OS */
79 OVF = (vsnprintf (Buf, sizeof (Buf), Format, ap) < 0);
82 Internal ("String size overflow");
85 /* Get the length of the line */
89 L = xmalloc (sizeof (Line) + Len);
91 /* Partially initialize the struct (the remaining fields are initialized
97 memcpy (L->Line, Buf, Len+1);
99 /* Return the new line */
105 Line* NewCodeLine (const char* Format, va_list ap)
106 /* Create a new code line and return it */
108 /* Create a new line struct */
109 Line* L = NewLine (Format, ap);
111 /* Initialize struct fields */
112 L->Index = LineIndex++;
114 /* Insert the line into the list */
115 if (FirstLine == 0) {
116 /* The list is empty */
117 L->Next = L->Prev = 0;
118 FirstLine = LastLine = L;
120 /* There are entries in the list, add the new one at the end */
127 /* Return the new line */
133 Line* NewCodeLineAfter (Line* LineBefore, const char* Format, va_list ap)
134 /* Create a new line, insert it after L and return it. */
136 /* Create a new line struct */
137 Line* L = NewLine (Format, ap);
139 /* Initialize struct fields. We use the same index for the inserted line
140 * as for its predecessor, since we cannot create new numbers on the
141 * fly and the index is only used to determine sort order.
143 L->Index = LineBefore->Index;
145 /* Insert the line after its predecessor */
146 L->Next = LineBefore->Next;
147 LineBefore->Next = L;
148 L->Prev = LineBefore;
152 /* This is the last line */
156 /* Return the new line */
162 void FreeCodeLine (Line* L)
163 /* Remove a line from the list and free it */
165 /* Unlink the line */
167 /* No line before this one */
170 L->Prev->Next = L->Next;
173 /* No line after this one */
176 L->Next->Prev = L->Prev;
179 /* Free the struct */