From 66a1169257be013f13698022260838a3e6b846fe Mon Sep 17 00:00:00 2001 From: sezero Date: Thu, 29 Dec 2011 15:10:18 +0000 Subject: [PATCH] some common.c cleanup: Made COM_InitFilesystem() public through common.h, moved its calling from COM_Init() to Host_Init() just after COM_Init(). Moved registration of registered and cmdline cvars and COM_Path_f command and the calling of COM_CheckRegistered() to COM_InitFilesystem(). Removed unused memsearch(). Fixed the stupidity in leading space elimination from com_cmdline. git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@573 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Quake/common.c | 49 ++++++++++++++++----------------------- quakespasm/Quake/common.h | 2 ++ quakespasm/Quake/host.c | 1 + 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/quakespasm/Quake/common.c b/quakespasm/Quake/common.c index 5a8e20c2..d55e7347 100644 --- a/quakespasm/Quake/common.c +++ b/quakespasm/Quake/common.c @@ -37,7 +37,7 @@ int com_nummissionpacks; //johnfitz qboolean fitzmode; -void COM_InitFilesystem (void); +static void COM_Path_f (void); // if a packfile directory differs from this, it is assumed to be hacked #define PAK0_COUNT 339 @@ -127,6 +127,7 @@ void InsertLinkBefore (link_t *l, link_t *before) l->prev->next = l; l->next->prev = l; } + void InsertLinkAfter (link_t *l, link_t *after) { l->next = after->next; @@ -814,7 +815,6 @@ float MSG_ReadAngle16 (void) } //johnfitz - //=========================================================================== void SZ_Alloc (sizebuf_t *buf, int startsize) @@ -884,7 +884,6 @@ void SZ_Print (sizebuf_t *buf, const char *data) //============================================================================ - /* ============ COM_SkipPath @@ -1146,7 +1145,7 @@ Immediately exits out if an alternate game was attempted to be started without being registered. ================ */ -void COM_CheckRegistered (void) +static void COM_CheckRegistered (void) { int h; unsigned short check[128]; @@ -1169,18 +1168,23 @@ void COM_CheckRegistered (void) COM_CloseFile (h); for (i = 0; i < 128; i++) + { if (pop[i] != (unsigned short)BigShort (check[i])) Sys_Error ("Corrupted data file."); + } - Cvar_SetROM ("cmdline", com_cmdline+1); //johnfitz -- eliminate leading space + for (i = 0; com_cmdline[i]; i++) + { + if (com_cmdline[i]!= ' ') + break; + } + + Cvar_SetROM ("cmdline", &com_cmdline[i]); Cvar_SetROM ("registered", "1"); Con_Printf ("Playing registered version.\n"); } -void COM_Path_f (void); - - /* ================ COM_InitArgv @@ -1295,13 +1299,6 @@ void COM_Init (void) if (COM_CheckParm("-fitz")) fitzmode = true; - - Cvar_RegisterVariable (®istered); - Cvar_RegisterVariable (&cmdline); - Cmd_AddCommand ("path", COM_Path_f); - COM_InitFilesystem (); - COM_CheckRegistered (); - #ifdef _DEBUG Cmd_AddCommand ("fitztest", FitzTest_f); //johnfitz #endif @@ -1342,18 +1339,6 @@ char *va (const char *format, ...) return va_buf; } - -/// just for debugging -int memsearch (byte *start, int count, int search) -{ - int i; - - for (i = 0; i < count; i++) - if (start[i] == search) - return i; - return -1; -} - /* ============================================================================= @@ -1422,7 +1407,7 @@ searchpath_t *com_searchpaths; COM_Path_f ============ */ -void COM_Path_f (void) +static void COM_Path_f (void) { searchpath_t *s; @@ -1860,7 +1845,7 @@ pack_t *COM_LoadPackFile (const char *packfile) COM_AddGameDirectory -- johnfitz -- modified based on topaz's tutorial ================= */ -void COM_AddGameDirectory (const char *dir) +static void COM_AddGameDirectory (const char *dir) { int i; unsigned int path_id; @@ -1931,6 +1916,10 @@ void COM_InitFilesystem (void) //johnfitz -- modified based on topaz's tutorial { int i, j; + Cvar_RegisterVariable (®istered); + Cvar_RegisterVariable (&cmdline); + Cmd_AddCommand ("path", COM_Path_f); + i = COM_CheckParm ("-basedir"); if (i && i < com_argc-1) q_strlcpy (com_basedir, com_argv[i + 1], sizeof(com_basedir)); @@ -1981,6 +1970,8 @@ void COM_InitFilesystem (void) //johnfitz -- modified based on topaz's tutorial com_modified = true; COM_AddGameDirectory (va("%s/%s", com_basedir, com_argv[i + 1])); } + + COM_CheckRegistered (); } diff --git a/quakespasm/Quake/common.h b/quakespasm/Quake/common.h index cfd3e3b6..89553ace 100644 --- a/quakespasm/Quake/common.h +++ b/quakespasm/Quake/common.h @@ -174,8 +174,10 @@ extern int safemode; */ int COM_CheckParm (const char *parm); + void COM_Init (void); void COM_InitArgv (int argc, char **argv); +void COM_InitFilesystem (void); const char *COM_SkipPath (const char *pathname); void COM_StripExtension (const char *in, char *out, size_t outsize); diff --git a/quakespasm/Quake/host.c b/quakespasm/Quake/host.c index 7d9c161a..9d3fc82c 100644 --- a/quakespasm/Quake/host.c +++ b/quakespasm/Quake/host.c @@ -841,6 +841,7 @@ void Host_Init (void) LOG_Init (host_parms); Cvar_Init (); //johnfitz COM_Init (); + COM_InitFilesystem (); Host_InitLocal (); W_LoadWadFile (); //johnfitz -- filename is now hard-coded for honesty if (cls.state != ca_dedicated)