summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2007-11-25 20:57:50 +0000
committerAndrey Nazarov <skuller@skuller.net>2007-11-25 20:57:50 +0000
commitb00e7bd024285970dd00cfc75d8e690bfa475501 (patch)
tree22ceeee3027fd4872f5621650557bc8ae4391948
parent5eaaac93ad3b0d2777815717059d977912bd96f7 (diff)
Changed Com_sprintf --> Q_concat in quite some cases.
Make sure WAVE sound driver is built by default. Added --disable-wave option to `configure'. Command line history is now remembered between sessions. ALT+Space refreshes all servers in Server Browser. Handle command line agruments like original Q2 engine did.
-rw-r--r--build/q2pro.mk18
-rwxr-xr-xconfigure15
-rw-r--r--source/cl_console.c13
-rw-r--r--source/cl_demo.c19
-rw-r--r--source/cl_local.h1
-rw-r--r--source/cl_locs.c4
-rw-r--r--source/cl_main.c34
-rw-r--r--source/cl_parse.c31
-rw-r--r--source/cl_ref.c8
-rw-r--r--source/cl_scrn.c8
-rw-r--r--source/cl_ui.c4
-rw-r--r--source/cl_view.c2
-rw-r--r--source/cmd.c12
-rw-r--r--source/com_local.h7
-rw-r--r--source/common.c90
-rw-r--r--source/cvar.c4
-rw-r--r--source/files.c59
-rw-r--r--source/gl_draw.c2
-rw-r--r--source/gl_images.c2
-rw-r--r--source/gl_main.c2
-rw-r--r--source/gl_sky.c8
-rw-r--r--source/mvd_client.c8
-rw-r--r--source/net_common.c2
-rw-r--r--source/prompt.c110
-rw-r--r--source/prompt.h4
-rw-r--r--source/q_field.c54
-rw-r--r--source/q_field.h1
-rw-r--r--source/q_shared.c36
-rw-r--r--source/q_shared.h10
-rw-r--r--source/r_bsp.c2
-rw-r--r--source/snd_main.c10
-rw-r--r--source/snd_mem.c2
-rw-r--r--source/sv_game.c18
-rw-r--r--source/sv_init.c4
-rw-r--r--source/sv_mvd.c2
-rw-r--r--source/sw_image.c2
-rw-r--r--source/sw_main.c8
-rw-r--r--source/sw_model.c4
-rw-r--r--source/sys_unix.c75
-rw-r--r--source/sys_win.c62
-rw-r--r--source/ui_demos.c6
-rw-r--r--source/ui_loading.c2
-rw-r--r--source/ui_menu.c44
-rw-r--r--source/ui_multiplayer.c4
-rw-r--r--source/ui_playerconfig.c15
-rw-r--r--source/ui_playermodels.c21
-rw-r--r--source/vid_win.c5
47 files changed, 476 insertions, 378 deletions
diff --git a/build/q2pro.mk b/build/q2pro.mk
index 8beaa8b..cbaf753 100644
--- a/build/q2pro.mk
+++ b/build/q2pro.mk
@@ -48,6 +48,7 @@ endif
endif #REF_HARD_LINKED
ifdef UI_HARD_LINKED
+
SRCFILES+=ui_addressbook.c \
ui_atoms.c \
ui_confirm.c \
@@ -73,7 +74,8 @@ SRCFILES+=ui_addressbook.c \
ui_savegame.c \
ui_startserver.c \
ui_video.c
-endif
+
+endif # UI_HARD_LINKED
ifdef USE_ZLIB
SRCFILES+=ioapi.c unzip.c
@@ -87,7 +89,15 @@ endif
ifdef MINGW
-SRCFILES+=sys_win.c snd_wave.c vid_win.c win_glimp.c win_wgl.c win_swimp.c
+SRCFILES+=sys_win.c vid_win.c win_glimp.c win_wgl.c
+
+ifndef REF_HARD_LINKED
+SRCFILES+=win_swimp.c
+endif
+
+ifdef USE_WAVE
+SRCFILES+=snd_wave.c
+endif
ifdef USE_DSOUND
SRCFILES+=snd_dx.c
@@ -101,7 +111,7 @@ LDFLAGS+=-mwindows -lws2_32 -lwinmm
RESFILES=q2pro.rc
-else
+else # MINGW
SRCFILES+=sys_unix.c
@@ -122,7 +132,7 @@ CFLAGS+=$(SDL_CFLAGS)
LDFLAGS+=-lX11 $(SDL_LDFLAGS)
endif
-endif
+endif # !MINGW
include $(SRCDIR)/build/target.mk
diff --git a/configure b/configure
index 6d40c48..903005e 100755
--- a/configure
+++ b/configure
@@ -21,6 +21,7 @@ pngconfig="libpng-config"
exesuffix=""
libsuffix=".so"
dsound="no"
+wave="???"
dinput="no"
oss="no"
evdev="no"
@@ -82,12 +83,14 @@ CYGWIN*)
targetos="Windows"
mingw="yes"
sdl="no"
+wave="yes"
CFLAGS="-mno-cygwin $CFLAGS"
;;
MINGW*)
targetos="Windows"
mingw="yes"
sdl="no"
+wave="yes"
;;
*BSD)
make="gmake"
@@ -132,6 +135,8 @@ for opt do
;;
--enable-dinput) dinput="yes"
;;
+ --disable-wave) wave="no"
+ ;;
--disable-oss) oss="no"
;;
--disable-zlib) zlib="no"
@@ -164,6 +169,7 @@ echo " --enable-openffa build OpenFFA deathmatch mod"
echo " --enable-mingw enable Windows build"
echo " --enable-dsound enable DirectSound driver"
echo " --enable-dinput enable DirectInput driver"
+echo " --disable-wave disable WAVE sound driver"
echo " --disable-oss disable OSS driver"
echo " --disable-evdev disable Evdev driver"
echo " --disable-zlib disable linking with zlib"
@@ -188,6 +194,9 @@ if [ "$mingw" = "yes" ]; then
homedir=""
asmflags="-DUNDERSCORES"
cfgfile="q2config.cfg"
+ if [ "$wave" = "???" ]; then
+ wave="yes"
+ fi
else
pathsep="/"
gamelib="game$cpu.so"
@@ -245,6 +254,7 @@ if [ "$client" = "yes" ]; then
if [ "$mingw" = "yes" ]; then
echo "DInput support $dinput"
echo "DSound support $dsound"
+ echo "WAVE sound support $wave"
else
echo "OSS support $oss"
echo "Evdev support $evdev"
@@ -399,6 +409,11 @@ if [ "$evdev" = "yes" ]; then
echo "#define USE_EVDEV 1" >> $config_h
fi
+if [ "$wave" = "yes" ]; then
+ echo "USE_WAVE=yes" >> $config_mk
+ echo "#define USE_WAVE 1" >> $config_h
+fi
+
if [ "$dsound" = "yes" ]; then
echo "USE_DSOUND=yes" >> $config_mk
echo "#define USE_DSOUND 1" >> $config_h
diff --git a/source/cl_console.c b/source/cl_console.c
index 04586c9..7eea034 100644
--- a/source/cl_console.c
+++ b/source/cl_console.c
@@ -75,6 +75,7 @@ static cvar_t *con_scale;
static cvar_t *con_font;
static cvar_t *con_background;
static cvar_t *con_scroll;
+static cvar_t *con_histfile;
// ============================================================================
@@ -326,11 +327,12 @@ void Con_Init( void ) {
con_background = Cvar_Get( "con_background", "conback", CVAR_ARCHIVE );
con_background->changed = con_param_changed;
con_scroll = Cvar_Get( "con_scroll", "0", CVAR_ARCHIVE );
+ con_histfile = Cvar_Get( "con_histfile", "history.txt", CVAR_ARCHIVE );
IF_Init( &con.prompt.inputLine, 1, MAX_FIELD_TEXT );
IF_Init( &con.chatPrompt.inputLine, 1, MAX_FIELD_TEXT );
- con.prompt.Printf = Con_Printf;
+ con.prompt.printf = Con_Printf;
// use default width if no video initialized yet
scr_glconfig.vidWidth = 640;
@@ -344,12 +346,21 @@ void Con_Init( void ) {
con.initialized = qtrue;
}
+void Con_PostInit( void ) {
+ if( con_histfile->string[0] ) {
+ Prompt_LoadHistory( &con.prompt, con_histfile->string );
+ }
+}
+
/*
================
Con_Shutdown
================
*/
void Con_Shutdown( void ) {
+ if( con_histfile->string[0] ) {
+ Prompt_SaveHistory( &con.prompt, con_histfile->string );
+ }
Prompt_Clear( &con.prompt );
}
diff --git a/source/cl_demo.c b/source/cl_demo.c
index ce77c86..172f955 100644
--- a/source/cl_demo.c
+++ b/source/cl_demo.c
@@ -254,7 +254,7 @@ void CL_Record_f( void ) {
if( *string == '/' ) {
Q_strncpyz( name, string + 1, sizeof( name ) );
} else {
- Com_sprintf( name, sizeof( name ), "demos/%s", string );
+ Q_concat( name, sizeof( name ), "demos/", string, NULL );
COM_AppendExtension( name, ".dm2", sizeof( name ) );
}
if( compressed ) {
@@ -417,9 +417,10 @@ static void CL_PlayDemo_f( void ) {
fileHandle_t demofile;
char *arg;
int length;
+ int argc = Cmd_Argc();
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if( argc < 2 ) {
+ Com_Printf( "Usage: %s <filename> [...]\n", Cmd_Argv( 0 ) );
return;
}
@@ -433,7 +434,7 @@ static void CL_PlayDemo_f( void ) {
FS_FOpenFile( name, &demofile, FS_MODE_READ );
} else {
// Search for matching extensions
- Com_sprintf( name, sizeof( name ), "demos/%s", arg );
+ Q_concat( name, sizeof( name ), "demos/", arg, NULL );
FS_FOpenFile( name, &demofile, FS_MODE_READ );
if( !demofile ) {
COM_AppendExtension( name, ".dm2", sizeof( name ) );
@@ -446,6 +447,16 @@ static void CL_PlayDemo_f( void ) {
return;
}
+#if 0
+ // add trailing filenames to play list
+ for( i = 2; i < argc; i++ ) {
+ arg = Cmd_Argv( i );
+ length = strlen( arg );
+ entry = Z_Malloc( sizeof( *entry ) + length );
+ memcpy( entry->filename, arg, length + 1 );
+ }
+#endif
+
if( sv_running->integer ) {
// if running a local server, kill it and reissue
SV_Shutdown( "Server was killed\n", KILL_DROP );
diff --git a/source/cl_local.h b/source/cl_local.h
index f004100..a874e85 100644
--- a/source/cl_local.h
+++ b/source/cl_local.h
@@ -606,6 +606,7 @@ void LOC_AddLocationsToScene( void );
// console.c
//
void Con_Init( void );
+void Con_PostInit( void );
void Con_Shutdown( void );
void Con_DrawConsole( void );
void Con_RunConsole( void );
diff --git a/source/cl_locs.c b/source/cl_locs.c
index a861bd5..c469037 100644
--- a/source/cl_locs.c
+++ b/source/cl_locs.c
@@ -62,14 +62,14 @@ LOC_LoadLocations
==============
*/
void LOC_LoadLocations( void ) {
- char path[MAX_QPATH];
+ char path[MAX_OSPATH];
char *buffer, *s, *p;
int line, count;
location_t *loc;
int argc;
// load from main directory
- Com_sprintf( path, sizeof( path ), "locs/%s.loc", cl.mapname );
+ Q_concat( path, sizeof( path ), "locs/", cl.mapname, ".loc", NULL );
FS_LoadFile( path, (void **)&buffer );
if( !buffer ) {
diff --git a/source/cl_main.c b/source/cl_main.c
index 7c0d7db..3aee4f7 100644
--- a/source/cl_main.c
+++ b/source/cl_main.c
@@ -303,9 +303,8 @@ void CL_Setenv_f( void ) {
if ( argc > 2 ) {
char buffer[ MAX_STRING_CHARS ];
- Q_strncpyz( buffer, Cmd_Argv( 1 ), sizeof( buffer ) );
- Q_strcat( buffer, sizeof( buffer ), "=" );
- Q_strcat( buffer, sizeof( buffer ), Cmd_ArgsFrom( 2 ) );
+ Q_concat( buffer, sizeof( buffer ), Cmd_Argv( 1 ), "=",
+ Cmd_ArgsFrom( 2 ), NULL );
putenv( buffer );
} else if ( argc == 2 ) {
@@ -1654,7 +1653,7 @@ void CL_RequestNextDownload ( void ) {
precache_check++;
continue;
}
- Com_sprintf( fn, sizeof( fn ), "sound/%s", cl.configstrings[ precache_check++ ] );
+ Q_concat( fn, sizeof( fn ), "sound/", cl.configstrings[ precache_check++ ], NULL );
if ( !CL_CheckOrDownloadFile( fn ) )
return; // started a download
}
@@ -1666,7 +1665,7 @@ void CL_RequestNextDownload ( void ) {
precache_check++; // zero is blank
while ( precache_check < CS_IMAGES + MAX_IMAGES &&
cl.configstrings[ precache_check ][ 0 ] ) {
- Com_sprintf( fn, sizeof( fn ), "pics/%s.pcx", cl.configstrings[ precache_check++ ] );
+ Q_concat( fn, sizeof( fn ), "pics/", cl.configstrings[ precache_check++ ], ".pcx", NULL );
if ( !CL_CheckOrDownloadFile( fn ) )
return; // started a download
}
@@ -1705,7 +1704,7 @@ void CL_RequestNextDownload ( void ) {
switch ( n ) {
case 0: // model
- Com_sprintf( fn, sizeof( fn ), "players/%s/tris.md2", model );
+ Q_concat( fn, sizeof( fn ), "players/", model, "/tris.md2", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 1;
return; // started a download
@@ -1714,7 +1713,7 @@ void CL_RequestNextDownload ( void ) {
/*FALL THROUGH*/
case 1: // weapon model
- Com_sprintf( fn, sizeof( fn ), "players/%s/weapon.md2", model );
+ Q_concat( fn, sizeof( fn ), "players/", model, "/weapon.md2", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 2;
return; // started a download
@@ -1723,7 +1722,7 @@ void CL_RequestNextDownload ( void ) {
/*FALL THROUGH*/
case 2: // weapon skin
- Com_sprintf( fn, sizeof( fn ), "players/%s/weapon.pcx", model );
+ Q_concat( fn, sizeof( fn ), "players/", model, "/weapon.pcx", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 3;
return; // started a download
@@ -1732,7 +1731,7 @@ void CL_RequestNextDownload ( void ) {
/*FALL THROUGH*/
case 3: // skin
- Com_sprintf( fn, sizeof( fn ), "players/%s/%s.pcx", model, skin );
+ Q_concat( fn, sizeof( fn ), "players/", model, "/", skin, ".pcx", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 4;
return; // started a download
@@ -1741,7 +1740,7 @@ void CL_RequestNextDownload ( void ) {
/*FALL THROUGH*/
case 4: // skin_i
- Com_sprintf( fn, sizeof( fn ), "players/%s/%s_i.pcx", model, skin );
+ Q_concat( fn, sizeof( fn ), "players/", model, "/", skin, "_i.pcx", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 5;
return; // started a download
@@ -1776,11 +1775,11 @@ void CL_RequestNextDownload ( void ) {
int n = precache_check++ - ENV_CNT - 1;
if ( n & 1 )
- Com_sprintf( fn, sizeof( fn ), "env/%s%s.pcx",
- cl.configstrings[ CS_SKY ], env_suf[ n / 2 ] );
+ Q_concat( fn, sizeof( fn ),
+ "env/", cl.configstrings[ CS_SKY ], env_suf[ n / 2 ], ".pcx", NULL );
else
- Com_sprintf( fn, sizeof( fn ), "env/%s%s.tga",
- cl.configstrings[ CS_SKY ], env_suf[ n / 2 ] );
+ Q_concat( fn, sizeof( fn ),
+ "env/", cl.configstrings[ CS_SKY ], env_suf[ n / 2 ], ".tga", NULL );
if ( !CL_CheckOrDownloadFile( fn ) )
return; // started a download
}
@@ -1800,11 +1799,11 @@ void CL_RequestNextDownload ( void ) {
char *texname = cl.cm.cache->surfaces[ precache_tex++ ].rname;
// Also check if 32bit images are present
- Com_sprintf( fn, sizeof( fn ), "textures/%s.jpg", texname );
+ Q_concat( fn, sizeof( fn ), "textures/", texname, ".jpg", NULL );
if ( FS_LoadFile( fn, NULL ) == -1 ) {
- Com_sprintf( fn, sizeof( fn ), "textures/%s.tga", texname );
+ Q_concat( fn, sizeof( fn ), "textures/", texname, ".tga", NULL );
if ( FS_LoadFile( fn, NULL ) == -1 ) {
- Com_sprintf( fn, sizeof( fn ), "textures/%s.wal", texname );
+ Q_concat( fn, sizeof( fn ), "textures/", texname, ".wal", NULL );
if ( !CL_CheckOrDownloadFile( fn ) ) {
return; // started a download
}
@@ -2704,6 +2703,7 @@ void CL_Init( void ) {
UI_OpenMenu( UIMENU_MAIN );
+ Con_PostInit();
Con_RunConsole();
Cvar_Set( "cl_running", "1" );
diff --git a/source/cl_parse.c b/source/cl_parse.c
index b42c7b2..b7dc0b8 100644
--- a/source/cl_parse.c
+++ b/source/cl_parse.c
@@ -985,8 +985,8 @@ noskin:
strcpy( skin_name, t + 1 );
// model file
- Com_sprintf( model_filename, sizeof( model_filename ),
- "players/%s/tris.md2", model_name );
+ Q_concat( model_filename, sizeof( model_filename ),
+ "players/", model_name, "/tris.md2", NULL );
ci->model = ref.RegisterModel( model_filename );
if( !ci->model && Q_stricmp( model_name, "male" ) ) {
strcpy( model_name, "male" );
@@ -995,8 +995,8 @@ noskin:
}
// skin file
- Com_sprintf( skin_filename, sizeof( skin_filename ),
- "players/%s/%s.pcx", model_name, skin_name );
+ Q_concat( skin_filename, sizeof( skin_filename ),
+ "players/", model_name, "/", skin_name, ".pcx", NULL );
ci->skin = ref.RegisterSkin( skin_filename );
// if we don't have the skin and the model was female,
@@ -1016,8 +1016,8 @@ noskin:
ci->model = ref.RegisterModel( model_filename );
// see if the skin exists for the male model
- Com_sprintf( skin_filename, sizeof( skin_filename ),
- "players/%s/%s.pcx", model_name, skin_name );
+ Q_concat( skin_filename, sizeof( skin_filename ),
+ "players/male/", skin_name, ".pcx", NULL );
ci->skin = ref.RegisterSkin( skin_filename );
}
@@ -1025,20 +1025,19 @@ noskin:
// didn't have it, so default to grunt
if( !ci->skin ) {
// see if the skin exists for the male model
- Com_sprintf( skin_filename, sizeof( skin_filename ),
- "players/%s/grunt.pcx", model_name );
+ strcpy( skin_filename, "players/male/grunt.pcx" );
ci->skin = ref.RegisterSkin( skin_filename );
}
// weapon file
for( i = 0; i < cl.numWeaponModels; i++ ) {
- Com_sprintf( weapon_filename, sizeof( weapon_filename ),
- "players/%s/%s", model_name, cl.weaponModels[i] );
+ Q_concat( weapon_filename, sizeof( weapon_filename ),
+ "players/", model_name, "/", cl.weaponModels[i], NULL );
ci->weaponmodel[i] = ref.RegisterModel( weapon_filename );
if( !ci->weaponmodel[i] && !Q_stricmp( model_name, "cyborg" ) ) {
// try male
- Com_sprintf( weapon_filename, sizeof( weapon_filename ),
- "players/male/%s", cl.weaponModels[i] );
+ Q_concat( weapon_filename, sizeof( weapon_filename ),
+ "players/male/", cl.weaponModels[i], NULL );
ci->weaponmodel[i] = ref.RegisterModel( weapon_filename );
}
if( !cl_vwep->integer )
@@ -1046,8 +1045,8 @@ noskin:
}
// icon file
- Com_sprintf( ci->iconname, sizeof( ci->iconname ),
- "/players/%s/%s_i.pcx", model_name, skin_name );
+ Q_concat( ci->iconname, sizeof( ci->iconname ),
+ "/players/", model_name, "/", skin_name, "_i.pcx", NULL );
ci->icon = ref.RegisterPic( ci->iconname );
}
@@ -1261,8 +1260,8 @@ static void CL_ParsePrint( void ) {
// filter text
if( cl_chat_filter->integer ) {
- Q_ClearStr( string, string, MAX_STRING_CHARS - 1 );
- Q_strcat( string, MAX_STRING_CHARS, "\n" );
+ int len = Q_ClearStr( string, string, MAX_STRING_CHARS - 1 );
+ string[len] = '\n';
}
Com_Printf( S_COLOR_ALT "%s", string );
diff --git a/source/cl_ref.c b/source/cl_ref.c
index 56bd56b..d9e500a 100644
--- a/source/cl_ref.c
+++ b/source/cl_ref.c
@@ -258,8 +258,8 @@ static qboolean CL_LoadRefresh( const char *name ) {
Ref_APISetupCallback( API_REFRESH, &ref );
#else
- Com_sprintf( path, sizeof( path ), "%s" PATH_SEP_STRING "%s" LIBSUFFIX,
- sys_refdir->string, name );
+ Q_concat( path, sizeof( path ), sys_refdir->string, PATH_SEP_STRING,
+ name, LIBSUFFIX, NULL );
entry = Sys_LoadLibrary( path, "moduleEntry", &reflib_library );
if( !entry ) {
Com_WPrintf( "Couldn't load %s\n", name );
@@ -292,6 +292,8 @@ static qboolean CL_LoadRefresh( const char *name ) {
if( !ref.Init( qtrue ) ) {
goto fail;
}
+
+ Sys_FixFPCW();
Com_Printf( "------------------------------------\n" );
@@ -382,7 +384,7 @@ void CL_InitRefresh( void ) {
while( 1 ) {
char buffer[MAX_QPATH];
- Com_sprintf( buffer, sizeof( buffer ), "ref_%s", vid_ref->string );
+ Q_concat( buffer, sizeof( buffer ), "ref_", vid_ref->string, NULL );
if( CL_LoadRefresh( buffer ) ) {
break;
}
diff --git a/source/cl_scrn.c b/source/cl_scrn.c
index 56c0b31..206e6ea 100644
--- a/source/cl_scrn.c
+++ b/source/cl_scrn.c
@@ -112,7 +112,7 @@ void CL_AddNetgraph (void)
// see what the latency was on this packet
in = cls.netchan->incoming_acknowledged & CMD_MASK;
- ping = cls.realtime - cl.history[in].realtime;
+ ping = cls.realtime - cl.history[in].sent;
ping /= 30;
if (ping > 30)
ping = 30;
@@ -726,12 +726,12 @@ void SCR_DrawInventory( void ) {
for( i = top; i < num && i < top + DISPLAY_ITEMS; i++ ) {
item = index[i];
// search for a binding
- Com_sprintf( string, sizeof( string ), "use %s",
- cl.configstrings[CS_ITEMS + item] );
+ Q_concat( string, sizeof( string ),
+ "use ", cl.configstrings[CS_ITEMS + item], NULL );
bind = Key_GetBinding( string );
Com_sprintf( string, sizeof( string ), "%6s %3i %s",
- bind, cl.inventory[item], cl.configstrings[CS_ITEMS + item] );
+ bind, cl.inventory[item], cl.configstrings[CS_ITEMS + item] );
if( item != selected ) {
HUD_DrawAltString( x, y, string );
diff --git a/source/cl_ui.c b/source/cl_ui.c
index 6dcdb4a..c8d1601 100644
--- a/source/cl_ui.c
+++ b/source/cl_ui.c
@@ -114,8 +114,8 @@ static qboolean CL_LoadUI( const char *name ) {
Com_Printf( "------- Loading %s -------\n", name );
- Com_sprintf( path, sizeof( path ), "%s" PATH_SEP_STRING "%s" LIBSUFFIX,
- sys_refdir->string, name );
+ Q_concat( path, sizeof( path ), sys_refdir->string, PATH_SEP_STRING,
+ name, LIBSUFFIX, NULL );
if( ( entry = Sys_LoadLibrary( path, "moduleEntry", &ui_library ) ) == NULL ) {
Com_DPrintf( "Couldn't load %s\n", name );
diff --git a/source/cl_view.c b/source/cl_view.c
index 9cc0046..9ecf1e6 100644
--- a/source/cl_view.c
+++ b/source/cl_view.c
@@ -374,7 +374,7 @@ void V_Gun_Model_f (void)
gun_model = 0;
return;
}
- Com_sprintf (name, sizeof(name), "models/%s/tris.md2", Cmd_Argv(1));
+ Q_concat (name, sizeof(name), "models/", Cmd_Argv(1), "/tris.md2", NULL );
gun_model = ref.RegisterModel (name);
}
diff --git a/source/cmd.c b/source/cmd.c
index b82c02d..d04aae6 100644
--- a/source/cmd.c
+++ b/source/cmd.c
@@ -1239,7 +1239,7 @@ Cmd_Exec_f
*/
static void Cmd_Exec_f( void ) {
char buffer[MAX_QPATH];
- char *f, *ext;
+ char *f;
if( Cmd_Argc() != 2 ) {
Com_Printf( "%s <filename> : execute a script file\n", Cmd_Argv( 0 ) );
@@ -1250,13 +1250,9 @@ static void Cmd_Exec_f( void ) {
FS_LoadFile( buffer, ( void ** )&f );
if( !f ) {
- ext = COM_FileExtension( buffer );
- if( !ext[0] ) {
- // try with *.cfg extension
- COM_DefaultExtension( buffer, ".cfg", sizeof( buffer ) );
- FS_LoadFile( buffer, ( void ** )&f );
- }
-
+ // try with *.cfg extension
+ COM_AppendExtension( buffer, ".cfg", sizeof( buffer ) );
+ FS_LoadFile( buffer, ( void ** )&f );
if( !f ) {
Com_Printf( "Couldn't exec %s\n", buffer );
return;
diff --git a/source/com_local.h b/source/com_local.h
index 329d2f6..cc337f3 100644
--- a/source/com_local.h
+++ b/source/com_local.h
@@ -815,7 +815,8 @@ int FS_Read( void *buffer, int len, fileHandle_t hFile );
int FS_Write( const void *buffer, int len, fileHandle_t hFile );
// properly handles partial reads
-void FS_FPrintf( fileHandle_t f, const char *format, ... );
+void FS_FPrintf( fileHandle_t f, const char *format, ... ) q_printf( 2, 3 );
+int FS_ReadLine( fileHandle_t f, char *buffer, int size );
int FS_Tell( fileHandle_t f );
int FS_RawTell( fileHandle_t f );
@@ -959,7 +960,7 @@ extern time_t com_startTime;
extern fileHandle_t com_logFile;
-void Qcommon_Init( char *commandLine );
+void Qcommon_Init( int argc, char **argv );
void Qcommon_Frame( void );
void Qcommon_Shutdown( qboolean fatalError );
@@ -1009,6 +1010,8 @@ char *Sys_GetCurrentDirectory( void );
void Sys_DebugBreak( void );
+void Sys_FixFPCW( void );
+
#ifdef USE_ANTICHEAT
qboolean Sys_GetAntiCheatAPI( void );
#endif
diff --git a/source/common.c b/source/common.c
index f848418..82e8c45 100644
--- a/source/common.c
+++ b/source/common.c
@@ -30,6 +30,9 @@ static jmp_buf abortframe; // an ERR_DROP occured, exit the entire frame
static char com_errorMsg[MAXPRINTMSG];
+static char **com_argv;
+static int com_argc;
+
cvar_t *host_speeds;
cvar_t *developer;
cvar_t *timescale;
@@ -481,7 +484,7 @@ static void Com_WriteConfig_f( void ) {
strcpy( buffer, COM_CONFIG_NAME );
} else {
Cmd_ArgvBuffer( 1, buffer, sizeof( buffer ) );
- COM_DefaultExtension( buffer, ".cfg", sizeof( buffer ) );
+ COM_AppendExtension( buffer, ".cfg", sizeof( buffer ) );
}
if( Com_WriteConfiguration( buffer ) ) {
@@ -1280,43 +1283,6 @@ finish:
return NULL;
}
-#define MAX_LINE_COMMANDS 128
-
-static char *com_commands[MAX_LINE_COMMANDS];
-static int com_numCommands;
-
-/*
-===============
-Com_ParseCommandLine
-
-===============
-*/
-static void Com_ParseCommandLine( char *commandLine ) {
- qboolean inquote = qfalse;
-
- if( !commandLine ) {
- return;
- }
-
- com_numCommands = 0;
- while( *commandLine ) {
- if( *commandLine == '\"' ) {
- inquote ^= 1;
- } else if( *commandLine == '+' && !inquote ) {
- com_commands[com_numCommands] = commandLine + 1;
- com_numCommands++;
-
- *commandLine = 0;
-
- if( com_numCommands == MAX_LINE_COMMANDS ) {
- break;
- }
- }
-
- commandLine++;
-
- }
-}
/*
===============
@@ -1335,23 +1301,24 @@ static void Com_AddEarlyCommands( qboolean clear ) {
int i;
char *s;
- for( i = 0; i < com_numCommands; i++ ) {
- s = com_commands[i];
- if( !*s ) {
+ for( i = 1; i < com_argc; i++ ) {
+ s = com_argv[i];
+ if( !s ) {
continue;
}
- Cmd_TokenizeString( s, qfalse );
- if( strcmp( Cmd_Argv( 0 ), "set" ) ) {
+ if( strcmp( s, "+set" ) ) {
continue;
}
- if( Cmd_Argc() != 3 ) {
+ if( i + 2 >= com_argc ) {
Com_Printf( "Usage: +set <variable> <value>\n" );
- } else {
- Cvar_SetEx( Cmd_Argv( 1 ), Cmd_Argv( 2 ), CVAR_SET_COMMAND_LINE );
+ com_argc = i;
+ break;
}
+ Cvar_SetEx( com_argv[ i + 1 ], com_argv[ i + 2 ], CVAR_SET_COMMAND_LINE );
if( clear ) {
- *s = 0;
+ com_argv[i] = com_argv[ i + 1 ] = com_argv[ i + 2 ] = NULL;
}
+ i += 2;
}
}
@@ -1373,19 +1340,27 @@ static qboolean Com_AddLateCommands( void ) {
char *s;
qboolean ret = qfalse;
- for( i = 0; i < com_numCommands; i++ ) {
- s = com_commands[i];
- if( !*s ) {
+ for( i = 1; i < com_argc; i++ ) {
+ s = com_argv[i];
+ if( !s ) {
continue;
}
+ if( *s == '+' ) {
+ if( ret ) {
+ Cbuf_AddText( "\n" );
+ }
+ s++;
+ } else if( ret ) {
+ Cbuf_AddText( " " );
+ }
Cbuf_AddText( s );
- Cbuf_AddText( "\n" );
ret = qtrue;
}
- if( ret ) {
- Cbuf_Execute();
- }
+ if( ret ) {
+ Cbuf_AddText( "\n" );
+ Cbuf_Execute();
+ }
return ret;
}
@@ -1396,7 +1371,7 @@ static qboolean Com_AddLateCommands( void ) {
Qcommon_Init
=================
*/
-void Qcommon_Init( char *commandLine ) {
+void Qcommon_Init( int argc, char **argv ) {
static const char *version = APPLICATION " " VERSION " " __DATE__ " " BUILDSTRING " " CPUSTRING;
if( _setjmp( abortframe ) )
@@ -1404,7 +1379,8 @@ void Qcommon_Init( char *commandLine ) {
Com_Printf( S_COLOR_CYAN "%s\n", version );
- Com_ParseCommandLine( commandLine );
+ com_argc = argc;
+ com_argv = argv;
// prepare enough of the subsystems to handle
// cvar and command buffer management
@@ -1549,8 +1525,6 @@ void Qcommon_Init( char *commandLine ) {
);
Com_Printf( "http://q2pro.sf.net\n\n" );
- com_numCommands = 0;
-
time( &com_startTime );
com_eventTime = Sys_Realtime();
diff --git a/source/cvar.c b/source/cvar.c
index cacb847..3522f6b 100644
--- a/source/cvar.c
+++ b/source/cvar.c
@@ -973,8 +973,8 @@ int Cvar_BitInfo( char *info, int bit ) {
if( !var->string[0] ) {
continue;
}
- length = Com_sprintf( newi, sizeof( newi ), "\\%s\\%s",
- var->name, var->string );
+ length = Q_concat( newi, sizeof( newi ),
+ "\\", var->name, "\\", var->string, NULL );
if( total + length >= MAX_INFO_STRING ) {
break;
}
diff --git a/source/files.c b/source/files.c
index d215577..31e43f4 100644
--- a/source/files.c
+++ b/source/files.c
@@ -445,13 +445,13 @@ static int FS_FOpenFileWrite( fsFile_t *file, const char *name ) {
#ifdef _WIN32
// allow writing into basedir on Windows
if( ( file->mode & FS_PATH_MASK ) == FS_PATH_BASE ) {
- Com_sprintf( file->fullpath, sizeof( file->fullpath ),
- "%s/" BASEGAME "/%s", sys_basedir->string, name );
+ Q_concat( file->fullpath, sizeof( file->fullpath ),
+ sys_basedir->string, "/" BASEGAME "/", name, NULL );
} else
#endif
{
- Com_sprintf( file->fullpath, sizeof( file->fullpath ),
- "%s/%s", fs_gamedir, name );
+ Q_concat( file->fullpath, sizeof( file->fullpath ),
+ fs_gamedir, "/", name, NULL );
}
mode = file->mode & FS_MODE_MASK;
@@ -581,7 +581,7 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique )
// found it!
fs_fileFromPak = qtrue;
- Com_sprintf( file->fullpath, sizeof( file->fullpath ), "%s/%s", pak->filename, entry->name );
+ Q_concat( file->fullpath, sizeof( file->fullpath ), pak->filename, "/", entry->name, NULL );
// open a new file on the pakfile
#if USE_ZLIB
@@ -636,8 +636,8 @@ static int FS_FOpenFileRead( fsFile_t *file, const char *name, qboolean unique )
continue;
}
// check a file in the directory tree
- Com_sprintf( file->fullpath, sizeof( file->fullpath ), "%s/%s",
- search->filename, name );
+ Q_concat( file->fullpath, sizeof( file->fullpath ),
+ search->filename, "/", name, NULL );
FS_ConvertToSysPath( file->fullpath );
@@ -744,6 +744,27 @@ int FS_Read( void *buffer, int len, fileHandle_t hFile ) {
return len;
}
+int FS_ReadLine( fileHandle_t f, char *buffer, int size ) {
+ fsFile_t *file = FS_FileForHandle( f );
+ char *s;
+ int len;
+
+ if( file->type != FS_REAL ) {
+ return 0;
+ }
+ do {
+ s = fgets( buffer, size, file->fp );
+ if( !s ) {
+ return 0;
+ }
+ len = strlen( s );
+ } while( len < 2 );
+
+ s[ len - 1 ] = 0;
+ return len - 1;
+}
+
+
/*
=================
FS_Write
@@ -1147,7 +1168,7 @@ qboolean FS_RemoveFile( const char *filename ) {
return qfalse;
}
- Com_sprintf( path, sizeof( path ), "%s/%s", fs_gamedir, filename );
+ Q_concat( path, sizeof( path ), fs_gamedir, "/", filename, NULL );
FS_ConvertToSysPath( path );
if( !Sys_RemoveFile( path ) ) {
@@ -1171,8 +1192,8 @@ qboolean FS_RenameFile( const char *from, const char *to ) {
return qfalse;
}
- Com_sprintf( frompath, sizeof( frompath ), "%s/%s", fs_gamedir, from );
- Com_sprintf( topath, sizeof( topath ), "%s/%s", fs_gamedir, to );
+ Q_concat( frompath, sizeof( frompath ), fs_gamedir, "/", from, NULL );
+ Q_concat( topath, sizeof( topath ), fs_gamedir, "/", to, NULL );
FS_ConvertToSysPath( frompath );
FS_ConvertToSysPath( topath );
@@ -1467,7 +1488,7 @@ static void FS_LoadPackFiles( const char *extension, pack_t *(loadfunc)( const c
}
qsort( list, numFiles, sizeof( list[0] ), pakcmp );
for( i = 0; i < numFiles; i++ ) {
- Com_sprintf( path, sizeof( path ), "%s/%s", fs_gamedir, list[i] );
+ Q_concat( path, sizeof( path ), fs_gamedir, "/", list[i], NULL );
pak = (*loadfunc)( path );
if( !pak )
continue;
@@ -1839,11 +1860,11 @@ char **FS_ListFiles( const char *path, const char *extension,
continue;
}
- Q_strncpyz( buffer, search->filename, sizeof( buffer ) );
if( *path ) {
- Q_strcat( buffer, sizeof( buffer ), "/" );
- Q_strcat( buffer, sizeof( buffer ), path );
- }
+ Q_concat( buffer, sizeof( buffer ), search->filename, "/", path, NULL );
+ } else {
+ Q_strncpyz( buffer, search->filename, sizeof( buffer ) );
+ }
if( flags & FS_SEARCH_BYFILTER ) {
dirlist = Sys_ListFiles( buffer, extension, flags|FS_SEARCH_NOSORT, &numFilesInDir );
@@ -2066,8 +2087,8 @@ static void FS_WhereIs_f( void ) {
}
}
} else {
- Com_sprintf( fullpath, sizeof( fullpath ), "%s/%s",
- search->filename, path );
+ Q_concat( fullpath, sizeof( fullpath ),
+ search->filename, "/", path, NULL );
FS_ConvertToSysPath( fullpath );
if( Sys_GetFileInfo( fullpath, &info ) ) {
Com_Printf( "%s/%s (%d bytes)\n", search->filename, filename,
@@ -2416,8 +2437,8 @@ static void FS_DefaultGamedir( void ) {
FS_AddGameDirectory( "%s/"BASEGAME, sys_homedir->string );
} else {
// already added as basedir
- Com_sprintf( fs_gamedir, sizeof( fs_gamedir ), "%s/"BASEGAME,
- sys_basedir->string );
+ Q_concat( fs_gamedir, sizeof( fs_gamedir ),
+ sys_basedir->string, "/" BASEGAME, NULL );
}
#if( _MSC_VER >= 1400 )
diff --git a/source/gl_draw.c b/source/gl_draw.c
index bf24608..2df1b55 100644
--- a/source/gl_draw.c
+++ b/source/gl_draw.c
@@ -119,7 +119,7 @@ qhandle_t GL_RegisterFont( const char *name ) {
char fullname[MAX_QPATH];
if( name[0] != '/' && name[0] != '\\' ) {
- Com_sprintf( fullname, sizeof( fullname ), "pics/%s", name );
+ Q_concat( fullname, sizeof( fullname ), "pics/", name, NULL );
COM_DefaultExtension( fullname, ".pcx", sizeof( fullname ) );
image = R_FindImage( fullname, it_charset );
} else {
diff --git a/source/gl_images.c b/source/gl_images.c
index 16de017..3f6a7f0 100644
--- a/source/gl_images.c
+++ b/source/gl_images.c
@@ -714,7 +714,7 @@ qhandle_t R_RegisterPic( const char *name ) {
if( name[0] == '*' ) {
image = R_FindImage( name, it_pic );
} else if( name[0] != '/' && name[0] != '\\' ) {
- Com_sprintf( fullname, sizeof( fullname ), "pics/%s", name );
+ Q_concat( fullname, sizeof( fullname ), "pics/", name, NULL );
COM_DefaultExtension( fullname, ".pcx", sizeof( fullname ) );
image = R_FindImage( fullname, it_pic );
} else {
diff --git a/source/gl_main.c b/source/gl_main.c
index 2475ded..38080cb 100644
--- a/source/gl_main.c
+++ b/source/gl_main.c
@@ -998,7 +998,7 @@ void GL_BeginRegistration( const char *name ) {
memset( &glr, 0, sizeof( glr ) );
glr.viewcluster1 = glr.viewcluster2 = -2;
- Com_sprintf( fullname, sizeof( fullname ), "maps/%s.bsp", name );
+ Q_concat( fullname, sizeof( fullname ), "maps/", name, ".bsp", NULL );
// check if the required world model was already loaded
if( !strcmp( r_world.name, fullname ) &&
diff --git a/source/gl_sky.c b/source/gl_sky.c
index bbc7afd..cfecbe2 100644
--- a/source/gl_sky.c
+++ b/source/gl_sky.c
@@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "gl_local.h"
-static char skyname[MAX_QPATH];
static float skyrotate;
static vec3_t skyaxis;
static image_t *sky_images[6];
@@ -370,16 +369,15 @@ void R_SetSky( const char *name, float rotate, vec3_t axis ) {
int i;
char pathname[MAX_QPATH];
// 3dstudio environment map names
- static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
+ static const char suf[6][3] = { "rt", "bk", "lf", "ft", "up", "dn" };
- Q_strncpyz( skyname, name, sizeof( skyname ) );
skyrotate = rotate;
VectorCopy (axis, skyaxis);
for (i=0 ; i<6 ; i++)
{
- Com_sprintf (pathname, sizeof(pathname), "env/%s%s.tga",
- skyname, suf[i]);
+ Q_concat( pathname, sizeof( pathname ),
+ "env/", name, suf[i], ".tga", NULL );
sky_images[i] = R_FindImage (pathname, it_sky);
if (!sky_images[i])
diff --git a/source/mvd_client.c b/source/mvd_client.c
index f527c93..721444e 100644
--- a/source/mvd_client.c
+++ b/source/mvd_client.c
@@ -796,7 +796,7 @@ void MVD_StreamedRecord_f( void ) {
if( name[0] == '/' ) {
Q_strncpyz( buffer, name + 1, sizeof( buffer ) );
} else {
- Com_sprintf( buffer, sizeof( buffer ), "demos/%s", name );
+ Q_concat( buffer, sizeof( buffer ), "demos/", name, NULL );
COM_AppendExtension( buffer, ".mvd2", sizeof( buffer ) );
}
@@ -863,8 +863,8 @@ void MVD_Connect_f( void ) {
strcpy( resource, p + 1 );
port = BigShort( 80 );
} else {
- Com_sprintf( resource, sizeof( resource ),
- "mvdstream/%s", Cmd_Argv( 2 ) );
+ Q_concat( resource, sizeof( resource ),
+ "mvdstream/", Cmd_Argv( 2 ), NULL );
port = BigShort( PORT_SERVER );
}
if( !NET_StringToAdr( host, &adr ) ) {
@@ -978,7 +978,7 @@ void MVD_Play_f( void ) {
if( name[0] == '/' ) {
Q_strncpyz( buffer, name + 1, sizeof( buffer ) );
} else {
- Com_sprintf( buffer, sizeof( buffer ), "demos/%s", name );
+ Q_concat( buffer, sizeof( buffer ), "demos/", name, NULL );
COM_AppendExtension( buffer, ".mvd2", sizeof( buffer ) );
}
FS_FOpenFile( buffer, &f, FS_MODE_READ );
diff --git a/source/net_common.c b/source/net_common.c
index 7465d67..96f57c6 100644
--- a/source/net_common.c
+++ b/source/net_common.c
@@ -294,7 +294,7 @@ static void NET_LogPacket( const netadr_t *address, const char *prefix,
FS_FPrintf( net_logFile, " " );
}
}
- FS_FPrintf( net_logFile, ": ", i );
+ FS_FPrintf( net_logFile, ": " );
for( j = 0; j < 16; j++ ) {
if( i * 16 + j < length ) {
c = data[i * 16 + j];
diff --git a/source/prompt.c b/source/prompt.c
index 2a7a6f3..db60110 100644
--- a/source/prompt.c
+++ b/source/prompt.c
@@ -127,13 +127,13 @@ static void Prompt_ShowMatches( commandPrompt_t *prompt, char **matches,
break;
}
match = matches[k];
- prompt->Printf( "%s", match );
+ prompt->printf( "%s", match );
len = colwidths[j] - strlen( match );
for( k = 0; k < len + 2; k++ ) {
- prompt->Printf( " " );
+ prompt->printf( " " );
}
}
- prompt->Printf( "\n" );
+ prompt->printf( "\n" );
}
}
@@ -145,7 +145,7 @@ static void Prompt_ShowIndividualMatches( commandPrompt_t *prompt ) {
qsort( matches + offset, numCommands,
sizeof( matches[0] ), SortStrcmp );
- prompt->Printf( "\n" S_COLOR_YELLOW "%i possible command%s:\n",
+ prompt->printf( "\n" S_COLOR_YELLOW "%i possible command%s:\n",
numCommands, ( numCommands % 10 ) != 1 ? "s" : "" );
Prompt_ShowMatches( prompt, matches, offset, offset + numCommands );
@@ -156,7 +156,7 @@ static void Prompt_ShowIndividualMatches( commandPrompt_t *prompt ) {
qsort( matches + offset, numCvars,
sizeof( matches[0] ), SortStrcmp );
- prompt->Printf( "\n" S_COLOR_YELLOW "%i possible variable%s:\n",
+ prompt->printf( "\n" S_COLOR_YELLOW "%i possible variable%s:\n",
numCvars, ( numCvars % 10 ) != 1 ? "s" : "" );
Prompt_ShowMatches( prompt, matches, offset, offset + numCvars );
@@ -167,7 +167,7 @@ static void Prompt_ShowIndividualMatches( commandPrompt_t *prompt ) {
qsort( matches + offset, numAliases,
sizeof( matches[0] ), SortStrcmp );
- prompt->Printf( "\n" S_COLOR_YELLOW "%i possible alias%s:\n",
+ prompt->printf( "\n" S_COLOR_YELLOW "%i possible alias%s:\n",
numAliases, ( numAliases % 10 ) != 1 ? "es" : "" );
Prompt_ShowMatches( prompt, matches, offset, offset + numAliases );
@@ -192,8 +192,7 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
pos = inputLine->cursorPos;
if( backslash ) {
if( inputLine->text[0] != '\\' && inputLine->text[0] != '/' ) {
- memmove( inputLine->text + 1, inputLine->text,
- sizeof( inputLine->text ) - 1 );
+ memmove( inputLine->text + 1, inputLine->text, size - 1 );
inputLine->text[0] = '\\';
}
text++; size--; pos--;
@@ -250,34 +249,20 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
if( numMatches == 1 ) {
/* we have finished completion! */
- s = matches[0];
- while( *s ) {
- if( *s <= 32 ) {
- break;
- }
- s++;
- }
- *text = 0;
- if( *s ) {
- Q_strcat( inputLine->text, sizeof( inputLine->text ), "\"" );
+ s = Cmd_RawArgsFrom( currentArg + 1 );
+ if( COM_HasSpaces( matches[0] ) ) {
+ pos += Q_concat( text, size, "\"", matches[0], "\" ", s, NULL );
+ } else {
+ pos += Q_concat( text, size, matches[0], " ", s, NULL );
}
- Q_strcat( inputLine->text, sizeof( inputLine->text ), matches[0] );
- if( *s ) {
- Q_strcat( inputLine->text, sizeof( inputLine->text ), "\"" );
- }
- Q_strcat( inputLine->text, sizeof( inputLine->text ), " " );
- Q_strcat( inputLine->text, sizeof( inputLine->text ),
- Cmd_RawArgsFrom( currentArg + 1 ) );
- inputLine->cursorPos = strlen( inputLine->text );
- inputLine->selectStart = inputLine->cursorPos;
- inputLine->selectEnd = inputLine->cursorPos;
+ inputLine->cursorPos = pos;
prompt->tooMany = qfalse;
Prompt_FreeMatches();
return;
}
if( numMatches > com_completion_treshold->integer && !prompt->tooMany ) {
- prompt->Printf( "Press TAB again to display all %d possibilities.\n",
+ prompt->printf( "Press TAB again to display all %d possibilities.\n",
numMatches );
inputLine->cursorPos = strlen( inputLine->text );
prompt->tooMany = qtrue;
@@ -311,18 +296,17 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
} while( *first );
text[length] = 0;
-
- inputLine->cursorPos = strlen( inputLine->text );
- inputLine->selectStart = inputLine->cursorPos;
- inputLine->selectEnd = inputLine->cursorPos;
+ pos += length;
+ size -= length;
if( currentArg + 1 < argc ) {
- Q_strcat( inputLine->text, sizeof( inputLine->text ), " " );
- Q_strcat( inputLine->text, sizeof( inputLine->text ),
- Cmd_RawArgsFrom( currentArg + 1 ) );
+ s = Cmd_RawArgsFrom( currentArg + 1 );
+ pos += Q_concat( text + length, size, " ", s, NULL );
}
- prompt->Printf( "]\\%s\n", Cmd_ArgsFrom( 0 ) );
+ inputLine->cursorPos = pos;
+
+ prompt->printf( "]\\%s\n", Cmd_ArgsFrom( 0 ) );
if( generator ) {
goto multicolumn;
}
@@ -331,7 +315,7 @@ void Prompt_CompleteCommand( commandPrompt_t *prompt, qboolean backslash ) {
case 0:
/* print in solid list */
for( i = 0 ; i < numMatches; i++ ) {
- prompt->Printf( "%s\n", sortedMatches[i] );
+ prompt->printf( "%s\n", sortedMatches[i] );
}
break;
case 1:
@@ -453,6 +437,56 @@ void Prompt_Clear( commandPrompt_t *prompt ) {
IF_Clear( &prompt->inputLine );
}
+void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename ) {
+ fileHandle_t f;
+ char *s;
+ int i;
+
+ FS_FOpenFile( filename, &f, FS_MODE_WRITE );
+ if( !f ) {
+ return;
+ }
+
+ i = prompt->inputLineNum - HISTORY_SIZE;
+ if( i < 0 ) {
+ i = 0;
+ }
+ for( ; i < prompt->inputLineNum; i++ ) {
+ s = prompt->history[i & HISTORY_MASK];
+ if( s ) {
+ FS_FPrintf( f, "%s\n", s );
+ }
+ }
+
+ FS_FCloseFile( f );
+}
+
+void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename ) {
+ char buffer[MAX_FIELD_TEXT];
+ fileHandle_t f;
+ int i, len;
+
+ FS_FOpenFile( filename, &f, FS_MODE_READ|FS_TYPE_REAL );
+ if( !f ) {
+ return;
+ }
+
+ for( i = 0; i < HISTORY_SIZE; i++ ) {
+ if( ( len = FS_ReadLine( f, buffer, sizeof( buffer ) ) ) < 1 ) {
+ break;
+ }
+ if( prompt->history[i] ) {
+ Z_Free( prompt->history[i] );
+ }
+ prompt->history[i] = memcpy( Z_Malloc( len + 1 ), buffer, len );
+ }
+
+ FS_FCloseFile( f );
+
+ prompt->historyLineNum = i;
+ prompt->inputLineNum = i;
+}
+
/*
====================
Prompt_Init
diff --git a/source/prompt.h b/source/prompt.h
index beca25f..886a52a 100644
--- a/source/prompt.h
+++ b/source/prompt.h
@@ -38,7 +38,7 @@ typedef struct commandPrompt_s {
int widthInChars;
qboolean tooMany;
- void (*Printf)( const char *fmt, ... );
+ void (* q_printf( 1, 2 ) printf)( const char *fmt, ... );
} commandPrompt_t;
@@ -48,3 +48,5 @@ char *Prompt_Action( commandPrompt_t *prompt );
void Prompt_HistoryUp( commandPrompt_t *prompt );
void Prompt_HistoryDown( commandPrompt_t *prompt );
void Prompt_Clear( commandPrompt_t *prompt );
+void Prompt_SaveHistory( commandPrompt_t *prompt, const char *filename );
+void Prompt_LoadHistory( commandPrompt_t *prompt, const char *filename );
diff --git a/source/q_field.c b/source/q_field.c
index 495896f..468799f 100644
--- a/source/q_field.c
+++ b/source/q_field.c
@@ -72,8 +72,6 @@ IF_Clear
void IF_Clear( inputField_t *field ) {
memset( field->text, 0, sizeof( field->text ) );
field->cursorPos = 0;
- field->selectStart = 0;
- field->selectEnd = 0;
}
/*
@@ -84,8 +82,6 @@ IF_Replace
void IF_Replace( inputField_t *field, const char *text ) {
Q_strncpyz( field->text, text, sizeof( field->text ) );
field->cursorPos = strlen( field->text );
- field->selectStart = 0;
- field->selectEnd = 0;
}
#ifndef DEDICATED_ONLY
@@ -93,29 +89,11 @@ void IF_Replace( inputField_t *field, const char *text ) {
/*
================
-IF_DeleteSelection
-================
-*/
-void IF_DeleteSelection( inputField_t *field ) {
- if( field->selectStart < field->selectEnd ) {
- memmove( field->text + field->selectStart,
- field->text + field->selectEnd,
- sizeof( field->text ) - field->selectStart );
- field->selectEnd = field->selectStart;
- }
-}
-
-/*
-================
IF_KeyEvent
================
*/
qboolean IF_KeyEvent( inputField_t *field, int key ) {
if( key == K_DEL ) {
- if( field->selectStart < field->selectEnd ) {
- IF_DeleteSelection( field );
- return qtrue;
- }
if( field->text[field->cursorPos] ) {
memmove( field->text + field->cursorPos,
field->text + field->cursorPos + 1,
@@ -125,10 +103,6 @@ qboolean IF_KeyEvent( inputField_t *field, int key ) {
}
if( key == K_BACKSPACE || ( key == 'h' && keys.IsDown( K_CTRL ) ) ) {
- if( field->selectStart < field->selectEnd ) {
- IF_DeleteSelection( field );
- return qtrue;
- }
if( field->cursorPos > 0 ) {
memmove( field->text + field->cursorPos - 1,
field->text + field->cursorPos,
@@ -250,14 +224,6 @@ qboolean IF_CharEvent( inputField_t *field, int key ) {
return qtrue;
}
- if( field->selectStart < field->selectEnd ) {
- IF_DeleteSelection( field );
- field->cursorPos = field->selectStart;
- field->text[field->cursorPos] = key;
- return qtrue;
-
- }
-
if( keys.GetOverstrikeMode() ) {
// replace the character at cursor and advance
field->text[field->cursorPos] = key;
@@ -266,9 +232,8 @@ qboolean IF_CharEvent( inputField_t *field, int key ) {
}
// insert new character at cursor position
- memmove( field->text + field->cursorPos + 1,
- field->text + field->cursorPos,
- sizeof( field->text ) - field->cursorPos - 1 );
+ memmove( field->text + field->cursorPos + 1, field->text + field->cursorPos,
+ sizeof( field->text ) - field->cursorPos - 1 );
field->text[field->cursorPos] = key;
field->cursorPos++;
@@ -286,9 +251,7 @@ Returns x offset of the rightmost character drawn.
int IF_Draw( inputField_t *field, int x, int y, uint32 flags, qhandle_t hFont ) {
char *text;
int cursorPos, offset, ret;
- int start, width;
int cw, ch;
- color_t selectColor;
if( field->cursorPos > sizeof( field->text ) - 1 ) {
Com_Error( ERR_FATAL, "IF_Draw: bad field->cursorPos" );
@@ -313,19 +276,6 @@ int IF_Draw( inputField_t *field, int x, int y, uint32 flags, qhandle_t hFont )
ref.DrawGetFontSize( &cw, &ch, hFont );
- /* draw selection background */
- if( field->selectStart < field->selectEnd ) {
- start = field->selectStart - offset;
- width = field->selectEnd - field->selectStart;
-
- if( width > ( field->visibleChars - 1 ) - start ) {
- width = ( field->visibleChars - 1 ) - start;
- }
-
- Vector4Set( selectColor, 156, 90, 84, 255 );
- ref.DrawFillEx( x + start * cw, y, width * cw, ch, selectColor );
- }
-
/* draw text */
ret = ref.DrawString( x, y, flags, field->visibleChars,
text + offset, hFont );
diff --git a/source/q_field.h b/source/q_field.h
index 85d0689..c6f3fb0 100644
--- a/source/q_field.h
+++ b/source/q_field.h
@@ -34,7 +34,6 @@ typedef struct inputField_s {
int maxChars;
int visibleChars;
int cursorPos;
- int selectStart, selectEnd;
} inputField_t;
qboolean IF_KeyEvent( inputField_t *field, int key );
diff --git a/source/q_shared.c b/source/q_shared.c
index 6b4a61b..150c95e 100644
--- a/source/q_shared.c
+++ b/source/q_shared.c
@@ -873,6 +873,16 @@ qboolean COM_IsNumeric( const char *string ) {
}
+qboolean COM_HasSpaces( const char *string ) {
+ while( *string ) {
+ if( *string <= 32 ) {
+ return qtrue;
+ }
+ string++;
+ }
+ return qfalse;
+}
+
/* Parses hexadecimal number until it encounters
* illegible symbol or end of string.
* Does not check for overflow.
@@ -1858,6 +1868,32 @@ int Q_strcat( char *dest, int destsize, const char *src ) {
/*
===============
+Q_concat
+===============
+*/
+int Q_concat( char *buffer, int size, ... ) {
+ va_list argptr;
+ const char *s;
+ int len, total = 0;
+
+ va_start( argptr, size );
+ while( ( s = va_arg( argptr, const char * ) ) != NULL ) {
+ len = strlen( s );
+ if( total + len >= size ) {
+ break;
+ }
+ memcpy( buffer + total, s, len );
+ total += len;
+ }
+ va_end( argptr );
+
+ buffer[total] = 0;
+ return total;
+}
+
+
+/*
+===============
Q_vsnprintf
Safe implementation of vsnprintf supposed to
diff --git a/source/q_shared.h b/source/q_shared.h
index f2066ba..3edc5af 100644
--- a/source/q_shared.h
+++ b/source/q_shared.h
@@ -30,9 +30,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef __GNUC__
-#define q_printf( f, a ) __attribute__(( format( printf, f, a ) ))
-#define q_noreturn __attribute__(( noreturn ))
-#define q_malloc __attribute__(( malloc ))
+#define q_printf( f, a ) __attribute__((format( printf, f, a )))
+#define q_noreturn __attribute__((noreturn))
+#define q_malloc __attribute__((malloc))
+#define q_sentinel __attribute__((sentinel))
#define q_likely( x ) __builtin_expect( !!(x), 1 )
#define q_unlikely( x ) __builtin_expect( !!(x), 0 )
@@ -47,6 +48,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define q_printf( f, a )
#define q_noreturn
#define q_malloc
+#define q_sentinel
#define q_likely( x ) !!(x)
#define q_unlikely( x ) !!(x)
@@ -447,6 +449,7 @@ void COM_AppendExtension( char *path, const char *extension, int pathSize );
char *COM_FileExtension( const char *in );
qboolean COM_IsNumeric( const char *string );
+qboolean COM_HasSpaces( const char *string );
char *COM_SimpleParse( const char **data_p );
char *COM_Parse( const char **data_p );
@@ -464,6 +467,7 @@ char *Com_ReplaceSeparators( char *s, int separator );
// buffer safe operations
int Q_strncpyz( char *dest, const char *src, int destsize );
int Q_strcat( char *dest, int destsize, const char *src );
+int Q_concat( char *buffer, int size, ... ) q_sentinel;
int Com_sprintf( char *dest, int destsize, const char *fmt, ... ) q_printf( 3, 4 );
int Q_vsnprintf( char *dest, int destsize, const char *fmt, va_list argptr );
diff --git a/source/r_bsp.c b/source/r_bsp.c
index 2c0dd3f..b3090db 100644
--- a/source/r_bsp.c
+++ b/source/r_bsp.c
@@ -240,7 +240,7 @@ static void Bsp_LoadTexinfo( lump_t *lump ) {
dst->animNext = NULL;
}
- Com_sprintf( path, sizeof( path ), "textures/%s.wal", dst->name );
+ Q_concat( path, sizeof( path ), "textures/", dst->name, ".wal", NULL );
texture = R_FindImage( path, it_wall );
if( texture ) {
dst->image = texture;
diff --git a/source/snd_main.c b/source/snd_main.c
index 4418b46..6fe6f5a 100644
--- a/source/snd_main.c
+++ b/source/snd_main.c
@@ -148,7 +148,7 @@ static void S_Play_f( void ) {
char name[MAX_QPATH];
if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <sound1> [sound2] ...\n", Cmd_Argv( 0 ) );
+ Com_Printf( "Usage: %s <sound> [...]\n", Cmd_Argv( 0 ) );
return;
}
@@ -716,15 +716,15 @@ static sfx_t *S_RegisterSexedSound( entity_state_t *ent, const char *base ) {
strcpy( model, "male" );
// see if we already know of the model specific sound
- Com_sprintf( buffer, sizeof( buffer ),
- "#players/%s/%s", model, base + 1 );
+ Q_concat( buffer, sizeof( buffer ),
+ "#players/", model, "/", base + 1, NULL );
sfx = S_FindName( buffer );
// see if it exists
if( !S_LoadSound( sfx ) ) {
// no, revert to the male sound in the pak0.pak
- Com_sprintf( buffer, sizeof( buffer ),
- "player/male/%s", base + 1 );
+ Q_concat( buffer, sizeof( buffer ),
+ "player/male/", base + 1, NULL );
sfx->truename = Z_TagCopyString( buffer, TAG_SOUND );
}
diff --git a/source/snd_mem.c b/source/snd_mem.c
index 3d90d39..c51d8f9 100644
--- a/source/snd_mem.c
+++ b/source/snd_mem.c
@@ -436,7 +436,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
if (name[0] == '#')
Q_strncpyz( namebuffer, name + 1, sizeof( namebuffer ) );
else
- Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name);
+ Q_concat( namebuffer, sizeof( namebuffer ), "sound/", name, NULL );
size = FS_LoadFile (namebuffer, (void **)&data);
diff --git a/source/sv_game.c b/source/sv_game.c
index f25fb7c..17de8bd 100644
--- a/source/sv_game.c
+++ b/source/sv_game.c
@@ -830,28 +830,28 @@ void SV_InitGameProgs ( void )
#ifdef _WIN32
// FIXME: check current debug directory first for
// e.g. running legacy stuff like Q2Admin
- Com_sprintf( path, sizeof( path ), "%s" PATH_SEP_STRING "release"
- PATH_SEP_STRING GAMELIB, Sys_GetCurrentDirectory() );
+ Q_concat( path, sizeof( path ), Sys_GetCurrentDirectory(),
+ PATH_SEP_STRING "release" PATH_SEP_STRING GAMELIB, NULL );
entry = Sys_LoadLibrary( path, "GetGameAPI", &game_library );
if( !entry )
#endif
{
// try refdir first for development purposes
- Com_sprintf( path, sizeof( path ), "%s" PATH_SEP_STRING GAMELIB,
- sys_refdir->string );
+ Q_concat( path, sizeof( path ), sys_refdir->string,
+ PATH_SEP_STRING GAMELIB, NULL );
entry = Sys_LoadLibrary( path, "GetGameAPI", &game_library );
if( !entry ) {
// try gamedir
if( fs_game->string[0] ) {
- Com_sprintf( path, sizeof( path ), "%s" PATH_SEP_STRING "%s"
- PATH_SEP_STRING GAMELIB, sys_libdir->string, fs_game->string );
+ Q_concat( path, sizeof( path ), sys_libdir->string,
+ PATH_SEP_STRING, fs_game->string, PATH_SEP_STRING GAMELIB, NULL );
entry = Sys_LoadLibrary( path, "GetGameAPI", &game_library );
}
if( !entry ) {
// try baseq2
- Com_sprintf( path, sizeof( path ), "%s" PATH_SEP_STRING BASEGAME
- PATH_SEP_STRING GAMELIB, sys_libdir->string );
+ Q_concat( path, sizeof( path ), sys_libdir->string,
+ PATH_SEP_STRING BASEGAME PATH_SEP_STRING GAMELIB, NULL );
entry = Sys_LoadLibrary( path, "GetGameAPI", &game_library );
if( !entry ) {
Com_Error( ERR_DROP, "Failed to load game DLL" );
@@ -945,5 +945,7 @@ void SV_InitGameProgs ( void )
// initialize
ge->Init ();
+
+ Sys_FixFPCW();
}
diff --git a/source/sv_init.c b/source/sv_init.c
index 142d593..5d9fe4e 100644
--- a/source/sv_init.c
+++ b/source/sv_init.c
@@ -96,7 +96,7 @@ void SV_SpawnServer( const char *server, const char *spawnpoint ) {
SV_ClientReset( client );
}
- Com_sprintf( string, sizeof( string ), "maps/%s.bsp", server );
+ Q_concat( string, sizeof( string ), "maps/", server, ".bsp", NULL );
strcpy( sv.configstrings[CS_MODELS + 1], string );
CM_LoadMap( &sv.cm, string, 0, &checksum );
@@ -342,7 +342,7 @@ void SV_Map (const char *levelstring, qboolean restart) {
spawnpoint[0] = 0;
}
- Com_sprintf( expanded, sizeof( expanded ), "maps/%s.bsp", level );
+ Q_concat( expanded, sizeof( expanded ), "maps/", level, ".bsp", NULL );
if( FS_LoadFile( expanded, NULL ) == -1 ) {
Com_Printf( "Can't find %s\n", expanded );
return;
diff --git a/source/sv_mvd.c b/source/sv_mvd.c
index 1e38f6c..4d62ec6 100644
--- a/source/sv_mvd.c
+++ b/source/sv_mvd.c
@@ -821,7 +821,7 @@ static void MVD_Record_f( void ) {
if( name[0] == '/' ) {
Q_strncpyz( buffer, name + 1, sizeof( buffer ) );
} else {
- Com_sprintf( buffer, sizeof( buffer ), "demos/%s", name );
+ Q_concat( buffer, sizeof( buffer ), "demos/", name, NULL );
COM_AppendExtension( buffer, ".mvd2", sizeof( buffer ) );
}
diff --git a/source/sw_image.c b/source/sw_image.c
index 0368d2b..e9fc91c 100644
--- a/source/sw_image.c
+++ b/source/sw_image.c
@@ -259,7 +259,7 @@ qhandle_t R_RegisterPic( const char *name ) {
char fullname[MAX_QPATH];
if( name[0] != '/' && name[0] != '\\' ) {
- Com_sprintf( fullname, sizeof( fullname ), "pics/%s", name );
+ Q_concat( fullname, sizeof( fullname ), "pics/", name, NULL );
COM_DefaultExtension( fullname, ".pcx", sizeof( fullname ) );
image = R_FindImage( fullname, it_pic );
} else {
diff --git a/source/sw_main.c b/source/sw_main.c
index 5c27d1d..501134d 100644
--- a/source/sw_main.c
+++ b/source/sw_main.c
@@ -1227,8 +1227,8 @@ extern mtexinfo_t r_skytexinfo[6];
void R_SetSky( const char *name, float rotate, vec3_t axis ) {
// 3dstudio environment map names
- static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
- static int r_skysideimage[6] = {5, 2, 4, 1, 0, 3};
+ static const char suf[6][3] = {"rt", "bk", "lf", "ft", "up", "dn"};
+ static const int r_skysideimage[6] = {5, 2, 4, 1, 0, 3};
int i;
char pathname[MAX_QPATH];
@@ -1238,8 +1238,8 @@ void R_SetSky( const char *name, float rotate, vec3_t axis ) {
for (i=0 ; i<6 ; i++)
{
- Com_sprintf (pathname, sizeof(pathname), "env/%s%s.pcx", skyname,
- suf[r_skysideimage[i]]);
+ Q_concat( pathname, sizeof( pathname ),
+ "env/", skyname, suf[r_skysideimage[i]], ".pcx", NULL );
r_skytexinfo[i].image = R_FindImage (pathname, it_sky);
}
}
diff --git a/source/sw_model.c b/source/sw_model.c
index 15664a4..fd60715 100644
--- a/source/sw_model.c
+++ b/source/sw_model.c
@@ -508,7 +508,7 @@ void Mod_LoadTexinfo (lump_t *l)
if (next > 0)
out->next = loadmodel->texinfo + next;
- Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture);
+ Q_concat( name, sizeof( name ), "textures/", in->texture, ".wal", NULL );
out->image = R_FindImage (name, it_wall);
if (!out->image)
{
@@ -1121,7 +1121,7 @@ void R_BeginRegistration( const char *model ) {
registration_sequence++;
r_oldviewcluster = -1; // force markleafs
- Com_sprintf (fullname, sizeof(fullname), "maps/%s.bsp", model);
+ Q_concat( fullname, sizeof( fullname ), "maps/", model, ".bsp", NULL );
D_FlushCaches ();
// explicitly free the old map if different
diff --git a/source/sys_unix.c b/source/sys_unix.c
index 7b471f0..c9e500b 100644
--- a/source/sys_unix.c
+++ b/source/sys_unix.c
@@ -131,7 +131,7 @@ static void Sys_InitTTY( void ) {
tty_erase = tty.c_cc[VERASE];
tcsetattr( 0, TCSADRAIN, &tty );
tty_prompt.widthInChars = 80;
- tty_prompt.Printf = Sys_Printf;
+ tty_prompt.printf = Sys_Printf;
tty_enabled = qtrue;
}
@@ -658,6 +658,27 @@ void Sys_FillAPI( sysAPI_t *api ) {
api->HunkFree = Hunk_Free;
}
+void Sys_FixFPCW( void ) {
+#ifdef __i386__
+ unsigned int cw;
+
+ __asm__ __volatile__( "fnstcw %0" : "=m" (cw) );
+
+ Com_DPrintf( "FPU control word: %x\n", cw );
+
+ if( cw & 0x300 ) {
+ Com_Printf( "Setting FPU to single precision mode\n" );
+ cw &= ~0x300;
+ }
+ if( cw & 0xC00 ) {
+ Com_Printf( "Setting FPU to round to nearest mode\n" );
+ cw &= ~0xC00;
+ }
+
+ __asm__ __volatile__( "fldcw %0" : : "m" (cw) );
+#endif
+}
+
/*
=================
Sys_Kill
@@ -718,7 +739,7 @@ void Sys_Init( void ) {
// specifies per-user writable directory for demos, screenshots, etc
s = getenv( "HOME" );
if( s && *s ) {
- Com_sprintf( homedir, sizeof( homedir ), "%s/"HOMEDIR, s );
+ Q_concat( homedir, sizeof( homedir ), s, "/" HOMEDIR, NULL );
} else {
homedir[0] = 0;
}
@@ -745,6 +766,8 @@ void Sys_Init( void ) {
}
}
+ Sys_FixFPCW();
+
Sys_FillAPI( &sys );
}
@@ -905,8 +928,8 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count,
if( !strcmp( findInfo->d_name, ".." ) ) {
continue;
}
- Com_sprintf( findPath, sizeof( findPath ), "%s/%s",
- path, findInfo->d_name );
+ Q_concat( findPath, sizeof( findPath ),
+ path, "/", findInfo->d_name, NULL );
if( stat( findPath, &st ) == -1 ) {
continue;
@@ -997,8 +1020,8 @@ char **Sys_ListFiles( const char *path, const char *extension,
continue;
}
- Com_sprintf( findPath, sizeof( findPath ), "%s/%s",
- path, findInfo->d_name );
+ Q_concat( findPath, sizeof( findPath ),
+ path, "/", findInfo->d_name, NULL );
if( stat( findPath, &st ) == -1 ) {
continue;
@@ -1077,41 +1100,6 @@ void Sys_FreeFileList( char **list ) {
}
/*
-===============================================================================
-
-MAIN
-
-===============================================================================
-*/
-
-static void _Qcommon_Init_ArgcArgv( int argc, char **argv ) {
- int i, length;
- char *cmdline;
-
- if( argc < 2 ) {
- Qcommon_Init( NULL );
- return;
- }
-
- length = 0;
- for( i = 1; i < argc; i++ ) {
- length += strlen( argv[i] ) + 1;
- }
-
- cmdline = alloca( length );
- if( cmdline != NULL ) {
- cmdline[0] = 0;
- for( i = 1; i < argc - 1; i++ ) {
- strcat( cmdline, argv[i] );
- strcat( cmdline, " " );
- }
- strcat( cmdline, argv[i] );
- }
-
- Qcommon_Init( cmdline );
-}
-
-/*
=================
main
=================
@@ -1127,15 +1115,16 @@ int main( int argc, char **argv ) {
}
}
- if ( !getuid() || !geteuid() ) {
+ if( !getuid() || !geteuid() ) {
Sys_Error( "You can not run " APPLICATION " as superuser "
"for security reasons!" );
}
- _Qcommon_Init_ArgcArgv( argc, argv );
+ Qcommon_Init( argc, argv );
while( 1 ) {
Qcommon_Frame();
}
+ return 1; // never gets here
}
diff --git a/source/sys_win.c b/source/sys_win.c
index ae0d45e..d321a5d 100644
--- a/source/sys_win.c
+++ b/source/sys_win.c
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef USE_DBGHELP
#include <dbghelp.h>
#endif
+#include <float.h>
sysAPI_t sys;
@@ -411,7 +412,7 @@ static void Sys_ConsoleInit( void ) {
mode |= ENABLE_WINDOW_INPUT;
SetConsoleMode( hinput, mode );
sys_con.widthInChars = sbinfo.dwSize.X;
- sys_con.Printf = Sys_Printf;
+ sys_con.printf = Sys_Printf;
gotConsole = qtrue;
Com_DPrintf( "System console initialized (%d cols, %d rows).\n",
@@ -453,7 +454,7 @@ static void Sys_InstallService_f( void ) {
return;
}
- Com_sprintf( serviceName, sizeof( serviceName ), "Q2PRO - %s", Cmd_Argv( 1 ) );
+ Q_concat( serviceName, sizeof( serviceName ), "Q2PRO - ", Cmd_Argv( 1 ), NULL );
length = GetModuleFileName( NULL, servicePath, MAX_PATH );
if( !length ) {
@@ -523,7 +524,7 @@ static void Sys_DeleteService_f( void ) {
return;
}
- Com_sprintf( serviceName, sizeof( serviceName ), "Q2PRO - %s", Cmd_Argv( 1 ) );
+ Q_concat( serviceName, sizeof( serviceName ), "Q2PRO - ", Cmd_Argv( 1 ), NULL );
service = OpenService(
scm,
@@ -788,6 +789,10 @@ void Sys_FillAPI( sysAPI_t *api ) {
api->HunkFree = Hunk_Free;
}
+void Sys_FixFPCW( void ) {
+ _controlfp( _PC_24|_RC_NEAR, _MCW_PC|_MCW_RC );
+}
+
/*
================
Sys_Init
@@ -933,7 +938,7 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count, const char *p
return;
}
- Com_sprintf( findPath, sizeof( findPath ), "%s\\*", path );
+ Q_concat( findPath, sizeof( findPath ), path, "\\*", NULL );
findHandle = FindFirstFileA( findPath, &findInfo );
if( findHandle == INVALID_HANDLE_VALUE ) {
@@ -946,7 +951,7 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count, const char *p
}
if( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
- Com_sprintf( dirPath, sizeof( dirPath ), "%s\\%s", path, findInfo.cFileName );
+ Q_concat( dirPath, sizeof( dirPath ), path, "\\", findInfo.cFileName, NULL );
Sys_ListFilteredFiles( listedFiles, count, dirPath, filter, flags, length );
}
@@ -960,7 +965,7 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count, const char *p
}
}
- Com_sprintf( dirPath, sizeof( dirPath ), "%s\\%s", path, findInfo.cFileName );
+ Q_concat( dirPath, sizeof( dirPath ), path, "\\", findInfo.cFileName, NULL );
if( !FS_WildCmp( filter, dirPath + length ) ) {
continue;
}
@@ -1016,12 +1021,12 @@ char **Sys_ListFiles( const char *rawPath, const char *extension, uint32 flags,
Sys_ListFilteredFiles( listedFiles, &count, path, findPath, flags, length + 1 );
} else {
if( !extension || strchr( extension, ';' ) ) {
- Com_sprintf( findPath, sizeof( findPath ), "%s\\*", path );
+ Q_concat( findPath, sizeof( findPath ), path, "\\*", NULL );
} else {
if( *extension == '.' ) {
extension++;
}
- Com_sprintf( findPath, sizeof( findPath ), "%s\\*.%s", path, extension );
+ Q_concat( findPath, sizeof( findPath ), path, "\\*.", extension, NULL );
extension = NULL; // do not check later
}
@@ -1503,6 +1508,43 @@ static void msvcrt_sucks( const wchar_t *expr, const wchar_t *func, const wchar_
}
#endif
+
+#define MAX_LINE_TOKENS 128
+
+static char *sys_argv[MAX_LINE_TOKENS];
+static int sys_argc;
+
+/*
+===============
+Sys_ParseCommandLine
+
+===============
+*/
+static void Sys_ParseCommandLine( char *line ) {
+ sys_argc = 1;
+ sys_argv[0] = APPLICATION;
+ while( *line ) {
+ while( *line && *line <= 32 ) {
+ line++;
+ }
+ if( *line == 0 ) {
+ break;
+ }
+ sys_argv[sys_argc++] = line;
+ while( *line > 32 ) {
+ line++;
+ }
+ if( *line == 0 ) {
+ break;
+ }
+ *line = 0;
+ if( sys_argc == MAX_LINE_TOKENS ) {
+ break;
+ }
+ line++;
+ }
+}
+
/*
==================
WinMain
@@ -1552,7 +1594,9 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
_set_invalid_parameter_handler( msvcrt_sucks );
#endif
- Qcommon_Init( lpCmdLine );
+ Sys_ParseCommandLine( lpCmdLine );
+
+ Qcommon_Init( sys_argc, sys_argv );
/* main program loop */
while( !shouldExit ) {
diff --git a/source/ui_demos.c b/source/ui_demos.c
index 81d9061..730a5b6 100644
--- a/source/ui_demos.c
+++ b/source/ui_demos.c
@@ -71,8 +71,8 @@ static void Demos_LoadInfo( int index ) {
return;
}
- Com_sprintf( buffer, sizeof( buffer ), "%s/%s",
- uis.m_demos_browse + 1, m_demos.names[index] );
+ Q_concat( buffer, sizeof( buffer ),
+ uis.m_demos_browse + 1, "/", m_demos.names[index], NULL );
client.GetDemoInfo( buffer, &m_demos.demo );
@@ -120,7 +120,7 @@ static char *Demos_BuildName( const char *path, const char *name,
demoInfo_t demo;
char *s;
- Com_sprintf( buffer, sizeof( buffer ), "%s/%s", path, name );
+ Q_concat( buffer, sizeof( buffer ), path, "/", name, NULL );
client.GetDemoInfo( buffer, &demo );
if( !demo.mapname[0] ) {
diff --git a/source/ui_loading.c b/source/ui_loading.c
index dfe0393..5f7e61d 100644
--- a/source/ui_loading.c
+++ b/source/ui_loading.c
@@ -61,7 +61,7 @@ void UI_DrawLoading( int realtime ) {
x = uis.glconfig.vidWidth / 2;
y = 8;
- Com_sprintf( buffer, sizeof( buffer ), "%s %s", loadingStatus.demoplayback ? "Playing back" : "Connecting to", loadingStatus.servername );
+ Q_concat( buffer, sizeof( buffer ), loadingStatus.demoplayback ? "Playing back " : "Connecting to ", loadingStatus.servername, NULL );
UI_DrawString( x, y, NULL, UI_CENTER|UI_DROPSHADOW, buffer );
y += 40;
diff --git a/source/ui_menu.c b/source/ui_menu.c
index a0fef6b..86ea81f 100644
--- a/source/ui_menu.c
+++ b/source/ui_menu.c
@@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static color_t colorField = { 15, 128, 235, 100 };
static color_t colorGray = { 127, 127, 127, 255 };
+#define UI_CALLBACK( x, y, z ) \
+ (x)->generic.parent->callback( (x)->generic.id, y, z )
+
/*
=================
Common_DoEnter
@@ -224,7 +227,7 @@ static void Keybind_Draw( menuKeybind_t *k ) {
k->generic.uiFlags | UI_RIGHT | flags, k->generic.name );
if( k->altbinding[0] ) {
- Com_sprintf( string, sizeof( string ), "%s or %s", k->binding, k->altbinding );
+ Q_concat( string, sizeof( string ), k->binding, " or ", k->altbinding, NULL );
} else if( k->binding[0] ) {
strcpy( string, k->binding );
} else {
@@ -320,7 +323,7 @@ static int Field_Char( menuField_t *f, int key ) {
}
ret = IF_CharEvent( &f->field, key );
- f->generic.parent->callback( f->generic.id, QM_CHANGE, ret );
+ UI_CALLBACK( f, QM_CHANGE, ret );
return ret ? QMS_SILENT : QMS_NOTHANDLED;
}
@@ -374,15 +377,14 @@ SpinControl_DoEnter
=================
*/
static int SpinControl_DoEnter( menuSpinControl_t *s ) {
- int oldvalue;
+ int oldvalue = s->curvalue;
- oldvalue = s->curvalue;
s->curvalue++;
- if( s->curvalue == s->numItems )
+ if( s->curvalue >= s->numItems )
s->curvalue = 0;
- s->generic.parent->callback( s->generic.id, QM_CHANGE, oldvalue );
+ UI_CALLBACK( s, QM_CHANGE, oldvalue );
return QMS_MOVE;
}
@@ -393,9 +395,8 @@ SpinControl_DoSlide
=================
*/
static int SpinControl_DoSlide( menuSpinControl_t *s, int dir ) {
- int oldvalue;
+ int oldvalue = s->curvalue;
- oldvalue = s->curvalue;
s->curvalue += dir;
if( s->curvalue < 0 ) {
@@ -404,10 +405,9 @@ static int SpinControl_DoSlide( menuSpinControl_t *s, int dir ) {
s->curvalue = 0;
}
- s->generic.parent->callback( s->generic.id, QM_CHANGE, oldvalue );
+ UI_CALLBACK( s, QM_CHANGE, oldvalue );
return QMS_MOVE;
-
}
/*
@@ -453,7 +453,6 @@ void MenuList_ValidatePrestep( menuList_t *l ) {
if( l->prestep > l->numItems - l->maxItems ) {
l->prestep = l->numItems - l->maxItems;
}
-
}
/*
@@ -519,7 +518,7 @@ void MenuList_SetValue( menuList_t *l, int value ) {
l->prestep = 0;
}
- l->generic.parent->callback( l->generic.id, QM_CHANGE, l->curvalue );
+ UI_CALLBACK( l, QM_CHANGE, l->curvalue );
}
@@ -616,7 +615,7 @@ static int MenuList_Key( menuList_t *l, int key ) {
case K_KP_UPARROW:
if( l->curvalue > 0 ) {
l->curvalue--;
- l->generic.parent->callback( l->generic.id, QM_CHANGE, l->curvalue );
+ UI_CALLBACK( l, QM_CHANGE, l->curvalue );
// scroll contents up
if( l->prestep > l->curvalue ) {
@@ -630,7 +629,7 @@ static int MenuList_Key( menuList_t *l, int key ) {
case K_KP_DOWNARROW:
if( l->curvalue < l->numItems - 1 ) {
l->curvalue++;
- l->generic.parent->callback( l->generic.id, QM_CHANGE, l->curvalue );
+ UI_CALLBACK( l, QM_CHANGE, l->curvalue );
// scroll contents down
if( l->prestep < l->curvalue - l->maxItems + 1 ) {
@@ -644,7 +643,7 @@ static int MenuList_Key( menuList_t *l, int key ) {
case K_KP_HOME:
l->prestep = 0;
l->curvalue = 0;
- l->generic.parent->callback( l->generic.id, QM_CHANGE, l->curvalue );
+ UI_CALLBACK( l, QM_CHANGE, l->curvalue );
return QMS_MOVE;
case K_END:
@@ -653,7 +652,7 @@ static int MenuList_Key( menuList_t *l, int key ) {
l->prestep = l->numItems - l->maxItems;
}
l->curvalue = l->numItems - 1;
- l->generic.parent->callback( l->generic.id, QM_CHANGE, l->curvalue );
+ UI_CALLBACK( l, QM_CHANGE, l->curvalue );
return QMS_MOVE;
case K_MWHEELUP:
@@ -690,11 +689,11 @@ static int MenuList_Key( menuList_t *l, int key ) {
i = MenuList_HitTest( l, uis.mouseCoords[0], uis.mouseCoords[1] );
if( i != -1 ) {
if( l->curvalue == i && uis.realtime - l->clickTime < DOUBLE_CLICK_DELAY ) {
- return l->generic.parent->callback( l->generic.id, QM_ACTIVATE, i );
+ return UI_CALLBACK( l, QM_ACTIVATE, i );
}
l->clickTime = uis.realtime;
l->curvalue = i;
- l->generic.parent->callback( l->generic.id, QM_CHANGE, i );
+ UI_CALLBACK( l, QM_CHANGE, i );
}
return QMS_SILENT;
case K_MOUSE2:
@@ -702,7 +701,7 @@ static int MenuList_Key( menuList_t *l, int key ) {
i = MenuList_HitTest( l, uis.mouseCoords[0], uis.mouseCoords[1] );
if( i != -1 ) {
l->curvalue = i;
- l->generic.parent->callback( l->generic.id, QM_CHANGE, i );
+ UI_CALLBACK( l, QM_CHANGE, i );
}
return QMS_SILENT;
}
@@ -962,7 +961,7 @@ ImageList_UpdatePos
*/
static void ImageList_UpdatePos( imageList_t *l ) {
l->prestep = l->curvalue - l->curvalue % ( l->numRows * l->numcolumns );
- l->generic.parent->callback( l->generic.id, QM_CHANGE, l->curvalue );
+ UI_CALLBACK( l, QM_CHANGE, l->curvalue );
}
/*
@@ -1067,7 +1066,7 @@ static int ImageList_Key( imageList_t *l, int key ) {
i = ImageList_HitTest( l, uis.mouseCoords[0], uis.mouseCoords[1] );
if( i != -1 ) {
if( l->curvalue == i && uis.realtime - l->clickTime < DOUBLE_CLICK_DELAY ) {
- return l->generic.parent->callback( l->generic.id, QM_ACTIVATE, i );
+ return UI_CALLBACK( l, QM_ACTIVATE, i );
}
l->clickTime = uis.realtime;
l->curvalue = i;
@@ -1186,7 +1185,7 @@ static int Slider_DoSlide( menuSlider_t *s, int dir ) {
else if( s->curvalue < s->minvalue )
s->curvalue = s->minvalue;
- if( ( ret = s->generic.parent->callback( s->generic.id, QM_CHANGE, s->curvalue ) ) != QMS_NOTHANDLED ) {
+ if( ( ret = UI_CALLBACK( s, QM_CHANGE, s->curvalue ) ) != QMS_NOTHANDLED ) {
return ret;
}
@@ -1229,7 +1228,6 @@ static void Slider_Draw( menuSlider_t *s ) {
}
UI_DrawChar( SMALLCHAR_WIDTH + RCOLUMN_OFFSET + s->generic.x + ( SLIDER_RANGE - 1 ) * SMALLCHAR_WIDTH * pos, s->generic.y, flags | UI_LEFT, 131 );
-
}
/*
diff --git a/source/ui_multiplayer.c b/source/ui_multiplayer.c
index ff92d33..f6065d2 100644
--- a/source/ui_multiplayer.c
+++ b/source/ui_multiplayer.c
@@ -87,7 +87,7 @@ static void UpdateSelection( void ) {
m_join.players.itemnames = NULL;
m_join.players.numItems = 0;
- m_join.menu.statusbar = "Press Space to refresh";
+ m_join.menu.statusbar = "Press Space to refresh; Hold ALT to refresh all";
}
}
@@ -323,7 +323,7 @@ static int JoinServer_MenuCallback( int id, int msg, int param ) {
if( param != 32 ) {
break;
}
- if( !keys.IsDown( K_SHIFT ) ) {
+ if( !keys.IsDown( K_ALT ) ) {
PingSelected();
} else {
PingServers();
diff --git a/source/ui_playerconfig.c b/source/ui_playerconfig.c
index a822e50..637fa95 100644
--- a/source/ui_playerconfig.c
+++ b/source/ui_playerconfig.c
@@ -67,9 +67,9 @@ static void ApplyChanges( void ) {
cvar.Set( "name", m_playerConfig.nameField.field.text );
- Com_sprintf( scratch, sizeof( scratch ), "%s/%s",
- uis.pmi[m_playerConfig.modelBox.curvalue].directory,
- uis.pmi[m_playerConfig.modelBox.curvalue].skindisplaynames[m_playerConfig.skinBox.curvalue] );
+ Q_concat( scratch, sizeof( scratch ),
+ uis.pmi[m_playerConfig.modelBox.curvalue].directory, "/",
+ uis.pmi[m_playerConfig.modelBox.curvalue].skindisplaynames[m_playerConfig.skinBox.curvalue], NULL );
cvar.Set( "skin", scratch );
@@ -78,13 +78,16 @@ static void ApplyChanges( void ) {
static void ReloadMedia( void ) {
char scratch[MAX_QPATH];
+ char *model = uis.pmi[m_playerConfig.modelBox.curvalue].directory;
+ char *skin = uis.pmi[m_playerConfig.modelBox.curvalue].skindisplaynames[m_playerConfig.skinBox.curvalue];
- Com_sprintf( scratch, sizeof( scratch ), "players/%s/tris.md2", uis.pmi[m_playerConfig.modelBox.curvalue].directory );
+ Q_concat( scratch, sizeof( scratch ), "players/", model, "/tris.md2", NULL );
m_playerConfig.entities[0].model = ref.RegisterModel( scratch );
- Com_sprintf( scratch, sizeof( scratch ), "players/%s/%s.pcx", uis.pmi[m_playerConfig.modelBox.curvalue].directory, uis.pmi[m_playerConfig.modelBox.curvalue].skindisplaynames[m_playerConfig.skinBox.curvalue] );
+
+ Q_concat( scratch, sizeof( scratch ), "players/", model, "/", skin, ".pcx", NULL );
m_playerConfig.entities[0].skin = ref.RegisterSkin( scratch );
- Com_sprintf( scratch, sizeof( scratch ), "players/%s/w_railgun.md2", uis.pmi[m_playerConfig.modelBox.curvalue].directory );
+ Q_concat( scratch, sizeof( scratch ), "players/", model, "/w_railgun.md2", NULL );
m_playerConfig.entities[1].model = ref.RegisterModel( scratch );
}
diff --git a/source/ui_playermodels.c b/source/ui_playermodels.c
index d7d0f78..ac2e589 100644
--- a/source/ui_playermodels.c
+++ b/source/ui_playermodels.c
@@ -28,7 +28,7 @@ PLAYER MODELS
=============================================================================
*/
-static const char *baseWeaponNames[] = {
+static const char baseWeaponNames[][32] = {
"w_bfg.md2",
"w_blaster.md2",
"w_chaingun.md2",
@@ -38,10 +38,11 @@ static const char *baseWeaponNames[] = {
"w_railgun.md2",
"w_rlauncher.md2",
"w_shotgun.md2",
- "w_sshotgun.md2",
- NULL
+ "w_sshotgun.md2"
};
+static const int numBaseWeaponNames = sizeof( baseWeaponNames ) / sizeof( baseWeaponNames[0] );
+
static qboolean IconOfSkinExists( char *skin, char **pcxfiles, int npcxfiles ) {
int i;
char scratch[MAX_OSPATH];
@@ -138,13 +139,13 @@ void PlayerModel_Load( void ) {
char **weaponNames;
// verify the existence of tris.md2
- Com_sprintf( scratch, sizeof( scratch ), "players/%s/tris.md2", dirnames[i] );
+ Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], "/tris.md2", NULL );
if( fs.LoadFile( scratch, NULL ) < 1 ) {
continue;
}
// verify the existence of at least one pcx skin
- Com_sprintf( scratch, sizeof( scratch ), "players/%s", dirnames[i] );
+ Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], NULL );
pcxnames = fs.ListFiles( scratch, ".pcx", 0, &npcxfiles );
if( !pcxnames ) {
continue;
@@ -180,7 +181,7 @@ void PlayerModel_Load( void ) {
fs.FreeFileList( pcxnames );
// load vweap models
- Com_sprintf( scratch, sizeof( scratch ), "players/%s/w_*.md2", dirnames[i] );
+ Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], "/w_*.md2", NULL );
weaponNames = fs.ListFiles( NULL, scratch, FS_SEARCH_BYFILTER, &numWeapons );
pmi = &uis.pmi[uis.numPlayerModels++];
@@ -190,16 +191,12 @@ void PlayerModel_Load( void ) {
pmi->weaponNames = UI_Malloc( sizeof( char * ) * numWeapons );
for( j = 0; j < numWeapons ; j++ ) {
- for( k = 0; baseWeaponNames[k] ; k++ ) {
+ for( k = 0; k < numBaseWeaponNames; k++ ) {
if( !strcmp( weaponNames[j], baseWeaponNames[k] ) ) {
+ pmi->weaponNames[pmi->numWeapons++] = UI_CopyString( weaponNames[j] );
break;
}
}
- if( !baseWeaponNames[k] ) {
- continue;
- }
-
- pmi->weaponNames[pmi->numWeapons++] = UI_CopyString( weaponNames[j] );
}
fs.FreeFileList( weaponNames );
diff --git a/source/vid_win.c b/source/vid_win.c
index 45be3c5..4fea763 100644
--- a/source/vid_win.c
+++ b/source/vid_win.c
@@ -125,7 +125,9 @@ static void Win_Show( const vrect_t *rc, qboolean fullscreen ) {
}
void Win_ModeChanged( void ) {
+#ifndef REF_HARD_LINKED
SWimp_ModeChanged();
+#endif
ref.ModeChanged( win.rc.width, win.rc.height, win.flags,
win.pitch, win.buffer );
SCR_ModeChanged();
@@ -476,9 +478,6 @@ LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
UINT lines;
int key;
-
-// this chunk of code theoretically only works under NT4 and Win98
-// since this message doesn't exist under Win95
if( ( short )HIWORD( wParam ) > 0 ) {
key = K_MWHEELUP;
} else {