/* * RcIoOpenInput * NB when an error occurs this function MUST return without altering errno */ FILE *RcIoOpenInput( const char *filename, bool text_mode ) /*********************************************************/ { FILE *fp; FileStackEntry *currfile; bool no_handles_available; if( text_mode ) { fp = fopen( filename, "rt" ); } else { fp = ResOpenFileRO( filename ); } no_handles_available = ( fp == NULL && errno == EMFILE ); if( no_handles_available ) { /* set currfile to be the first (not before first) entry */ /* close open files except the current input file until able to open */ /* don't close the current file because Offset isn't set */ for( currfile = InStack.Stack + 1; currfile < InStack.Current && no_handles_available; ++currfile ) { if( currfile->Physical.IsOpen ) { ClosePhysicalFile( &(currfile->Physical) ); if( text_mode ) { fp = fopen( filename, "rt" ); } else { fp = ResOpenFileRO( filename ); } no_handles_available = ( fp == NULL && errno == EMFILE ); } } } return( fp ); } /* RcIoOpenInput */
extern int RcIoPopInputFile( void ) /*********************************/ { PhysFileInfo * phys; phys = &(InStack.Current->Physical); ClosePhysicalFile( phys ); InStack.Current--; if( IsEmptyFileStack( InStack ) ) { return( TRUE ); } else { ReadBuffer( &(InStack) ); return( FALSE ); } } /* RcIoPopInputFile */
bool RcIoPopTextInputFile( void ) /*******************************/ { PhysFileInfo * phys; phys = &(InStack.Current->Physical); ClosePhysicalFile( phys ); FreeLogicalFilename(); FreePhysicalFilename(); InStack.Current--; if( IsEmptyFileStack( InStack ) ) { return( true ); } else { ReadBuffer( &(InStack) ); return( false ); } } /* RcIoPopTextInputFile */