]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/eclass_def.cpp
more eol-style
[xonotic/netradiant.git] / radiant / eclass_def.cpp
index 6c22dbf4c6cdf91b70974e011c41f5e9fcc6bdb4..d598886070a2ec2857ee33060ae703c3d1e7c1a8 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 "cmdlib.h"\r
-\r
-#include "synapse.h"\r
-#define USE_QERTABLE_DEFINE\r
-#include "qerplugin.h"\r
-#define USE_ECLASSMANAGER_DEFINE\r
-#include "ieclass.h"\r
-#define USE_SCRIPLIBTABLE_DEFINE\r
-#include "iscriplib.h"\r
-\r
-#define __VFSTABLENAME g_FileSystemTable_def\r
-#define USE_VFSTABLE_DEFINE\r
-#include "ifilesystem.h"\r
-\r
-\r
-#include "eclass_def.h"\r
-\r
-/*! \file eclass_def.cpp\r
-    \brief .def entity description format\r
-    implements parsing for .def entity format\r
-    this is statically linked into the radiant core as we always need it, but really considered\r
-    as an idependant module by the rest of the core. "ECLASS_MAJOR" "def"\r
-*/\r
-\r
-_QERScripLibTable g_ScripLibTable;\r
-_EClassManagerTable g_EClassManagerTable;\r
-_QERFuncTable_1 g_FuncTable;\r
-_QERFileSystemTable g_FileSystemTable_def;\r
-\r
-CSynapseBuiltinClientDef eclass_def;\r
-\r
-// forward declare, I'm cheap\r
-void Eclass_ScanFile (char *filename);\r
-\r
-const char* EClass_GetExtension()\r
-{\r
-  return "def";\r
-}\r
-\r
-void CSynapseBuiltinClientDef::EnumerateInterfaces(CSynapseServer *server)\r
-{\r
-  AddAPI(SCRIPLIB_MAJOR, NULL, sizeof(g_ScripLibTable), SYN_REQUIRE, &g_ScripLibTable);\r
-  AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);\r
-  AddAPI(ECLASSMANAGER_MAJOR, NULL, sizeof(g_EClassManagerTable), SYN_REQUIRE, &g_EClassManagerTable);\r
-  // hardcode the minor for now, we can still add it to the synapse.config at some point\r
-  AddAPI(VFS_MAJOR, "pk3", sizeof(g_FileSystemTable_def), SYN_REQUIRE, &g_FileSystemTable_def);\r
-  \r
-  AddAPI(ECLASS_MAJOR, "def", sizeof(_EClassTable));\r
-}\r
-\r
-bool CSynapseBuiltinClientDef::RequestAPI(APIDescriptor_t *pAPI)\r
-{\r
-  if (!strcmp(pAPI->major_name, ECLASS_MAJOR))\r
-  {\r
-    _EClassTable* pTable= static_cast<_EClassTable*>(pAPI->mpTable);\r
-    pTable->m_pfnScanFile = &Eclass_ScanFile;\r
-    pTable->m_pfnGetExtension = &EClass_GetExtension;\r
-    \r
-    return true;    \r
-  }\r
-  \r
-  Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());\r
-  return false;\r
-}\r
-\r
-#include "version.h"\r
-\r
-const char* CSynapseBuiltinClientDef::GetInfo()\r
-{\r
-  return "Builtin .def module built " __DATE__ " " RADIANT_VERSION;\r
-}\r
-\r
-// ------------------------------------------------------------------------------------------------\r
-\r
-qboolean eclass_found;\r
-char *debugname;\r
-\r
-void setSpecialLoad(eclass_t *e, const char* pWhat, char*& p)\r
-{\r
-  // Hydra: removed some amazingly bad cstring usage, whoever wrote that\r
-  // needs to be taken out and shot.\r
-\r
-  char *pText = NULL;\r
-  char *where = NULL;\r
-\r
-  p = NULL; // incase we don't find what we're looking for.\r
-  where = strstr(e->comments,pWhat);\r
-  if (!where)\r
-    return;\r
-\r
-  pText = where + strlen(pWhat);\r
-  if (*pText == '\"')\r
-    pText++;\r
-\r
-  where = strchr(pText,'\"');\r
-  if (where)\r
-  {\r
-    int len = (where-pText);\r
-    p = new char[len + 1];\r
-    strncpy(p,pText,len);\r
-    p[len]=0; // just to make sure, as most implementations of strncpy don't null terminate\r
-  }\r
-  else\r
-    p = strdup(pText);\r
-}\r
-\r
-eclass_t *Eclass_InitFromText (char *text)\r
-{\r
-       char    *t;\r
-       int             len;\r
-       int             r, i;\r
-       char    parms[256], *p;\r
-       eclass_t        *e;\r
-       char    color[128];\r
-\r
-       e = (eclass_t*)malloc(sizeof(*e));\r
-       memset (e, 0, sizeof(*e));\r
-       \r
-       text += strlen("/*QUAKED ");\r
-\r
-  // grab the name\r
-       text = COM_Parse (text);\r
-       e->name = (char*)malloc (strlen(Get_COM_Token())+1);\r
-       strcpy (e->name, Get_COM_Token());\r
-       debugname = e->name;\r
-\r
-  // grab the color, reformat as texture name\r
-  r = sscanf (text," (%f %f %f)", &e->color[0], &e->color[1], &e->color[2]);\r
-  if (r != 3) {\r
-               return e;\r
-  }\r
-       sprintf (color, "(%f %f %f)", e->color[0], e->color[1], e->color[2]);\r
-       //strcpy (e->texdef.name, color);\r
-       e->texdef.SetName(color);\r
-\r
-       while (*text != ')')\r
-  {\r
-    if (!*text) {\r
-                       return e;\r
-    }\r
-               text++;\r
-       }\r
-       text++;\r
-       \r
-  // get the size      \r
-       text = COM_Parse (text);\r
-       if (Get_COM_Token()[0] == '(')\r
-       {       // parse the size as two vectors\r
-               e->fixedsize = true;\r
-               r = sscanf (text,"%f %f %f) (%f %f %f)", &e->mins[0], &e->mins[1], &e->mins[2],\r
-                       &e->maxs[0], &e->maxs[1], &e->maxs[2]);\r
-    if (r != 6) {\r
-                       return e;\r
-    }\r
-\r
-               for (i=0 ; i<2 ; i++)\r
-               {\r
-                       while (*text != ')')\r
-                       {\r
-        if (!*text) {\r
-                                       return e;\r
-        }\r
-                               text++;\r
-                       }\r
-                       text++;\r
-               }\r
-       }\r
-       \r
-  // get the flags\r
-       \r
-  // copy to the first /n\r
-       p = parms;\r
-       while (*text && *text != '\n')\r
-               *p++ = *text++;\r
-       *p = 0;\r
-       text++;\r
-       \r
-  // any remaining words are parm flags\r
-       p = parms;\r
-       for (i=0 ; i<MAX_FLAGS ; i++)\r
-       {\r
-               p = COM_Parse (p);\r
-               if (!p)\r
-                       break;\r
-               strcpy (e->flagnames[i], Get_COM_Token());\r
-       } \r
-\r
-  // find the length until close comment\r
-       for (t=text ; t[0] && !(t[0]=='*' && t[1]=='/') ; t++)\r
-       ;\r
-       \r
-  // copy the comment block out\r
-       len = t-text;\r
-       e->comments = (char*)malloc (len+1);\r
-       memcpy (e->comments, text, len);\r
-#ifdef _WIN32\r
-  // the win32 Gtk widgets are expecting text stuff to be in unix format (that is CR only instead of DOS's CR/LF)\r
-  // we convert on the fly by replacing the LF with a ' ' (yeah I'm cheap)\r
-       for (i=0 ; i<len ; i++)\r
-               if (text[i] == '\r')\r
-                       e->comments[i] = ' ';\r
-               else\r
-                       e->comments[i] = text[i];\r
-#endif\r
-  e->comments[len] = 0;\r
-       \r
-  setSpecialLoad(e, "model=", e->modelpath);\r
-  setSpecialLoad(e, "skin=", e->skinpath);\r
-  char *pFrame = NULL;\r
-  setSpecialLoad(e, "frame=", pFrame);\r
-  if (pFrame != NULL)\r
-  {\r
-    e->nFrame = atoi(pFrame);\r
-    delete pFrame; //Hydra - Fixed memory leak!\r
-  }\r
-\r
-  if(!e->skinpath)\r
-         setSpecialLoad(e, "texture=", e->skinpath);\r
-\r
-  // setup show flags\r
-  e->nShowFlags = 0;\r
-  if (strcmpi(e->name, "light") == 0 || strcmpi(e->name, "dlight") == 0 || strcmpi(e->name, "lightjunior") == 0)\r
-  {\r
-    e->nShowFlags |= ECLASS_LIGHT;\r
-  }\r
-\r
-  if (  (strnicmp(e->name, "info_player", strlen("info_player")) == 0)\r
-      ||(strnicmp(e->name, "path_corner", strlen("path_corner")) == 0) \r
-      ||(strnicmp(e->name, "team_ctf", strlen("team_ctf")) == 0) \r
-      ||(strnicmp(e->name, "misc_teleporter_dest", strlen("misc_teleporter_dest")) == 0) \r
-         )\r
-  {\r
-    e->nShowFlags |= ECLASS_ANGLE;\r
-  }\r
-  if (strcmpi(e->name, "path") == 0)\r
-  {\r
-    e->nShowFlags |= ECLASS_PATH;\r
-  }\r
-  if (strcmpi(e->name, "misc_model") == 0)\r
-  {\r
-    e->nShowFlags |= ECLASS_MISCMODEL;\r
-  }\r
-\r
-\r
-  return e;\r
-}\r
-\r
-void Eclass_ScanFile (char *filename)\r
-{\r
-       int             size;\r
-       char    *data;\r
-       eclass_t        *e;\r
-       int             i;\r
-       char    temp[1024];\r
-       \r
-       QE_ConvertDOSToUnixName( temp, filename );\r
-       \r
-       size = vfsLoadFullPathFile(filename, (void**)&data);\r
-  if (size <= 0)\r
-  {\r
-    Sys_FPrintf (SYS_ERR, "Eclass_ScanFile: %s not found\n", filename);\r
-    return;\r
-  }\r
-  Sys_Printf ("ScanFile: %s\n", temp); \r
-  eclass_found = false;\r
-  for (i=0 ; i<size ; i++)\r
-  {\r
-    if (!strncmp(data+i, "/*QUAKED",8))\r
-    {\r
-      e = Eclass_InitFromText (data+i);\r
-      if (e)\r
-        Eclass_InsertAlphabetized (e);\r
-      else\r
-        Sys_FPrintf (SYS_ERR, "Error parsing: %s in %s\n",debugname, filename);\r
-      \r
-      // single ?\r
-      *Get_Eclass_E() = e;\r
-      Set_Eclass_Found(true);\r
-      if ( Get_Parsing_Single() )\r
-        break;\r
-    }\r
-  }\r
-    \r
-  g_free (data);               \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 "cmdlib.h"
+
+#include "synapse.h"
+#define USE_QERTABLE_DEFINE
+#include "qerplugin.h"
+#define USE_ECLASSMANAGER_DEFINE
+#include "ieclass.h"
+#define USE_SCRIPLIBTABLE_DEFINE
+#include "iscriplib.h"
+
+#define __VFSTABLENAME g_FileSystemTable_def
+#define USE_VFSTABLE_DEFINE
+#include "ifilesystem.h"
+
+
+#include "eclass_def.h"
+
+/*! \file eclass_def.cpp
+    \brief .def entity description format
+    implements parsing for .def entity format
+    this is statically linked into the radiant core as we always need it, but really considered
+    as an idependant module by the rest of the core. "ECLASS_MAJOR" "def"
+*/
+
+_QERScripLibTable g_ScripLibTable;
+_EClassManagerTable g_EClassManagerTable;
+_QERFuncTable_1 g_FuncTable;
+_QERFileSystemTable g_FileSystemTable_def;
+
+CSynapseBuiltinClientDef eclass_def;
+
+// forward declare, I'm cheap
+void Eclass_ScanFile (char *filename);
+
+const char* EClass_GetExtension()
+{
+  return "def";
+}
+
+void CSynapseBuiltinClientDef::EnumerateInterfaces(CSynapseServer *server)
+{
+  AddAPI(SCRIPLIB_MAJOR, NULL, sizeof(g_ScripLibTable), SYN_REQUIRE, &g_ScripLibTable);
+  AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
+  AddAPI(ECLASSMANAGER_MAJOR, NULL, sizeof(g_EClassManagerTable), SYN_REQUIRE, &g_EClassManagerTable);
+  // hardcode the minor for now, we can still add it to the synapse.config at some point
+  AddAPI(VFS_MAJOR, "pk3", sizeof(g_FileSystemTable_def), SYN_REQUIRE, &g_FileSystemTable_def);
+  
+  AddAPI(ECLASS_MAJOR, "def", sizeof(_EClassTable));
+}
+
+bool CSynapseBuiltinClientDef::RequestAPI(APIDescriptor_t *pAPI)
+{
+  if (!strcmp(pAPI->major_name, ECLASS_MAJOR))
+  {
+    _EClassTable* pTable= static_cast<_EClassTable*>(pAPI->mpTable);
+    pTable->m_pfnScanFile = &Eclass_ScanFile;
+    pTable->m_pfnGetExtension = &EClass_GetExtension;
+    
+    return true;    
+  }
+  
+  Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
+  return false;
+}
+
+#include "version.h"
+
+const char* CSynapseBuiltinClientDef::GetInfo()
+{
+  return "Builtin .def module built " __DATE__ " " RADIANT_VERSION;
+}
+
+// ------------------------------------------------------------------------------------------------
+
+qboolean eclass_found;
+char *debugname;
+
+void setSpecialLoad(eclass_t *e, const char* pWhat, char*& p)
+{
+  // Hydra: removed some amazingly bad cstring usage, whoever wrote that
+  // needs to be taken out and shot.
+
+  char *pText = NULL;
+  char *where = NULL;
+
+  p = NULL; // incase we don't find what we're looking for.
+  where = strstr(e->comments,pWhat);
+  if (!where)
+    return;
+
+  pText = where + strlen(pWhat);
+  if (*pText == '\"')
+    pText++;
+
+  where = strchr(pText,'\"');
+  if (where)
+  {
+    int len = (where-pText);
+    p = new char[len + 1];
+    strncpy(p,pText,len);
+    p[len]=0; // just to make sure, as most implementations of strncpy don't null terminate
+  }
+  else
+    p = strdup(pText);
+}
+
+eclass_t *Eclass_InitFromText (char *text)
+{
+       char    *t;
+       int             len;
+       int             r, i;
+       char    parms[256], *p;
+       eclass_t        *e;
+       char    color[128];
+
+       e = (eclass_t*)malloc(sizeof(*e));
+       memset (e, 0, sizeof(*e));
+       
+       text += strlen("/*QUAKED ");
+
+  // grab the name
+       text = COM_Parse (text);
+       e->name = (char*)malloc (strlen(Get_COM_Token())+1);
+       strcpy (e->name, Get_COM_Token());
+       debugname = e->name;
+
+  // grab the color, reformat as texture name
+  r = sscanf (text," (%f %f %f)", &e->color[0], &e->color[1], &e->color[2]);
+  if (r != 3) {
+               return e;
+  }
+       sprintf (color, "(%f %f %f)", e->color[0], e->color[1], e->color[2]);
+       //strcpy (e->texdef.name, color);
+       e->texdef.SetName(color);
+
+       while (*text != ')')
+  {
+    if (!*text) {
+                       return e;
+    }
+               text++;
+       }
+       text++;
+       
+  // get the size      
+       text = COM_Parse (text);
+       if (Get_COM_Token()[0] == '(')
+       {       // parse the size as two vectors
+               e->fixedsize = true;
+               r = sscanf (text,"%f %f %f) (%f %f %f)", &e->mins[0], &e->mins[1], &e->mins[2],
+                       &e->maxs[0], &e->maxs[1], &e->maxs[2]);
+    if (r != 6) {
+                       return e;
+    }
+
+               for (i=0 ; i<2 ; i++)
+               {
+                       while (*text != ')')
+                       {
+        if (!*text) {
+                                       return e;
+        }
+                               text++;
+                       }
+                       text++;
+               }
+       }
+       
+  // get the flags
+       
+  // copy to the first /n
+       p = parms;
+       while (*text && *text != '\n')
+               *p++ = *text++;
+       *p = 0;
+       text++;
+       
+  // any remaining words are parm flags
+       p = parms;
+       for (i=0 ; i<MAX_FLAGS ; i++)
+       {
+               p = COM_Parse (p);
+               if (!p)
+                       break;
+               strcpy (e->flagnames[i], Get_COM_Token());
+       } 
+
+  // find the length until close comment
+       for (t=text ; t[0] && !(t[0]=='*' && t[1]=='/') ; t++)
+       ;
+       
+  // copy the comment block out
+       len = t-text;
+       e->comments = (char*)malloc (len+1);
+       memcpy (e->comments, text, len);
+#ifdef _WIN32
+  // the win32 Gtk widgets are expecting text stuff to be in unix format (that is CR only instead of DOS's CR/LF)
+  // we convert on the fly by replacing the LF with a ' ' (yeah I'm cheap)
+       for (i=0 ; i<len ; i++)
+               if (text[i] == '\r')
+                       e->comments[i] = ' ';
+               else
+                       e->comments[i] = text[i];
+#endif
+  e->comments[len] = 0;
+       
+  setSpecialLoad(e, "model=", e->modelpath);
+  setSpecialLoad(e, "skin=", e->skinpath);
+  char *pFrame = NULL;
+  setSpecialLoad(e, "frame=", pFrame);
+  if (pFrame != NULL)
+  {
+    e->nFrame = atoi(pFrame);
+    delete pFrame; //Hydra - Fixed memory leak!
+  }
+
+  if(!e->skinpath)
+         setSpecialLoad(e, "texture=", e->skinpath);
+
+  // setup show flags
+  e->nShowFlags = 0;
+  if (strcmpi(e->name, "light") == 0 || strcmpi(e->name, "dlight") == 0 || strcmpi(e->name, "lightjunior") == 0)
+  {
+    e->nShowFlags |= ECLASS_LIGHT;
+  }
+
+  if (  (strnicmp(e->name, "info_player", strlen("info_player")) == 0)
+      ||(strnicmp(e->name, "path_corner", strlen("path_corner")) == 0) 
+      ||(strnicmp(e->name, "team_ctf", strlen("team_ctf")) == 0) 
+      ||(strnicmp(e->name, "misc_teleporter_dest", strlen("misc_teleporter_dest")) == 0) 
+         )
+  {
+    e->nShowFlags |= ECLASS_ANGLE;
+  }
+  if (strcmpi(e->name, "path") == 0)
+  {
+    e->nShowFlags |= ECLASS_PATH;
+  }
+  if (strcmpi(e->name, "misc_model") == 0)
+  {
+    e->nShowFlags |= ECLASS_MISCMODEL;
+  }
+
+
+  return e;
+}
+
+void Eclass_ScanFile (char *filename)
+{
+       int             size;
+       char    *data;
+       eclass_t        *e;
+       int             i;
+       char    temp[1024];
+       
+       QE_ConvertDOSToUnixName( temp, filename );
+       
+       size = vfsLoadFullPathFile(filename, (void**)&data);
+  if (size <= 0)
+  {
+    Sys_FPrintf (SYS_ERR, "Eclass_ScanFile: %s not found\n", filename);
+    return;
+  }
+  Sys_Printf ("ScanFile: %s\n", temp); 
+  eclass_found = false;
+  for (i=0 ; i<size ; i++)
+  {
+    if (!strncmp(data+i, "/*QUAKED",8))
+    {
+      e = Eclass_InitFromText (data+i);
+      if (e)
+        Eclass_InsertAlphabetized (e);
+      else
+        Sys_FPrintf (SYS_ERR, "Error parsing: %s in %s\n",debugname, filename);
+      
+      // single ?
+      *Get_Eclass_E() = e;
+      Set_Eclass_Found(true);
+      if ( Get_Parsing_Single() )
+        break;
+    }
+  }
+    
+  g_free (data);               
+}