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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "lsprev.c    1.1 - 89/07/03" */
  5.  
  6. #include <errno.h>
  7. #include "lseq_.h"
  8.  
  9. /*man---------------------------------------------------------------------------
  10. NAME
  11.      lsprev - previous lseq record
  12.  
  13. SYNOPSIS
  14.      #include <lseq.h>
  15.  
  16.      int lsprev(lsp)
  17.      lseq_t *lsp;
  18.  
  19. DESCRIPTION
  20.      The lsprev function retreats the cursor of lseq lsp to the previous
  21.      record.  If the cursor is currently null, it will be moved to the last
  22.      record.  If the cursor is currently on the last record, it will be
  23.      moved to null.  If lsp is empty, the cursor will remain set to null.
  24.  
  25.      lsprev will fail if one or more of the following is true:
  26.  
  27.      [EINVAL]       lsp is not a valid lseq pointer.
  28.      [LSELOCK]      lsp is not locked.
  29.      [LSENOPEN]     lsp is not open.
  30.  
  31. SEE ALSO
  32.      lscursor, lsfirst, lslast, lsnext.
  33.  
  34. DIAGNOSTICS
  35.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  36.      value of -1 is returned, and errno set to indicate the error.
  37.  
  38. ------------------------------------------------------------------------------*/
  39. int lsprev(lsp)
  40. lseq_t *lsp;
  41. {
  42.     int rs = 0;
  43.  
  44.     errno = 0;
  45.  
  46.     /* validate arguments */
  47.     if (!ls_valid(lsp)) {
  48.         errno = EINVAL;
  49.         return -1;
  50.     }
  51.  
  52.     /* check if not open */
  53.     if (!(lsp->flags & LSOPEN)) {
  54.         errno = LSENOPEN;
  55.         return -1;
  56.     }
  57.  
  58.     /* check if not locked */
  59.     if (!(lsp->flags & LSLOCKS)) {
  60.         errno = LSELOCK;
  61.         return -1;
  62.     }
  63.  
  64.     /* move cursor */
  65.     if (lsp->clspos == 0) {
  66.         lsp->clspos = lsp->lshdr.last;
  67.     } else {
  68.         lsp->clspos = lsp->clsrp->prev;
  69.     }
  70.  
  71.     /* read in new current record */
  72.     if (lsp->clspos == 0) {
  73.         ls_rcinit(lsp, lsp->clsrp);
  74.     } else {
  75.         rs = ls_rcget(lsp, lsp->clspos, lsp->clsrp);
  76.         if (rs == -1) {
  77.             LSEPRINT;
  78.             return -1;
  79.         }
  80.     }
  81.  
  82.     errno = 0;
  83.     return 0;
  84. }
  85.