1 /* $Id: textlist.h,v 1.6 2003/01/20 15:30:22 ukai Exp $ */
2 #ifndef TEXTLIST_H
3 #define TEXTLIST_H
4 #include "Str.h"
5 #include <limits.h>
6 #define GENERAL_LIST_MAX (INT_MAX / 32)
7 
8 /* General doubly linked list */
9 
10 typedef struct _listitem {
11     void *ptr;
12     struct _listitem *next;
13     struct _listitem *prev;
14 } ListItem;
15 
16 typedef struct _generallist {
17     ListItem *first;
18     ListItem *last;
19     int nitem;
20 } GeneralList;
21 
22 extern ListItem *newListItem(void *s, ListItem *n, ListItem *p);
23 extern GeneralList *newGeneralList(void);
24 extern void pushValue(GeneralList *tl, void *s);
25 extern void *popValue(GeneralList *tl);
26 extern void *rpopValue(GeneralList *tl);
27 extern void delValue(GeneralList *tl, ListItem *it);
28 extern GeneralList *appendGeneralList(GeneralList *, GeneralList *);
29 
30 /* Text list */
31 
32 typedef struct _textlistitem {
33     char *ptr;
34     struct _textlistitem *next;
35     struct _textlistitem *prev;
36 } TextListItem;
37 
38 typedef struct _textlist {
39     TextListItem *first;
40     TextListItem *last;
41     int nitem;
42 } TextList;
43 
44 #define newTextList() ((TextList *)newGeneralList())
45 #define pushText(tl, s) pushValue((GeneralList *)(tl), (void *)allocStr((s),-1))
46 #define popText(tl) ((char *)popValue((GeneralList *)(tl)))
47 #define rpopText(tl) ((char *)rpopValue((GeneralList *)(tl)))
48 #define delText(tl, i) delValue((GeneralList *)(tl), (void *)(i))
49 #define appendTextList(tl, tl2) ((TextList *)appendGeneralList((GeneralList *)(tl), (GeneralList *)(tl2)))
50 
51 /* Line text list */
52 
53 typedef struct _TextLine {
54     Str line;
55     int pos;
56 } TextLine;
57 
58 typedef struct _textlinelistitem {
59     TextLine *ptr;
60     struct _textlinelistitem *next;
61     struct _textlinelistitem *prev;
62 } TextLineListItem;
63 
64 typedef struct _textlinelist {
65     TextLineListItem *first;
66     TextLineListItem *last;
67     int nitem;
68 } TextLineList;
69 
70 extern TextLine *newTextLine(Str line, int pos);
71 extern void appendTextLine(TextLineList *tl, Str line, int pos);
72 #define newTextLineList() ((TextLineList *)newGeneralList())
73 #define pushTextLine(tl,lbuf) pushValue((GeneralList *)(tl),(void *)(lbuf))
74 #define popTextLine(tl) ((TextLine *)popValue((GeneralList *)(tl)))
75 #define rpopTextLine(tl) ((TextLine *)rpopValue((GeneralList *)(tl)))
76 #define appendTextLineList(tl, tl2) ((TextLineList *)appendGeneralList((GeneralList *)(tl), (GeneralList *)(tl2)))
77 
78 #endif				/* not TEXTLIST_H */
79