home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / LLS.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  7KB  |  133 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /* =======================================================================
  4.     LLS.h           Generic Singly Linked List for fixed size data-items.
  5.  
  6.                     v1.00  94-08-21
  7.                     v1.01  95-10-21  Changed ListCountInit to unsigned.
  8.  
  9.  _____              This version is Public Domain.
  10.  /_|__|             A.Reitsma, Delft, The Netherlands.
  11. /  | \  --------------------------------------------------------------- */
  12.  
  13. #ifndef LLS__H
  14. #define LLS__H
  15.  
  16. #ifndef FAR
  17. #include "extkword.h"
  18. #endif
  19.  
  20. #ifndef LL__ERR_H
  21. #define LL__ERR_H       /* same values used in LLD ...                  */
  22.  
  23. enum ListErrors         /* return values for LLScheck()                 */
  24. {                       /* The highest value is returned                */
  25.  
  26.     LIST_NO_PROBLEMS,   /* All is OK (multiple use)                     */
  27.     LIST_EMPTY,         /* No data available                            */
  28.     LIST_ERRORS,        /* Dummy to separate warnings from              */
  29.                         /* ---- REAL errors --------------------------- */
  30.     LIST_CORRUPT1,      /* invalid last node pointer: Not NULL          */
  31.                         /*      (empty list: ptr should have been NULL) */
  32.     LIST_CORRUPT2,      /* invalid current node pointer: Not NULL       */
  33.                         /*      (empty list: ptr should have been NULL) */
  34.     LIST_CORRUPT3,      /* invalid last node pointer: Not really last.  */
  35.     LIST_CORRUPT4,      /* invalid last node pointer: Not in list.      */
  36.     LIST_ERR_LAST,      /* invalid last node pointer: NULL              */
  37.     LIST_CORRUPT5,      /* invalid current node pointer: Not in list.   */
  38.     LIST_CORRUPT6,      /* invalid current->next node pointer: NULL     */
  39.                         /*      although the list is not empty          */
  40.     LIST_CORRUPT7,      /* NULL current node pointer                    */
  41.     LIST_ERR_HEAD,      /* NULL first node pointer                      */
  42.     LIST_NOT_CREATED,   /* List deleted or not created                  */
  43.     LIST_INV_NUMBER,    /* List number out of range                     */
  44.     LIST_SYSTEM_NULL,   /* List system not initialized                  */
  45. };
  46.             /* NOTE: 'invalid last node pointer' errors will ONLY occur */
  47.             /* when LLS.c is compiled with USE_LASTPTR defined ...      */
  48.  
  49. typedef int (*CompFunPtr)( const void *, const void * );
  50.                                              /* simplifies declarations */
  51. #endif
  52.  
  53. /* ---- LL system management and maintenance -------------------------- */
  54. int  LLSsystemInit( unsigned ListCount );
  55.                /* returns -1 on failure. It is not required to call it. */
  56.                /* A second call does nothing: ListCount is ignored.     */
  57.  
  58. int  LLScreate( int ItemSize );
  59.                         /* returns list number to use or -1 on failure. */
  60.                         /* MUST be called before using a list.          */
  61.                         /* Calls LLsystemInit if necessary.             */
  62.  
  63. void LLSdelete( int List ); /* delete entire list, data is NOT free()'d */
  64.  
  65. int  LLScheck( int List ); /* returns enum ListErrors value             */
  66.                            /* its primary purpose is debugging.         */
  67.  
  68. /* ---- Node management --------------------------------------------------
  69.    Functions changing current node pointer to the new node.
  70.    Each created list has its own -- fixed -- datasize. See LLcreate().
  71.    An ellipsis "..." indicates the data to insert.
  72. */
  73. int  LLSnodeInsert( int List, ... );      /* insert BEFORE current node */
  74. int  LLSnodeAdd( int List, ... );         /* insert AFTER current node  */
  75.          /* a return value of -1 indicates a memory allocation problem. */
  76.  
  77. /* Functions NOT changing the current node pointer.
  78.    Especially intended for implementation of Queue's and Stacks.
  79. */
  80. int  LLSnodePrepend( int List, ... );           /* insert as first node */
  81. int  LLSnodeAppend( int List, ... );            /* insert as last node  */
  82.          /* a return value of -1 indicates a memory allocation problem. */
  83.  
  84. /* The following four functions are essentially the same as the preceding
  85.    four. The data is however not passed by value but by reference.
  86. */
  87. int  LLSnodeInsertFrom( int List, void * Source );
  88. int  LLSnodeAddFrom( int List, void * Source );
  89. int  LLSnodePrependFrom( int List, void * Source );
  90. int  LLSnodeAppendFrom( int List, void * Source );
  91.  
  92. void LLSnodeDelete( int List );                  /* remove current node */
  93.         /* current node ptr moved to next node. UNLESS the deleted node */
  94.         /* was the last node: then current ptr moved to previous node   */
  95.  
  96. int  LLSnodeFind( int List, CompFunPtr Compare, void * DataPtr );
  97.         /* Find *DataPtr in the List using the *Compare function.       */
  98.         /* Returns the return value of *Compare. 0 == equal == found.   */
  99.         /* non-zero == not found. Current node is set to found node.    */
  100.         /* Returns 2 for an empty list.                                 */
  101.         /* First checked node is current node.                          */
  102.         /* A NULL Compare-function defaults to the use of memcmp() with */
  103.         /* the list's itemsize as third (size) parameter.               */
  104.         /* simple implementation. FindFirst and FindNext may be needed. */
  105.  
  106. /* ---- current node pointer management ----------------------------------
  107.    These functions change the current node pointer and return 1 when there
  108.    was a change. A return of 0 indicates trying to move past the begin or
  109.    the end of the list, or an empty list. The return value is intended for
  110.    iteration purposes. I.e. stopping a scan through a list.
  111. */
  112. int  LLSnodePtr2First( int List );
  113. int  LLSnodePtr2Last( int List );
  114. int  LLSnodePtr2Next( int List );
  115. int  LLSnodePtr2Prev( int List );
  116.  
  117. /* ---- stored data management -------------------------------------------
  118.    return typed data:
  119. */
  120. int  LLSnodeInt( int List );
  121. long LLSnodeLong( int List );
  122. void * LLSnodePtr( int List );
  123. void FAR * LLSnodeFptr( int List );
  124.  
  125. /* 'return' typeless data. The return value is the size of the data.
  126.    The data is transferred to Destination.
  127.    If 'Destination' is NULL, the only action is returning the size.
  128. */
  129. int LLSnodeDataTo( int List, void * Destination );
  130.  
  131. #endif /* LLS__H */
  132. /* ==== LLS.h  end ==================================================== */
  133.