home *** CD-ROM | disk | FTP | other *** search
-
- /* i4index.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Creates an Index File
- */
-
- #include "d4all.h"
- #include "u4error.h"
-
- #include <string.h>
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern INDEX *v4index ;
- extern int v4cur_base ;
- extern int v4block_max ;
- extern int v4lock_wait ;
-
- extern unsigned char _osmajor;
-
- int i4index( char *name, char *expression, int unique, int safety)
- {
- return( i4index_filter(name,expression,unique,safety, (I4FILTER *) 0) ) ;
- }
-
- #ifdef KR
- int i4index_filter( name, expression, unique, safety, filter_routine )
- char *name ;
- char *expression ;
- int unique ;
- int safety ;
- int (*filter_routine)() ;
- #else
- int i4index_filter( char *name, char *expression, int unique, int safety,
- int (*filter_routine)(void) )
- #endif
- {
- int index_ref, rc ;
- INDEX *index_ptr ;
- BASE *base_ptr ;
- char full_name[90] ;
-
- #ifdef CLIPPER
- u4name_full( full_name, name, ".NTX" ) ;
- #else
- u4name_full( full_name, name, ".NDX" ) ;
- #endif
- rc = i4ref( full_name ) ;
- if ( rc >= 0 )
- {
- if ( safety )
- {
- u4error( E_CREATE, full_name, (char *) 0 ) ;
- return( -1 ) ;
- }
- else
- {
- if ( i4close(rc) < 0 ) return( -1 ) ;
- }
- }
-
- base_ptr = d4ptr() ;
- if ( base_ptr == (BASE *) 0)
- {
- u4error( E_CREATE, full_name, (char *) 0 ) ;
- return( -1) ;
- }
-
- if ( (rc = d4lock_all( v4lock_wait, 1)) < 0)
- return( rc ) ;
-
- base_ptr->index_ref= index_ref= h4get((char **)&v4index, base_ptr->index_ref) ;
- if ( index_ref < 0 ) return -1 ;
-
- index_ptr = v4index + index_ref ;
- index_ptr->base_ref = v4cur_base ;
- index_ptr->block_first = index_ptr->block_last = index_ptr->block_ref = -1 ;
- index_ptr->block_max = v4block_max ;
- strncpy( index_ptr->name, full_name, 64) ;
-
- #ifdef CLIPPER
- index_ptr->unique = unique ? 1 : 0 ;
- #else
- index_ptr->unique = unique ? 0x100 : 0 ;
- #endif
- strncpy( index_ptr->expression, expression, sizeof(index_ptr->expression) ) ;
-
- if ( safety )
- index_ptr->file_hand = u4open( full_name, 1 ) ;
- else
- index_ptr->file_hand = u4open( full_name, 2 ) ;
-
- if (index_ptr->file_hand < 0)
- {
- i4close( index_ref ) ;
- return( -1) ;
- }
-
- index_ptr->filter = filter_routine ;
-
- if ( (rc = i4reindex( index_ref)) < 0)
- {
- i4close( index_ref ) ;
- return rc ;
- }
- i4select( index_ref) ;
-
- return( index_ref ) ;
- }
-