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

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