Add Cbuf_Execute_Sets to execute /only/ +set commands.
	Break out common code from Cbuf_Execute and Cbuf_Execute_Sets into
	a local function.
cmd.h:
	add prototype for Cbuf_Execute_Sets
host.c:
	use it
This commit is contained in:
Bill Currie 2000-04-18 10:13:17 +00:00
parent 6cdc6a95a9
commit 09183d0628
3 changed files with 60 additions and 36 deletions

View File

@ -38,6 +38,7 @@
#include <lib_replace.h>
#include <zone.h>
#include <string.h>
#include <ctype.h>
#include <net.h>
#include <common_quakedef.h>
@ -153,51 +154,53 @@ void Cbuf_InsertText (char *text)
}
}
/*
============
Cbuf_Execute
============
*/
void Cbuf_Execute (void)
static void
extract_line(char *line)
{
int i;//, li;
int i;
char *text;
char line[1024] = {0};
int quotes;
while (cmd_text.cursize)
{
// find a \n or ; line break
text = (char *)cmd_text.data;
// find a \n or ; line break
text = (char *)cmd_text.data;
quotes = 0;
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' || text[i] == '\r')
break;
}
quotes = 0;
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' || text[i] == '\r')
break;
}
memcpy (line, text, i);
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
memcpy (line, text, i);
line[i] = '\0';
if (i == cmd_text.cursize)
cmd_text.cursize = 0;
else {
i++;
cmd_text.cursize -= i;
Q_memcpy (text, text+i, cmd_text.cursize);
}
}
// 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
{
i++;
cmd_text.cursize -= i;
Q_memcpy (text, text+i, cmd_text.cursize);
}
Cbuf_Execute
// execute the command line
*/
void
Cbuf_Execute (void)
{
char line[1024] = {0};
while (cmd_text.cursize) {
extract_line (line);
// execute the command line
Cmd_ExecuteString (line, src_command);
if (cmd_wait)
@ -208,6 +211,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(line[3]))
printf("+%s\n",line),
Cmd_ExecuteString (line, src_command);
}
}
/*
==============================================================================

View File

@ -60,6 +60,7 @@ void Cbuf_InsertText (char *text);
// commands.
void Cbuf_Execute (void);
void Cbuf_Execute_Sets (void);
// Pulls off \n terminated lines of text from the command buffer and sends
// them through Cmd_ExecuteString. Stops when the buffer is empty.
// Normally called once per frame, but may be explicitly invoked.

View File

@ -558,6 +558,7 @@ Host_Init (quakeparms_t *parms)
// FIXME: stuff only +set here, shouldn't stuff all commands --KB
Cmd_StuffCmds_f ();
Cbuf_Execute_Sets ();
Cbuf_Execute ();
V_Init ();