list.h revision b3307321
1b3307321Smrg/* $Xorg: list.h,v 1.4 2001/02/09 02:06:03 xorgcvs Exp $ */
2b3307321Smrg/** ------------------------------------------------------------------------
3b3307321Smrg	This file contains routines for manipulating generic lists.
4b3307321Smrg	Lists are implemented with a "harness".  In other words, each
5b3307321Smrg	node in the list consists of two pointers, one to the data item
6b3307321Smrg	and one to the next node in the list.  The head of the list is
7b3307321Smrg	the same struct as each node, but the "item" ptr is used to point
8b3307321Smrg	to the current member of the list (used by the first_in_list and
9b3307321Smrg	next_in_list functions).
10b3307321Smrg
11b3307321SmrgCopyright 1994 Hewlett-Packard Co.
12b3307321SmrgCopyright 1996, 1998  The Open Group
13b3307321Smrg
14b3307321SmrgPermission to use, copy, modify, distribute, and sell this software and its
15b3307321Smrgdocumentation for any purpose is hereby granted without fee, provided that
16b3307321Smrgthe above copyright notice appear in all copies and that both that
17b3307321Smrgcopyright notice and this permission notice appear in supporting
18b3307321Smrgdocumentation.
19b3307321Smrg
20b3307321SmrgThe above copyright notice and this permission notice shall be included
21b3307321Smrgin all copies or substantial portions of the Software.
22b3307321Smrg
23b3307321SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24b3307321SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25b3307321SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26b3307321SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
27b3307321SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28b3307321SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29b3307321SmrgOTHER DEALINGS IN THE SOFTWARE.
30b3307321Smrg
31b3307321SmrgExcept as contained in this notice, the name of The Open Group shall
32b3307321Smrgnot be used in advertising or otherwise to promote the sale, use or
33b3307321Smrgother dealings in this Software without prior written authorization
34b3307321Smrgfrom The Open Group.
35b3307321Smrg
36b3307321Smrg    -------------------------------------------------------------------- **/
37b3307321Smrg/* $XFree86$ */
38b3307321Smrg
39b3307321Smrg#ifndef LIST_DEF
40b3307321Smrg#define LIST_DEF
41b3307321Smrg
42b3307321Smrg#include <X11/Xfuncproto.h>
43b3307321Smrg#define LESS	-1
44b3307321Smrg#define EQUAL	0
45b3307321Smrg#define GREATER	1
46b3307321Smrg#define DUP_WHOLE_LIST	0
47b3307321Smrg#define START_AT_CURR	1
48b3307321Smrg
49b3307321Smrgtypedef struct _list_item {
50b3307321Smrg    struct _list_item *next;
51b3307321Smrg    union {
52b3307321Smrg	void *item;		 /* in normal list node, pts to data */
53b3307321Smrg	struct _list_item *curr; /* in list head, pts to curr for 1st, next */
54b3307321Smrg    } ptr;
55b3307321Smrg} list, list_item, *list_ptr;
56b3307321Smrg
57b3307321Smrgtypedef void (*DESTRUCT_FUNC_PTR)(
58b3307321Smrgvoid *
59b3307321Smrg);
60b3307321Smrg
61b3307321Smrgvoid zero_list(
62b3307321Smrg          list_ptr
63b3307321Smrg    );
64b3307321Smrgint add_to_list (
65b3307321Smrg          list_ptr , void *
66b3307321Smrg    );
67b3307321Smrglist_ptr new_list (
68b3307321Smrg          void
69b3307321Smrg    );
70b3307321Smrglist_ptr dup_list_head (
71b3307321Smrg          list_ptr , int
72b3307321Smrg    );
73b3307321Smrgunsigned int list_length(
74b3307321Smrg          list_ptr
75b3307321Smrg    );
76b3307321Smrgvoid *delete_from_list (
77b3307321Smrg          list_ptr , void *
78b3307321Smrg    );
79b3307321Smrgvoid delete_list(
80b3307321Smrg          list_ptr , int
81b3307321Smrg    );
82b3307321Smrgvoid delete_list_destroying (
83b3307321Smrg          list_ptr , DESTRUCT_FUNC_PTR
84b3307321Smrg    );
85b3307321Smrgvoid *first_in_list (
86b3307321Smrg          list_ptr
87b3307321Smrg    );
88b3307321Smrgvoid *next_in_list (
89b3307321Smrg          list_ptr
90b3307321Smrg    );
91b3307321Smrgint list_is_empty (
92b3307321Smrg          list_ptr
93b3307321Smrg    );
94b3307321Smrg
95b3307321Smrg#endif
96