home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-1.ZIP / SOURCE.ZIP / I4CLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-14  |  1.7 KB  |  76 lines

  1.  
  2. /* i4close.c   (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  All rights reserved.
  3.  
  4.    Closes an index file.
  5. */
  6.  
  7. #include "d4base.h"
  8. #include "u4error.h"
  9.  
  10. #ifndef UNIX
  11.    #include <io.h>
  12. #endif
  13.  
  14. extern  INDEX  *v4index ;
  15. extern  BASE   *v4base  ;
  16. extern  BLOCK  *v4block ;
  17. extern  int     v4index_free ;
  18.  
  19. i4close( index_ref )
  20. int      index_ref ;
  21. {
  22.    INDEX *index_ptr ;
  23.    BASE  *base_ptr  ;
  24.    int    index_on ;
  25.  
  26.    if ( index_ref < 0)
  27.    {
  28.       u4error( E_I_CLOSE, (char *) 0) ;
  29.       return( -1) ;
  30.    }
  31.  
  32.    if ( v4index_free == index_ref )  v4index_free =  -1 ;
  33.  
  34.    index_ptr =  v4index + index_ref ;
  35.    if (index_ptr->base_ref < 0)
  36.    {
  37.       u4error( E_I_CLOSE, (char *) 0) ;
  38.       return( -1) ;
  39.    }
  40.  
  41.    base_ptr  =  v4base  + index_ptr->base_ref ;
  42.    for( index_on=base_ptr->index_ref; index_on >= 0; index_on = v4index[index_on].prev)
  43.       if ( index_on == index_ref )  break ;
  44.  
  45.    if ( index_on != index_ref )
  46.    {
  47.       u4error( E_I_CLOSE, (char *) 0) ;
  48.       return( -1) ;
  49.    }
  50.  
  51.    if ( i4free( index_ref ) < 0)  return -1 ;
  52.    if ( i4unlock( index_ref ) < 0)   /* This function also frees block memory */
  53.       return( -1) ;
  54.  
  55.    if ( index_ptr->dos_file >= 0)
  56.       if ( close( index_ptr->dos_file ) < 0)
  57.       {
  58.      u4error( E_I_CLOSE, (char *) 0) ;
  59.      return( -1) ;
  60.       }
  61.  
  62.    if ( index_ptr->compile != (char *) 0)
  63.       h4free_memory( index_ptr->compile ) ;
  64.  
  65.    if ( base_ptr->index_ref == index_ref )
  66.     base_ptr->index_ref =  h4free( (char **) &v4index, index_ref ) ;
  67.    else
  68.     h4free( (char **) &v4index, index_ref) ;
  69.  
  70.    if ( base_ptr->current_index == index_ref )
  71.     base_ptr->current_index =  -1 ;
  72.  
  73.    return( 0) ;
  74. }
  75.  
  76.