]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
got rid of host_parms.argc and argv, now uses com_argc and com_argv directly
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 20 Aug 2002 07:08:40 +0000 (07:08 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 20 Aug 2002 07:08:40 +0000 (07:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2262 d7cf8633-e32d-0410-b094-e92efae38249

common.c
common.h
host.c
quakedef.h
sys_linux.c
sys_shared.c
sys_win.c

index 1f38d06ca54ac2c341d9fa3af9683a1ea82bb460..a6aeab1e3f2ddfb84eb6ec395cef81d404415f97 100644 (file)
--- a/common.c
+++ b/common.c
@@ -29,14 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
-#define NUM_SAFE_ARGVS  7
-
-static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1];
-static char *argvdummy = " ";
-
-static char *safeargvs[NUM_SAFE_ARGVS] =
-       {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-window"};
-
 cvar_t registered = {0, "registered","0"};
 cvar_t cmdline = {0, "cmdline","0"};
 
@@ -735,64 +727,45 @@ void COM_Path_f (void);
 COM_InitArgv
 ================
 */
-void COM_InitArgv (int argc, char **argv)
+void COM_InitArgv (void)
 {
-       qboolean        safe;
-       int             i, j, n;
-
-// reconstitute the command line for the cmdline externally visible cvar
+       int i, j, n;
+       // reconstitute the command line for the cmdline externally visible cvar
        n = 0;
-
-       for (j=0 ; (j<MAX_NUM_ARGVS) && (j< argc) ; j++)
+       for (j = 0;(j < MAX_NUM_ARGVS) && (j < com_argc);j++)
        {
                i = 0;
-
-               while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i])
-               {
-                       com_cmdline[n++] = argv[j][i++];
-               }
-
+               while ((n < (CMDLINE_LENGTH - 1)) && com_argv[j][i])
+                       com_cmdline[n++] = com_argv[j][i++];
                if (n < (CMDLINE_LENGTH - 1))
                        com_cmdline[n++] = ' ';
                else
                        break;
        }
-
        com_cmdline[n] = 0;
+}
 
-       safe = false;
-
-       for (com_argc=0 ; (com_argc<MAX_NUM_ARGVS) && (com_argc < argc) ;
-                com_argc++)
-       {
-               largv[com_argc] = argv[com_argc];
-               if (!strcmp ("-safe", argv[com_argc]))
-                       safe = true;
-       }
+void COM_InitGameType (void)
+{
+       char name[128];
+       COM_StripExtension(com_argv[0], name);
+       COM_ToLowerString(name, name);
 
-       if (safe)
-       {
-       // force all the safe-mode switches. Note that we reserved extra space in
-       // case we need to add these, so we don't need an overflow check
-               for (i=0 ; i<NUM_SAFE_ARGVS ; i++)
-               {
-                       largv[com_argc] = safeargvs[i];
-                       com_argc++;
-               }
-       }
+       if (strstr(name, "transfusion"))
+               gamemode = GAME_TRANSFUSION;
+       else if (strstr(name, "zymotic"))
+               gamemode = GAME_ZYMOTIC;
+       else if (strstr(name, "fiendarena"))
+               gamemode = GAME_FIENDARENA;
+       else if (strstr(name, "nehahra"))
+               gamemode = GAME_NEHAHRA;
+       else if (strstr(name, "hipnotic"))
+               gamemode = GAME_HIPNOTIC;
+       else if (strstr(name, "rogue"))
+               gamemode = GAME_ROGUE;
+       else
+               gamemode = GAME_NORMAL;
 
-       largv[com_argc] = argvdummy;
-       com_argv = largv;
-
-#if TRANSFUSION
-       gamemode = GAME_TRANSFUSION;
-#elif ZYMOTIC
-       gamemode = GAME_ZYMOTIC;
-#elif FIENDARENA
-       gamemode = GAME_FIENDARENA;
-#elif NEHAHRA
-       gamemode = GAME_NEHAHRA;
-#else
        if (COM_CheckParm ("-transfusion"))
                gamemode = GAME_TRANSFUSION;
        else if (COM_CheckParm ("-zymotic"))
@@ -805,11 +778,16 @@ void COM_InitArgv (int argc, char **argv)
                gamemode = GAME_HIPNOTIC;
        else if (COM_CheckParm ("-rogue"))
                gamemode = GAME_ROGUE;
-#endif
+       else if (COM_CheckParm ("-quake"))
+               gamemode = GAME_NORMAL;
+
        switch(gamemode)
        {
        case GAME_NORMAL:
-               gamename = "DarkPlaces";
+               if (registered.integer)
+                       gamename = "DarkPlaces-Quake";
+               else
+                       gamename = "DarkPlaces-SharewareQuake";
                break;
        case GAME_HIPNOTIC:
                gamename = "Darkplaces-Hipnotic";
@@ -830,7 +808,7 @@ void COM_InitArgv (int argc, char **argv)
                gamename = "Transfusion";
                break;
        default:
-               Sys_Error("COM_InitArgv: unknown gamemode %i\n", gamemode);
+               Sys_Error("COM_InitGameType: unknown gamemode %i\n", gamemode);
                break;
        }
 }
@@ -1573,3 +1551,11 @@ void COM_ToUpperString(char *in, char *out)
        }
 }
 
+int COM_StringBeginsWith(const char *s, const char *match)
+{
+       for (;*s && *match;s++, match++)
+               if (*s != *match)
+                       return false;
+       return true;
+}
+
index 80998f8e7de530fb1c8b1154c0172decb50e4a0e..b5b7bebf85fea4563ff61dce357d34283f6d2a31 100644 (file)
--- a/common.h
+++ b/common.h
@@ -138,7 +138,8 @@ extern      char    **com_argv;
 
 int COM_CheckParm (char *parm);
 void COM_Init (void);
-void COM_InitArgv (int argc, char **argv);
+void COM_InitArgv (void);
+void COM_InitGameType (void);
 
 char *COM_SkipPath (char *pathname);
 void COM_StripExtension (char *in, char *out);
@@ -178,8 +179,9 @@ extern int gamemode;
 extern char *gamename;
 
 // LordHavoc: useful...
-extern void COM_ToLowerString(char *in, char *out);
-extern void COM_ToUpperString(char *in, char *out);
+void COM_ToLowerString(char *in, char *out);
+void COM_ToUpperString(char *in, char *out);
+int COM_StringBeginsWith(const char *s, const char *match);
 
 typedef struct stringlist_s
 {
diff --git a/host.c b/host.c
index 5d570becb6c0d0231bcef2af9ae83a7354405a44..32562e138ec36c6b7f89317a5b4c1a3ce0fef9c9 100644 (file)
--- a/host.c
+++ b/host.c
@@ -807,8 +807,6 @@ void Host_Init (void)
        // LordHavoc: quake never seeded the random number generator before... heh
        srand(time(NULL));
 
-       com_argc = host_parms.argc;
-       com_argv = host_parms.argv;
        // FIXME: this is evil, but possibly temporary
        if (COM_CheckParm("-developer"))
        {
index e6c80d41bd6c2a61454ae42f0df2139f426524ae..23c2061a2c8a63495d0c8be88b0a3b17d097d3af 100644 (file)
@@ -197,9 +197,7 @@ extern char *buildstring;
 
 //=============================================================================
 
-// the host system specifies the base of the directory tree, the
-// command line parms passed to the program, and the amount of memory
-// available for the program to use
+// the host system specifies the base of the directory tree
 
 typedef struct
 {
@@ -207,8 +205,6 @@ typedef struct
 #if CACHEENABLE
        char    *cachedir;              // for development over ISDN lines
 #endif
-       int             argc;
-       char    **argv;
 } quakeparms_t;
 
 
index 0dc1ce9e61ae8da4f4dc1263115945178c7147b2..451844ce69e8ad45dec978e853893a5940e5b561 100644 (file)
 
 #include "quakedef.h"
 
-char *basedir = ".";
-#if CACHEENABLE
-char *cachedir = "/tmp";
-#endif
-
 // =======================================================================
 // General routines
 // =======================================================================
@@ -144,7 +139,7 @@ void Sys_Sleep(void)
        usleep(1);
 }
 
-int main (int c, char **v)
+int main (int argc, char **argv)
 {
        double frameoldtime, framenewtime;
 
@@ -152,9 +147,12 @@ int main (int c, char **v)
 
        memset(&host_parms, 0, sizeof(host_parms));
 
-       host_parms.argc = c;
-       host_parms.argv = v;
-       host_parms.basedir = basedir;
+       com_argc = argc;
+       com_argv = argv;
+       host_parms.basedir = ".";
+#if CACHEENABLE
+       host_parms.cachedir = "/tmp";
+#endif
 
        fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
 
index 11f160402fd6a2f10098f04d42b74c8ae94d12e0..5b81ce0ea877c19e7fbb8eed83bbe09c50d2bdf7 100644 (file)
@@ -1,7 +1,9 @@
 
 #include "quakedef.h"
 #include <time.h>
-#ifndef WIN32
+#ifdef WIN32
+#include <direct.h>
+#else
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -45,7 +47,7 @@ static char qfont_table[256] = {
        'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
        'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
        '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
-       'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o', 
+       'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
        'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
        'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
 };
@@ -237,6 +239,9 @@ void Sys_Shared_EarlyInit(void)
 {
        Memory_Init ();
 
+       COM_InitArgv();
+       COM_InitGameType();
+
 #if defined(__linux__)
        sprintf (engineversion, "%s Linux %s", gamename, buildstring);
 #elif defined(WIN32)
index 5bd55f902cf5babb09e16b5d8c93caa14ade9318..a0c2ed038163f53e885f419c443863de79f2f220 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -351,10 +351,10 @@ static char       *empty_string = "";
 
 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 {
-       double                  frameoldtime, framenewtime;
-       MEMORYSTATUS    lpBuffer;
-       static  char    cwd[1024];
-       int                             t;
+       double frameoldtime, framenewtime;
+       MEMORYSTATUS lpBuffer;
+//     static char cwd[1024];
+       int t;
 
        /* previous instances do not exist in Win32 */
        if (hPrevInstance)
@@ -366,28 +366,34 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        lpBuffer.dwLength = sizeof(MEMORYSTATUS);
        GlobalMemoryStatus (&lpBuffer);
 
+/*
        if (!GetCurrentDirectory (sizeof(cwd), cwd))
                Sys_Error ("Couldn't determine current directory");
 
        if (cwd[strlen(cwd)-1] == '/')
                cwd[strlen(cwd)-1] = 0;
+*/
 
        memset(&host_parms, 0, sizeof(host_parms));
 
-       host_parms.basedir = cwd;
+//     host_parms.basedir = cwd;
+       host_parms.basedir = ".";
+#if CACHEENABLE
+       host_parms.cachedir = ".";
+#endif
 
-       host_parms.argc = 1;
+       com_argc = 1;
        argv[0] = empty_string;
 
-       while (*lpCmdLine && (host_parms.argc < MAX_NUM_ARGVS))
+       while (*lpCmdLine && (com_argc < MAX_NUM_ARGVS))
        {
                while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
                        lpCmdLine++;
 
                if (*lpCmdLine)
                {
-                       argv[host_parms.argc] = lpCmdLine;
-                       host_parms.argc++;
+                       argv[com_argc] = lpCmdLine;
+                       com_argc++;
 
                        while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
                                lpCmdLine++;
@@ -399,7 +405,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
                        }
                }
        }
-       host_parms.argv = argv;
+       com_argv = argv;
 
        Sys_Shared_EarlyInit();