home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR41 / CBASE11.ZIP / LSSETCUR.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  2KB  |  100 lines

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