home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_1.iso / msdos / c / cbase11.a03 / CBASE11.ZIP / LSEQ / LSDELCUR.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  3KB  |  118 lines

  1. /*
  2.  *    Copyright (c) 1989-1992 Citadel Software, Inc.
  3.  *    All Rights Reserved
  4.  */
  5.  
  6. /* #ident    "@(#)lsdelcur.c    1.7 - 93/01/01" */
  7.  
  8. #include <port.h>
  9.  
  10. /* standard headers */
  11. #include <errno.h>
  12.  
  13. /* library headers */
  14. #include <blkio.h>
  15.  
  16. /* local headers */
  17. #include "lseq_.h"
  18.  
  19. /*man---------------------------------------------------------------------------
  20. NAME
  21.      lsdelcur - delete current lseq record
  22.  
  23. SYNOPSIS
  24.      #include <lseq.h>
  25.  
  26.      int lsdelcur(lsp)
  27.      lseq_t *lsp;
  28.  
  29. DESCRIPTION
  30.      The lsdelcur function deletes the current record from lseq lsp.
  31.      The The cursor is positioned to the record following the deleted
  32.      record.
  33.  
  34.      lsdelcur will fail if one or more of the following is true:
  35.  
  36.      [EINVAL]       lsp is not a valid lseq pointer.
  37.      [LSELOCK]      lsp is not write locked.
  38.      [LSENOPEN]     lsp is not open.
  39.      [LSENREC]      The cursor is null.
  40.  
  41. SEE ALSO
  42.      lsinsert, lssearch.
  43.  
  44. DIAGNOSTICS
  45.      Upon successful completion, a value of 0 is returned.  Otherwise,
  46.      a value of -1 is returned, and errno set to indicate the error.
  47.  
  48. ------------------------------------------------------------------------------*/
  49. #ifdef AC_PROTO
  50. int lsdelcur(lseq_t * lsp)
  51. #else
  52. int lsdelcur(lsp)
  53. lseq_t * lsp;
  54. #endif
  55. {
  56.     bpos_t bpos = 0;
  57.  
  58.     /* validate arguments */
  59.     if (!ls_valid(lsp)) {
  60.         errno = EINVAL;
  61.         return -1;
  62.     }
  63.  
  64.     /* check if not open */
  65.     if (!(lsp->flags & LSOPEN)) {
  66.         errno = LSENOPEN;
  67.         return -1;
  68.     }
  69.  
  70.     /* check if not write locked */
  71.     if (!(lsp->flags & LSWRLCK)) {
  72.         errno = LSELOCK;
  73.         return -1;
  74.     }
  75.  
  76.     /* check if cursor is null */
  77.     if (lsp->clspos == NIL) {
  78.         errno = LSENREC;
  79.         return -1;
  80.     }
  81.  
  82.     /* fix links */
  83.     if (lsp->clsrp->next == NIL) {
  84.         lsp->lshdr.last = lsp->clsrp->prev;
  85.     } else {
  86.         if (bputbf(lsp->bp, (bpos_t)lsp->clsrp->next, offsetof(lsrec_t, prev), &lsp->clsrp->prev, sizeof(lsp->clsrp->prev)) == -1) {
  87.             LSERRLOG;
  88.             return -1;
  89.         }
  90.     }
  91.     if (lsp->clsrp->prev == NIL) {
  92.         lsp->lshdr.first = lsp->clsrp->next;
  93.     } else {
  94.         if (bputbf(lsp->bp, (bpos_t)lsp->clsrp->prev, offsetof(lsrec_t, next), &lsp->clsrp->next, sizeof(lsp->clsrp->next)) == -1) {
  95.             LSERRLOG;
  96.             return -1;
  97.         }
  98.     }
  99.  
  100.     /* decrement record count */
  101.     --lsp->lshdr.reccnt;
  102.  
  103.     /* return block to free list */
  104.     bpos = lsp->clspos;
  105.     if (bflpush(lsp->bp, &bpos) == -1) {
  106.         LSERRLOG;
  107.         return -1;
  108.     }
  109.  
  110.     /* position cursor to next record */
  111.     if (lsnext(lsp) == -1) {
  112.         LSERRLOG;
  113.         return -1;
  114.     }
  115.  
  116.     return 0;
  117. }
  118.