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

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "lssetcur.c    1.1 - 89/07/03" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8. /* #include <string.h> */
  9. #include "lseq_.h"
  10.  
  11. /*man---------------------------------------------------------------------------
  12. NAME
  13.      lssetcur - set lseq cursor
  14.  
  15. SYNOPSIS
  16.      #include <lseq.h>
  17.  
  18.      int lssetcur(lsp, lspos_p)
  19.      lseq_t *lsp;
  20.      lspos_t *lspos_p;
  21.  
  22. DESCRIPTION
  23.      The lssetcur function sets the current cursor position of lseq lsp to
  24.      the value pointed to by lspos_p.  lspos_p should point to a cursor
  25.      value saved previously with lsgetcur.  If lspos_p is the NULL pointer,
  26.      the cursor is set to null.  It is important to remember that an lseq
  27.      position saved with lsgetcur is not valid after that lseq has been
  28.      unlocked.
  29.  
  30.      lssetcur will fail if one or more of the following is true:
  31.  
  32.      [EINVAL]       lsp is not a valid lseq pointer.
  33.      [LSELOCK]      lsp is not locked.
  34.      [LSENOPEN]     lsp is not open.
  35.  
  36. SEE ALSO
  37.      lsgetcur.
  38.  
  39. DIAGNOSTICS
  40.      Upon successful completion, a value of 0 is returned.  Otherwise, a
  41.      value of -1 is returned, and errno set to indicate the error.
  42.  
  43. ------------------------------------------------------------------------------*/
  44. int lssetcur(lsp, lspos_p)
  45. lseq_t *  lsp;
  46. lspos_t * lspos_p;
  47. {
  48.     int rs = 0;
  49.  
  50.     errno = 0;
  51.  
  52.     /* validate arguments */
  53.     if (!ls_valid(lsp)) {
  54.         errno = EINVAL;
  55.         return -1;
  56.     }
  57.  
  58.     /* check if not open */
  59.     if (!(lsp->flags & LSOPEN)) {
  60.         errno = EINVAL;
  61.         return -1;
  62.     }
  63.  
  64.     /* check locks */
  65.     if (!(lsp->flags & LSLOCKS)) {
  66.         errno = LSELOCK;
  67.         return -1;
  68.     }
  69.  
  70.     /* set new currency */
  71.     if (lspos_p == NULL) {
  72.         memset((void *)&lsp->clspos, 0, sizeof(lsp->clspos));
  73.     } else {
  74.         memcpy((void *)&lsp->clspos, (void *)lspos_p, sizeof(lsp->clspos));
  75.     }
  76.  
  77.     /* read in new current record */
  78.     if (lsp->clspos == 0) {
  79.         ls_rcinit(lsp, lsp->clsrp);
  80.     } else {
  81.         rs = ls_rcget(lsp, lsp->clspos, lsp->clsrp);
  82.         if (rs == -1) {
  83.             LSEPRINT;
  84.             return -1;
  85.         }
  86.     }
  87.  
  88.     errno = 0;
  89.     return 0;
  90. }
  91.