1 /* $Id: textlist.c,v 1.6 2003/04/07 16:27:11 ukai Exp $ */
7 /* General doubly linked list */
10 newListItem(void *s, ListItem *n, ListItem *p)
23 GeneralList *tl = New(GeneralList);
24 tl->first = tl->last = NULL;
30 pushValue(GeneralList *tl, void *s)
35 it = newListItem(s, NULL, tl->last);
36 if (tl->first == NULL) {
49 popValue(GeneralList *tl)
53 if (tl == NULL || tl->first == NULL)
58 tl->first->prev = NULL;
66 rpopValue(GeneralList *tl)
70 if (tl == NULL || tl->last == NULL)
75 tl->last->next = NULL;
83 delValue(GeneralList *tl, ListItem *it)
86 it->prev->next = it->next;
90 it->next->prev = it->prev;
97 appendGeneralList(GeneralList *tl, GeneralList *tl2)
102 tl->last->next = tl2->first;
103 tl2->first->prev = tl->last;
104 tl->last = tl2->last;
105 tl->nitem += tl2->nitem;
108 tl->first = tl2->first;
109 tl->last = tl2->last;
110 tl->nitem = tl2->nitem;
113 tl2->first = tl2->last = NULL;
124 newTextLine(Str line, int pos)
126 TextLine *lbuf = New(TextLine);
130 lbuf->line = Strnew();
136 appendTextLine(TextLineList *tl, Str line, int pos)
140 if (tl->last == NULL) {
141 pushTextLine(tl, newTextLine(Strdup(line), pos));
144 lbuf = tl->last->ptr;
146 Strcat(lbuf->line, line);