diff --git a/tools/quake3/common/scriplib.cpp b/tools/quake3/common/scriplib.cpp index 8707b702..f7bebd7f 100644 --- a/tools/quake3/common/scriplib.cpp +++ b/tools/quake3/common/scriplib.cpp @@ -26,6 +26,7 @@ #include "qstringops.h" #include "qpathops.h" #include "scriplib.h" +#include "stream/stringstream.h" #include "vfs.h" #include #include @@ -66,7 +67,7 @@ bool tokenready; // only true if UnGetToken was just called ============== */ static bool AddScriptToStack( const char *filename, int index, bool verbose ){ - if ( MemBuffer buffer = vfsLoadFile( filename, index ) ) { + if ( MemBuffer buffer = vfsLoadFile( filename, index, true ) ) { if( verbose ){ if ( index > 0 ) Sys_Printf( "entering %s (%d)\n", filename, index + 1 ); @@ -136,7 +137,7 @@ void UnGetToken(){ static bool EndOfScript( bool crossline ){ if ( !crossline ) { - Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } scriptstack.pop_back(); @@ -181,7 +182,7 @@ skipspace: { if ( *script.it++ == '\n' ) { if ( !crossline ) { - Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } script.line++; scriptline = script.line; @@ -196,7 +197,7 @@ skipspace: if ( *script.it == ';' || *script.it == '#' || ( script.it[0] == '/' && script.it[1] == '/' ) ) { if ( !crossline ) { - Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } while ( *script.it++ != '\n' ) if ( script.it >= script.end ) { @@ -214,7 +215,7 @@ skipspace: { if ( *script.it == '\n' ) { if ( !crossline ) { - Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } script.line++; scriptline = script.line; @@ -243,7 +244,7 @@ skipspace: break; } if ( token_p == token + MAXTOKEN ) { - Error( "Token too large on line %i\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Token too large on line %i\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } } script.it++; @@ -256,7 +257,7 @@ skipspace: break; } if ( token_p == token + MAXTOKEN ) { - Error( "Token too large on line %i\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Token too large on line %i\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } } } @@ -308,7 +309,7 @@ void MatchToken( const char *match ) { GetToken( true ); if ( !strEqual( token, match ) ) { - Error( "MatchToken( \"%s\" ) failed at line %i in file %s", match, scriptline, g_strLoadedFileLocation ); + Error( "MatchToken( \"%s\" ) failed at line %i in file %s", match, scriptline, g_loadedScriptLocation.c_str() ); } } diff --git a/tools/quake3/common/vfs.cpp b/tools/quake3/common/vfs.cpp index 41c6a974..05f90cf1 100644 --- a/tools/quake3/common/vfs.cpp +++ b/tools/quake3/common/vfs.cpp @@ -98,7 +98,7 @@ static std::forward_list g_pakFiles; static std::vector g_strDirs; std::vector g_strForbiddenDirs; static constexpr bool g_bUsePak = true; -char g_strLoadedFileLocation[1024]; +StringOutputStream g_loadedScriptLocation; // ============================================================================= // Static functions @@ -262,11 +262,11 @@ int vfsGetFileCount( const char *filename ){ } // NOTE: when loading a file, you have to allocate one extra byte and set it to \0 -MemBuffer vfsLoadFile( const char *filename, int index /* = 0 */ ){ +MemBuffer vfsLoadFile( const char *filename, int index /* = 0 */, bool script /* = false */ ){ - const auto load_full_path = [] ( const char *filename ) -> MemBuffer + const auto load_full_path = [script] ( const char *filename ) -> MemBuffer { - strcpy( g_strLoadedFileLocation, filename ); + if( script ) g_loadedScriptLocation( filename ); MemBuffer buffer; @@ -308,7 +308,7 @@ MemBuffer vfsLoadFile( const char *filename, int index /* = 0 */ ){ { if ( strEqual( file.name.c_str(), fixedname ) && 0 == index-- ) { - std::snprintf( g_strLoadedFileLocation, std::size( g_strLoadedFileLocation ), "%s :: %s", file.pak.unzFilePath.c_str(), filename ); + if( script ) g_loadedScriptLocation( file.pak.unzFilePath.c_str(), " :: ", filename ); unzFile zipfile = file.pak.zipfile; *(unz_s*)zipfile = file.zipinfo; diff --git a/tools/quake3/common/vfs.h b/tools/quake3/common/vfs.h index aed12e83..ff700b10 100644 --- a/tools/quake3/common/vfs.h +++ b/tools/quake3/common/vfs.h @@ -39,10 +39,10 @@ int vfsGetFileCount( const char *filename ); /// \param[in] index -1: \p filename is absolute path /// \param[in] index >= 0: \p filename is relative path in VSF, Nth occurrence of file /// \return non-empty \c MemBuffer on success -MemBuffer vfsLoadFile( const char *filename, int index = 0 ); +MemBuffer vfsLoadFile( const char *filename, int index = 0, bool script = false ); std::vector vfsListShaderFiles( const char *shaderPath ); bool vfsPackFile( const char *filename, const char *packname, const int compLevel ); bool vfsPackFile_Absolute_Path( const char *filepath, const char *filename, const char *packname, const int compLevel ); extern std::vector g_strForbiddenDirs; -extern char g_strLoadedFileLocation[1024]; +extern class StringOutputStream g_loadedScriptLocation; diff --git a/tools/quake3/q3map2/autopk3.cpp b/tools/quake3/q3map2/autopk3.cpp index 94912314..8fc6fcbf 100644 --- a/tools/quake3/q3map2/autopk3.cpp +++ b/tools/quake3/q3map2/autopk3.cpp @@ -381,7 +381,7 @@ int pk3BSPMain( Args& args ){ /* handle { } section */ if ( !( GetToken( true ) && strEqual( token, "{" ) ) ) { Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s", - scriptFile.c_str(), scriptline, token, g_strLoadedFileLocation ); + scriptFile.c_str(), scriptline, token, g_loadedScriptLocation.c_str() ); } while ( GetToken( true ) && !strEqual( token, "}" ) ) @@ -410,7 +410,7 @@ int pk3BSPMain( Args& args ){ /* handle { } section */ if ( !( GetToken( true ) && strEqual( token, "{" ) ) ) { Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s", - scriptFile.c_str(), scriptline, token, g_strLoadedFileLocation ); + scriptFile.c_str(), scriptline, token, g_loadedScriptLocation.c_str() ); } bool hasmap = false; @@ -797,7 +797,7 @@ int repackBSPMain( Args& args ){ /* handle { } section */ if ( !( text.GetToken( true ) && strEqual( token, "{" ) ) ) { Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s", - scriptFile.c_str(), scriptline, token, g_strLoadedFileLocation ); + scriptFile.c_str(), scriptline, token, g_loadedScriptLocation.c_str() ); } bool hasmap = false; diff --git a/tools/quake3/q3map2/convert_obj.cpp b/tools/quake3/q3map2/convert_obj.cpp index 5da9b197..e46aab2f 100644 --- a/tools/quake3/q3map2/convert_obj.cpp +++ b/tools/quake3/q3map2/convert_obj.cpp @@ -216,7 +216,7 @@ void Convert_ReferenceLightmaps( const char* base, std::vector& lmIndices ) /* handle { } section */ if ( !( GetToken( true ) && strEqual( token, "{" ) ) ) Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s", - shaderfile, scriptline, token, g_strLoadedFileLocation ); + shaderfile, scriptline, token, g_loadedScriptLocation.c_str() ); while ( GetToken( true ) && !strEqual( token, "}" ) ) { /* parse stage directives */ diff --git a/tools/quake3/q3map2/shaders.cpp b/tools/quake3/q3map2/shaders.cpp index b6d21f2d..a03a133f 100644 --- a/tools/quake3/q3map2/shaders.cpp +++ b/tools/quake3/q3map2/shaders.cpp @@ -782,17 +782,17 @@ shaderInfo_t& ShaderInfoForShader( const char *shaderName ){ static void Parse1DMatrixAppend( ShaderTextCollector& text, int x, float *m ){ if ( !text.GetToken( true ) || !strEqual( token, "(" ) ) { - Error( "Parse1DMatrixAppend(): line %d: ( not found!\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Parse1DMatrixAppend(): line %d: ( not found!\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } for ( int i = 0; i < x; ++i ) { if ( !text.GetToken( false ) ) { - Error( "Parse1DMatrixAppend(): line %d: Number not found!\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Parse1DMatrixAppend(): line %d: Number not found!\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } m[ i ] = atof( token ); } if ( !text.GetToken( true ) || !strEqual( token, ")" ) ) { - Error( "Parse1DMatrixAppend(): line %d: ) not found!\nFile location be: %s\n", scriptline, g_strLoadedFileLocation ); + Error( "Parse1DMatrixAppend(): line %d: ) not found!\nFile location be: %s\n", scriptline, g_loadedScriptLocation.c_str() ); } } @@ -823,7 +823,7 @@ static void ParseShaderFile( const char *filename ){ /* handle { } section */ if ( !( text.GetToken( true ) && strEqual( token, "{" ) ) ) { Error( "ParseShaderFile(): %s, line %d: { not found!\nFound instead: %s\nLast known shader: %s\nFile location be: %s\n", - filename, scriptline, token, si.shader.c_str(), g_strLoadedFileLocation ); + filename, scriptline, token, si.shader.c_str(), g_loadedScriptLocation.c_str() ); } while ( text.GetToken( true ) && !strEqual( token, "}" ) )