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 / I4GO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-14  |  1.7 KB  |  74 lines

  1.  
  2. /*  i4go.c   (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  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 "d4base.h"
  26. #include <string.h>
  27.  
  28. extern INDEX   *v4index ;
  29.  
  30.  
  31. i4go( index_ref, value_ptr, rec_num )
  32. int   index_ref ;
  33. char *value_ptr ;
  34. long  rec_num ;
  35. {
  36.    INDEX  *index_ptr ;
  37.    int    rc, len_compare ;
  38.  
  39.    index_ptr =  v4index + index_ref ;
  40.    len_compare =  index_ptr->key_len ;
  41.  
  42.    switch( i4seek( index_ref, value_ptr )  )
  43.    {
  44.       case  1:  /* Inexact */
  45.      len_compare =  strlen( value_ptr ) ;
  46.  
  47.       case  0:  /* Found */
  48.  
  49.      /* Go until either record number located or on after */
  50.      do
  51.      {
  52.         /* Was the record located ? */
  53.         if ( b4key(index_ref)->rec_num == rec_num )
  54.            return( 0) ;  /* Success */
  55.  
  56.         if ( (rc = (int) i4skip( index_ref, 1L)) <= 0 )  break ;
  57.      }  while ( memcmp(b4key(index_ref)->value, value_ptr, len_compare) == 0) ;
  58.  
  59.      if ( rc == -1 )  return( -1 ) ;  /* Error Return */
  60.      if ( rc ==  0 )  return(  4 ) ;  /* EOF but key Located */
  61.  
  62.      return(  1 ) ;  /* Key Located, Record Not */
  63.  
  64.       case  2:   /* On After */
  65.      return( 2 ) ;
  66.  
  67.       case  3:  /* EOF */
  68.      return(  3 ) ;
  69.    }
  70.    return( -1 ) ;
  71. }
  72.  
  73.  
  74.