OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / bltList.h
1 /*
2  * bltList.h --
3  *
4  * Copyright 1993-1998 Lucent Technologies, Inc.
5  *
6  * Permission to use, copy, modify, and distribute this software and
7  * its documentation for any purpose and without fee is hereby
8  * granted, provided that the above copyright notice appear in all
9  * copies and that both that the copyright notice and warranty
10  * disclaimer appear in supporting documentation, and that the names
11  * of Lucent Technologies any of their entities not be used in
12  * advertising or publicity pertaining to distribution of the software
13  * without specific, written prior permission.
14  *
15  * Lucent Technologies disclaims all warranties with regard to this
16  * software, including all implied warranties of merchantability and
17  * fitness.  In no event shall Lucent Technologies be liable for any
18  * special, indirect or consequential damages or any damages
19  * whatsoever resulting from loss of use, data or profits, whether in
20  * an action of contract, negligence or other tortuous action, arising
21  * out of or in connection with the use or performance of this
22  * software.
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  * A Blt_ListNode is the container structure for the Blt_List.
32  */
33 struct Blt_ListNodeStruct {
34     struct Blt_ListNodeStruct *prevPtr; /* Link to the previous node */
35     struct Blt_ListNodeStruct *nextPtr; /* Link to the next node */
36     ClientData clientData;      /* Pointer to the data object */
37     struct Blt_ListStruct *listPtr; /* List to eventually insert node */
38     union {                     /* Key has one of these forms: */
39         CONST char *oneWordValue; /* One-word value for key. */
40         int *words[1];          /* Multiple integer words for key.
41                                  * The actual size will be as large
42                                  * as necessary for this table's
43                                  * keys. */
44         char string[4];         /* String for key.  The actual size
45                                  * will be as large as needed to hold
46                                  * the key. */
47     } key;                      /* MUST BE LAST FIELD IN RECORD!! */
48 };
49
50 typedef int (Blt_ListCompareProc) _ANSI_ARGS_((Blt_ListNode *node1Ptr, 
51         Blt_ListNode *node2Ptr));
52
53 /*
54  * A Blt_List is a doubly chained list structure.
55  */
56 struct Blt_ListStruct {
57     struct Blt_ListNodeStruct *headPtr; /* Pointer to first element in list */
58     struct Blt_ListNodeStruct *tailPtr; /* Pointer to last element in list */
59     int nNodes;                 /* Number of node currently in the list. */
60     int type;                   /* Type of keys in list. */
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 /* _BLT_LIST_H */