limit erroneous script files location reporting to script files

(was reporting image files during .map parsing)
This commit is contained in:
Garux
2025-10-31 02:30:55 +05:00
parent b76a5e22ae
commit a2404a5743
6 changed files with 24 additions and 23 deletions
+9 -8
View File
@@ -26,6 +26,7 @@
#include "qstringops.h"
#include "qpathops.h"
#include "scriplib.h"
#include "stream/stringstream.h"
#include "vfs.h"
#include <list>
#include <cerrno>
@@ -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() );
}
}
+5 -5
View File
@@ -98,7 +98,7 @@ static std::forward_list<VFS_PAKFILE> g_pakFiles;
static std::vector<CopiedString> g_strDirs;
std::vector<CopiedString> 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;
+2 -2
View File
@@ -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<CopiedString> 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<CopiedString> g_strForbiddenDirs;
extern char g_strLoadedFileLocation[1024];
extern class StringOutputStream g_loadedScriptLocation;
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -216,7 +216,7 @@ void Convert_ReferenceLightmaps( const char* base, std::vector<int>& 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 */
+4 -4
View File
@@ -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, "}" ) )