version 1.2, 1996/06/26 05:36:34 |
version 1.3, 1996/11/30 21:08:58 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
/* $NetBSD: list.h,v 1.4 1995/06/14 15:19:28 christos Exp $ */ |
/* $NetBSD: list.h,v 1.5 1996/11/06 17:59:11 christos Exp $ */ |
|
|
/* |
/* |
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
* |
* |
* from: @(#)list.h 5.3 (Berkeley) 6/1/90 |
* from: @(#)list.h 8.1 (Berkeley) 6/6/93 |
*/ |
*/ |
|
|
/* |
/* |
|
|
* to a list as a whole, the user keeps a pointer to the header; that |
* to a list as a whole, the user keeps a pointer to the header; that |
* header is initialized by a call to List_Init(), which creates an empty |
* header is initialized by a call to List_Init(), which creates an empty |
* list given a pointer to a List_Links structure (described below). |
* list given a pointer to a List_Links structure (described below). |
* |
* |
* The links are contained in a two-element structure called List_Links. |
* The links are contained in a two-element structure called List_Links. |
* A list joins List_Links records (that is, each List_Links structure |
* A list joins List_Links records (that is, each List_Links structure |
* points to other List_Links structures), but if the List_Links is the |
* points to other List_Links structures), but if the List_Links is the |
* first field within a larger structure, then the larger structures are |
* first field within a larger structure, then the larger structures are |
* effectively linked together as follows: |
* effectively linked together as follows: |
* |
* |
* header |
* header |
* (List_Links) first elt. second elt. |
* (List_Links) first elt. second elt. |
* ----------------- ----------------- ----------------- |
* ----------------- ----------------- ----------------- |
* ..-> | nextPtr | ----> | List_Links | ----> | List_Links |----.. |
* ..-> | nextPtr | ----> | List_Links | ----> | List_Links |----.. |
* | - - - - - - - | | | | | |
* | - - - - - - - | | | | | |
* ..-- | prevPtr | <---- | | <---- | |<---.. |
* ..-- | prevPtr | <---- | | <---- | |<---.. |
* ----------------- - --- --- --- - - --- --- --- - |
* ----------------- - --- --- --- - - --- --- --- - |
* | rest of | | rest of | |
* | rest of | | rest of | |
* | structure | | structure | |
* | structure | | structure | |
* | | | | |
* | | | | |
* | ... | | ... | |
* | ... | | ... | |
* ----------------- ----------------- |
* ----------------- ----------------- |
* |
* |
* It is possible to link structures through List_Links fields that are |
* It is possible to link structures through List_Links fields that are |
* not at the beginning of the larger structure, but it is then necessary |
* not at the beginning of the larger structure, but it is then necessary |
* to perform pointer arithmetic to find the beginning of the larger |
* to perform pointer arithmetic to find the beginning of the larger |
* structure, given a pointer to some point within it. |
* structure, given a pointer to some point within it. |
* |
* |
* A typical structure might be something like: |
* A typical structure might be something like: |
* |
* |
* typedef struct { |
* typedef struct { |
* List_Links links; |
* List_Links links; |
* char ch; |
* char ch; |
* integer flags; |
* integer flags; |
* } EditChar; |
* } EditChar; |
* |
* |
* Before an element is inserted in a list for the first time, it must |
* Before an element is inserted in a list for the first time, it must |
* be initialized by calling the macro List_InitElement(). |
* be initialized by calling the macro List_InitElement(). |
*/ |
*/ |
|
|
#define List_InitElement(elementPtr) \ |
#define List_InitElement(elementPtr) \ |
(elementPtr)->prevPtr = (List_Links *) NIL; \ |
(elementPtr)->prevPtr = (List_Links *) NIL; \ |
(elementPtr)->nextPtr = (List_Links *) NIL; |
(elementPtr)->nextPtr = (List_Links *) NIL; |
|
|
/* |
/* |
* Macros for stepping through or selecting parts of lists |
* Macros for stepping through or selecting parts of lists |
*/ |
*/ |
|
|
* Macro to loop through a list and perform an operation on each member. |
* Macro to loop through a list and perform an operation on each member. |
* |
* |
* Usage: LIST_FORALL(headerPtr, itemPtr) { |
* Usage: LIST_FORALL(headerPtr, itemPtr) { |
* / * |
* / * |
* * operation on itemPtr, which points to successive members |
* * operation on itemPtr, which points to successive members |
* * of the list |
* * of the list |
* * |
* * |
* * It may be appropriate to first assign |
* * It may be appropriate to first assign |
* * foobarPtr = (Foobar *) itemPtr; |
* * foobarPtr = (Foobar *) itemPtr; |
* * to refer to the entire Foobar structure. |
* * to refer to the entire Foobar structure. |
|
|
* LIST_ATFRONT(headerPtr) -- insert at front of list |
* LIST_ATFRONT(headerPtr) -- insert at front of list |
* LIST_ATREAR(headerPtr) -- insert at end of list |
* LIST_ATREAR(headerPtr) -- insert at end of list |
* |
* |
* For example, |
* For example, |
* |
* |
* List_Insert(itemPtr, LIST_AFTER(otherPtr)); |
* List_Insert(itemPtr, LIST_AFTER(otherPtr)); |
* |
* |