home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CBASE09.ZIP / LSEQ.ZIP / LSEQ.H < prev    next >
Text File  |  1989-08-30  |  5KB  |  126 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "lseq.h    1.1 - 89/07/03" */
  5.  
  6. /*man---------------------------------------------------------------------------
  7. NAME
  8.      lseq - linked sequential file management library
  9.  
  10. SYNOPSIS
  11.      #include <lseq.h>
  12.  
  13. DESCRIPTION
  14.      The lseq library consists of a set of routines for the creation and
  15.      manipulation of doubly-linked sequential files.
  16.  
  17.      lseq uses the blkio library for file access and buffering.  Therefore
  18.      bexit should be used in place of exit when using lseq.
  19.  
  20. SEE ALSO
  21.      lsclose, lscreate, lscursor, lsdelcur, lsfirst, lsgetcur, lsgetlck,
  22.      lsgetr, lsgetrf, lsinscur, lsinsert, lslast, lslock, lsnext, lsopen,
  23.      lsprev, lsputr, lsputrf, lsreccnt, lsrecsize, lssearch, lssetbuf,
  24.      lssetcur, lssetvbuf, lssync.
  25.  
  26. ------------------------------------------------------------------------------*/
  27. #ifndef LSEQ_H        /* prevent multiple includes */
  28. #define LSEQ_H
  29.  
  30. #include <blkio.h>
  31. /* #include <stddef.h> */
  32.  
  33. /* lseq constants */
  34. #define LSOPEN_MAX    BOPEN_MAX    /* max # lseqs open at once */
  35. #define LSBUFCNT    ((size_t)10)    /* default # of records to buffer */
  36.  
  37. /* macro to calculate buffer size needed by a lseq */
  38. #define LSBUFSIZ(RECSIZE, BUFCNT)    (sizeof(lshdr_t) + ((BUFCNT) *    \
  39.                     (offsetof(lsrec_t, recbuf) + (RECSIZE)))
  40.  
  41. /* lseq type definitions */
  42. typedef bpos_t    lspos_t;    /* lseq position */
  43.  
  44. typedef struct {        /* lseq record */
  45.     lspos_t next;        /* next record in list */
  46.     lspos_t prev;        /* previous record in list */
  47.     void *recbuf;        /* record contents */
  48. } lsrec_t;
  49.  
  50. typedef struct {        /* lseq file header */
  51.     bpos_t flh;        /* block number of free list head */
  52.     size_t recsize;        /* size of records */
  53.     int flags;        /* flags */
  54.     lspos_t first;        /* position of first record */
  55.     lspos_t last;        /* position of last record */
  56.     size_t reccnt;        /* number of records currently stored in lseq */
  57. } lshdr_t;
  58.  
  59. typedef struct {        /* lseq control structure */
  60.     lshdr_t lshdr;        /* file header */
  61.     BLKFILE *bp;        /* block file */
  62.     int flags;        /* status flags */
  63.     lspos_t clspos;        /* current lseq position */
  64.     lsrec_t *clsrp;        /* current record */
  65. } lseq_t;
  66. extern lseq_t lsb[LSOPEN_MAX];    /* lseq control structure table declaration */
  67.  
  68. /* lshdr flag bits */
  69. #define LSHMOD          (01)    /* lseq file being modified */
  70.  
  71. /* lsb flag bits */
  72. #define LSOPEN          (03)    /* open status bits */
  73. #define LSREAD          (01)    /* lseq is open for reading */
  74. #define LSWRITE          (02)    /* lseq is open for writing */
  75. #define LSLOCKS         (030)    /* lock status bits */
  76. #define LSRDLCK         (010)    /* lseq is read locked */
  77. #define LSWRLCK         (020)    /* lseq is write locked */
  78. #define LSERR        (0100)    /* error has occurred on this lseq */
  79.  
  80. /* function declarations */
  81. int        lsclose(/* lseq_t *lsp */);
  82. int        lscreate(/* char *filename, size_t recsize */);
  83. #define        lscursor(LSP)    ((void *)(((LSP)->clspos == 0) ? NULL : ~NULL))
  84. int        lsdelcur(/* lseq_t *lsp */);
  85. int        lsfirst(/* lseq_t *lsp */);
  86. int        lsgetcur(/* lseq_t *lsp, lspos_t *lspos_p */);
  87. int        lsgetlck(/* lseq_t *lsp */);
  88. int        lsgetr(/* lseq_t *lsp, void *buf */);
  89. int        lsgetrf(/* lseq_t *lsp, size_t offset, void *buf, size_t bufsize */);
  90. int        lsinscur(/* lseq_t *lsp, void *buf */);
  91. int        lsinsert(/* lseq_t *lsp, void *buf */);
  92. int        lslast(/* lseq_t *lsp */);
  93. int        lslock(/* lseq_t *lsp, int l_type */);
  94. int        lsnext(/* lseq_t *lsp */);
  95. lseq_t *    lsopen(/* char *filename, char *type */);
  96. int        lsprev(/* lseq_t *lsp */);
  97. int        lsputr(/* lseq_t *lsp, void *buf */);
  98. int        lsputrf(/* lseq_t *lsp, size_t offset, void *buf, size_t bufsize */);
  99. #define        lsreccnt(LSP)    ((LSP)->lshdr.reccnt)
  100. #define        lsrecsize(LSP)    ((LSP)->lshdr.recsize)
  101. int        lssearch(/* lseq_t *lsp, size_t offset, void *buf, size_t bufsize, lscmp_t (*cmp_p)() */);
  102. int        lssetbuf(/* lseq_t *lsp, void *buf */);
  103. int        lssetcur(/* lseq_t *lsp, lspos_t *lspos_p */);
  104. int        lssetvbuf(/* lseq_t *lsp, void *buf, size_t bufcnt */);
  105. int        lssync(/* lseq_t *lsp */);
  106.  
  107. /* lseq lock types */
  108. #define LS_UNLCK    (0)    /* unlock */
  109. #define LS_RDLCK    (1)    /* read lock */
  110. #define LS_WRLCK    (2)    /* write lock */
  111. #define LS_RDLKW    (3)    /* read lock, wait */
  112. #define LS_WRLKW    (4)    /* write lock, wait */
  113.  
  114. /* lseq error codes */
  115. #define LSEOS        (-50)    /* start of lseq error code domain */
  116. #define LSEMFILE    (LSEOS - 1)    /* too many open lseqs */
  117. #define LSECORRUPT    (LSEOS - 2)    /* lseq is corrupt */
  118. #define LSENOPEN    (LSEOS - 3)    /* lseq not open */
  119. #define LSENBUF        (LSEOS - 4)    /* buffering is off */
  120. #define LSELOCK        (LSEOS - 5)    /* incorrect lock type */
  121. #define LSENREC        (LSEOS - 6)    /* no record */
  122. #define LSEBOUND    (LSEOS - 7)    /* record boundary error */
  123. #define LSEPANIC    (LSEOS - 10)    /* internal lseq error */
  124.  
  125. #endif        /* #ifndef LSEQ_H */
  126.