cmd.c:
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:
parent
6cdc6a95a9
commit
09183d0628
54
common/cmd.c
54
common/cmd.c
|
@ -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,26 +154,17 @@ 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;
|
||||
|
||||
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] == ';')
|
||||
|
@ -183,20 +175,31 @@ void Cbuf_Execute (void)
|
|||
|
||||
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
|
||||
|
||||
if (i == cmd_text.cursize)
|
||||
cmd_text.cursize = 0;
|
||||
else
|
||||
{
|
||||
else {
|
||||
i++;
|
||||
cmd_text.cursize -= i;
|
||||
Q_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
|
||||
Cmd_ExecuteString (line, src_command);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 ();
|
||||
|
|
Loading…
Reference in New Issue