]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/common/scriplib.c
Merge commit '84881a66140ad93d0b6cd4d55efbbb459bd91f48' into master-merge
[xonotic/netradiant.git] / tools / quake3 / common / scriplib.c
index 2a18e96f14dd60a9799f3a36cfebd1af30793525..7655aa8f25eaa74237be4bc05c449f5bfd058fb7 100644 (file)
@@ -58,6 +58,7 @@ qboolean tokenready;                     // only qtrue if UnGetToken was just ca
  */
 void AddScriptToStack( const char *filename, int index ){
        int size;
+       void* buffer;
 
        script++;
        if ( script == &scriptstack[MAX_INCLUDES] ) {
@@ -65,10 +66,11 @@ void AddScriptToStack( const char *filename, int index ){
        }
        strcpy( script->filename, ExpandPath( filename ) );
 
-       size = vfsLoadFile( script->filename, (void **)&script->buffer, index );
+       size = vfsLoadFile( script->filename, &buffer, index );
 
        if ( size == -1 ) {
                Sys_Printf( "Script file %s was not found\n", script->filename );
+               script--;
        }
        else
        {
@@ -78,11 +80,12 @@ void AddScriptToStack( const char *filename, int index ){
                else{
                        Sys_Printf( "entering %s\n", script->filename );
                }
-       }
 
-       script->line = 1;
-       script->script_p = script->buffer;
-       script->end_p = script->buffer + size;
+               script->buffer = buffer;
+               script->line = 1;
+               script->script_p = script->buffer;
+               script->end_p = script->buffer + size;
+       }
 }
 
 
@@ -98,7 +101,35 @@ void LoadScriptFile( const char *filename, int index ){
        endofscript = qfalse;
        tokenready = qfalse;
 }
+/* &unload current; for autopacker */
+void SilentLoadScriptFile( const char *filename, int index ){
+       int size;
+
+       if ( script->buffer != NULL && !endofscript ) {
+               free( script->buffer );
+               script->buffer = NULL;
+       }
+
+       script = scriptstack;
+
+       script++;
+       if ( script == &scriptstack[MAX_INCLUDES] ) {
+               Error( "script file exceeded MAX_INCLUDES" );
+       }
+       strcpy( script->filename, ExpandPath( filename ) );
+
+       size = vfsLoadFile( script->filename, (void **)&script->buffer, index );
 
+       if ( size == -1 ) {
+               Sys_Printf( "Script file %s was not found\n", script->filename );
+       }
+       script->line = 1;
+       script->script_p = script->buffer;
+       script->end_p = script->buffer + size;
+
+       endofscript = qfalse;
+       tokenready = qfalse;
+}
 
 /*
    ==============
@@ -144,7 +175,7 @@ void UnGetToken( void ){
 
 qboolean EndOfScript( qboolean crossline ){
        if ( !crossline ) {
-               Error( "Line %i is incomplete\n",scriptline );
+               Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation );
        }
 
        if ( !strcmp( script->filename, "memory buffer" ) ) {
@@ -153,7 +184,7 @@ qboolean EndOfScript( qboolean crossline ){
        }
 
        if ( script->buffer == NULL ) {
-               Sys_Printf( "WARNING: Attempt to free already freed script buffer\n" );
+               Sys_FPrintf( SYS_WRN, "WARNING: Attempt to free already freed script buffer\n" );
        }
        else{
                free( script->buffer );
@@ -196,14 +227,14 @@ qboolean GetToken( qboolean crossline ){
 // skip space
 //
 skipspace:
-       while ( *script->script_p <= 32 )
+       while ( script->script_p < script->end_p && *script->script_p <= 32 )
        {
                if ( script->script_p >= script->end_p ) {
                        return EndOfScript( crossline );
                }
                if ( *script->script_p++ == '\n' ) {
                        if ( !crossline ) {
-                               Error( "Line %i is incomplete\n",scriptline );
+                               Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation );
                        }
                        script->line++;
                        scriptline = script->line;
@@ -218,7 +249,7 @@ skipspace:
        if ( *script->script_p == ';' || *script->script_p == '#'
                 || ( script->script_p[0] == '/' && script->script_p[1] == '/' ) ) {
                if ( !crossline ) {
-                       Error( "Line %i is incomplete\n",scriptline );
+                       Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation );
                }
                while ( *script->script_p++ != '\n' )
                        if ( script->script_p >= script->end_p ) {
@@ -232,7 +263,7 @@ skipspace:
        // /* */ comments
        if ( script->script_p[0] == '/' && script->script_p[1] == '*' ) {
                if ( !crossline ) {
-                       Error( "Line %i is incomplete\n",scriptline );
+                       Error( "Line %i is incomplete\nFile location be: %s\n", scriptline, g_strLoadedFileLocation );
                }
                script->script_p += 2;
                while ( script->script_p[0] != '*' && script->script_p[1] != '/' )
@@ -265,7 +296,7 @@ skipspace:
                                break;
                        }
                        if ( token_p == &token[MAXTOKEN] ) {
-                               Error( "Token too large on line %i\n",scriptline );
+                               Error( "Token too large on line %i\nFile location be: %s\n", scriptline, g_strLoadedFileLocation );
                        }
                }
                script->script_p++;
@@ -278,7 +309,7 @@ skipspace:
                                break;
                        }
                        if ( token_p == &token[MAXTOKEN] ) {
-                               Error( "Token too large on line %i\n",scriptline );
+                               Error( "Token too large on line %i\nFile location be: %s\n", scriptline, g_strLoadedFileLocation );
                        }
                }
        }
@@ -303,12 +334,11 @@ skipspace:
    ==============
  */
 qboolean TokenAvailable( void ) {
-       int oldLine, oldScriptLine;
+       int oldLine;
        qboolean r;
 
        /* save */
        oldLine = scriptline;
-       oldScriptLine = script->line;
 
        /* test */
        r = GetToken( qtrue );