Skip to content

Commit be176ba

Browse files
author
stgatilov
committed
#5869. Reimplemented path shortening for warnings.
Now lexer and parser have GetFileName (absolute) and GetDisplayFileName (relative / short / cleaned). Display filename is used for parser/lexer warnings, and for GUI warnings (and for some mission-related warnings too). This surely cannot break anything =) git-svn-id: http://svn.thedarkmod.com/svn/darkmod_src/trunk@10036 49c82d7f-2e2a-0410-a16f-ae8f201b507f
1 parent fe2b528 commit be176ba

File tree

7 files changed

+32
-9
lines changed

7 files changed

+32
-9
lines changed

game/Missions/MissionDB.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void CMissionDB::ReloadMissionInfoFile()
6363
{
6464
if (!src.ReadToken(&token))
6565
{
66-
src.Warning("Missing name on info declaration in %s line %d", src.GetFileName(), src.GetLineNum());
66+
src.Warning("Missing name on info declaration in %s line %d", src.GetDisplayFileName(), src.GetLineNum());
6767
break;
6868
}
6969

game/Missions/ModInfoDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool CModInfoDecl::Parse(idLexer& src)
3535

3636
if (key.type != TT_PUNCTUATION || key.subtype != P_BRACEOPEN)
3737
{
38-
src.Warning("Cannot find opening brace in file %s:%d.", src.GetFileName(), src.GetLineNum());
38+
src.Warning("Cannot find opening brace in file %s:%d.", src.GetDisplayFileName(), src.GetLineNum());
3939
return false;
4040
}
4141

idlib/Lexer.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ void idLexer::Error( const char *str, ... ) {
218218
va_end(ap);
219219

220220
if ( idLexer::flags & LEXFL_NOFATALERRORS ) {
221-
idLib::common->Warning( "file %s, line %d: %s", idLexer::filename.c_str(), idLexer::line, text );
221+
idLib::common->Warning( "file %s, line %d: %s", idLexer::displayFilename.c_str(), idLexer::line, text );
222222
} else {
223-
idLib::common->Error( "file %s, line %d: %s", idLexer::filename.c_str(), idLexer::line, text );
223+
idLib::common->Error( "file %s, line %d: %s", idLexer::displayFilename.c_str(), idLexer::line, text );
224224
}
225225
}
226226

@@ -240,7 +240,7 @@ void idLexer::Warning( const char *str, ... ) {
240240
va_start( ap, str );
241241
vsprintf( text, str, ap );
242242
va_end( ap );
243-
idLib::common->Warning( "file %s, line %d: %s", idLexer::filename.c_str(), idLexer::line, text );
243+
idLib::common->Warning( "file %s, line %d: %s", idLexer::displayFilename.c_str(), idLexer::line, text );
244244
}
245245

246246
/*
@@ -1652,6 +1652,12 @@ int idLexer::LoadFile( const char *filename, bool OSPath ) {
16521652
idLexer::filename = fp->GetFullPath();
16531653
idLib::fileSystem->CloseFile( fp );
16541654

1655+
// stgatilov #5869: compute shorter non-absolute path for warnings
1656+
// make it relative to TDM root if possible
1657+
const char *tdmroot = cvarSystem->GetCVarString( "fs_basepath" );
1658+
displayFilename = idLexer::filename;
1659+
displayFilename.StripLeadingOnce(tdmroot);
1660+
16551661
idLexer::buffer = buf;
16561662
idLexer::length = length;
16571663
// pointer in script buffer
@@ -1681,6 +1687,7 @@ int idLexer::LoadMemory( const char *ptr, int length, const char *name, int star
16811687
return false;
16821688
}
16831689
idLexer::filename = name;
1690+
idLexer::displayFilename = name;
16841691
idLexer::buffer = ptr;
16851692
idLexer::fileTime = 0;
16861693
idLexer::length = length;

idlib/Lexer.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class idLexer {
285285
int EndOfFile( void );
286286
// returns the current filename
287287
const char * GetFileName( void );
288+
const char * GetDisplayFileName( void );
288289
// get offset in script
289290
const int GetFileOffset( void );
290291
// get file time
@@ -306,7 +307,8 @@ class idLexer {
306307

307308
private:
308309
int loaded; // set when a script file is loaded from file or memory
309-
idStr filename; // file name of the script
310+
idStr displayFilename; // shortened file path for printing warnings
311+
idStr filename; // file path of the script (absolute)
310312
int allocated; // true if buffer memory was allocated
311313
const char * buffer; // buffer containing the script
312314
const char * script_p; // current pointer in the script
@@ -346,6 +348,10 @@ ID_INLINE const char *idLexer::GetFileName( void ) {
346348
return idLexer::filename;
347349
}
348350

351+
ID_INLINE const char *idLexer::GetDisplayFileName( void ) {
352+
return idLexer::displayFilename;
353+
}
354+
349355
ID_INLINE const int idLexer::GetFileOffset( void ) {
350356
return idLexer::script_p - idLexer::buffer;
351357
}

idlib/Parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void idParser::PushScript( idLexer *script ) {
410410

411411
for ( s = idParser::scriptstack; s; s = s->next ) {
412412
if ( !idStr::Icmp(s->GetFileName(), script->GetFileName()) ) {
413-
idParser::Warning( "'%s' recursively included", script->GetFileName() );
413+
idParser::Warning( "'%s' recursively included", script->GetDisplayFileName() );
414414
return;
415415
}
416416
}

idlib/Parser.h

+10
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class idParser {
145145
int GetFlags( void ) const;
146146
// returns the current filename
147147
const char * GetFileName( void ) const;
148+
const char * GetDisplayFileName( void ) const;
148149
// get current offset in current script
149150
const int GetFileOffset( void ) const;
150151
// get file time for current script
@@ -246,6 +247,15 @@ ID_INLINE const char *idParser::GetFileName( void ) const {
246247
}
247248
}
248249

250+
ID_INLINE const char *idParser::GetDisplayFileName( void ) const {
251+
if ( idParser::scriptstack ) {
252+
return idParser::scriptstack->GetDisplayFileName();
253+
}
254+
else {
255+
return "";
256+
}
257+
}
258+
249259
ID_INLINE const int idParser::GetFileOffset( void ) const {
250260
if ( idParser::scriptstack ) {
251261
return idParser::scriptstack->GetFileOffset();

ui/Window.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ bool idWindow::ParseScript(idParser *src, idGuiScriptList &list, int *timeParm,
16701670
}
16711671

16721672
//stgatilov: add filename string to window pool if not there yet
1673-
const char *srcFilename = src->GetFileName();
1673+
const char *srcFilename = src->GetDisplayFileName();
16741674
srcFilename = AddSourceFilenameToPool(srcFilename);
16751675

16761676
idGuiScript *gs = new idGuiScript();
@@ -2251,7 +2251,7 @@ bool idWindow::Parse( idParser *src, bool rebuild) {
22512251
src->ExpectTokenType( TT_NAME, 0, &token );
22522252

22532253
//stgatilov: add filename string to window pool if not there yet
2254-
srcLocation = {src->GetFileName(), src->GetLineNum()};
2254+
srcLocation = {src->GetDisplayFileName(), src->GetLineNum()};
22552255
srcLocation.filename = AddSourceFilenameToPool(srcLocation.filename);
22562256

22572257
SetInitialState(token);

0 commit comments

Comments
 (0)