| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef _BLT_LIST_H |
| 25 |
#define _BLT_LIST_H |
| 26 |
|
| 27 |
typedef struct Blt_ListStruct *Blt_List; |
| 28 |
typedef struct Blt_ListNodeStruct *Blt_ListNode; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
struct Blt_ListNodeStruct { |
| 34 |
struct Blt_ListNodeStruct *prevPtr; |
| 35 |
struct Blt_ListNodeStruct *nextPtr; |
| 36 |
ClientData clientData; |
| 37 |
struct Blt_ListStruct *listPtr; |
| 38 |
union { |
| 39 |
CONST char *oneWordValue; |
| 40 |
int *words[1]; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
char string[4]; |
| 45 |
|
| 46 |
|
| 47 |
} key; |
| 48 |
}; |
| 49 |
|
| 50 |
typedef int (Blt_ListCompareProc) _ANSI_ARGS_((Blt_ListNode *node1Ptr, |
| 51 |
Blt_ListNode *node2Ptr)); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
struct Blt_ListStruct { |
| 57 |
struct Blt_ListNodeStruct *headPtr; |
| 58 |
struct Blt_ListNodeStruct *tailPtr; |
| 59 |
int nNodes; |
| 60 |
int type; |
| 61 |
}; |
| 62 |
|
| 63 |
EXTERN void Blt_ListInit _ANSI_ARGS_((Blt_List list, int type)); |
| 64 |
EXTERN void Blt_ListReset _ANSI_ARGS_((Blt_List list)); |
| 65 |
EXTERN Blt_List Blt_ListCreate _ANSI_ARGS_((int type)); |
| 66 |
EXTERN void Blt_ListDestroy _ANSI_ARGS_((Blt_List list)); |
| 67 |
EXTERN Blt_ListNode Blt_ListCreateNode _ANSI_ARGS_((Blt_List list, |
| 68 |
CONST char *key)); |
| 69 |
EXTERN void Blt_ListDeleteNode _ANSI_ARGS_((Blt_ListNode node)); |
| 70 |
|
| 71 |
EXTERN Blt_ListNode Blt_ListAppend _ANSI_ARGS_((Blt_List list, CONST char *key, |
| 72 |
ClientData clientData)); |
| 73 |
EXTERN Blt_ListNode Blt_ListPrepend _ANSI_ARGS_((Blt_List list, CONST char *key, |
| 74 |
ClientData clientData)); |
| 75 |
EXTERN void Blt_ListLinkAfter _ANSI_ARGS_((Blt_List list, Blt_ListNode node, |
| 76 |
Blt_ListNode afterNode)); |
| 77 |
EXTERN void Blt_ListLinkBefore _ANSI_ARGS_((Blt_List list, Blt_ListNode node, |
| 78 |
Blt_ListNode beforeNode)); |
| 79 |
EXTERN void Blt_ListUnlinkNode _ANSI_ARGS_((Blt_ListNode node)); |
| 80 |
EXTERN Blt_ListNode Blt_ListGetNode _ANSI_ARGS_((Blt_List list, |
| 81 |
CONST char *key)); |
| 82 |
EXTERN void Blt_ListDeleteNodeByKey _ANSI_ARGS_((Blt_List list, |
| 83 |
CONST char *key)); |
| 84 |
EXTERN Blt_ListNode Blt_ListGetNthNode _ANSI_ARGS_((Blt_List list, |
| 85 |
int position, int direction)); |
| 86 |
EXTERN void Blt_ListSort _ANSI_ARGS_((Blt_List list, |
| 87 |
Blt_ListCompareProc * proc)); |
| 88 |
|
| 89 |
#define Blt_ListGetLength(list) \ |
| 90 |
(((list) == NULL) ? 0 : ((struct Blt_ListStruct *)list)->nNodes) |
| 91 |
#define Blt_ListFirstNode(list) \ |
| 92 |
(((list) == NULL) ? NULL : ((struct Blt_ListStruct *)list)->headPtr) |
| 93 |
#define Blt_ListLastNode(list) \ |
| 94 |
(((list) == NULL) ? NULL : ((struct Blt_ListStruct *)list)->tailPtr) |
| 95 |
#define Blt_ListPrevNode(node) ((node)->prevPtr) |
| 96 |
#define Blt_ListNextNode(node) ((node)->nextPtr) |
| 97 |
#define Blt_ListGetKey(node) \ |
| 98 |
(((node)->listPtr->type == BLT_STRING_KEYS) \ |
| 99 |
? (node)->key.string : (node)->key.oneWordValue) |
| 100 |
#define Blt_ListGetValue(node) ((node)->clientData) |
| 101 |
#define Blt_ListSetValue(node, value) \ |
| 102 |
((node)->clientData = (ClientData)(value)) |
| 103 |
#define Blt_ListAppendNode(list, node) \ |
| 104 |
(Blt_ListLinkBefore((list), (node), (Blt_ListNode)NULL)) |
| 105 |
#define Blt_ListPrependNode(list, node) \ |
| 106 |
(Blt_ListLinkAfter((list), (node), (Blt_ListNode)NULL)) |
| 107 |
|
| 108 |
#endif |