This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.5a
in repository iortcw.

commit af101ee8d822ac3134a468f02ecd174342a82459
Author: MAN-AT-ARMS <m4n4t4...@gmail.com>
Date:   Sun Feb 21 21:00:41 2016 -0500

    All: More informative warnings with line numbers in shader checking
---
 MP/code/qcommon/q_shared.c   |  8 +++---
 MP/code/qcommon/q_shared.h   |  3 +--
 MP/code/rend2/tr_shader.c    | 59 +++++++++++++++++++++++++++-----------------
 MP/code/renderer/tr_shader.c | 59 +++++++++++++++++++++++++++-----------------
 SP/code/game/g_func_decs.h   |  2 +-
 SP/code/qcommon/q_shared.c   | 19 +++++++-------
 SP/code/qcommon/q_shared.h   |  2 +-
 SP/code/rend2/tr_shader.c    | 48 ++++++++++++++++++++++++++---------
 SP/code/renderer/tr_shader.c | 54 +++++++++++++++++++++++++++++-----------
 9 files changed, 166 insertions(+), 88 deletions(-)

diff --git a/MP/code/qcommon/q_shared.c b/MP/code/qcommon/q_shared.c
index aa53348..6c9bf5a 100644
--- a/MP/code/qcommon/q_shared.c
+++ b/MP/code/qcommon/q_shared.c
@@ -605,16 +605,14 @@ void COM_MatchToken( char **buf_p, char *match ) {
 =================
 SkipBracedSection
 
-The next token should be an open brace.
+The next token should be an open brace or set depth to 1 if already parsed it.
 Skips until a matching close brace is found.
 Internal brace depths are properly skipped.
 =================
 */
-void SkipBracedSection (char **program) {
+qboolean SkipBracedSection (char **program, int depth) {
        char                    *token;
-       int                             depth;
 
-       depth = 0;
        do {
                token = COM_ParseExt( program, qtrue );
                if( token[1] == 0 ) {
@@ -626,6 +624,8 @@ void SkipBracedSection (char **program) {
                        }
                }
        } while( depth && *program );
+
+       return ( depth == 0 );
 }
 
 /*
diff --git a/MP/code/qcommon/q_shared.h b/MP/code/qcommon/q_shared.h
index 05feac0..1127b81 100644
--- a/MP/code/qcommon/q_shared.h
+++ b/MP/code/qcommon/q_shared.h
@@ -840,8 +840,7 @@ typedef struct pc_token_s
 
 void    COM_MatchToken( char**buf_p, char *match );
 
-void SkipBracedSection( char **program );
-void SkipBracedSection_Depth( char **program, int depth ); // start at given 
depth if already matching stuff
+qboolean SkipBracedSection( char **program, int depth );
 void SkipRestOfLine( char **data );
 
 void Parse1DMatrix( char **buf_p, int x, float *m );
diff --git a/MP/code/rend2/tr_shader.c b/MP/code/rend2/tr_shader.c
index 060371e..4caba04 100644
--- a/MP/code/rend2/tr_shader.c
+++ b/MP/code/rend2/tr_shader.c
@@ -39,21 +39,8 @@ static shader_t shader;
 static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
 
 #define FILE_HASH_SIZE      4096
-
 static shader_t*       hashTable[FILE_HASH_SIZE];
 
-// Ridah
-// Table containing string indexes for each shader found in the scripts, 
referenced by their checksum
-// values.
-typedef struct shaderStringPointer_s
-{
-       char *pStr;
-       struct shaderStringPointer_s *next;
-} shaderStringPointer_t;
-//
-shaderStringPointer_t shaderChecksumLookup[FILE_HASH_SIZE];
-// done.
-
 /*
 ================
 return a hash value for the filename
@@ -3170,8 +3157,7 @@ static char *FindShaderInShaderText( const char 
*shadername ) {
 
                if ( token[0] == '{' ) {
                        // skip the definition
-//                     SkipBracedSection_Depth( &p, 1 );
-                       SkipBracedSection( &p );
+                       SkipBracedSection( &p, 0 );
                } else if ( !Q_stricmp( token, shadername ) ) {
                        return p;
                } else {
@@ -3671,7 +3657,9 @@ static void ScanAndLoadShaderFiles( void ) {
        char *p;
        int numShaderFiles;
        int i;
-       char *oldp, *token, *textEnd;
+       char *token, *textEnd;
+       char shaderName[MAX_QPATH];
+       int shaderLine;
 
        long sum = 0, summand;
        // scan for shader files
@@ -3713,26 +3701,51 @@ static void ScanAndLoadShaderFiles( void ) {
 
                // Do a simple check on the shader structure in that file to 
make sure one bad shader file cannot fuck up all other shaders.
                p = buffers[i];
+               COM_BeginParseSession(filename);
                while(1)
                {
                        token = COM_ParseExt(&p, qtrue);
                        
                        if(!*token)
                                break;
-                       
-                       oldp = p;
-                       
+
+                       Q_strncpyz(shaderName, token, sizeof(shaderName));
+                       shaderLine = COM_GetCurrentParseLine();
+
                        token = COM_ParseExt(&p, qtrue);
-                       if(token[0] != '{' && token[1] != '\0')
+                       if( !Q_stricmp( shaderName, token ) ) {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Invalid shader name \"%s\" on line %d.\n",
+                                                       filename, shaderName, 
shaderLine);
+                               break;
+                       }
+
+                       if(token[0] != '{' || token[1] != '\0')
                        {
-                               ri.Printf(PRINT_WARNING, "WARNING: Bad shader 
file %s has incorrect syntax.\n", filename);
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing opening brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if (token[0])
+                               {
+                                       ri.Printf(PRINT_WARNING, " (found 
\"%s\" on line %d)", token, COM_GetCurrentParseLine());
+                               }
+                               ri.Printf(PRINT_WARNING, "...Ignored\n");
                                ri.FS_FreeFile(buffers[i]);
                                buffers[i] = NULL;
                                break;
                        }
 
-                       SkipBracedSection(&oldp);
-                       p = oldp;
+                       if(!SkipBracedSection(&p, 1))
+                       {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing closing brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if( !Q_stricmp( filename, "common.shader" ) ) { 
// HACK...Broken shader in pak0.pk3
+                                       ri.Printf(PRINT_WARNING, 
"...Ignored\n");
+                                       ri.FS_FreeFile(buffers[i]);
+                                       buffers[i] = NULL;
+                                       break;
+                               } else {
+                                       ri.Printf(PRINT_WARNING, ".\n");
+                               }
+                       }
                }
 
                if (buffers[i])
diff --git a/MP/code/renderer/tr_shader.c b/MP/code/renderer/tr_shader.c
index 0ba56ee..eb16488 100644
--- a/MP/code/renderer/tr_shader.c
+++ b/MP/code/renderer/tr_shader.c
@@ -39,21 +39,8 @@ static shader_t shader;
 static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
 
 #define FILE_HASH_SIZE      4096
-
 static shader_t*       hashTable[FILE_HASH_SIZE];
 
-// Ridah
-// Table containing string indexes for each shader found in the scripts, 
referenced by their checksum
-// values.
-typedef struct shaderStringPointer_s
-{
-       char *pStr;
-       struct shaderStringPointer_s *next;
-} shaderStringPointer_t;
-//
-shaderStringPointer_t shaderChecksumLookup[FILE_HASH_SIZE];
-// done.
-
 /*
 ================
 return a hash value for the filename
@@ -2471,8 +2458,7 @@ static char *FindShaderInShaderText( const char 
*shadername ) {
 
                if ( token[0] == '{' ) {
                        // skip the definition
-//                     SkipBracedSection_Depth( &p, 1 );
-                       SkipBracedSection( &p );
+                       SkipBracedSection( &p, 0 );
                } else if ( !Q_stricmp( token, shadername ) ) {
                        return p;
                } else {
@@ -2995,7 +2981,9 @@ static void ScanAndLoadShaderFiles( void ) {
        char *p;
        int numShaderFiles;
        int i;
-       char *oldp, *token, *textEnd;
+       char *token, *textEnd;
+       char shaderName[MAX_QPATH];
+       int shaderLine;
 
        long sum = 0, summand;
        // scan for shader files
@@ -3024,26 +3012,51 @@ static void ScanAndLoadShaderFiles( void ) {
 
                // Do a simple check on the shader structure in that file to 
make sure one bad shader file cannot fuck up all other shaders.
                p = buffers[i];
+               COM_BeginParseSession(filename);
                while(1)
                {
                        token = COM_ParseExt(&p, qtrue);
                        
                        if(!*token)
                                break;
-                       
-                       oldp = p;
-                       
+
+                       Q_strncpyz(shaderName, token, sizeof(shaderName));
+                       shaderLine = COM_GetCurrentParseLine();
+
                        token = COM_ParseExt(&p, qtrue);
-                       if(token[0] != '{' && token[1] != '\0')
+                       if( !Q_stricmp( shaderName, token ) ) {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Invalid shader name \"%s\" on line %d.\n",
+                                                       filename, shaderName, 
shaderLine);
+                               break;
+                       }
+
+                       if(token[0] != '{' || token[1] != '\0')
                        {
-                               ri.Printf(PRINT_WARNING, "WARNING: Bad shader 
file %s has incorrect syntax.\n", filename);
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing opening brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if (token[0])
+                               {
+                                       ri.Printf(PRINT_WARNING, " (found 
\"%s\" on line %d)", token, COM_GetCurrentParseLine());
+                               }
+                               ri.Printf(PRINT_WARNING, "...Ignored\n");
                                ri.FS_FreeFile(buffers[i]);
                                buffers[i] = NULL;
                                break;
                        }
 
-                       SkipBracedSection(&oldp);
-                       p = oldp;
+                       if(!SkipBracedSection(&p, 1))
+                       {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing closing brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if( !Q_stricmp( filename, "common.shader" ) ) { 
// HACK...Broken shader in pak0.pk3
+                                       ri.Printf(PRINT_WARNING, 
"...Ignored\n");
+                                       ri.FS_FreeFile(buffers[i]);
+                                       buffers[i] = NULL;
+                                       break;
+                               } else {
+                                       ri.Printf(PRINT_WARNING, ".\n");
+                               }
+                       }
                }
 
                if (buffers[i])
diff --git a/SP/code/game/g_func_decs.h b/SP/code/game/g_func_decs.h
index 5fd9377..00921ff 100644
--- a/SP/code/game/g_func_decs.h
+++ b/SP/code/game/g_func_decs.h
@@ -69,7 +69,7 @@ extern void Parse3DMatrix ( char * * buf_p , int z , int y , 
int x , float * m )
 extern void Parse2DMatrix ( char * * buf_p , int y , int x , float * m ) ;
 extern void Parse1DMatrix ( char * * buf_p , int x , float * m ) ;
 extern void SkipRestOfLine ( char * * data ) ;
-extern void SkipBracedSection ( char * * program ) ;
+extern qboolean SkipBracedSection ( char * * program , int depth ) ;
 extern void COM_MatchToken ( char * * buf_p , char * match ) ;
 extern char * COM_ParseExt ( char * * data_p , qboolean allowLineBreaks ) ;
 extern int COM_Compress ( char * data_p ) ;
diff --git a/SP/code/qcommon/q_shared.c b/SP/code/qcommon/q_shared.c
index 2aefbf9..ca356c0 100644
--- a/SP/code/qcommon/q_shared.c
+++ b/SP/code/qcommon/q_shared.c
@@ -644,26 +644,27 @@ void COM_MatchToken( char **buf_p, char *match ) {
 =================
 SkipBracedSection
 
-The next token should be an open brace.
+The next token should be an open brace or set depth to 1 if already parsed it.
 Skips until a matching close brace is found.
 Internal brace depths are properly skipped.
 =================
 */
-void SkipBracedSection( char **program ) {
-       char            *token;
-       int depth;
+qboolean SkipBracedSection (char **program, int depth) {
+       char                    *token;
 
-       depth = 0;
        do {
                token = COM_ParseExt( program, qtrue );
-               if ( token[1] == 0 ) {
-                       if ( token[0] == '{' ) {
+               if( token[1] == 0 ) {
+                       if( token[0] == '{' ) {
                                depth++;
-                       } else if ( token[0] == '}' )     {
+                       }
+                       else if( token[0] == '}' ) {
                                depth--;
                        }
                }
-       } while ( depth && *program );
+       } while( depth && *program );
+
+       return ( depth == 0 );
 }
 
 /*
diff --git a/SP/code/qcommon/q_shared.h b/SP/code/qcommon/q_shared.h
index 25469eb..f37ca78 100644
--- a/SP/code/qcommon/q_shared.h
+++ b/SP/code/qcommon/q_shared.h
@@ -852,7 +852,7 @@ typedef struct pc_token_s
 
 void    COM_MatchToken( char**buf_p, char *match );
 
-void SkipBracedSection( char **program );
+qboolean SkipBracedSection( char **program, int depth );
 void SkipRestOfLine( char **data );
 
 void Parse1DMatrix( char **buf_p, int x, float *m );
diff --git a/SP/code/rend2/tr_shader.c b/SP/code/rend2/tr_shader.c
index f593fdc..eb4ccae 100644
--- a/SP/code/rend2/tr_shader.c
+++ b/SP/code/rend2/tr_shader.c
@@ -3200,7 +3200,6 @@ static char *FindShaderInShaderText( const char 
*shadername ) {
                        pShaderString = pShaderString->next;
                }
        }
-
        // done.
 
        /*
@@ -3215,7 +3214,7 @@ static char *FindShaderInShaderText( const char 
*shadername ) {
 
                if ( token[0] == '{' ) {
                        // skip the definition
-                       SkipBracedSection( &p );
+                       SkipBracedSection( &p, 0 );
                } else if ( !Q_stricmp( token, shadername ) ) {
                        return p;
                } else {
@@ -3742,7 +3741,7 @@ static void BuildShaderChecksumLookup( void ) {
 
                if ( !Q_stricmp( token, "{" ) ) {
                        // skip braced section
-                       SkipBracedSection( &p );
+                       SkipBracedSection( &p, 0 );
                        continue;
                }
 
@@ -3785,7 +3784,9 @@ static void ScanAndLoadShaderFiles( void ) {
        char *p;
        int numShaderFiles;
        int i;
-       char *oldp, *token, *textEnd;
+       char *token, *textEnd;
+       char shaderName[MAX_QPATH];
+       int shaderLine;
 
        long sum = 0, summand;
        // scan for shader files
@@ -3827,26 +3828,51 @@ static void ScanAndLoadShaderFiles( void ) {
 
                // Do a simple check on the shader structure in that file to 
make sure one bad shader file cannot fuck up all other shaders.
                p = buffers[i];
+               COM_BeginParseSession(filename);
                while(1)
                {
                        token = COM_ParseExt(&p, qtrue);
                        
                        if(!*token)
                                break;
-                       
-                       oldp = p;
-                       
+
+                       Q_strncpyz(shaderName, token, sizeof(shaderName));
+                       shaderLine = COM_GetCurrentParseLine();
+
                        token = COM_ParseExt(&p, qtrue);
-                       if(token[0] != '{' && token[1] != '\0')
+                       if( !Q_stricmp( shaderName, token ) ) {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Invalid shader name \"%s\" on line %d.\n",
+                                                       filename, shaderName, 
shaderLine);
+                               break;
+                       }
+
+                       if(token[0] != '{' || token[1] != '\0')
                        {
-                               ri.Printf(PRINT_WARNING, "WARNING: Bad shader 
file %s has incorrect syntax.\n", filename);
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing opening brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if (token[0])
+                               {
+                                       ri.Printf(PRINT_WARNING, " (found 
\"%s\" on line %d)", token, COM_GetCurrentParseLine());
+                               }
+                               ri.Printf(PRINT_WARNING, "...Ignored\n");
                                ri.FS_FreeFile(buffers[i]);
                                buffers[i] = NULL;
                                break;
                        }
 
-                       SkipBracedSection(&oldp);
-                       p = oldp;
+                       if(!SkipBracedSection(&p, 1))
+                       {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing closing brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if( !Q_stricmp( filename, "common.shader" ) ) { 
// HACK...Broken shader in pak0.pk3
+                                       ri.Printf(PRINT_WARNING, 
"...Ignored\n");
+                                       ri.FS_FreeFile(buffers[i]);
+                                       buffers[i] = NULL;
+                                       break;
+                               } else {
+                                       ri.Printf(PRINT_WARNING, ".\n");
+                               }
+                       }
                }
 
                if (buffers[i])
diff --git a/SP/code/renderer/tr_shader.c b/SP/code/renderer/tr_shader.c
index d205e19..dd05d4b 100644
--- a/SP/code/renderer/tr_shader.c
+++ b/SP/code/renderer/tr_shader.c
@@ -2496,7 +2496,6 @@ static char *FindShaderInShaderText( const char 
*shadername ) {
                        pShaderString = pShaderString->next;
                }
        }
-
        // done.
 
        /*
@@ -2511,7 +2510,7 @@ static char *FindShaderInShaderText( const char 
*shadername ) {
 
                if ( token[0] == '{' ) {
                        // skip the definition
-                       SkipBracedSection( &p );
+                       SkipBracedSection( &p, 0 );
                } else if ( !Q_stricmp( token, shadername ) ) {
                        return p;
                } else {
@@ -3060,7 +3059,7 @@ static void BuildShaderChecksumLookup( void ) {
 
                if ( !Q_stricmp( token, "{" ) ) {
                        // skip braced section
-                       SkipBracedSection( &p );
+                       SkipBracedSection( &p, 0 );
                        continue;
                }
 
@@ -3103,7 +3102,9 @@ static void ScanAndLoadShaderFiles( void ) {
        char *p;
        int numShaderFiles;
        int i;
-       char *oldp, *token, *textEnd;
+       char *token, *textEnd;
+       char shaderName[MAX_QPATH];
+       int shaderLine;
 
        long sum = 0, summand;
        // scan for shader files
@@ -3129,33 +3130,58 @@ static void ScanAndLoadShaderFiles( void ) {
                
                if ( !buffers[i] )
                        ri.Error( ERR_DROP, "Couldn't load %s", filename );
-
+               
                // Do a simple check on the shader structure in that file to 
make sure one bad shader file cannot fuck up all other shaders.
                p = buffers[i];
+               COM_BeginParseSession(filename);
                while(1)
                {
                        token = COM_ParseExt(&p, qtrue);
                        
                        if(!*token)
                                break;
-                       
-                       oldp = p;
-                       
+
+                       Q_strncpyz(shaderName, token, sizeof(shaderName));
+                       shaderLine = COM_GetCurrentParseLine();
+
                        token = COM_ParseExt(&p, qtrue);
-                       if(token[0] != '{' && token[1] != '\0')
+                       if( !Q_stricmp( shaderName, token ) ) {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Invalid shader name \"%s\" on line %d.\n",
+                                                       filename, shaderName, 
shaderLine);
+                               break;
+                       }
+
+                       if(token[0] != '{' || token[1] != '\0')
                        {
-                               ri.Printf(PRINT_WARNING, "WARNING: Bad shader 
file %s has incorrect syntax.\n", filename);
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing opening brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if (token[0])
+                               {
+                                       ri.Printf(PRINT_WARNING, " (found 
\"%s\" on line %d)", token, COM_GetCurrentParseLine());
+                               }
+                               ri.Printf(PRINT_WARNING, "...Ignored\n");
                                ri.FS_FreeFile(buffers[i]);
                                buffers[i] = NULL;
                                break;
                        }
 
-                       SkipBracedSection(&oldp);
-                       p = oldp;
+                       if(!SkipBracedSection(&p, 1))
+                       {
+                               ri.Printf(PRINT_WARNING, "WARNING: In shader 
file %s...Shader \"%s\" on line %d is missing closing brace",
+                                                       filename, shaderName, 
shaderLine);
+                               if( !Q_stricmp( filename, "common.shader" ) ) { 
// HACK...Broken shader in pak0.pk3
+                                       ri.Printf(PRINT_WARNING, 
"...Ignored\n");
+                                       ri.FS_FreeFile(buffers[i]);
+                                       buffers[i] = NULL;
+                                       break;
+                               } else {
+                                       ri.Printf(PRINT_WARNING, ".\n");
+                               }
+                       }
                }
-
+               
                if (buffers[i])
-                       sum += summand;
+                       sum += summand;         
        }
 
        // build single large buffer

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/iortcw.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to