home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / FED_PLUS.EXE / LINKLIST.H < prev    next >
C/C++ Source or Header  |  1994-07-25  |  5KB  |  179 lines

  1. #ifndef LINKLIST_H
  2. #define    LINKLIST_H
  3.  
  4. /* $Id: linklist.h,v 1.2 1993/10/15 18:49:23 libes Exp $ */
  5.  
  6. /*
  7.  * This work was supported by the United States Government, and is
  8.  * not subject to copyright.
  9.  *
  10.  * $Log: linklist.h,v $
  11.  * Revision 1.2  1993/10/15  18:49:23  libes
  12.  * CADDETC certified
  13.  *
  14.  * Revision 1.5  1993/03/19  20:44:12  libes
  15.  * added included
  16.  *
  17.  * Revision 1.4  1993/01/19  22:17:27  libes
  18.  * *** empty log message ***
  19.  *
  20.  * Revision 1.3  1992/08/18  17:15:40  libes
  21.  * rm'd extraneous error messages
  22.  *
  23.  * Revision 1.2  1992/06/08  18:07:35  libes
  24.  * prettied up interface to print_objects_when_running
  25.  */
  26.  
  27. /*************/
  28. /* constants */
  29. /*************/
  30.  
  31. #define LINK_NULL    (Link)NULL
  32. #define LIST_NULL    (Linked_List)NULL
  33.  
  34. /*****************/
  35. /* packages used */
  36. /*****************/
  37.  
  38. #include "basic.h"
  39. #include "memory.h"
  40.  
  41. /************/
  42. /* typedefs */
  43. /************/
  44.  
  45. typedef struct Linked_List *Linked_List;
  46.  
  47. #ifdef __STDC__
  48. #else /* old C */
  49. #endif /*__STDC__*/
  50.  
  51. /****************/
  52. /* modules used */
  53. /****************/
  54.  
  55. #include "error.h"
  56.  
  57. /***************************/
  58. /* hidden type definitions */
  59. /***************************/
  60.  
  61. typedef struct Link {
  62.     struct Link*    next;
  63.     struct Link*    prev;
  64.     Generic        data;
  65. } *Link;
  66.  
  67. struct Linked_List {
  68.     Link mark;
  69. };
  70.  
  71. /********************/
  72. /* global variables */
  73. /********************/
  74.  
  75. #ifdef LINKLIST_C
  76. #include "defstart.h"
  77. #else
  78. #include "decstart.h"
  79. #endif /*LINKED_LIST_C*/
  80.  
  81. GLOBAL Error    ERROR_empty_list    INITIALLY(ERROR_none);
  82. GLOBAL struct freelist_head LINK_fl;
  83. GLOBAL struct freelist_head LIST_fl;
  84. GLOBAL Linked_List LINK__l;        /* for LISTcreate_with macro - ugh */
  85.  
  86. #include "de_end.h"
  87.  
  88. /******************************/
  89. /* macro function definitions */   
  90. /******************************/
  91.  
  92. #define LINK_new()    (struct Link *)MEM_new(&LINK_fl)
  93. #define LINK_destroy(x)    MEM_destroy(&LINK_fl,(Freelist *)(Generic)x)
  94. #define LIST_new()    (struct Linked_List *)MEM_new(&LIST_fl)
  95. #define LIST_destroy(x)    MEM_destroy(&LIST_fl,(Freelist *)(Generic)x)
  96.  
  97. /* following could be optimized */
  98. #define LISTcreate_with(x)    (LINK__l = LISTcreate()),\
  99.                 LISTadd(LINK__l,x),\
  100.                 LINK_l)
  101.  
  102. /* accessing links */
  103. #define LINKdata(link)    (link)->data
  104. #define LINKnext(link)    (link)->next
  105. #define LINKprev(link)    (link)->prev
  106.  
  107. /* iteration */
  108. #define    LISTdo(list, elt, type)                        \
  109.    {struct Linked_List*    __l = (list);                    \
  110.     type        elt;                        \
  111.     Link        __p;                        \
  112.     if (__l) {                                \
  113.     for (__p = __l->mark; (__p = __p->next) != __l->mark; ) {    \
  114.         (elt) = (type)((__p)->data);
  115.  
  116. #define    LISTdo_links(list, link)                    \
  117.    {Linked_List     __in = (list);                    \
  118.     Link        link;                        \
  119.     if (__in != LIST_NULL) {                        \
  120.     for ((link) = __in->mark; ((link) = (link)->next) != __in->mark; ) {
  121. #define    LISTod    }}}
  122.  
  123. /* accessing */
  124. #define LISTpeek_first(list)                        \
  125.     (((struct Linked_List*)list)->mark->next->data)
  126.  
  127. /* function aliases */
  128. #define    LISTadd(list, item)    LISTadd_last(list, item)
  129. #define    LISTadd_all(list, items)                    \
  130.     LISTdo(items, e, Generic)                        \
  131.     LISTadd(list, e);                        \
  132.     LISTod;
  133.  
  134. /***********************/
  135. /* function prototypes */
  136. /***********************/
  137.  
  138. extern void LISTinitialize PROTO((void));
  139. extern Linked_List LISTcreate PROTO((void));
  140. /*extern Linked_List LISTcreate_with PROTO((Generic));*/
  141. extern Linked_List LISTcopy PROTO((Linked_List ));
  142. extern Generic    LISTadd_first PROTO((Linked_List, Generic));
  143. extern Generic    LISTadd_last PROTO((Linked_List, Generic));
  144. extern Generic    LISTadd_after PROTO((Linked_List, Link, Generic));
  145. extern Generic    LISTadd_before PROTO((Linked_List, Link, Generic));
  146. extern Generic    LISTremove_first PROTO((Linked_List));
  147. extern Generic    LISTremove PROTO((Linked_List, Link));
  148. extern Generic    LISTget_first PROTO((Linked_List));
  149. extern Generic    LISTget_second PROTO((Linked_List));
  150. extern Generic  LISTget_nth PROTO((Linked_List,int));
  151. extern void    LISTfree PROTO((Linked_List));
  152. extern int    LISTget_length PROTO((Linked_List));
  153. extern int LISTempty(struct Linked_List *list);
  154. extern void LISTinitialize(void );
  155. extern struct Linked_List *LISTcreate(void);
  156. extern struct Linked_List *LISTcopy(struct Linked_List *src);
  157. extern void LISTfree(struct Linked_List *list);
  158. extern char *LISTadd_first(struct Linked_List *list,char *item);
  159. extern char *LISTadd_last(struct Linked_List *list,char *item);
  160. extern char *LISTadd_after(struct Linked_List *list,struct Link *link,char *item);
  161. extern char *LISTadd_before(struct Linked_List *list,struct Link *link,char *item);
  162. extern char *LISTremove_first(struct Linked_List *list);
  163. extern char *LISTremove(struct Linked_List *list,struct Link *link);
  164. extern char *LISTget_first(struct Linked_List *list);
  165. extern char *LISTget_second(struct Linked_List *list);
  166. extern char *LISTget_nth(struct Linked_List *list,int n);
  167. extern int LISTget_length(struct Linked_List *list);
  168. /*******************************/
  169. /* inline function definitions */
  170. /*******************************/
  171.  
  172. Boolean
  173. LISTempty(Linked_List list);
  174.  
  175.  
  176.  
  177.  
  178. #endif /*LINKED_LIST_H*/
  179.