home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 308_01 / list.h < prev    next >
Text File  |  1990-06-17  |  3KB  |  89 lines

  1.  
  2.  
  3. /*
  4.     HEADER:         CUG308;
  5.     TITLE:          Generic linked list header file;
  6.     DESCRIPTION:    "Header file for linked list module";
  7.     VERSION:        2.01;
  8.     DATE:           5/6/90;
  9.     COMPILERS:      STANDARD C;
  10.     KEYWORDS:       list header;
  11.     FILENAME:       LIST.H;
  12.     SEE-ALSO:       LIST.C, LIST.DOC;
  13.     AUTHOR:         Michael Kelly
  14.             254 Gold St. Boston, Ma. 02127;
  15.     COPYRIGHT:      May be used freely if authorship is acknowledged;
  16. */
  17.  
  18.  
  19. /*
  20.  *  prevent multiple includes
  21.  */
  22. #if !defined(LIST_H)
  23. #define LIST_H
  24.  
  25. #define LIST_SLOT_INC 2     /* list table expanded by this increment */
  26.  
  27. /*
  28.  *  global List error indicator (like errno)
  29.  */
  30. enum Lerror  {
  31.     OK,                 /* no error                      */
  32.     NO_MEM,             /* not enough memory                  */
  33.     NULL_PTR,           /* NULL pointer - (usually a function argument)  */
  34.     EMPTY_LIST,         /* empty List                      */
  35.     INV_SIZE,           /* invalid size - (usually itemsize == 0)      */
  36.     NO_LISTS,           /* no Lists - (no Lists are active)          */
  37.     RE_INIT,            /* reinitialize - (init an already active List)  */
  38.     INV_ID,             /* invalid List id - (using a destroyed List)    */
  39.     FATAL_ERROR         /* fatal error - (program termination suggested) */
  40.     };
  41.  
  42. extern enum Lerror lerror;
  43.  
  44. enum Place  {
  45.     FIRST, LAST, CURRENT };
  46.  
  47. typedef struct ENTRY  {
  48.     size_t itemsize;
  49.     void   *item;
  50. }
  51. Entry;
  52.  
  53. typedef struct LINK  {
  54.     struct LINK    *next;
  55.     struct LINK *prev;
  56.     Entry     *entry;
  57. }
  58. Link;
  59.  
  60. typedef struct LIST  {
  61.     int (*add)(int id, void *item, size_t itemsize, enum Place place);
  62.     int (*delete)(int id);
  63.     int (*remitem)(int id, void *itembuf);
  64.     int (*chgcompare)(int id, int (*newcompare)());
  65.     int (*find)(int id, void *item1);
  66.     int (*replitem)(int id, void *newitem, size_t newsize);
  67.     int (*cmpitem)(int id, void *item1);
  68.     int (*sort)(int id);
  69.     int (*getitem)(int id, void *itembuf);
  70.     size_t (*getsize)(int id);
  71.     void *(*getptr)(int id);
  72.     int (*first)(int id);
  73.     int (*last)(int id);
  74.     int (*next)(int id);
  75.     int (*prev)(int id);
  76.     int (*destroy)(int id);
  77.     Link  *First, *Last, *Current;              /* Private */
  78.     int (*compare)();               /* Private */
  79.     int id;                                     /* List id : Private */
  80.     size_t entries;                             /* items in list -- */
  81. }                        /* treat as -- */
  82. List;                                           /* "read only" variable */
  83.  
  84. extern int initlist(List *newlist, int (*cmpfunc)());
  85. extern int compact_list_table(void);
  86.  
  87. #endif
  88.  
  89.