static void PP_Include( const char *ptr ) { const char *filename; char delim; int incl_type; size_t len; while( *ptr == ' ' || *ptr == '\t' ) ++ptr; filename = ptr + 1; if( *ptr == '<' ) { delim = '>'; incl_type = PPINCLUDE_SYS; } else if( *ptr == '"' ) { delim = '"'; incl_type = PPINCLUDE_USR; } else { PP_GenError( "Unrecognized INCLUDE directive" ); return; } ++ptr; while( *ptr != delim && *ptr != '\0' ) ++ptr; len = ptr - filename; if( PP_OpenInclude( filename, len, incl_type ) == NULL ) { sprintf( PPLineBuf + 1, "%cerror Unable to open '%*s'\n", PreProcChar, (int)len, filename ); PPNextTokenPtr = PPLineBuf + 1; } else { PP_GenLine(); } }
void PP_Include( char *ptr ) { char *filename; char delim; int incl_type; while( *ptr == ' ' || *ptr == '\t' ) ++ptr; filename = ptr+1; if( *ptr == '<' ) { delim = '>'; incl_type = PPINCLUDE_SYS; } else if( *ptr == '"' ) { delim = '"'; incl_type = PPINCLUDE_USR; } else { PP_GenError( "Unrecognized INCLUDE directive" ); return; } ++ptr; while( *ptr != delim && *ptr != '\0' ) ++ptr; *ptr = '\0'; if( PP_OpenInclude( filename, incl_type ) == NULL ) { filename = doStrDup( filename ); // want to reuse buffer PPCharPtr = &PPLineBuf[1]; sprintf( PPCharPtr, "%cerror Unable to open '%s'\n", PreProcChar, filename ); PP_Free( filename ); } else { PP_GenLine(); } }
int PP_Init2( const char *filename, unsigned flags, const char *include_path, const char *leadbytes ) { FILE *handle; int hash; for( hash = 0; hash < HASH_SIZE; hash++ ) { PPHashTable[hash] = NULL; } NestLevel = 0; SkipLevel = 0; PPFlags = flags; memset( MBCharLen, 0, 256 ); if( leadbytes != NULL ) { PP_SetLeadBytes( leadbytes ); } else if( flags & PPFLAG_DB_KANJI ) { SetRange( 0x81, 0x9f, 1 ); SetRange( 0xe0, 0xfc, 1 ); } else if( flags & PPFLAG_DB_CHINESE ) { SetRange( 0x81, 0xfc, 1 ); } else if( flags & PPFLAG_DB_KOREAN ) { SetRange( 0x81, 0xfd, 1 ); } else if( flags & PPFLAG_UTF8 ) { SetRange( 0xc0, 0xdf, 1 ); SetRange( 0xe0, 0xef, 2 ); SetRange( 0xf0, 0xf7, 3 ); SetRange( 0xf8, 0xfb, 4 ); SetRange( 0xfc, 0xfd, 5 ); } IncludePath2 = PP_Malloc( 1 ); *IncludePath2 = '\0'; IncludePath2 = AddIncludePath( IncludePath2, include_path ); if( (PPFlags & PPFLAG_IGNORE_INCLUDE) == 0 ) { IncludePath2 = AddIncludePath( IncludePath2, PP_GetEnv( "INCLUDE" ) ); } PP_AddMacro( "__LINE__", 8 ); PP_AddMacro( "__FILE__", 8 ); PP_AddMacro( "__DATE__", 8 ); PP_AddMacro( "__TIME__", 8 ); PP_AddMacro( "__STDC__", 8 ); PP_TimeInit(); handle = PP_Open( filename ); if( handle == NULL ) return( -1 ); PP_GenLine(); PPSavedChar = '\0'; PPTokenPtr = PPNextTokenPtr; return( 0 ); }
static void PP_RCInclude( const char *ptr ) { const char *filename; bool quoted = false; size_t len; while( *ptr == ' ' || *ptr == '\t' ) ++ptr; if( *ptr == '\"' ) { ptr++; quoted = true; } filename = ptr; ++ptr; if( quoted ) { while( *ptr != '\"' ) { ptr++; } } else { for( ;; ) { if( *ptr == ' ' ) break; if( *ptr == '\t' ) break; if( *ptr == '\r' ) break; if( *ptr == '\n' ) break; if( *ptr == '\0' ) break; if( *ptr == '\"' ) break; ++ptr; } } len = ptr - filename; if( PP_OpenInclude( filename, len, PPINCLUDE_USR ) == NULL ) { sprintf( PPLineBuf + 1, "%cerror Unable to open '%*s'\n", PreProcChar, (int)len, filename ); PPNextTokenPtr = PPLineBuf + 1; } else { PP_GenLine(); } }
void PP_RCInclude( char *ptr ) { char *filename; int quoted = 0; while( *ptr == ' ' || *ptr == '\t' ) ++ptr; if( *ptr == '\"' ) { ptr++; quoted = 1; } filename = ptr; ++ptr; if( quoted ) { while( *ptr != '\"' ) { ptr++; } } else { for( ;; ) { if( *ptr == ' ' ) break; if( *ptr == '\t' ) break; if( *ptr == '\r' ) break; if( *ptr == '\n' ) break; if( *ptr == '\0' ) break; if( *ptr == '\"' ) break; ++ptr; } } *ptr = '\0'; if( PP_OpenInclude( filename, PPINCLUDE_USR ) == NULL ) { filename = doStrDup( filename ); // want to reuse buffer PPCharPtr = &PPLineBuf[1]; sprintf( PPCharPtr, "%cerror Unable to open '%s'\n", PreProcChar, filename ); PP_Free( filename ); } else { PP_GenLine(); } }
static size_t PP_ReadLine( char *line_generated ) { FILELIST *this_file; size_t len; unsigned char c; if( PP_File == NULL ) { // if end of main file return( 0 ); // - indicate EOF } PPLineNumber = PP_File->linenum; PPLineBuf[0] = '\0'; PPNextTokenPtr = PPLineBuf + 1; *line_generated = 0; len = 1; for( ;; ) { for( ;; ) { for( ;; ) { c = *PPBufPtr; if( c == DOS_EOF_CHAR ) { // 17-oct-94 c = '\n'; if( len != 1 ) break; c = DOS_EOF_CHAR; } else { ++PPBufPtr; if( c != '\0' ) { break; } } if( c == DOS_EOF_CHAR || (PP_ReadBuf() == 0) ) { // if the last line of a file does not end with a carriage // return then still return what is on that line if( len > 1 ) { c = '\n'; break; } this_file = PP_File; fclose( this_file->handle ); PP_File = this_file->prev_file; PPBufPtr = this_file->prev_bufptr; PP_Free( this_file->filename ); PP_Free( this_file ); if( PP_File == NULL ) { // if end of main file return( 0 ); // - indicate EOF } PP_GenLine(); *line_generated = 1; len = strlen( PPNextTokenPtr ); return( len ); } } PPLineBuf[len] = c; if( c == '\n' ) break; ++len; } PP_File->linenum++; if( PPLineBuf[len - 1] == '\r' ) --len; if( PPLineBuf[len - 1] != '\\' ) break; --len; } PPLineBuf[len++] = '\n'; PPLineBuf[len++] = '\0'; PPNextTokenPtr = PPLineBuf + 1; return( len ); }