extern bool RcIoTextInputShutdown( void ) /***************************************/ { if( InStack.Buffer != NULL ) { RESFREE( InStack.Buffer ); InStack.Buffer = NULL; InStack.BufferSize = 0; if( IsEmptyFileStack( InStack ) ) { return( false ); } else { while( !IsEmptyFileStack( InStack ) ) { RcIoPopTextInputFile(); } // return( true ); } } return( true ); } /* RcIoTextInputShutdown */
extern const LogicalFileInfo * RcIoGetLogicalFileInfo( void ) /***********************************************************/ { if( IsEmptyFileStack( InStack ) ) { return( NULL ); } else { return( &(InStack.Current->Logical) ); } } /* RcIoGetLogicalFileInfo */
extern int RcIoTextInputShutdown( void ) /**************************************/ { if( InStack.Buffer != NULL ) { RcMemFree( InStack.Buffer ); InStack.Buffer = NULL; InStack.BufferSize = 0; if( IsEmptyFileStack( InStack ) ) { return( FALSE ); } else { while( !IsEmptyFileStack( InStack ) ) { RcIoPopInputFile(); } // return( TRUE ); } } return( TRUE ); } /* RcIoTextInputShutdown */
extern int RcIoIsCOrHFile( void ) /*******************************/ /* returns true if the current file is a .c or .h file, false otherwise */ { if( IsEmptyFileStack( InStack ) ) { return( FALSE ); } else { return( InStack.Current->Logical.IsCOrHFile ); } } /* RcIoIsCOrHFile */
extern void RcIoOverrideIsCOrHFlag( void ) /****************************************/ { LogicalFileInfo * log; if( !IsEmptyFileStack( InStack ) ) { log = &(InStack.Current->Logical); log->IsCOrHFile = FALSE; } } /* RcIoOverrideIsCOrHFlag */
static void SetPhysFileOffset( FileStack * stack ) /************************************************/ { PhysFileInfo *phys; size_t charsinbuff; if( !IsEmptyFileStack( *stack ) ) { phys = &(stack->Current->Physical); charsinbuff = stack->BufferSize - ( stack->NextChar - stack->Buffer ); phys->Offset = ftell( phys->fp ) - charsinbuff; } } /* SetPhysFileOffset */
extern void RcIoSetLogicalFileInfo( int linenum, char * filename ) /****************************************************************/ { LogicalFileInfo * log; if( !IsEmptyFileStack( InStack ) ) { log = &(InStack.Current->Logical); log->LineNum = linenum; if( filename != NULL ) { strncpy( log->Filename, filename, _MAX_PATH ); RcIoSetIsCOrHFlag(); } } } /* RcIoSetLogicalFileInfo */
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 */
extern void RcIoSetIsCOrHFlag( void ) /***********************************/ { LogicalFileInfo * log; char ext[_MAX_EXT]; if( !IsEmptyFileStack( InStack ) ) { log = &(InStack.Current->Logical); _splitpath( log->Filename, NULL, NULL, NULL, ext ); /* if this is a c or h file ext will be '.', '[ch]', '\0' */ if( ( ext[1] == 'c' || ext[1] == 'h' || ext[1] == 'C' || ext[1] == 'H' ) && ext[2] == '\0' ) { /* if the logical file is a c or h file */ log->IsCOrHFile = true; } else { log->IsCOrHFile = false; } } } /* RcIoSetIsCOrHFlag */
int RcIoGetChar( void ) /*********************/ { bool isempty; bool error; if( IsEmptyFileStack( InStack ) ) { return( EOF ); } if( InStack.NextChar >= InStack.EofChar ) { /* we have reached the end of the buffer */ if( InStack.NextChar >= InStack.Buffer + InStack.BufferSize ) { /* try to read next buffer */ error = ReadBuffer( &(InStack) ); if( error ) { /* this error is reported in ReadBuffer so just terminate */ RcFatalError( ERR_NO_MSG ); } } if( InStack.NextChar >= InStack.EofChar ) { /* this is a real EOF */ /* unstack one file */ isempty = RcIoPopTextInputFile(); if( isempty ) { return( EOF ); } else { /* if we are still at the EOF char, there has been an error */ if( InStack.NextChar >= InStack.EofChar ) { /* this error is reported in ReadBuffer so just terminate */ RcFatalError( ERR_NO_MSG ); } else { /* return \n which will end the current token properly */ /* if it it is not a string and end it with a runaway */ /* string error for strings */ return( '\n' ); } } } } return( GetLogChar( &InStack ) ); } /* RcIoGetChar */
extern void RcIoSetLogicalFileInfo( int linenum, const char * filename ) /**********************************************************************/ { LogicalFileInfo * log; if( !IsEmptyFileStack( InStack ) ) { log = &(InStack.Current->Logical); log->LineNum = linenum; if( filename != NULL ) { if( log->Filename == NULL ) { log->Filename = RESALLOC( strlen( filename ) + 1 ); strcpy( log->Filename, filename ); } else if( strcmp( log->Filename, filename ) != 0 ) { RESFREE( log->Filename ); log->Filename = RESALLOC( strlen( filename ) + 1 ); strcpy( log->Filename, filename ); } RcIoSetIsCOrHFlag(); } } } /* RcIoSetLogicalFileInfo */