]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3data/q3data.c
Centralise compile checks
[xonotic/netradiant.git] / tools / quake3 / q3data / q3data.c
index 05ff92208cb4400a7c50fc0d8021e4fdfb02125f..0544076b6456d9e1a73f73c15d218df026c08eff 100644 (file)
-#ifdef _WIN32\r
-#include <io.h>\r
-#endif\r
-#include "q3data.h"\r
-#include "md3lib.h"\r
-\r
-#include "vfs.h"\r
-\r
-qboolean       g_verbose;\r
-qboolean       g_stripify = qtrue;\r
-qboolean       g_release;                      // don't grab, copy output data to new tree\r
-char           g_releasedir[1024];     // c:\quake2\baseq2, etc\r
-qboolean       g_archive;                      // don't grab, copy source data to new tree\r
-char           g_only[256];            // if set, only grab this cd\r
-qboolean       g_skipmodel;            // set true when a cd is not g_only\r
-\r
-// bogus externs for some TA hacks (common/ using them against q3map)\r
-char *moddir = NULL;\r
-// some old defined that was in cmdlib lost during merge\r
-char writedir[1024];\r
-\r
-#if defined (__linux__) || defined (__APPLE__)\r
-#define strlwr strlower\r
-#endif\r
-\r
-/*\r
-=======================================================\r
-\r
-  PAK FILES\r
-\r
-=======================================================\r
-*/\r
-\r
-typedef struct\r
-{\r
-       char    name[56];\r
-       int             filepos, filelen;\r
-} packfile_t;\r
-\r
-typedef struct\r
-{\r
-       char    id[4];\r
-       int             dirofs;\r
-       int             dirlen;\r
-} packheader_t;\r
-\r
-packfile_t             pfiles[16384];\r
-FILE                   *pakfile;\r
-packfile_t             *pf;\r
-packheader_t   pakheader;\r
-\r
-/*\r
-==============\r
-ReleaseFile\r
-\r
-Filename should be gamedir reletive.\r
-Either copies the file to the release dir, or adds it to\r
-the pak file.\r
-==============\r
-*/\r
-void ReleaseFile (char *filename)\r
-{\r
-       char    source[1024];\r
-       char    dest[1024];\r
-\r
-       if (!g_release)\r
-               return;\r
-\r
-       sprintf (source, "%s%s", gamedir, filename);\r
-       sprintf (dest, "%s/%s", g_releasedir, filename);\r
-       printf ("copying to %s\n", dest);\r
-  QCopyFile (source, dest);\r
-  return;\r
-}\r
-\r
-typedef struct\r
-{\r
-       // shader\r
-       // opaque\r
-       // opaque 2\r
-       // blend \r
-       // blend 2\r
-       char names[5][1024];\r
-       int      num;\r
-} ShaderFiles_t;\r
-\r
-ShaderFiles_t s_shaderFiles;\r
-\r
-void FindShaderFiles( char *filename )\r
-{\r
-       char buffer[1024];\r
-       char stripped[1024];\r
-       char linebuffer[1024];\r
-       int len, i;\r
-       char *buf;\r
-       char *diffuseExtensions[] =\r
-       {\r
-               ".TGA",\r
-               ".WAL",\r
-               ".PCX",\r
-               0\r
-       };\r
-       char *otherExtensions[] =\r
-       {\r
-               ".specular.TGA",\r
-               ".blend.TGA",\r
-               ".alpha.TGA",\r
-               0\r
-       };\r
-\r
-       s_shaderFiles.num = 0;\r
-\r
-       strcpy( stripped, filename );\r
-       if ( strrchr( stripped, '.' ) )\r
-               *strrchr( stripped, '.' ) = 0;\r
-       strcat( stripped, ".shader" );\r
-\r
-       if ( FileExists( stripped ) )\r
-       {\r
-               char *p;\r
-               char mapa[512], mapb[512];\r
-\r
-               strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );\r
-               s_shaderFiles.num++;\r
-\r
-               // load and parse\r
-               len = LoadFile( stripped, (void **)&buf);\r
-\r
-               p = buf;\r
-\r
-               while ( p - buf < len )\r
-               {\r
-                       i = 0;\r
-\r
-                       // skip spaces\r
-                       while ( *p == ' ' || *p == '\n' || *p == '\t' )\r
-                               p++;\r
-\r
-                       // grab rest of the line\r
-                       while ( *p != 0 && *p != '\n' )\r
-                       {\r
-                               linebuffer[i] = *p;\r
-                               i++;\r
-                               p++;\r
-                       }\r
-                       if ( *p == '\n' )\r
-                               p++;\r
-                       linebuffer[i] = 0;\r
-\r
-                       strlwr( linebuffer );\r
-\r
-                       // see if the line specifies an opaque map or blendmap\r
-                       if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||\r
-                                strstr( linebuffer, "blendmap" ) == linebuffer )\r
-                       {\r
-                               int j;\r
-\r
-                               i = 0;\r
-\r
-                               mapa[0] = mapb[0] = 0;\r
-\r
-                               // skip past the keyword\r
-                               while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )\r
-                                       i++;\r
-                               // skip past spaces\r
-                               while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )\r
-                                       i++;\r
-\r
-                               // grab first map name\r
-                               j = 0;\r
-                               while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )\r
-                               {\r
-                                       mapa[j] = linebuffer[i];\r
-                                       j++;\r
-                                       i++;\r
-                               }\r
-                               mapa[j] = 0;\r
-\r
-                               // skip past spaces\r
-                               while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )\r
-                                       i++;\r
-\r
-                               // grab second map name\r
-                               j = 0;\r
-                               while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )\r
-                               {\r
-                                       mapb[j] = linebuffer[i];\r
-                                       j++;\r
-                                       i++;\r
-                               }\r
-                               mapb[j] = 0;\r
-\r
-                               // store map names\r
-                               if ( mapa[0] != 0 && mapa[0] != '-' )\r
-                               {\r
-                                       sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );\r
-                                       s_shaderFiles.num++;\r
-                               }\r
-                               if ( mapb[0] != 0 && mapb[0] != '-' && mapb[0] != '^' && mapb[0] != '*' )\r
-                               {\r
-                                       sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapb );\r
-                                       s_shaderFiles.num++;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       else\r
-       {\r
-               if ( strrchr( stripped, '.' ) )\r
-                       *strrchr( stripped, '.' ) = 0;\r
-\r
-               // look for diffuse maps\r
-               for ( i = 0; i < 3; i++ )\r
-               {\r
-                       strcpy( buffer, stripped );\r
-                       strcat( buffer, diffuseExtensions[i] );\r
-                       if ( FileExists( buffer ) )\r
-                       {\r
-                               strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );\r
-                               s_shaderFiles.num++;\r
-                               break;\r
-                       }\r
-               }\r
-               for ( i = 0; i < 3; i++ )\r
-               {\r
-                       strcpy( buffer, stripped );\r
-                       strcat( buffer, otherExtensions[i] );\r
-                       if ( FileExists( buffer ) )\r
-                       {\r
-                               strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );\r
-                               s_shaderFiles.num++;\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-/*\r
-==============\r
-ReleaseShader\r
-\r
-Copies all needed files for a shader to the release directory\r
-==============\r
-*/\r
-void ReleaseShader( char *filename ) \r
-{\r
-       char fullpath[1024];\r
-       char dest[1024];\r
-       char stripped[1024];\r
-       int i;\r
-\r
-       sprintf( fullpath, "%s%s", gamedir, filename );\r
-\r
-       FindShaderFiles( fullpath );\r
-\r
-       for ( i = 0; i < s_shaderFiles.num; i++ )\r
-       {\r
-               strcpy( stripped, s_shaderFiles.names[i] );\r
-               if ( strstr( stripped, gamedir ) )\r
-               {\r
-                       memmove( stripped, stripped+ strlen( gamedir ), strlen( stripped ) );\r
-               }\r
-               sprintf( dest, "%s/%s", g_releasedir, stripped );\r
-               printf ("copying to %s\n", dest );\r
-               QCopyFile( s_shaderFiles.names[i], dest );\r
-  }\r
-}\r
-\r
-/*\r
-===============\r
-Cmd_File\r
-\r
-This is only used to cause a file to be copied during a release\r
-build (default.cfg, maps, etc)\r
-===============\r
-*/\r
-void Cmd_File (void)\r
-{\r
-       GetToken (qfalse);\r
-       ReleaseFile (token);\r
-}\r
-\r
-/*\r
-===============\r
-PackDirectory_r\r
-\r
-===============\r
-*/\r
-#ifdef _WIN32\r
-#include "io.h"\r
-void PackDirectory_r (char *dir)\r
-{\r
-       struct _finddata_t fileinfo;\r
-       int             handle;\r
-       char    dirstring[1024];\r
-       char    filename[1024];\r
-\r
-       sprintf (dirstring, "%s%s/*.*", gamedir, dir);\r
-\r
-       handle = _findfirst (dirstring, &fileinfo);\r
-       if (handle == -1)\r
-               return;\r
-\r
-       do\r
-       {\r
-               sprintf (filename, "%s/%s", dir, fileinfo.name);\r
-               if (fileinfo.attrib & _A_SUBDIR)\r
-               {       // directory\r
-                       if (fileinfo.name[0] != '.')    // don't pak . and ..\r
-                               PackDirectory_r (filename);\r
-                       continue;\r
-               }\r
-               // copy or pack the file\r
-               ReleaseFile (filename);         \r
-       } while (_findnext( handle, &fileinfo ) != -1);\r
-\r
-       _findclose (handle);\r
-}\r
-#else\r
-\r
-#include <sys/types.h>\r
-#ifndef WIN32\r
-#include <sys/dir.h>\r
-#else\r
-#include <sys/dirent.h>\r
-#endif\r
-\r
-void PackDirectory_r (char *dir)\r
-{\r
-#ifdef NeXT\r
-       struct direct **namelist, *ent;\r
-#else\r
-       struct dirent **namelist, *ent;\r
-#endif\r
-       int             count;\r
-       struct stat st;\r
-       int                     i;\r
-       int                     len;\r
-       char            fullname[1024];\r
-       char            dirstring[1024];\r
-       char            *name;\r
-       \r
-       sprintf (dirstring, "%s%s", gamedir, dir);\r
-       count = scandir(dirstring, &namelist, NULL, NULL);\r
-       \r
-       for (i=0 ; i<count ; i++)\r
-       {\r
-               ent = namelist[i];      \r
-               name = ent->d_name;\r
-\r
-               if (name[0] == '.')\r
-                       continue;\r
-       \r
-               sprintf (fullname, "%s/%s", dir, name);\r
-               sprintf (dirstring, "%s%s/%s", gamedir, dir, name);\r
-               \r
-               if (stat (dirstring, &st) == -1)\r
-                       Error ("fstating %s", pf->name);\r
-               if (st.st_mode & S_IFDIR)\r
-               {       // directory\r
-                       PackDirectory_r (fullname);\r
-                       continue;\r
-               }\r
-\r
-               // copy or pack the file\r
-               ReleaseFile (fullname);         \r
-       }\r
-}\r
-#endif\r
-\r
-\r
-/*\r
-===============\r
-Cmd_Dir\r
-\r
-This is only used to cause a directory to be copied during a\r
-release build (sounds, etc)\r
-===============\r
-*/\r
-void Cmd_Dir (void)\r
-{\r
-       GetToken (qfalse);\r
-       PackDirectory_r (token);        \r
-}\r
-\r
-//========================================================================\r
-\r
-#define        MAX_RTEX        16384\r
-int            numrtex;\r
-char   rtex[MAX_RTEX][64];\r
-\r
-void ReleaseTexture (char *name)\r
-{\r
-       int             i;\r
-       char    path[1024];\r
-\r
-       for (i=0 ; i<numrtex ; i++)\r
-               if (!Q_stricmp(name, rtex[i]))\r
-                       return;\r
-\r
-       if (numrtex == MAX_RTEX)\r
-               Error ("numrtex == MAX_RTEX");\r
-\r
-       strcpy (rtex[i], name);\r
-       numrtex++;\r
-\r
-       sprintf (path, "textures/%s.wal", name);\r
-       ReleaseFile (path);\r
-}\r
-\r
-/*\r
-===============\r
-Cmd_Maps\r
-\r
-Only relevent for release and pak files.\r
-Releases the .bsp files for the maps, and scans all of the files to\r
-build a list of all textures used, which are then released.\r
-===============\r
-*/\r
-void Cmd_Maps (void)\r
-{\r
-       char    map[1024];\r
-\r
-       while (TokenAvailable ())\r
-       {\r
-               GetToken (qfalse);\r
-               sprintf (map, "maps/%s.bsp", token);\r
-               ReleaseFile (map);\r
-\r
-               if (!g_release)\r
-                       continue;\r
-\r
-               // get all the texture references\r
-               sprintf (map, "%smaps/%s.bsp", gamedir, token);\r
-               LoadBSPFile( map );\r
-       }\r
-}\r
-\r
-\r
-//==============================================================\r
-\r
-/*\r
-===============\r
-ParseScript\r
-===============\r
-*/\r
-void ParseScript (void)\r
-{\r
-       while (1)\r
-       {\r
-               do\r
-               {       // look for a line starting with a $ command\r
-                       GetToken (qtrue);\r
-                       if (endofscript)\r
-                               return;\r
-                       if (token[0] == '$')\r
-                               break;                          \r
-                       while (TokenAvailable())\r
-                               GetToken (qfalse);\r
-               } while (1);\r
-       \r
-               //\r
-               // model commands\r
-               //\r
-               if (!strcmp (token, "$modelname"))\r
-                       Cmd_Modelname ();\r
-               else if (!strcmp (token, "$base"))\r
-                       Cmd_Base ();\r
-               else if ( !strcmp( token, "$exit" ) )\r
-                       break;\r
-               else if ( !strcmp( token, "$3dsconvert" ) )\r
-                       Cmd_3DSConvert();\r
-               else if (!strcmp (token, "$spritebase"))\r
-                       Cmd_SpriteBase ();\r
-               else if (!strcmp (token, "$cd"))\r
-                       Cmd_Cd ();\r
-               else if (!strcmp (token, "$origin"))\r
-                       Cmd_Origin ();\r
-               else if (!strcmp (token, "$scale"))\r
-                       Cmd_ScaleUp ();\r
-               else if (!strcmp (token, "$frame"))\r
-                       Cmd_Frame ();\r
-               else if (!strcmp (token, "$skin" ))\r
-                       Cmd_Skin();\r
-               else if (!strcmp (token, "$spriteshader"))\r
-                       Cmd_SpriteShader();\r
-               else if (!strcmp( token, "$aseconvert" ))\r
-                       Cmd_ASEConvert( qfalse );\r
-               else if (!strcmp( token, "$aseanimconvert" ) )\r
-                       Cmd_ASEConvert( qtrue );\r
-\r
-               //\r
-               // image commands\r
-               //\r
-               else if (!strcmp (token, "$grab"))\r
-                       Cmd_Grab ();\r
-               else if (!strcmp (token, "$raw"))\r
-                       Cmd_Raw ();\r
-               else if (!strcmp (token, "$colormap"))\r
-                       Cmd_Colormap ();\r
-               else if (!strcmp (token, "$environment"))\r
-                       Cmd_Environment ();\r
-\r
-               //\r
-               // video\r
-               //\r
-               else if (!strcmp (token, "$video"))\r
-                       Cmd_Video ();\r
-               //\r
-               // misc\r
-               //\r
-               else if (!strcmp (token, "$file"))\r
-                       Cmd_File ();\r
-               else if (!strcmp (token, "$dir"))\r
-                       Cmd_Dir ();\r
-               else if (!strcmp (token, "$maps"))\r
-                       Cmd_Maps ();\r
-               else\r
-                       Error ("bad command %s\n", token);\r
-       }\r
-}\r
-\r
-//=======================================================\r
-\r
-#include "version.h"\r
-\r
-/*\r
-==============\r
-main\r
-==============\r
-*/\r
-int main (int argc, char **argv)\r
-{\r
-       static  int             i;              // VC4.2 compiler bug if auto...\r
-       char    path[1024];\r
-\r
-  // using GtkRadiant's versioning next to Id's versioning\r
-  printf ("Q3Data      - (c) 1999 Id Software Inc.\n");\r
-  printf ("GtkRadiant  - v" RADIANT_VERSION " " __DATE__ "\n");\r
-\r
-       ExpandWildcards (&argc, &argv);\r
-\r
-       for (i=1 ; i<argc ; i++)\r
-       {\r
-               if (!strcmp(argv[i], "-archive"))\r
-               {\r
-                       archive = qtrue;\r
-                       strcpy (archivedir, argv[i+1]);\r
-                       printf ("Archiving source to: %s\n", archivedir);\r
-                       i++;\r
-               }\r
-               else if (!strcmp(argv[i], "-release"))\r
-               {\r
-                       g_release = qtrue;\r
-                       strcpy (g_releasedir, argv[i+1]);\r
-                       printf ("Copy output to: %s\n", g_releasedir);\r
-                       i++;\r
-               }\r
-               else if ( !strcmp( argv[i], "-nostrips" ) )\r
-               {\r
-                       g_stripify = qfalse;\r
-                       printf( "Not optimizing for strips\n" );\r
-               }\r
-               else if ( !strcmp( argv[i], "-writedir" ) )\r
-               {\r
-                       strcpy( writedir, argv[i+1] );\r
-                       printf( "Write output to: %s\n", writedir );\r
-                       i++;\r
-               }\r
-               else if ( !strcmp( argv[i], "-verbose" ) )\r
-               {\r
-                       g_verbose = qtrue;\r
-               }\r
-               else if ( !strcmp( argv[i], "-dump" ) )\r
-               {\r
-                       printf( "Dumping contents of: '%s'\n", argv[i+1] );\r
-                       if ( strstr( argv[i+1], ".md3" ) )\r
-                       {\r
-                               MD3_Dump( argv[i+1] );\r
-                       }\r
-                       else\r
-                       {\r
-                               Error( "Do not know how to dump the contents of '%s'\n", argv[i+1] );\r
-                       }\r
-                       i++;\r
-               }\r
-               else if ( !strcmp( argv[i], "-3dsconvert" ) )\r
-               {\r
-      // NOTE TTimo this is broken, tried on a sample .3ds\r
-      // what happens .. it calls the Convert3DStoMD3,\r
-      // which calls the scriptlib function in non initialized state .. and crashes\r
-                       printf( "Converting %s.3DS to %s.MD3\n", argv[i+1], argv[i+1] );\r
-                       SetQdirFromPath( argv[i+1] );\r
-      vfsInitDirectory( gamedir );\r
-                       Convert3DStoMD3( argv[i+1] );\r
-                       i++;\r
-               }\r
-               else if (!strcmp(argv[i], "-only"))\r
-               {\r
-                       strcpy (g_only, argv[i+1]);\r
-                       printf ("Only grabbing %s\n", g_only);\r
-                       i++;\r
-               }\r
-               else if (!strcmp(argv[i], "-gamedir"))\r
-               {\r
-                       strcpy(gamedir, argv[i+1]);\r
-                       i++;\r
-               }\r
-               else if (argv[i][0] == '-')\r
-                       Error ("Unknown option \"%s\"", argv[i]);\r
-               else\r
-                       break;\r
-       }\r
-\r
-       if (i == argc)\r
-               Error ("usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]");\r
-\r
-       for ( ; i<argc ; i++)\r
-       {\r
-               printf ("--------------- %s ---------------\n", argv[i]);\r
-               // load the script\r
-               strcpy (path, argv[i]);\r
-               DefaultExtension (path, ".qdt");\r
-               if(!gamedir[0])\r
-                       SetQdirFromPath (path);\r
-    // NOTE TTimo\r
-    // q3data went through a partial conversion to use the vfs\r
-    // it was never actually tested before 1.1.1\r
-    // the code is still mostly using direct file access calls\r
-    vfsInitDirectory( gamedir );\r
-               LoadScriptFile (ExpandArg(path), -1);\r
-               \r
-               //\r
-               // parse it\r
-               //\r
-               ParseScript ();\r
-\r
-               // write out the last model\r
-               FinishModel ( TYPE_UNKNOWN );\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
+/*
+   Copyright (C) 1999-2006 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 "globaldefs.h"
+#if GDEF_OS_WINDOWS
+#include <io.h>
+#endif
+#include "q3data.h"
+#include "md3lib.h"
+
+#include "vfs.h"
+
+qboolean g_verbose;
+qboolean g_stripify = qtrue;
+qboolean g_release;             // don't grab, copy output data to new tree
+char g_releasedir[1024];        // c:\quake2\baseq2, etc
+qboolean g_archive;             // don't grab, copy source data to new tree
+char g_only[256];               // if set, only grab this cd
+qboolean g_skipmodel;           // set true when a cd is not g_only
+
+// bogus externs for some TA hacks (common/ using them against q3map)
+char *moddir = NULL;
+// some old defined that was in cmdlib lost during merge
+char writedir[1024];
+
+#if GDEF_OS_LINUX || GDEF_OS_MACOS
+#define strlwr strlower
+#endif
+
+/*
+   =======================================================
+
+   PAK FILES
+
+   =======================================================
+ */
+
+unsigned Com_BlockChecksum( void *buffer, int length );
+
+typedef struct
+{
+       char name[56];
+       int filepos, filelen;
+} packfile_t;
+
+typedef struct
+{
+       char id[4];
+       int dirofs;
+       int dirlen;
+} packheader_t;
+
+packfile_t pfiles[16384];
+FILE            *pakfile;
+packfile_t      *pf;
+packheader_t pakheader;
+
+/*
+   ==============
+   ReleaseFile
+
+   Filename should be gamedir reletive.
+   Either copies the file to the release dir, or adds it to
+   the pak file.
+   ==============
+ */
+void ReleaseFile( char *filename ){
+       char source[1024];
+       char dest[1024];
+
+       if ( !g_release ) {
+               return;
+       }
+
+       sprintf( source, "%s%s", gamedir, filename );
+       sprintf( dest, "%s/%s", g_releasedir, filename );
+       printf( "copying to %s\n", dest );
+       QCopyFile( source, dest );
+       return;
+}
+
+typedef struct
+{
+       // shader
+       // opaque
+       // opaque 2
+       // blend
+       // blend 2
+       char names[5][1024];
+       int num;
+} ShaderFiles_t;
+
+ShaderFiles_t s_shaderFiles;
+
+void FindShaderFiles( char *filename ){
+       char buffer[1024];
+       char stripped[1024];
+       char linebuffer[1024];
+       int len, i;
+       char *buf;
+       char *diffuseExtensions[] =
+       {
+               ".TGA",
+               ".WAL",
+               ".PCX",
+               0
+       };
+       char *otherExtensions[] =
+       {
+               ".specular.TGA",
+               ".blend.TGA",
+               ".alpha.TGA",
+               0
+       };
+
+       s_shaderFiles.num = 0;
+
+       strcpy( stripped, filename );
+       if ( strrchr( stripped, '.' ) ) {
+               *strrchr( stripped, '.' ) = 0;
+       }
+       strcat( stripped, ".shader" );
+
+       if ( FileExists( stripped ) ) {
+               char *p;
+               char mapa[512], mapb[512];
+
+               strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );
+               s_shaderFiles.num++;
+
+               // load and parse
+               len = LoadFile( stripped, (void **)&buf );
+
+               p = buf;
+
+               while ( p - buf < len )
+               {
+                       i = 0;
+
+                       // skip spaces
+                       while ( *p == ' ' || *p == '\n' || *p == '\t' )
+                               p++;
+
+                       // grab rest of the line
+                       while ( *p != 0 && *p != '\n' )
+                       {
+                               linebuffer[i] = *p;
+                               i++;
+                               p++;
+                       }
+                       if ( *p == '\n' ) {
+                               p++;
+                       }
+                       linebuffer[i] = 0;
+
+                       strlwr( linebuffer );
+
+                       // see if the line specifies an opaque map or blendmap
+                       if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||
+                                strstr( linebuffer, "blendmap" ) == linebuffer ) {
+                               int j;
+
+                               i = 0;
+
+                               mapa[0] = mapb[0] = 0;
+
+                               // skip past the keyword
+                               while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
+                                       i++;
+                               // skip past spaces
+                               while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
+                                       i++;
+
+                               // grab first map name
+                               j = 0;
+                               while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
+                               {
+                                       mapa[j] = linebuffer[i];
+                                       j++;
+                                       i++;
+                               }
+                               mapa[j] = 0;
+
+                               // skip past spaces
+                               while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
+                                       i++;
+
+                               // grab second map name
+                               j = 0;
+                               while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
+                               {
+                                       mapb[j] = linebuffer[i];
+                                       j++;
+                                       i++;
+                               }
+                               mapb[j] = 0;
+
+                               // store map names
+                               if ( mapa[0] != 0 && mapa[0] != '-' ) {
+                                       sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );
+                                       s_shaderFiles.num++;
+                               }
+                               if ( mapb[0] != 0 && mapb[0] != '-' && mapb[0] != '^' && mapb[0] != '*' ) {
+                                       sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapb );
+                                       s_shaderFiles.num++;
+                               }
+                       }
+               }
+       }
+       else
+       {
+               if ( strrchr( stripped, '.' ) ) {
+                       *strrchr( stripped, '.' ) = 0;
+               }
+
+               // look for diffuse maps
+               for ( i = 0; i < 3; i++ )
+               {
+                       strcpy( buffer, stripped );
+                       strcat( buffer, diffuseExtensions[i] );
+                       if ( FileExists( buffer ) ) {
+                               strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
+                               s_shaderFiles.num++;
+                               break;
+                       }
+               }
+               for ( i = 0; i < 3; i++ )
+               {
+                       strcpy( buffer, stripped );
+                       strcat( buffer, otherExtensions[i] );
+                       if ( FileExists( buffer ) ) {
+                               strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
+                               s_shaderFiles.num++;
+                       }
+               }
+       }
+}
+
+/*
+   ==============
+   ReleaseShader
+
+   Copies all needed files for a shader to the release directory
+   ==============
+ */
+void ReleaseShader( char *filename ){
+       char fullpath[1024];
+       char dest[1024];
+       char stripped[1024];
+       int i;
+
+       sprintf( fullpath, "%s%s", gamedir, filename );
+
+       FindShaderFiles( fullpath );
+
+       for ( i = 0; i < s_shaderFiles.num; i++ )
+       {
+               strcpy( stripped, s_shaderFiles.names[i] );
+               if ( strstr( stripped, gamedir ) ) {
+                       memmove( stripped, stripped + strlen( gamedir ), strlen( stripped ) );
+               }
+               sprintf( dest, "%s/%s", g_releasedir, stripped );
+               printf( "copying to %s\n", dest );
+               QCopyFile( s_shaderFiles.names[i], dest );
+       }
+}
+
+/*
+   ===============
+   Cmd_File
+
+   This is only used to cause a file to be copied during a release
+   build (default.cfg, maps, etc)
+   ===============
+ */
+void Cmd_File( void ){
+       GetToken( qfalse );
+       ReleaseFile( token );
+}
+
+/*
+   ===============
+   PackDirectory_r
+
+   ===============
+ */
+#if GDEF_OS_WINDOWS
+#include "io.h"
+void PackDirectory_r( char *dir ){
+       struct _finddata_t fileinfo;
+       int handle;
+       char dirstring[1024];
+       char filename[1024];
+
+       sprintf( dirstring, "%s%s/*.*", gamedir, dir );
+
+       handle = _findfirst( dirstring, &fileinfo );
+       if ( handle == -1 ) {
+               return;
+       }
+
+       do
+       {
+               sprintf( filename, "%s/%s", dir, fileinfo.name );
+               if ( fileinfo.attrib & _A_SUBDIR ) { // directory
+                       if ( fileinfo.name[0] != '.' ) {  // don't pak . and ..
+                               PackDirectory_r( filename );
+                       }
+                       continue;
+               }
+               // copy or pack the file
+               ReleaseFile( filename );
+       } while ( _findnext( handle, &fileinfo ) != -1 );
+
+       _findclose( handle );
+}
+#else
+
+#include <sys/types.h>
+#if !GDEF_OS_WINDOWS
+#include <sys/dir.h>
+#else
+#include <sys/dirent.h>
+#endif
+
+void PackDirectory_r( char *dir ){
+#ifdef NeXT
+       struct direct **namelist, *ent;
+#else
+       struct dirent **namelist, *ent;
+#endif
+       int count;
+       struct stat st;
+       int i;
+       int len;
+       char fullname[1024];
+       char dirstring[1024];
+       char        *name;
+
+       sprintf( dirstring, "%s%s", gamedir, dir );
+       count = scandir( dirstring, &namelist, NULL, NULL );
+
+       for ( i = 0 ; i < count ; i++ )
+       {
+               ent = namelist[i];
+               name = ent->d_name;
+
+               if ( name[0] == '.' ) {
+                       continue;
+               }
+
+               sprintf( fullname, "%s/%s", dir, name );
+               sprintf( dirstring, "%s%s/%s", gamedir, dir, name );
+
+               if ( stat( dirstring, &st ) == -1 ) {
+                       Error( "fstating %s", pf->name );
+               }
+               if ( st.st_mode & S_IFDIR ) { // directory
+                       PackDirectory_r( fullname );
+                       continue;
+               }
+
+               // copy or pack the file
+               ReleaseFile( fullname );
+       }
+}
+#endif
+
+
+/*
+   ===============
+   Cmd_Dir
+
+   This is only used to cause a directory to be copied during a
+   release build (sounds, etc)
+   ===============
+ */
+void Cmd_Dir( void ){
+       GetToken( qfalse );
+       PackDirectory_r( token );
+}
+
+//========================================================================
+
+#define MAX_RTEX    16384
+int numrtex;
+char rtex[MAX_RTEX][64];
+
+void ReleaseTexture( char *name ){
+       int i;
+       char path[1024];
+
+       for ( i = 0 ; i < numrtex ; i++ )
+               if ( !Q_stricmp( name, rtex[i] ) ) {
+                       return;
+               }
+
+       if ( numrtex == MAX_RTEX ) {
+               Error( "numrtex == MAX_RTEX" );
+       }
+
+       strcpy( rtex[i], name );
+       numrtex++;
+
+       sprintf( path, "textures/%s.wal", name );
+       ReleaseFile( path );
+}
+
+/*
+   ===============
+   Cmd_Maps
+
+   Only relevent for release and pak files.
+   Releases the .bsp files for the maps, and scans all of the files to
+   build a list of all textures used, which are then released.
+   ===============
+ */
+void Cmd_Maps( void ){
+       char map[1024];
+
+       while ( TokenAvailable() )
+       {
+               GetToken( qfalse );
+               sprintf( map, "maps/%s.bsp", token );
+               ReleaseFile( map );
+
+               if ( !g_release ) {
+                       continue;
+               }
+
+               // get all the texture references
+               sprintf( map, "%smaps/%s.bsp", gamedir, token );
+               LoadBSPFile( map );
+       }
+}
+
+
+//==============================================================
+
+/*
+   ===============
+   ParseScript
+   ===============
+ */
+void ParseScript( void ){
+       while ( 1 )
+       {
+               do
+               {   // look for a line starting with a $ command
+                       GetToken( qtrue );
+                       if ( endofscript ) {
+                               return;
+                       }
+                       if ( token[0] == '$' ) {
+                               break;
+                       }
+                       while ( TokenAvailable() )
+                               GetToken( qfalse );
+               } while ( 1 );
+
+               //
+               // model commands
+               //
+               if ( !strcmp( token, "$modelname" ) ) {
+                       Cmd_Modelname();
+               }
+               else if ( !strcmp( token, "$base" ) ) {
+                       Cmd_Base();
+               }
+               else if ( !strcmp( token, "$exit" ) ) {
+                       break;
+               }
+               else if ( !strcmp( token, "$3dsconvert" ) ) {
+                       Cmd_3DSConvert();
+               }
+               else if ( !strcmp( token, "$spritebase" ) ) {
+                       Cmd_SpriteBase();
+               }
+               else if ( !strcmp( token, "$cd" ) ) {
+                       Cmd_Cd();
+               }
+               else if ( !strcmp( token, "$origin" ) ) {
+                       Cmd_Origin();
+               }
+               else if ( !strcmp( token, "$scale" ) ) {
+                       Cmd_ScaleUp();
+               }
+               else if ( !strcmp( token, "$frame" ) ) {
+                       Cmd_Frame();
+               }
+               else if ( !strcmp( token, "$skin" ) ) {
+                       Cmd_Skin();
+               }
+               else if ( !strcmp( token, "$spriteshader" ) ) {
+                       Cmd_SpriteShader();
+               }
+               else if ( !strcmp( token, "$aseconvert" ) ) {
+                       Cmd_ASEConvert( qfalse );
+               }
+               else if ( !strcmp( token, "$aseanimconvert" ) ) {
+                       Cmd_ASEConvert( qtrue );
+               }
+
+               //
+               // image commands
+               //
+               else if ( !strcmp( token, "$grab" ) ) {
+                       Cmd_Grab();
+               }
+               else if ( !strcmp( token, "$raw" ) ) {
+                       Cmd_Raw();
+               }
+               else if ( !strcmp( token, "$colormap" ) ) {
+                       Cmd_Colormap();
+               }
+               else if ( !strcmp( token, "$environment" ) ) {
+                       Cmd_Environment();
+               }
+
+               //
+               // video
+               //
+               else if ( !strcmp( token, "$video" ) ) {
+                       Cmd_Video();
+               }
+               //
+               // misc
+               //
+               else if ( !strcmp( token, "$file" ) ) {
+                       Cmd_File();
+               }
+               else if ( !strcmp( token, "$dir" ) ) {
+                       Cmd_Dir();
+               }
+               else if ( !strcmp( token, "$maps" ) ) {
+                       Cmd_Maps();
+               }
+               else{
+                       Error( "bad command %s\n", token );
+               }
+       }
+}
+
+//=======================================================
+
+#include "version.h"
+
+/*
+   ==============
+   main
+   ==============
+ */
+int main( int argc, char **argv ){
+       static int i;           // VC4.2 compiler bug if auto...
+       char path[1024];
+
+       // using GtkRadiant's versioning next to Id's versioning
+       printf( "Q3Data      - (c) 1999 Id Software Inc.\n" );
+       printf( "NetRadiant  - v" RADIANT_VERSION " " __DATE__ "\n" );
+
+       ExpandWildcards( &argc, &argv );
+
+       for ( i = 1 ; i < argc ; i++ )
+       {
+               if ( !strcmp( argv[i], "-archive" ) ) {
+                       archive = qtrue;
+                       strcpy( archivedir, argv[i + 1] );
+                       printf( "Archiving source to: %s\n", archivedir );
+                       i++;
+               }
+               else if ( !strcmp( argv[i], "-release" ) ) {
+                       g_release = qtrue;
+                       strcpy( g_releasedir, argv[i + 1] );
+                       printf( "Copy output to: %s\n", g_releasedir );
+                       i++;
+               }
+               else if ( !strcmp( argv[i], "-nostrips" ) ) {
+                       g_stripify = qfalse;
+                       printf( "Not optimizing for strips\n" );
+               }
+               else if ( !strcmp( argv[i], "-writedir" ) ) {
+                       strcpy( writedir, argv[i + 1] );
+                       printf( "Write output to: %s\n", writedir );
+                       i++;
+               }
+               else if ( !strcmp( argv[i], "-verbose" ) ) {
+                       g_verbose = qtrue;
+               }
+               else if ( !strcmp( argv[i], "-dump" ) ) {
+                       printf( "Dumping contents of: '%s'\n", argv[i + 1] );
+                       if ( strstr( argv[i + 1], ".md3" ) ) {
+                               MD3_Dump( argv[i + 1] );
+                       }
+                       else
+                       {
+                               Error( "Do not know how to dump the contents of '%s'\n", argv[i + 1] );
+                       }
+                       i++;
+               }
+               else if ( !strcmp( argv[i], "-3dsconvert" ) ) {
+                       // NOTE TTimo this is broken, tried on a sample .3ds
+                       // what happens .. it calls the Convert3DStoMD3,
+                       // which calls the scriptlib function in non initialized state .. and crashes
+                       printf( "Converting %s.3DS to %s.MD3\n", argv[i + 1], argv[i + 1] );
+                       SetQdirFromPath( argv[i + 1] );
+                       vfsInitDirectory( gamedir );
+                       Convert3DStoMD3( argv[i + 1] );
+                       i++;
+               }
+               else if ( !strcmp( argv[i], "-only" ) ) {
+                       strcpy( g_only, argv[i + 1] );
+                       printf( "Only grabbing %s\n", g_only );
+                       i++;
+               }
+               else if ( !strcmp( argv[i], "-gamedir" ) ) {
+                       strcpy( gamedir, argv[i + 1] );
+                       i++;
+               }
+               else if ( argv[i][0] == '-' ) {
+                       Error( "Unknown option \"%s\"", argv[i] );
+               }
+               else{
+                       break;
+               }
+       }
+
+       if ( i == argc ) {
+               Error( "usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]" );
+       }
+
+       for ( ; i < argc ; i++ )
+       {
+               printf( "--------------- %s ---------------\n", argv[i] );
+               // load the script
+               strcpy( path, argv[i] );
+               DefaultExtension( path, ".qdt" );
+               if ( !gamedir[0] ) {
+                       SetQdirFromPath( path );
+               }
+               // NOTE TTimo
+               // q3data went through a partial conversion to use the vfs
+               // it was never actually tested before 1.1.1
+               // the code is still mostly using direct file access calls
+               vfsInitDirectory( gamedir );
+               LoadScriptFile( ExpandArg( path ), -1 );
+
+               //
+               // parse it
+               //
+               ParseScript();
+
+               // write out the last model
+               FinishModel( TYPE_UNKNOWN );
+       }
+
+       return 0;
+}