]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/parse.cpp
Merge branch 'subdiv' into 'master'
[xonotic/netradiant.git] / radiant / parse.cpp
index c37b74e760c7f8c2dec2589f91d5dde41136d120..ac5dd3b26313f395004da29a5deacc2dc0abe32e 100644 (file)
@@ -1,6 +1,6 @@
 /*
-   Copyright (C) 1999-2007 id Software, Inc. and contributors.
-   For a list of contributors, see the accompanying CONTRIBUTORS file.
+   Copyright (C) 2001-2006, William Joseph.
+   All Rights Reserved.
 
    This file is part of GtkRadiant.
 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "stdafx.h"
+#include "parse.h"
 
-char token[MAXTOKEN];
-qboolean unget;
-char*     script_p;
-int scriptline;
+#include "script/scripttokeniser.h"
+#include "script/scripttokenwriter.h"
 
-// Hydra: added support for GetTokenExtra()
-char *currentdelimiters;
-qboolean script_keepdelimiter;
+class ScriptLibraryAPI
+{
+_QERScripLibTable m_scriptlibrary;
+public:
+typedef _QERScripLibTable Type;
+STRING_CONSTANT( Name, "*" );
 
-void StartTokenParsing( char *data ){
-       scriptline = 1;
-       script_p = data;
-       unget = false;
-
-       // Hydra: added support for GetTokenExtra()
-       currentdelimiters = NULL;
-       script_keepdelimiter = true;
+ScriptLibraryAPI(){
+       m_scriptlibrary.m_pfnNewScriptTokeniser = &NewScriptTokeniser;
+       m_scriptlibrary.m_pfnNewSimpleTokeniser = &NewSimpleTokeniser;
+       m_scriptlibrary.m_pfnNewSimpleTokenWriter = &NewSimpleTokenWriter;
 }
-
-
-qboolean GetToken( qboolean crossline ){
-       char    *token_p;
-
-       if ( unget ) {                   // is a token already waiting?
-               unget = false;
-               return true;
-       }
-
-       //
-       // skip space
-       //
-skipspace:
-       while ( *script_p <= 32 )
-       {
-               if ( !*script_p ) {
-                       if ( !crossline ) {
-                               Sys_Printf( "Warning: Line %i is incomplete [01]\n",scriptline );
-                       }
-                       return false;
-               }
-
-               if ( *script_p++ == '\n' ) {
-                       if ( !crossline ) {
-                               Sys_Printf( "Warning: Line %i is incomplete [02]\n",scriptline );
-                       }
-                       scriptline++;
-               }
-       }
-
-       if ( script_p[0] == '/' && script_p[1] == '/' ) { // comment field
-               if ( !crossline ) {
-                       Sys_Printf( "Warning: Line %i is incomplete [03]\n",scriptline );
-               }
-               while ( *script_p++ != '\n' )
-                       if ( !*script_p ) {
-                               if ( !crossline ) {
-                                       Sys_Printf( "Warning: Line %i is incomplete [04]\n",scriptline );
-                               }
-                               return false;
-                       }
-               scriptline++; // Hydra: fixed bad line numbers problem
-               goto skipspace;
-       }
-
-       //
-       // copy token
-       //
-       token_p = token;
-
-       if ( *script_p == '"' ) {
-               script_p++;
-               while ( *script_p != '"' )
-               {
-                       if ( !*script_p ) {
-                               Error( "EOF inside quoted token" );
-                       }
-                       *token_p++ = *script_p++;
-                       if ( token_p == &token[MAXTOKEN] ) {
-                               Error( "Token too large on line %i",scriptline );
-                       }
-               }
-               script_p++;
-       }
-       else{
-               while ( *script_p > 32 )
-               {
-                       // Hydra: added support for GetTokenExtra(), care was taken to maintain speed
-                       if ( ( currentdelimiters ) && ( !script_keepdelimiter ) && ( strchr( currentdelimiters,*( script_p ) ) ) ) {
-                               break;
-                       }
-
-                       *token_p++ = *script_p++;
-                       if ( token_p == &token[MAXTOKEN] ) {
-                               Error( "Token too large on line %i",scriptline );
-                       }
-
-                       // Hydra: added support for GetTokenExtra()
-                       if ( ( currentdelimiters ) && ( strchr( currentdelimiters,*( script_p - 1 ) ) ) ) {
-                               break;
-                       }
-
-               }
-       }
-
-       *token_p = 0;
-
-       return true;
-}
-
-void UngetToken( void ){
-       unget = true;
+_QERScripLibTable* getTable(){
+       return &m_scriptlibrary;
 }
+};
 
-/*
-   ==============
-   GetTokenExtra
-
-   This function expands the use of GetToken() so it can be used to parse
-   more complex file formats.
-
-   Hydra - Notes:
-   You can use this function to split a string like this
-
-   string1:("string2")
-
-   into two strings, like this:
-   string1
-   string2
+#include "modulesystem/singletonmodule.h"
+#include "modulesystem/moduleregistry.h"
 
-   whilst still checking for the brackets and colons, like this:
-
-   GetTokenExtra(false,":",false);// contains "string1"
-   GetTokenExtra(false,":",true); // contains ":"
-   GetTokenExtra(false,"(",true); // contains "("
-   GetToken(false);               // contains "string2"
-   GetTokenExtra(false,")",true); // contains ")"
-
-   here's what you get, given the same string, with this code:
-
-   GetToken(false); // contains "string1:("string2")"
-
-   Parsing will end if any character in the script matches any one of the
-   characters in the "delimiters" string.
-
-   it's also possible to do things like this:
-
-   source strings:
-   1,2
-   1:2
-   1-2
-   1*2
-
-   code:
-   GetTokenExtra(false,",:-*",false); // token contains "1"
-   GetTokenExtra(false,",:-*",false); // token contains the delimiter that was used
-   GetToken(false);                   // contains "2"
-   ==============
- */
-qboolean GetTokenExtra( qboolean crossline,char *delimiters, qboolean keepdelimiter ){
-       qboolean result;
-       char *olddelimiters = currentdelimiters; // store it
-
-       currentdelimiters = delimiters; // change the delimiters
-       script_keepdelimiter = keepdelimiter; // change the global flag
-
-       result = GetToken( crossline );
-       currentdelimiters = olddelimiters; // restore it
-       return( result );
-}
-
-/*
-   ==============
-   TokenAvailable
-
-   Returns true if there is another token on the line
-   ==============
- */
-qboolean TokenAvailable( void ){
-       char *search_p;
-
-       search_p = script_p;
-
-       while ( *search_p <= 32 )
-       {
-               if ( *search_p == '\n' ) {
-                       return false;
-               }
-               if ( *search_p == 0 ) {
-                       return false;
-               }
-               search_p++;
-       }
-
-       if ( *search_p == ';' ) {
-               return false;
-       }
-
-       return true;
-}
+typedef SingletonModule<ScriptLibraryAPI> ScriptLibraryModule;
+typedef Static<ScriptLibraryModule> StaticScriptLibraryModule;
+StaticRegisterModule staticRegisterScriptLibrary( StaticScriptLibraryModule::instance() );