home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: LinkList.h
- Author: Copyright © 1992 John Winters
- Version: 1.33 (30 May 1994)
- Purpose: Linked list management routines
- */
-
-
- #ifndef __dl_linklist_h
- #define __dl_linklist_h
-
- #ifndef __dl_core_h
- #include "Core.h"
- #endif
-
-
- /* Implementation notes
- * ====================
- * This module provides support for a linked list structure.
- * YOU must supply an anchor for the list (a variable of type
- * linklist_header). This is used to record pointers to the start and end
- * of the list.
- * The list itself is made up of your own structures, defined as follows:
- * struct listelement
- * {
- * linklist_header header;
- * ... Your own data here ...
- * } listelement;
- *
- * a list-terminating pointer is represented as NULL
- *
- * The header's next field stores a pointer to the FIRST item
- * its previous field stores a pointer to the LAST item
- * (both these pointers will be nulls if the list is empty)
- *
- * To insert items into the list, you must malloc memory for one of your
- * own listelement data structures, then call the appropriate function
- * To delete an item from the list, call the unlink function, and then free
- * all memory used by your structure.
- */
-
-
- typedef struct linklist_header
- {
- struct linklist_header *next;
- struct linklist_header *previous;
- } linklist_header ;
-
-
-
- /* Add an item to a linked list- at head or tail of list.
- * AddToHead inserts the given item at the head of the list
- * AddToTail inserts the given item at the end of the list
- *
- * InsertBefore inserts the given item BEFORE the item "pos"
- * InsertAfter inserts the given item AFTER the item "pos"
- */
- extern void LinkList_AddToHead(linklist_header *anchor, linklist_header *item);
- extern void LinkList_AddToTail(linklist_header *anchor, linklist_header *item);
- extern void LinkList_InsertBefore(linklist_header *anchor,
- linklist_header *pos,
- linklist_header *item);
- extern void LinkList_InsertAfter(linklist_header *anchor,
- linklist_header *pos,
- linklist_header *item);
-
-
- /* LinkList_InList
- * Returns TRUE if the item is curently in the list. Note that this does
- * NOT check item contents, merely compares item pointers.
- * To check item contents, you must chain through the list yourself.
- */
- extern BOOL LinkList_InList(linklist_header *anchor, linklist_header *item);
-
-
- /* LinkList_ListLength
- * Returns the number of items in the list. It follows all the links
- * and counts them... if you need this value a lot, I suggest you modify
- * LinkList to keep a count in the anchor...
- */
- extern int LinkList_ListLength(linklist_header *anchor);
-
-
-
- /* LinkList_Unlink
- * Unlinks the item "item" from the given list.
- * You must then free the memory used by it yourself.
- */
- extern void LinkList_Unlink(linklist_header *anchor, linklist_header *item);
-
-
- /* Return pointers to the first/last item in the list
- * extern void *LinkList_FirstItem(linklist_header *anchor);
- * extern void *LinkList_LastItem(linklist_header *anchor);
- */
- #define LinkList_FirstItem(x) ((void *)(x)->next)
- #define LinkList_LastItem(x) ((void *)(x)->previous)
-
-
- /* LinkList_Init
- * Initialises a list anchor. Should be called before anchor used
- * extern void LinkList_Init(linklist_header *item);
- */
- #define LinkList_Init(x) \
- { \
- (x)->next = NULL; \
- (x)->previous = NULL; \
- }
-
-
- /* LinkList_InitItem
- * Initialises a list item. Should be called before item used,
- * except when that item is immediately linked into a list
- * extern void LinkList_InitItem(linklist_header *item);
- */
- #define LinkList_InitItem(x) \
- { \
- (x)->next = NULL; \
- (x)->previous = NULL; \
- }
-
-
- /* Return the next/previous item of a given one. If the current item is at
- * the head/tail of the list, NULLPOINTER will be returned.
- * extern void *LinkList_NextItem(linklist_header *item);
- * extern void *LinkList_PreviousItem(linklist_header *item);
- *
- * Old definitions:
- * #define LinkList_NextItem(x) ((void *)(x)->next)
- * #define LinkList_PreviousItem(x) ((void *)(x)->previous)
- *
- * NEW definitions:
- * you can now use LinkList_NextItem(&item);
- * instead of LinkList_NextItem(&item->header);
- */
- #define LinkList_NextItem(x) ((void *) ((linklist_header *)(x))->next)
- #define LinkList_PreviousItem(x) ((void *) ((linklist_header *)(x))->previous)
-
- #endif
-