home *** CD-ROM | disk | FTP | other *** search
-
- /* i4add.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Parameters
-
- Name Type Use
-
- index_ref int A reference to the index file.
- value_ptr char * The new key's value.
- rec_num long The new key's record number.
-
-
- Function Return
-
- Type: int
-
- 0 - Successful Add
- 1 - Index file has flagged for unique keys only and
- the key's value is a duplicate.
- 2 - The record was located in the index file.
- */
-
- #include "d4all.h"
- #include "u4error.h"
- #include "p4misc.h"
-
- #include <string.h>
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern INDEX *v4index ;
- extern BLOCK *v4block ;
-
-
- i4add( int index_ref, char *value_ptr, long rec_num )
- {
- INDEX *index_ptr ;
- char key_data[MAX_KEY_SIZE+8] ;
- KEY *key_ptr ;
- int rc ;
-
- rc = i4filter_check( index_ref ) ;
- if ( rc != 0 ) return rc ;
-
- index_ptr = v4index + index_ref ;
-
- /* Position the correct key */
- rc = i4go( index_ref, value_ptr, rec_num) ;
- if ( rc < 0 ) return( rc) ;
- if ( rc == 0 ) return( 2) ;
- if ( (rc == 1 || rc == 4) && index_ptr->unique ) return( 1 ) ;
- if ( rc == 3 || rc == 4 )
- {
- if ( ! b4leaf(index_ref) )
- if ( i4bottom( index_ref ) < 0 ) return( -1 ) ;
- v4block[index_ptr->block_ref].key_on = v4block[index_ptr->block_ref].num_keys;
- }
-
- #ifdef CLIPPER
- if ( ! b4leaf(index_ref) )
- {
- if ( i4skip(index_ref, -1L) != -1L ) return -1 ;
-
- v4block[index_ptr->block_ref].key_on =
- v4block[index_ptr->block_ref].num_keys ;
- }
- #endif
-
- index_ptr->version = index_ptr->old_version+1 ;
-
- /* Prepare 'key' for the call to 'b4add'. */
- key_ptr = (KEY *) key_data ;
- key_ptr->file_block = 0 ;
- key_ptr->rec_num = rec_num ;
- memcpy( key_ptr->value, value_ptr, (size_t) index_ptr->key_len ) ;
-
- if ( b4add( index_ref, key_ptr) < 0 ) return -1 ;
- return( 0) ;
- }
-
-
-