home *** CD-ROM | disk | FTP | other *** search
-
- /* i4close.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Closes an index file.
- */
-
- #include "d4all.h"
- #include "u4error.h"
-
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern INDEX *v4index ;
- extern BASE *v4base ;
- extern BLOCK *v4block ;
- extern int v4index_free ;
-
- i4close( int index_ref )
- {
- INDEX *index_ptr ;
- BASE *base_ptr ;
- int index_on ;
-
- if ( index_ref < 0)
- {
- u4error( E_I_CLOSE, (char *) 0) ;
- return( -1) ;
- }
-
- if ( v4index_free == index_ref ) v4index_free = -1 ;
-
- index_ptr = v4index + index_ref ;
- if (index_ptr->base_ref < 0)
- {
- u4error( E_I_CLOSE, (char *) 0) ;
- return( -1) ;
- }
-
- if ( index_ptr->base_ref >= 0 )
- {
- base_ptr = v4base + index_ptr->base_ref ;
- for( index_on=base_ptr->index_ref; index_on >= 0; index_on = v4index[index_on].prev)
- if ( index_on == index_ref ) break ;
-
- if ( index_on != index_ref )
- {
- u4error( E_I_CLOSE, (char *) 0) ;
- return( -1) ;
- }
- }
-
- if ( i4free( index_ref ) < 0) return -1 ;
- if ( i4unlock( index_ref ) < 0) /* This function also frees block memory */
- return( -1) ;
-
- if ( index_ptr->file_hand >= 0)
- if ( close( index_ptr->file_hand ) < 0)
- {
- u4error( E_I_CLOSE, (char *) 0) ;
- return( -1) ;
- }
-
- if ( index_ptr->compile != (char *) 0)
- h4free_memory( index_ptr->compile ) ;
-
- if ( index_ptr->base_ref >= 0 )
- {
- if ( base_ptr->index_ref == index_ref )
- base_ptr->index_ref = h4free( (char **) &v4index, index_ref ) ;
- else
- h4free( (char **) &v4index, index_ref) ;
-
- if ( base_ptr->current_index == index_ref )
- base_ptr->current_index = -1 ;
- }
-
- return( 0) ;
- }
-
-