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