home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / I4GO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-05  |  1.8 KB  |  77 lines

  1.  
  2. /*  i4go.c   (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  3.  
  4.     Parameters
  5.  
  6.        Name        Type     Use
  7.  
  8.        index_ref    int           A reference to the index file.
  9.        value_ptr    char *       A pointer to the key value.
  10.        rec_num      long     A record number to search for.
  11.  
  12.  
  13.     Function Return
  14.  
  15.        Type:       int
  16.      -1 -  Error
  17.       0 -  Successfully Located
  18.       1 -  Key Value Located; Record Number not Located.
  19.            (Positioned at key after 'value_ptr')
  20.       2 -  Neither Key Value nor Record Number Located
  21.            (Positioned at key after 'value_ptr')
  22.       3 -  EOF  (Just at End)
  23. */
  24.  
  25. #include "p4misc.h"
  26. #include "d4all.h"
  27.  
  28. #include <string.h>
  29.  
  30. extern INDEX   *v4index ;
  31.  
  32.  
  33. i4go( int index_ref, char *value_ptr, long rec_num )
  34. {
  35.    INDEX  *index_ptr ;
  36.    int    rc, len_compare ;
  37.  
  38.    index_ptr =  v4index + index_ref ;
  39.    len_compare =  index_ptr->key_len ;
  40.  
  41.    switch( i4seek( index_ref, value_ptr )  )
  42.    {
  43.       case  1:  /* Inexact */
  44.      len_compare =  (int) strlen( value_ptr ) ;
  45.  
  46.       case  0:  /* Found */
  47.  
  48.      /* Go until either record number located or on after */
  49.      do
  50.      {
  51.         /* Was the record located ? */
  52.         if ( i4key(index_ref)->rec_num == rec_num )
  53.            return( 0) ;  /* Success */
  54.  
  55.         /* Is the record greater ? */
  56.         if ( i4key(index_ref)->rec_num > rec_num )
  57.            return 1 ;  /* Success */
  58.  
  59.         if ( (rc = (int) i4skip( index_ref, 1L)) <= 0 )  break ;
  60.      }  while ( memcmp(i4key(index_ref)->value, value_ptr, (size_t) len_compare) == 0) ;
  61.  
  62.      if ( rc == -1 )  return( -1 ) ;  /* Error Return */
  63.      if ( rc ==  0 )  return(  4 ) ;  /* EOF but key Located */
  64.  
  65.      return(  1 ) ;  /* Key Located, Record Not */
  66.  
  67.       case  2:   /* On After */
  68.      return( 2 ) ;
  69.  
  70.       case  3:  /* EOF */
  71.      return(  3 ) ;
  72.    }
  73.    return( -1 ) ;
  74. }
  75.  
  76.  
  77.