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

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /* =======================================================================
  4.     LLD.h           Generic Doubly 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 LLD__H
  14. #define LLD__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 LLS ...                  */
  22.  
  23. enum ListErrors         /* return values for LLDcheck()                 */
  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: != first->next    */
  31.                         /*      (empty list) or link error              */
  32.     LIST_CORRUPT2,      /* invalid current node pointer: != first->next */
  33.                         /*      (empty list)                            */
  34.     LIST_CORRUPT3,      /* invalid last node pointer: Not really last.  */
  35.     LIST_CORRUPT4,      /* invalid last node pointer: Not in list,      */
  36.                         /*      or link error after current node        */
  37.     LIST_ERR_LAST,      /* invalid last node pointer: NULL              */
  38.     LIST_CORRUPT5,      /* invalid current node pointer: Not in list,   */
  39.                         /*      or link error before current node       */
  40.     LIST_CORRUPT6,      /* invalid current->next node pointer: NULL     */
  41.                         /*      although the list is not empty          */
  42.     LIST_CORRUPT7,      /* NULL current node pointer                    */
  43.     LIST_ERR_HEAD,      /* NULL first node pointer                      */
  44.                         /*      or error in head node                   */
  45.     LIST_NOT_CREATED,   /* List deleted or not created                  */
  46.     LIST_INV_NUMBER,    /* List number out of range                     */
  47.     LIST_SYSTEM_NULL,   /* List system not initialized                  */
  48. };
  49.  
  50. typedef int (*CompFunPtr)( const void *, const void * );
  51.                                              /* simplifies declarations */
  52. #endif
  53.  
  54. /* ---- LL system management and maintenance -------------------------- */
  55. int  LLDsystemInit( unsigned ListCount );
  56.                /* returns -1 on failure. It is not required to call it. */
  57.                /* A second call does nothing: ListCount is ignored.     */
  58.  
  59. int  LLDcreate( int ItemSize );
  60.                         /* returns list number to use or -1 on failure. */
  61.                         /* MUST be called before using a list.          */
  62.                         /* Calls LLsystemInit if necessary.             */
  63.  
  64. void LLDdelete( int List ); /* delete entire list, data is NOT free()'d */
  65.  
  66. int  LLDcheck( int List ); /* returns enum ListErrors value             */
  67.                            /* its primary purpose is debugging.         */
  68.  
  69. /* ---- Node management --------------------------------------------------
  70.    Functions changing current node pointer to the new node.
  71.    Each created list has its own -- fixed -- datasize. See LLcreate().
  72.    An ellipsis "..." indicates the data to insert.
  73. */
  74. int  LLDnodeInsert( int List, ... );      /* insert BEFORE current node */
  75. int  LLDnodeAdd( int List, ... );         /* insert AFTER current node  */
  76.          /* a return value of -1 indicates a memory allocation problem. */
  77.  
  78. /* Functions NOT changing the current node pointer.
  79.    Especially intended for implementation of Queue's and Stacks.
  80. */
  81. int  LLDnodePrepend( int List, ... );           /* insert as first node */
  82. int  LLDnodeAppend( int List, ... );            /* insert as last node  */
  83.          /* a return value of -1 indicates a memory allocation problem. */
  84.  
  85. /* The following four functions are essentially the same as the preceding
  86.    four. The data is however not passed by value but by reference.
  87. */
  88. int  LLDnodeInsertFrom( int List, void * Source );
  89. int  LLDnodeAddFrom( int List, void * Source );
  90. int  LLDnodePrependFrom( int List, void * Source );
  91. int  LLDnodeAppendFrom( int List, void * Source );
  92.  
  93. void LLDnodeDelete( int List );                  /* remove current node */
  94.         /* current node ptr moved to next node. UNLESS the deleted node */
  95.         /* was the last node: then current ptr moved to previous node   */
  96.  
  97. int  LLDnodeFind( int List, CompFunPtr Compare, void * DataPtr );
  98.         /* Find *DataPtr in the List using the *Compare function.       */
  99.         /* Returns the return value of *Compare. 0 == equal == found.   */
  100.         /* non-zero == not found. Current node is set to found node.    */
  101.         /* Returns 2 for an empty list.                                 */
  102.         /* First checked node is current node.                          */
  103.         /* A NULL Compare-function defaults to the use of memcmp() with */
  104.         /* the list's itemsize as third (size) parameter.               */
  105.         /* simple implementation. FindFirst and FindNext may be needed. */
  106.  
  107. /* ---- current node pointer management ----------------------------------
  108.    These functions change the current node pointer and return 1 when there
  109.    was a change. A return of 0 indicates trying to move past the begin or
  110.    the end of the list, or an empty list. The return value is intended for
  111.    iteration purposes. I.e. stopping a scan through a list.
  112. */
  113. int  LLDnodePtr2First( int List );
  114. int  LLDnodePtr2Last( int List );
  115. int  LLDnodePtr2Next( int List );
  116. int  LLDnodePtr2Prev( int List );
  117.  
  118. /* ---- stored data management -------------------------------------------
  119.    return typed data:
  120. */
  121. int  LLDnodeInt( int List );
  122. long LLDnodeLong( int List );
  123. void * LLDnodePtr( int List );
  124. void FAR * LLDnodeFptr( int List );
  125.  
  126. /* 'return' typeless data. The return value is the size of the data.
  127.    The data is transferred to Destination.
  128.    If 'Destination' is NULL, the only action is returning the size.
  129. */
  130. int LLDnodeDataTo( int List, void * Destination );
  131.  
  132. #endif /* LLD__H */
  133. /* ==== LLD.h  end ==================================================== */
  134.