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

  1.  
  2. /*  i4add.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 *      The new key's value.
  10.        rec_num      long    The new key's record number.
  11.  
  12.  
  13.     Function Return
  14.  
  15.        Type:       int
  16.  
  17.       0 -  Successful Add
  18.       1 -  Index file has flagged for unique keys only and
  19.            the key's value is a duplicate.
  20.       2 -  The record was located in the index file.
  21. */
  22.  
  23. #include "d4base.h"
  24. #include "u4error.h"
  25.  
  26. #include <string.h>
  27. #ifndef UNIX
  28.    #include <io.h>
  29. #endif
  30.  
  31. extern INDEX   *v4index ;
  32. extern BLOCK   *v4block ;
  33.  
  34.  
  35. i4add( index_ref, value_ptr, rec_num )
  36. int   index_ref ;
  37. char *value_ptr ;
  38. long  rec_num ;
  39. {
  40.    INDEX *index_ptr ;
  41.    char   key_data[MAX_KEY_SIZE+8] ;
  42.    KEY   *key_ptr ;
  43.    int    rc ;
  44.  
  45.    index_ptr =  v4index + index_ref ;
  46.  
  47.    /* Position the correct key */
  48.    rc =  i4go( index_ref, value_ptr, rec_num) ;
  49.    if ( rc <  0 ) return( -1) ;
  50.    if ( rc == 0 ) return(  2) ;
  51.    if ( (rc == 1 || rc == 4)  && index_ptr->unique )  return( 1 ) ;
  52.    if ( rc == 3 || rc == 4 )
  53.    {
  54.       if ( ! b4leaf(index_ref) )
  55.      if ( i4bottom( index_ref ) < 0 ) return( -1 ) ;
  56.       v4block[index_ptr->block_ref].key_on = v4block[index_ptr->block_ref].num_keys;
  57.    }
  58.  
  59.    #ifdef CLIPPER
  60.       if ( ! b4leaf(index_ref) )
  61.       {
  62.      if ( i4skip(index_ref, -1L)  !=  -1L )  return -1 ;
  63.  
  64.      v4block[index_ptr->block_ref].key_on =
  65.          v4block[index_ptr->block_ref].num_keys ;
  66.       }
  67.    #endif
  68.  
  69.    index_ptr->version =  index_ptr->old_version+1 ;
  70.  
  71.    /* Prepare 'key' for the call to 'b4add'. */
  72.    key_ptr =  (KEY *) key_data ;
  73.    key_ptr->file_block =  0 ;
  74.    key_ptr->rec_num    =  rec_num ;
  75.    memcpy( key_ptr->value, value_ptr, index_ptr->key_len ) ;
  76.  
  77.    if ( b4add( index_ref, key_ptr) < 0 )  return -1 ;
  78.    return( 0) ;
  79. }
  80.  
  81.  
  82.