home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / D4TOP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-19  |  1.2 KB  |  66 lines

  1.  
  2. /*  d4top.c    (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  3.  
  4.     Reads the top record of the database.
  5.     Sets the current record to the top record.
  6.     Uses the active record ordering.
  7.  
  8.     Returns
  9.        0 Success
  10.        3 EOF
  11.       -1 Error
  12.  
  13. */
  14.  
  15. #include "d4all.h"
  16. #include "u4error.h"
  17.  
  18. extern    BASE  *v4base ;
  19. extern  INDEX *v4index ;
  20. extern    int    v4cur_base ;
  21.  
  22. d4top()
  23. {
  24.    BASE *base_ptr ;
  25.    int     rc ;
  26.  
  27.    if ( v4cur_base < 0 ) 
  28.    {
  29.       u4error( E_D_MISSING, (char *) 0 ) ; 
  30.       return( -1 ) ;
  31.    }
  32.  
  33.    base_ptr =  v4base + v4cur_base ;
  34.    base_ptr->bof =  base_ptr->eof =  0 ;
  35.  
  36.    if ( base_ptr->current_index >= 0)
  37.    {
  38.       rc =  i4top( base_ptr->current_index ) ;
  39.       if ( rc < 0 )  return rc ;
  40.       if ( rc == 0)
  41.       {
  42.      rc =  d4go( i4key(base_ptr->current_index)->rec_num ) ;
  43.      if ( rc == 1 ) 
  44.      {
  45.         u4error( E_I_RECORD, i4name(base_ptr->current_index), (char *) 0) ;
  46.         return -1 ;
  47.      }
  48.      return( rc ) ;
  49.       }
  50.    }
  51.    else
  52.    {
  53.       if ( d4reccount() >= 1 )
  54.      return( d4go( 1L) ) ;
  55.    }
  56.  
  57.    /* EOF  -  No Records */
  58.    d4blank() ;
  59.    base_ptr->rec_num = d4reccount()+1L ;
  60.    base_ptr->bof =  base_ptr->eof =  1 ;
  61.  
  62.    return( 3 ) ;
  63. }
  64.  
  65.  
  66.