home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / I4ADD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  2.0 KB  |  83 lines

  1.  
  2. /*  i4add.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 *      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 "d4all.h"
  24. #include "u4error.h"
  25. #include "p4misc.h"
  26.  
  27. #include <string.h>
  28. #ifndef UNIX
  29. #include <io.h>
  30. #endif
  31.  
  32. extern INDEX   *v4index ;
  33. extern BLOCK   *v4block ;
  34.  
  35.  
  36. i4add( int index_ref, char *value_ptr, long rec_num )
  37. {
  38.    INDEX *index_ptr ;
  39.    char   key_data[MAX_KEY_SIZE+8] ;
  40.    KEY   *key_ptr ;
  41.    int    rc ;
  42.  
  43.    rc =  i4filter_check( index_ref ) ;
  44.    if ( rc != 0 )  return rc ;
  45.  
  46.    index_ptr =  v4index + index_ref ;
  47.  
  48.    /* Position the correct key */
  49.    rc =  i4go( index_ref, value_ptr, rec_num) ;
  50.    if ( rc < 0 ) return( rc) ;
  51.    if ( rc == 0 ) return(  2) ;
  52.    if ( (rc == 1 || rc == 4)  && index_ptr->unique )  return( 1 ) ;
  53.    if ( rc == 3 || rc == 4 )
  54.    {
  55.       if ( ! b4leaf(index_ref) )
  56.      if ( i4bottom( index_ref ) < 0 ) return( -1 ) ;
  57.       v4block[index_ptr->block_ref].key_on = v4block[index_ptr->block_ref].num_keys;
  58.    }
  59.  
  60.    #ifdef CLIPPER
  61.       if ( ! b4leaf(index_ref) )
  62.       {
  63.      if ( i4skip(index_ref, -1L)  !=  -1L )  return -1 ;
  64.  
  65.      v4block[index_ptr->block_ref].key_on =
  66.          v4block[index_ptr->block_ref].num_keys ;
  67.       }
  68.    #endif
  69.  
  70.    index_ptr->version =  index_ptr->old_version+1 ;
  71.  
  72.    /* Prepare 'key' for the call to 'b4add'. */
  73.    key_ptr =  (KEY *) key_data ;
  74.    key_ptr->file_block =  0 ;
  75.    key_ptr->rec_num    =  rec_num ;
  76.    memcpy( key_ptr->value, value_ptr, (size_t) index_ptr->key_len ) ;
  77.  
  78.    if ( b4add( index_ref, key_ptr) < 0 )  return -1 ;
  79.    return( 0) ;
  80. }
  81.  
  82.  
  83.