]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/parse.cpp
more eol-style
[xonotic/netradiant.git] / radiant / parse.cpp
index be6d1586e70a7020de0bceaece789de0710431aa..3760bf0038e9e24a73616978f91d8009ad70b14e 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) 1999-2007 id Software, Inc. and contributors.
+For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+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 "stdafx.h"
+
+char     token[MAXTOKEN];
+qboolean  unget;
+char*    script_p;
+int      scriptline;
+
+// Hydra: added support for GetTokenExtra()
+char *currentdelimiters;
+qboolean  script_keepdelimiter;
+
+void StartTokenParsing (char *data)
+{
+  scriptline = 1;
+  script_p = data;
+  unget = false;
+
+  // Hydra: added support for GetTokenExtra()
+  currentdelimiters = NULL;
+  script_keepdelimiter = true;
+}
+
+
+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;
+}
+
+/*
+==============
+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
+
+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;
+}