mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-10 06:42:26 +00:00
command line and config file parsing ala OT
This commit is contained in:
parent
6bb69779a4
commit
ce25c13a65
4 changed files with 228 additions and 114 deletions
|
@ -112,6 +112,9 @@ void Cmd_ForwardToServer (void);
|
|||
|
||||
void Cmd_StuffCmds_f (void);
|
||||
|
||||
void Cbuf_Execute_Sets (void);
|
||||
void Cmd_Exec_File (char *path);
|
||||
|
||||
extern char com_token[1024];
|
||||
char *COM_Parse (char *data);
|
||||
|
||||
|
|
|
@ -67,12 +67,15 @@
|
|||
#endif
|
||||
#include "cl_slist.h"
|
||||
|
||||
extern cvar_t *fs_basepath;
|
||||
extern cvar_t *fs_sharepath;
|
||||
// we need to declare some mouse variables here, because the menu system
|
||||
// references them even when on a unix system.
|
||||
|
||||
qboolean noclip_anglehack; // remnant from old quake
|
||||
|
||||
|
||||
cvar_t *fs_globalcfg;
|
||||
/* cvar_t rcon_password = {"rcon_password", "", false};
|
||||
CVAR_FIXME */
|
||||
cvar_t *rcon_password;
|
||||
|
@ -1683,7 +1686,8 @@ void Host_Init (quakeparms_t *parms)
|
|||
host_parms = *parms;
|
||||
|
||||
if (parms->memsize < MINIMUM_MEMORY)
|
||||
Sys_Error ("Only %4.1f megs of memory reported, can't execute game", parms->memsize / (float)0x100000);
|
||||
Sys_Error ("Only %4.1f megs of memory reported, can't execute game",
|
||||
parms->memsize / (float)0x100000);
|
||||
|
||||
Memory_Init (parms->membase, parms->memsize);
|
||||
Cvar_Init ();
|
||||
|
@ -1692,13 +1696,37 @@ void Host_Init (quakeparms_t *parms)
|
|||
Cbuf_Init ();
|
||||
Cmd_Init ();
|
||||
cl_Cmd_Init ();
|
||||
V_Init ();
|
||||
|
||||
// execute +set as early as possible
|
||||
Cmd_StuffCmds_f ();
|
||||
Cbuf_Execute_Sets ();
|
||||
|
||||
// execute the global configuration file if it exists
|
||||
// would have been nice if Cmd_Exec_f could have been used, but it
|
||||
// only reads from within the quake file system, and changing that is
|
||||
// probably Not A Good Thing (tm).
|
||||
fs_globalcfg = Cvar_Get("fs_globalcfg", FS_GLOBALCFG,
|
||||
CVAR_ROM, "global configuration file");
|
||||
Cmd_Exec_File (fs_globalcfg->string);
|
||||
Cbuf_Execute_Sets ();
|
||||
|
||||
V_Init ();
|
||||
CL_InitCvars ();
|
||||
SCR_InitCvars ();
|
||||
VID_InitCvars ();
|
||||
COM_Init ();
|
||||
|
||||
// reparse the command line for + commands other than set
|
||||
// (sets still done, but it doesn't matter)
|
||||
Cmd_StuffCmds_f ();
|
||||
Cbuf_Execute ();
|
||||
|
||||
// make these read-only
|
||||
fs_basepath = Cvar_Get ("fs_basepath", fs_basepath->string, CVAR_ROM,
|
||||
"the location of your game directories");
|
||||
fs_sharepath = Cvar_Get ("fs_sharepath", fs_sharepath->string,
|
||||
CVAR_ROM, "read-only game directories");
|
||||
|
||||
Host_FixupModelNames();
|
||||
|
||||
NET_Init (PORT_CLIENT);
|
||||
|
|
178
source/cmd.c
178
source/cmd.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
cmd.c
|
||||
|
||||
(description)
|
||||
Quake script command processing module
|
||||
|
||||
Copyright (C) 1996-1997 Id Software, Inc.
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
|||
#include "commdef.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void Cmd_ForwardToServer (void);
|
||||
|
||||
|
@ -57,10 +58,7 @@ cmdalias_t *cmd_alias;
|
|||
|
||||
qboolean cmd_wait;
|
||||
|
||||
/* cvar_t cl_warncmd = {"cl_warncmd", "0"};
|
||||
CVAR_FIXME */
|
||||
cvar_t *cl_warncmd;
|
||||
|
||||
//=============================================================================
|
||||
|
||||
/*
|
||||
|
@ -157,52 +155,54 @@ void Cbuf_InsertText (char *text)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cbuf_Execute
|
||||
============
|
||||
*/
|
||||
void Cbuf_Execute (void)
|
||||
static void
|
||||
extract_line(char *line)
|
||||
{
|
||||
int i;
|
||||
char *text;
|
||||
char line[1024];
|
||||
int quotes;
|
||||
|
||||
while (cmd_text.cursize)
|
||||
{
|
||||
// find a \n or ; line break
|
||||
text = (char *)cmd_text.data;
|
||||
|
||||
quotes = 0;
|
||||
for (i=0 ; i< cmd_text.cursize ; i++)
|
||||
{
|
||||
for (i=0 ; i< cmd_text.cursize ; i++) {
|
||||
if (text[i] == '"')
|
||||
quotes++;
|
||||
if ( !(quotes&1) && text[i] == ';')
|
||||
break; // don't break if inside a quoted string
|
||||
if (text[i] == '\n')
|
||||
if (text[i] == '\n' || text[i] == '\r')
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
memcpy (line, text, i);
|
||||
line[i] = 0;
|
||||
|
||||
line[i] = '\0';
|
||||
// delete the text from the command buffer and move remaining commands down
|
||||
// this is necessary because commands (exec, alias) can insert data at the
|
||||
// beginning of the text buffer
|
||||
|
||||
if (i == cmd_text.cursize)
|
||||
cmd_text.cursize = 0;
|
||||
else
|
||||
{
|
||||
else {
|
||||
i++;
|
||||
cmd_text.cursize -= i;
|
||||
memcpy (text, text+i, cmd_text.cursize);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Cbuf_Execute
|
||||
|
||||
*/
|
||||
void
|
||||
Cbuf_Execute (void)
|
||||
{
|
||||
char line[1024] = {0};
|
||||
|
||||
while (cmd_text.cursize) {
|
||||
extract_line (line);
|
||||
// execute the command line
|
||||
//Con_DPrintf("+%s\n",line),
|
||||
Cmd_ExecuteString (line);
|
||||
|
||||
if (cmd_wait)
|
||||
|
@ -213,6 +213,25 @@ void Cbuf_Execute (void)
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
Cbuf_Execute
|
||||
|
||||
*/
|
||||
void
|
||||
Cbuf_Execute_Sets (void)
|
||||
{
|
||||
char line[1024] = {0};
|
||||
|
||||
while (cmd_text.cursize) {
|
||||
extract_line (line);
|
||||
// execute the command line
|
||||
if (strncmp(line,"set",3)==0
|
||||
&& isspace((int) line[3]))
|
||||
//Con_DPrintf("+%s\n",line),
|
||||
Cmd_ExecuteString (line);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
@ -236,60 +255,74 @@ void Cmd_StuffCmds_f (void)
|
|||
{
|
||||
int i, j;
|
||||
int s;
|
||||
char *text, *build, c;
|
||||
char *build, c;
|
||||
|
||||
// build the combined string to parse from
|
||||
s = 0;
|
||||
for (i=1 ; i<com_argc ; i++)
|
||||
{
|
||||
if (!com_argv[i])
|
||||
continue; // NEXTSTEP nulls out -NXHost
|
||||
s += strlen (com_argv[i]) + 1;
|
||||
}
|
||||
s = strlen (com_cmdline);
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
text = Z_Malloc (s+1);
|
||||
text[0] = 0;
|
||||
for (i=1 ; i<com_argc ; i++)
|
||||
{
|
||||
if (!com_argv[i])
|
||||
continue; // NEXTSTEP nulls out -NXHost
|
||||
strcat (text,com_argv[i]);
|
||||
if (i != com_argc-1)
|
||||
strcat (text, " ");
|
||||
}
|
||||
|
||||
// pull out the commands
|
||||
build = Z_Malloc (s+1);
|
||||
build[0] = 0;
|
||||
|
||||
for (i=0 ; i<s-1 ; i++)
|
||||
{
|
||||
if (text[i] == '+')
|
||||
if (com_cmdline[i] == '+')
|
||||
{
|
||||
i++;
|
||||
|
||||
for (j=i ; (text[j] != '+') && (text[j] != '-') && (text[j] != 0) ; j++)
|
||||
for (j=i ; ((com_cmdline[j] != '+')
|
||||
&& (com_cmdline[j] != '-')
|
||||
&& (com_cmdline[j] != 0)) ; j++)
|
||||
;
|
||||
|
||||
c = text[j];
|
||||
text[j] = 0;
|
||||
c = com_cmdline[j];
|
||||
com_cmdline[j] = 0;
|
||||
|
||||
strcat (build, text+i);
|
||||
strcat (build, com_cmdline+i);
|
||||
strcat (build, "\n");
|
||||
text[j] = c;
|
||||
com_cmdline[j] = c;
|
||||
i = j-1;
|
||||
}
|
||||
}
|
||||
|
||||
//Con_Printf("[\n%s]\n",build);
|
||||
|
||||
if (build[0])
|
||||
Cbuf_InsertText (build);
|
||||
|
||||
Z_Free (text);
|
||||
Z_Free (build);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Cmd_Exec_File
|
||||
|
||||
*/
|
||||
void
|
||||
Cmd_Exec_File (char *path)
|
||||
{
|
||||
char *f;
|
||||
int mark;
|
||||
int len;
|
||||
char base[32];
|
||||
QFile *file;
|
||||
|
||||
if ((file = Qopen (path, "r")) != NULL) {
|
||||
// extract the filename base name for hunk tag
|
||||
COM_FileBase (path, base);
|
||||
len = COM_filelength (file);
|
||||
mark = Hunk_LowMark ();
|
||||
f = (char *)Hunk_AllocName (len+1, base);
|
||||
if (f) {
|
||||
f[len] = 0;
|
||||
Qread (file, f, len);
|
||||
Qclose (file);
|
||||
Cbuf_InsertText (f);
|
||||
}
|
||||
Hunk_FreeToLowMark (mark);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
|
@ -315,8 +348,6 @@ void Cmd_Exec_f (void)
|
|||
Con_Printf ("couldn't exec %s\n",Cmd_Argv(1));
|
||||
return;
|
||||
}
|
||||
/* if (!Cvar_Command () && (cl_warncmd.value || developer.value))
|
||||
CVAR_FIXME */
|
||||
if (!Cvar_Command () && (cl_warncmd->value || developer->value))
|
||||
Con_Printf ("execing %s\n",Cmd_Argv(1));
|
||||
|
||||
|
@ -412,6 +443,41 @@ void Cmd_Alias_f (void)
|
|||
a->value = CopyString (cmd);
|
||||
}
|
||||
|
||||
void Cmd_UnAlias_f (void)
|
||||
{
|
||||
cmdalias_t *a, *prev;
|
||||
char *s;
|
||||
|
||||
if (Cmd_Argc() != 2)
|
||||
{
|
||||
Con_Printf ("unalias <alias>: erase an existing alias\n");
|
||||
return;
|
||||
}
|
||||
|
||||
s = Cmd_Argv(1);
|
||||
if (strlen(s) >= MAX_ALIAS_NAME)
|
||||
{
|
||||
Con_Printf ("Alias name is too long\n");
|
||||
return;
|
||||
}
|
||||
|
||||
prev = cmd_alias;
|
||||
for (a = cmd_alias ; a ; a = a->next)
|
||||
{
|
||||
if (!strcmp(s, a->name))
|
||||
{
|
||||
Z_Free (a->value);
|
||||
prev->next = a->next;
|
||||
if (a == cmd_alias)
|
||||
cmd_alias = a->next;
|
||||
Z_Free (a);
|
||||
return;
|
||||
}
|
||||
prev = a;
|
||||
}
|
||||
Con_Printf ("Unknown alias \"%s\"\n", s);
|
||||
}
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
||||
|
@ -652,6 +718,10 @@ void Cmd_ExecuteString (char *text)
|
|||
}
|
||||
}
|
||||
|
||||
// Tonik: check cvars
|
||||
if (Cvar_Command())
|
||||
return;
|
||||
|
||||
// check alias
|
||||
for (a=cmd_alias ; a ; a=a->next)
|
||||
{
|
||||
|
@ -662,10 +732,7 @@ void Cmd_ExecuteString (char *text)
|
|||
}
|
||||
}
|
||||
|
||||
// check cvars
|
||||
/* if (!Cvar_Command () && (cl_warncmd.value || developer.value))
|
||||
CVAR_FIXME */
|
||||
if (!Cvar_Command () && (cl_warncmd->value || developer->value))
|
||||
if (cl_warncmd->value || developer->value)
|
||||
Con_Printf ("Unknown command \"%s\"\n", Cmd_Argv(0));
|
||||
|
||||
}
|
||||
|
@ -721,6 +788,7 @@ void Cmd_Init (void)
|
|||
Cmd_AddCommand ("exec",Cmd_Exec_f);
|
||||
Cmd_AddCommand ("echo",Cmd_Echo_f);
|
||||
Cmd_AddCommand ("alias",Cmd_Alias_f);
|
||||
Cmd_AddCommand ("unalias",Cmd_UnAlias_f);
|
||||
Cmd_AddCommand ("wait", Cmd_Wait_f);
|
||||
Cmd_AddCommand ("cmdlist", Cmd_CmdList_f);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ netadr_t master_adr[MAX_MASTERS]; // address of group servers
|
|||
|
||||
client_t *host_client; // current client
|
||||
|
||||
cvar_t *fs_globalcfg;
|
||||
|
||||
/* cvar_t sv_mintic = {"sv_mintic","0.03"}; // bound the size of the
|
||||
CVAR_FIXME */
|
||||
cvar_t *sv_mintic; // bound the size of the
|
||||
|
@ -1860,6 +1862,19 @@ void SV_Init (quakeparms_t *parms)
|
|||
Cbuf_Init ();
|
||||
Cmd_Init ();
|
||||
|
||||
// execute +set as early as possible
|
||||
Cmd_StuffCmds_f ();
|
||||
Cbuf_Execute_Sets ();
|
||||
|
||||
// execute the global configuration file if it exists
|
||||
// would have been nice if Cmd_Exec_f could have been used, but it
|
||||
// only reads from within the quake file system, and changing that is
|
||||
// probably Not A Good Thing (tm).
|
||||
fs_globalcfg = Cvar_Get("fs_globalcfg", FS_GLOBALCFG,
|
||||
CVAR_ROM, "global configuration file");
|
||||
Cmd_Exec_File (fs_globalcfg->string);
|
||||
Cbuf_Execute_Sets ();
|
||||
|
||||
COM_Init ();
|
||||
|
||||
PR_Init ();
|
||||
|
|
Loading…
Reference in a new issue