| 1 |
/* $XConsortium: list.h /main/4 1996/10/14 15:04:04 swick $ */ |
| 2 |
/** ------------------------------------------------------------------------ |
| 3 |
This file contains routines for manipulating generic lists. |
| 4 |
Lists are implemented with a "harness". In other words, each |
| 5 |
node in the list consists of two pointers, one to the data item |
| 6 |
and one to the next node in the list. The head of the list is |
| 7 |
the same struct as each node, but the "item" ptr is used to point |
| 8 |
to the current member of the list (used by the first_in_list and |
| 9 |
next_in_list functions). |
| 10 |
|
| 11 |
Copyright (c) 1994 Hewlett-Packard Co. |
| 12 |
Copyright (c) 1996 X Consortium |
| 13 |
|
| 14 |
Permission is hereby granted, free of charge, to any person obtaining |
| 15 |
a copy of this software and associated documentation files (the |
| 16 |
"Software"), to deal in the Software without restriction, including |
| 17 |
without limitation the rights to use, copy, modify, merge, publish, |
| 18 |
distribute, sublicense, and sell copies of the Software, and to |
| 19 |
permit persons to whom the Software is furnished to do so, subject to |
| 20 |
the following conditions: |
| 21 |
|
| 22 |
The above copyright notice and this permission notice shall be included |
| 23 |
in all copies or substantial portions of the Software. |
| 24 |
|
| 25 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 26 |
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 28 |
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 29 |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 30 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 31 |
OTHER DEALINGS IN THE SOFTWARE. |
| 32 |
|
| 33 |
Except as contained in this notice, the name of the X Consortium shall |
| 34 |
not be used in advertising or otherwise to promote the sale, use or |
| 35 |
other dealings in this Software without prior written authorization |
| 36 |
from the X Consortium. |
| 37 |
|
| 38 |
-------------------------------------------------------------------- **/ |
| 39 |
|
| 40 |
#ifndef LIST_DEF |
| 41 |
#define LIST_DEF |
| 42 |
|
| 43 |
#define LESS -1 |
| 44 |
#define EQUAL 0 |
| 45 |
#define GREATER 1 |
| 46 |
#define DUP_WHOLE_LIST 0 |
| 47 |
#define START_AT_CURR 1 |
| 48 |
|
| 49 |
typedef struct _list_item { |
| 50 |
struct _list_item *next; |
| 51 |
union { |
| 52 |
void *item; /* in normal list node, pts to data */ |
| 53 |
struct _list_item *curr; /* in list head, pts to curr for 1st, next */ |
| 54 |
} ptr; |
| 55 |
} list, list_item, *list_ptr; |
| 56 |
|
| 57 |
typedef void (*DESTRUCT_FUNC_PTR)( |
| 58 |
#if NeedFunctionPrototypes |
| 59 |
void * |
| 60 |
#endif |
| 61 |
); |
| 62 |
|
| 63 |
void zero_list( |
| 64 |
#if NeedFunctionPrototypes |
| 65 |
list_ptr |
| 66 |
#endif |
| 67 |
); |
| 68 |
int add_to_list ( |
| 69 |
#if NeedFunctionPrototypes |
| 70 |
list_ptr , void * |
| 71 |
#endif |
| 72 |
); |
| 73 |
list_ptr new_list ( |
| 74 |
#if NeedFunctionPrototypes |
| 75 |
void |
| 76 |
#endif |
| 77 |
); |
| 78 |
list_ptr dup_list_head ( |
| 79 |
#if NeedFunctionPrototypes |
| 80 |
list_ptr , int |
| 81 |
#endif |
| 82 |
); |
| 83 |
unsigned int list_length( |
| 84 |
#if NeedFunctionPrototypes |
| 85 |
list_ptr |
| 86 |
#endif |
| 87 |
); |
| 88 |
void *delete_from_list ( |
| 89 |
#if NeedFunctionPrototypes |
| 90 |
list_ptr , void * |
| 91 |
#endif |
| 92 |
); |
| 93 |
void delete_list( |
| 94 |
#if NeedFunctionPrototypes |
| 95 |
list_ptr , int |
| 96 |
#endif |
| 97 |
); |
| 98 |
void delete_list_destroying ( |
| 99 |
#if NeedFunctionPrototypes |
| 100 |
list_ptr , DESTRUCT_FUNC_PTR |
| 101 |
#endif |
| 102 |
); |
| 103 |
void *first_in_list ( |
| 104 |
#if NeedFunctionPrototypes |
| 105 |
list_ptr |
| 106 |
#endif |
| 107 |
); |
| 108 |
void *next_in_list ( |
| 109 |
#if NeedFunctionPrototypes |
| 110 |
list_ptr |
| 111 |
#endif |
| 112 |
); |
| 113 |
int list_is_empty ( |
| 114 |
#if NeedFunctionPrototypes |
| 115 |
list_ptr |
| 116 |
#endif |
| 117 |
); |
| 118 |
|
| 119 |
#endif |