home *** CD-ROM | disk | FTP | other *** search
-
- /* i4seek.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Locates the index key.
-
- Following Returns
-
- 0 - Exact Find
- 1 - Inexact Find
- 2 - On key After
- 3 - EOF
-
- */
-
- #include "d4all.h"
- #include "p4misc.h"
-
- #include <string.h>
-
- extern INDEX *v4index ;
- extern BLOCK *v4block ;
- extern int v4lock_wait ;
-
- i4seek( int index_ref, void *search_string )
- {
- int rc, ref ;
-
- #ifdef CLIPPER
- int key_len, compare_len ;
-
- key_len = v4index[index_ref].key_len ;
- #endif
-
- if ( (rc = i4lock( index_ref, v4lock_wait)) < 0 ) return rc ;
-
- /* Do initial search, moving up only as far as necessary */
- while ( b4up(index_ref) >= 0 ) ;
- if ( v4index[index_ref].block_ref < 0 )
- if ( b4down( index_ref, -1 ) < 0 ) return -1 ;
-
- /* Repeat until the key is found */
- for(;;)
- {
- /* Locate in the current block */
- rc = b4search( index_ref, (char *) search_string ) ;
- if ( rc < 0) return( -1) ;
-
- /* If we are on a 'leaf' of the 'tree' */
- if ( b4leaf(index_ref) )
- {
- if ( rc == 3 )
- {
- #ifdef CLIPPER
- while (1)
- {
- if ( b4up(index_ref) < 0 ) return 3 ;
-
- ref = v4index[index_ref].block_ref ;
-
- if ( v4block[ref].key_on < v4block[ref].num_keys )
- {
- compare_len = (int) strlen((char *)search_string) ;
- if ( compare_len > key_len )
- compare_len = key_len ;
-
- if ( memcmp(search_string, i4key(index_ref)->value,
- (size_t) compare_len) == 0 )
- {
- if ( compare_len == key_len )
- return 0 ;
- else
- return 1 ;
- }
- return( 2 ) ;
- }
- }
- #else
- /* EOF */
- /* Note: Assignment to 'ref' seems to fix the introduction of
- an Optimization error */
- ref = v4index[index_ref].block_ref ;
- v4block[ ref ].key_on = v4block[ ref ].num_keys+1 ;
- #endif
- }
- return( rc) ; /* b4search has the same "rc" conventions */
- }
- else
- {
- /* We should be able to move down as we are not on a leaf */
- if ( b4down( index_ref, -1 ) < 0 ) return( -1 ) ;
- }
- }
- }
-
-