home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-1.ZIP / SOURCE.ZIP / D4SEEK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-14  |  1.8 KB  |  86 lines

  1.  
  2. /*  d4seek.c   (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  All rights reserved.
  3.  
  4.     Locates and reads the record.
  5.  
  6.     Returns
  7.        0 Success
  8.        1 Inexact Find
  9.        2 On record after
  10.        3 EOF
  11.       -1 Error
  12.  
  13. */
  14.  
  15. #include "d4base.h"
  16. #include "u4error.h"
  17. #include <string.h>
  18.  
  19. extern  BASE  *v4base ;
  20. extern  INDEX *v4index ;
  21. extern  int    v4cur_base ;
  22.  
  23.  
  24. d4seek( search_string )
  25. void   *search_string ;
  26. {
  27.    BASE *base_ptr ;
  28.    int   rc, index_ref ;
  29.  
  30.    if ( v4cur_base < 0 ) 
  31.    {
  32.       u4error( E_D_MISSING, (char *) 0 ) ; 
  33.       return( -1 ) ;
  34.    }
  35.  
  36.    base_ptr =  v4base + v4cur_base ;
  37.  
  38.    if ( base_ptr->current_index >= 0)
  39.       index_ref =  base_ptr->current_index ;
  40.    else
  41.       index_ref =  base_ptr->index_ref ;
  42.  
  43.    if (index_ref < 0)
  44.    {
  45.       u4error( E_NO_INDEX, base_ptr->name, (char *) 0 ) ;
  46.       return( -1 ) ;
  47.    }
  48.  
  49.    #ifdef CLIPPER
  50.       if ( v4index[index_ref].i_type == 'N' ||
  51.        v4index[index_ref].i_type == 'F' ) 
  52.       {
  53.      char  seek_buf[32] ;
  54.      c4dtok( index_ref, *((double *)search_string), seek_buf ) ;
  55.      rc =  i4seek( index_ref, seek_buf ) ;
  56.       }
  57.       else
  58.      rc =  i4seek( index_ref, search_string) ;
  59.    #else
  60.       if ( v4index[index_ref].i_type == 'D' ) 
  61.       {
  62.      double  seek_doub ;
  63.      if ( c4dt_index( search_string, &seek_doub ) < 0) 
  64.      {
  65.         u4error( E_DATE, "d4seek Date:", search_string, (char *) 0 ) ;
  66.         return -1 ;
  67.      }
  68.      rc =  i4seek( index_ref, (char *) &seek_doub ) ;
  69.       }
  70.       else
  71.      rc =  i4seek( index_ref, search_string) ;
  72.    #endif
  73.  
  74.    if ( rc == 3)
  75.    {
  76.       memset( base_ptr->buffer, (int) ' ', (size_t) base_ptr->buffer_len ) ;
  77.       base_ptr->rec_num = 0 ;
  78.       return( 3 ) ;
  79.    }
  80.  
  81.    if ( d4go( b4key(base_ptr->current_index)->rec_num ) < 0 ) return( -1 ) ;
  82.    return( rc ) ;
  83. }
  84.  
  85.  
  86.