X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=tools%2Fquake2%2Fqdata_heretic2%2Fcommon%2Fscriplib.c;h=af5e57165c83e629400a14a7037158e4b4e8e257;hp=15042d5da011aeaf89d41d9e00d8dc328ac91208;hb=830125fad042fad35dc029b6eb57c8156ad7e176;hpb=515673c08f8718a237e90c2130a1f5294f966d6a diff --git a/tools/quake2/qdata_heretic2/common/scriplib.c b/tools/quake2/qdata_heretic2/common/scriplib.c index 15042d5d..af5e5716 100644 --- a/tools/quake2/qdata_heretic2/common/scriplib.c +++ b/tools/quake2/qdata_heretic2/common/scriplib.c @@ -1,23 +1,23 @@ /* -Copyright (C) 1999-2007 id Software, Inc. and contributors. -For a list of contributors, see the accompanying CONTRIBUTORS file. + Copyright (C) 1999-2007 id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ // scriplib.c @@ -26,46 +26,46 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "scriplib.h" /* -============================================================================= + ============================================================================= - PARSING STUFF + PARSING STUFF -============================================================================= -*/ + ============================================================================= + */ typedef struct { - char filename[1024]; + char filename[1024]; char *buffer,*script_p,*end_p; - int line; + int line; } script_t; -#define MAX_INCLUDES 8 -script_t scriptstack[MAX_INCLUDES]; -script_t *script; -int scriptline; +#define MAX_INCLUDES 8 +script_t scriptstack[MAX_INCLUDES]; +script_t *script; +int scriptline; -char token[MAXTOKEN]; +char token[MAXTOKEN]; qboolean endofscript; qboolean tokenready; // only true if UnGetScriptToken was just called /* -============== -AddScriptToStack -============== -*/ -void AddScriptToStack (char *filename) -{ - int size; + ============== + AddScriptToStack + ============== + */ +void AddScriptToStack( char *filename ){ + int size; script++; - if (script == &scriptstack[MAX_INCLUDES]) - Error ("script file exceeded MAX_INCLUDES"); - strcpy (script->filename, ExpandPath (filename) ); + if ( script == &scriptstack[MAX_INCLUDES] ) { + Error( "script file exceeded MAX_INCLUDES" ); + } + strcpy( script->filename, ExpandPath( filename ) ); - size = LoadFile (script->filename, (void **)&script->buffer); + size = LoadFile( script->filename, (void **)&script->buffer ); - printf ("entering %s\n", script->filename); + printf( "entering %s\n", script->filename ); script->line = 1; @@ -75,14 +75,13 @@ void AddScriptToStack (char *filename) /* -============== -LoadScriptFile -============== -*/ -void LoadScriptFile (char *filename) -{ + ============== + LoadScriptFile + ============== + */ +void LoadScriptFile( char *filename ){ script = scriptstack; - AddScriptToStack (filename); + AddScriptToStack( filename ); endofscript = false; tokenready = false; @@ -90,17 +89,17 @@ void LoadScriptFile (char *filename) /* -============== -ParseFromMemory -============== -*/ -void ParseFromMemory (char *buffer, int size) -{ + ============== + ParseFromMemory + ============== + */ +void ParseFromMemory( char *buffer, int size ){ script = scriptstack; script++; - if (script == &scriptstack[MAX_INCLUDES]) - Error ("script file exceeded MAX_INCLUDES"); - strcpy (script->filename, "memory buffer" ); + if ( script == &scriptstack[MAX_INCLUDES] ) { + Error( "script file exceeded MAX_INCLUDES" ); + } + strcpy( script->filename, "memory buffer" ); script->buffer = buffer; script->line = 1; @@ -113,108 +112,108 @@ void ParseFromMemory (char *buffer, int size) /* -============== -UnGetScriptToken + ============== + UnGetScriptToken -Signals that the current token was not used, and should be reported -for the next GetScriptToken. Note that + Signals that the current token was not used, and should be reported + for the next GetScriptToken. Note that -GetScriptToken (true); -UnGetScriptToken (); -GetScriptToken (false); + GetScriptToken (true); + UnGetScriptToken (); + GetScriptToken (false); -could cross a line boundary. -============== -*/ -void UnGetScriptToken (void) -{ + could cross a line boundary. + ============== + */ +void UnGetScriptToken( void ){ tokenready = true; } -qboolean EndOfScript (qboolean crossline) -{ - if (!crossline) - Error ("Line %i is incomplete\n",scriptline); +qboolean EndOfScript( qboolean crossline ){ + if ( !crossline ) { + Error( "Line %i is incomplete\n",scriptline ); + } - if (!strcmp (script->filename, "memory buffer")) - { + if ( !strcmp( script->filename, "memory buffer" ) ) { endofscript = true; return false; } - free (script->buffer); - if (script == scriptstack+1) - { + free( script->buffer ); + if ( script == scriptstack + 1 ) { endofscript = true; return false; } script--; scriptline = script->line; - printf ("returning to %s\n", script->filename); - return GetScriptToken (crossline); + printf( "returning to %s\n", script->filename ); + return GetScriptToken( crossline ); } /* -============== -GetScriptToken -============== -*/ -qboolean GetScriptToken (qboolean crossline) -{ + ============== + GetScriptToken + ============== + */ +qboolean GetScriptToken( qboolean crossline ){ char *token_p; - if (tokenready) // is a token allready waiting? - { + if ( tokenready ) { // is a token allready waiting? tokenready = false; return true; } - if (script->script_p >= script->end_p) - return EndOfScript (crossline); + if ( script->script_p >= script->end_p ) { + return EndOfScript( crossline ); + } // // skip space // skipspace: - while (*script->script_p <= 32) + while ( *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); + if ( script->script_p >= script->end_p ) { + return EndOfScript( crossline ); + } + if ( *script->script_p++ == '\n' ) { + if ( !crossline ) { + Error( "Line %i is incomplete\n",scriptline ); + } scriptline = script->line++; } } - if (script->script_p >= script->end_p) - return EndOfScript (crossline); + if ( script->script_p >= script->end_p ) { + return EndOfScript( crossline ); + } // ; # // comments - if (*script->script_p == ';' || *script->script_p == '#' - || ( script->script_p[0] == '/' && script->script_p[1] == '/') ) - { - if (!crossline) - Error ("Line %i is incomplete\n",scriptline); - while (*script->script_p++ != '\n') - if (script->script_p >= script->end_p) - return EndOfScript (crossline); + if ( *script->script_p == ';' || *script->script_p == '#' + || ( script->script_p[0] == '/' && script->script_p[1] == '/' ) ) { + if ( !crossline ) { + Error( "Line %i is incomplete\n",scriptline ); + } + while ( *script->script_p++ != '\n' ) + if ( script->script_p >= script->end_p ) { + return EndOfScript( crossline ); + } goto skipspace; } // /* */ comments - if (script->script_p[0] == '/' && script->script_p[1] == '*') - { - if (!crossline) - Error ("Line %i is incomplete\n",scriptline); - script->script_p+=2; - while (script->script_p[0] != '*' && script->script_p[1] != '/') + if ( script->script_p[0] == '/' && script->script_p[1] == '*' ) { + if ( !crossline ) { + Error( "Line %i is incomplete\n",scriptline ); + } + script->script_p += 2; + while ( script->script_p[0] != '*' && script->script_p[1] != '/' ) { script->script_p++; - if (script->script_p >= script->end_p) - return EndOfScript (crossline); + if ( script->script_p >= script->end_p ) { + return EndOfScript( crossline ); + } } script->script_p += 2; goto skipspace; @@ -225,37 +224,40 @@ skipspace: // token_p = token; - if (*script->script_p == '"') - { + if ( *script->script_p == '"' ) { // quoted token script->script_p++; - while (*script->script_p != '"') + while ( *script->script_p != '"' ) { *token_p++ = *script->script_p++; - if (script->script_p == script->end_p) + if ( script->script_p == script->end_p ) { break; - if (token_p == &token[MAXTOKEN]) - Error ("Token too large on line %i\n",scriptline); + } + if ( token_p == &token[MAXTOKEN] ) { + Error( "Token too large on line %i\n",scriptline ); + } } script->script_p++; } - else // regular token - while ( *script->script_p > 32 && *script->script_p != ';') - { - *token_p++ = *script->script_p++; - if (script->script_p == script->end_p) - break; - if (token_p == &token[MAXTOKEN]) - Error ("Token too large on line %i\n",scriptline); + else{ // regular token + while ( *script->script_p > 32 && *script->script_p != ';' ) + { + *token_p++ = *script->script_p++; + if ( script->script_p == script->end_p ) { + break; + } + if ( token_p == &token[MAXTOKEN] ) { + Error( "Token too large on line %i\n",scriptline ); + } + } } *token_p = 0; - if (!strcmp (token, "$include")) - { - GetScriptToken (false); - AddScriptToStack (token); - return GetScriptToken (crossline); + if ( !strcmp( token, "$include" ) ) { + GetScriptToken( false ); + AddScriptToStack( token ); + return GetScriptToken( crossline ); } return true; @@ -263,35 +265,36 @@ skipspace: /* -============== -ScriptTokenAvailable + ============== + ScriptTokenAvailable -Returns true if there is another token on the line -============== -*/ -qboolean ScriptTokenAvailable (void) -{ + Returns true if there is another token on the line + ============== + */ +qboolean ScriptTokenAvailable( void ){ char *search_p; search_p = script->script_p; - if (search_p >= script->end_p) + if ( search_p >= script->end_p ) { return false; + } - while ( *search_p <= 32) + while ( *search_p <= 32 ) { - if (*search_p == '\n') + if ( *search_p == '\n' ) { return false; + } search_p++; - if (search_p == script->end_p) + if ( search_p == script->end_p ) { return false; + } } - if (*search_p == ';') + if ( *search_p == ';' ) { return false; + } return true; } - -