[quake3-commits] r1659 - in trunk/code: client qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Oct 12 12:03:19 EDT 2009


Author: thilo
Date: 2009-10-12 12:03:18 -0400 (Mon, 12 Oct 2009)
New Revision: 1659

Modified:
   trunk/code/client/cl_main.c
   trunk/code/qcommon/common.c
Log:
Fix environment variable handling for Linux, make setenv command added before parsing of configuration files. (https://bugzilla.icculus.org/show_bug.cgi?id=3626)


Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2009-10-12 03:21:02 UTC (rev 1658)
+++ trunk/code/client/cl_main.c	2009-10-12 16:03:18 UTC (rev 1659)
@@ -1452,41 +1452,6 @@
 
 /*
 ==================
-CL_Setenv_f
-
-Mostly for controlling voodoo environment variables
-==================
-*/
-void CL_Setenv_f( void ) {
-	int argc = Cmd_Argc();
-
-	if ( argc > 2 ) {
-		char buffer[1024];
-		int i;
-
-		strcpy( buffer, Cmd_Argv(1) );
-		strcat( buffer, "=" );
-
-		for ( i = 2; i < argc; i++ ) {
-			strcat( buffer, Cmd_Argv( i ) );
-			strcat( buffer, " " );
-		}
-
-		putenv( buffer );
-	} else if ( argc == 2 ) {
-		char *env = getenv( Cmd_Argv(1) );
-
-		if ( env ) {
-			Com_Printf( "%s=%s\n", Cmd_Argv(1), env );
-		} else {
-			Com_Printf( "%s undefined\n", Cmd_Argv(1));
-		}
-	}
-}
-
-
-/*
-==================
 CL_Disconnect_f
 ==================
 */
@@ -3238,7 +3203,6 @@
 	Cmd_AddCommand ("globalservers", CL_GlobalServers_f);
 	Cmd_AddCommand ("rcon", CL_Rcon_f);
 	Cmd_SetCommandCompletionFunc( "rcon", CL_CompleteRcon );
-	Cmd_AddCommand ("setenv", CL_Setenv_f );
 	Cmd_AddCommand ("ping", CL_Ping_f );
 	Cmd_AddCommand ("serverstatus", CL_ServerStatus_f );
 	Cmd_AddCommand ("showip", CL_ShowIP_f );
@@ -3305,7 +3269,6 @@
 	Cmd_RemoveCommand ("localservers");
 	Cmd_RemoveCommand ("globalservers");
 	Cmd_RemoveCommand ("rcon");
-	Cmd_RemoveCommand ("setenv");
 	Cmd_RemoveCommand ("ping");
 	Cmd_RemoveCommand ("serverstatus");
 	Cmd_RemoveCommand ("showip");

Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2009-10-12 03:21:02 UTC (rev 1658)
+++ trunk/code/qcommon/common.c	2009-10-12 16:03:18 UTC (rev 1659)
@@ -2362,6 +2362,43 @@
 	* ( int * ) 0 = 0x12345678;
 }
 
+/*
+==================
+Com_Setenv_f
+
+For controlling environment variables
+==================
+*/
+void Com_Setenv_f(void)
+{
+	int argc = Cmd_Argc();
+	char *arg1 = Cmd_Argv(1);
+
+	if(argc > 2)
+	{
+		char *arg2 = Cmd_ArgsFrom(2);
+		
+		#ifdef _MSC_VER
+		// windows already removes env variable if value is an empty string
+		_putenv_s(arg1, arg2);
+		#else
+		if(!*arg2)
+			unsetenv(arg1);
+		else
+			setenv(arg1, arg2, 1);
+		#endif
+	}
+	else if(argc == 2)
+	{
+		char *env = getenv(arg1);
+		
+		if(env)
+			Com_Printf("%s=%s\n", arg1, env);
+		else
+			Com_Printf("%s undefined\n", arg1);
+        }
+}
+
 #ifndef STANDALONE
 
 // TTimo: centralizing the cl_cdkey stuff after I discovered a buffer overflow problem with the dedicated server version
@@ -2568,12 +2605,25 @@
 
 	Com_InitJournaling();
 
+	// Add some commands here already so users can use them from config files
+	Cmd_AddCommand ("setenv", Com_Setenv_f);
+	if (com_developer && com_developer->integer)
+	{
+		Cmd_AddCommand ("error", Com_Error_f);
+		Cmd_AddCommand ("crash", Com_Crash_f);
+		Cmd_AddCommand ("freeze", Com_Freeze_f);
+	}
+	Cmd_AddCommand ("quit", Com_Quit_f);
+	Cmd_AddCommand ("changeVectors", MSG_ReportChangeVectors_f );
+	Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );
+	Cmd_SetCommandCompletionFunc( "writeconfig", Cmd_CompleteCfgName );
+
+	// Make it execute the configuration files
 	Cbuf_AddText ("exec default.cfg\n");
 
 	// skip the q3config.cfg if "safe" is on the command line
-	if ( !Com_SafeMode() ) {
-		Cbuf_AddText ("exec " Q3CONFIG_CFG "\n");
-	}
+	if (!Com_SafeMode())
+		Cbuf_AddText("exec " Q3CONFIG_CFG "\n");
 
 	Cbuf_AddText ("exec autoexec.cfg\n");
 
@@ -2632,16 +2682,6 @@
 
 	com_introPlayed = Cvar_Get( "com_introplayed", "0", CVAR_ARCHIVE);
 
-	if ( com_developer && com_developer->integer ) {
-		Cmd_AddCommand ("error", Com_Error_f);
-		Cmd_AddCommand ("crash", Com_Crash_f );
-		Cmd_AddCommand ("freeze", Com_Freeze_f);
-	}
-	Cmd_AddCommand ("quit", Com_Quit_f);
-	Cmd_AddCommand ("changeVectors", MSG_ReportChangeVectors_f );
-	Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );
-	Cmd_SetCommandCompletionFunc( "writeconfig", Cmd_CompleteCfgName );
-
 	s = va("%s %s %s", Q3_VERSION, PLATFORM_STRING, __DATE__ );
 	com_version = Cvar_Get ("version", s, CVAR_ROM | CVAR_SERVERINFO );
 



More information about the quake3-commits mailing list