mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-27 06:34:11 +00:00
Fixed an error in extract line that caused escaped quotes to be parsed as
normal quotes and made it so executed files are always inserted into the console buffer so that class config files in TF can use the new parser features, even though the exec command is run in the legacy buffer
This commit is contained in:
parent
777495e069
commit
0a90ddc51f
1 changed files with 33 additions and 13 deletions
|
@ -59,9 +59,18 @@ typedef struct cmdalias_s {
|
||||||
|
|
||||||
cmdalias_t *cmd_alias;
|
cmdalias_t *cmd_alias;
|
||||||
cmd_source_t cmd_source;
|
cmd_source_t cmd_source;
|
||||||
dstring_t *cmd_buffer, *cmd_legacybuffer, *cmd_activebuffer, *cmd_argbuf;
|
|
||||||
|
/* FIXME: All these separate buffers are sort of hacky
|
||||||
|
The command buffer interface should be generalized and
|
||||||
|
each part of QF (console, stufftext, config files and scripts)
|
||||||
|
that needs one should allocate and maintain its own.
|
||||||
|
*/
|
||||||
|
dstring_t *cmd_buffer; // Console buffer
|
||||||
|
dstring_t *cmd_legacybuffer; // Server stuffcmd buffer with absolute backwards-compatibility
|
||||||
|
dstring_t *cmd_activebuffer; // Buffer currently being executed
|
||||||
|
dstring_t *cmd_argbuf; // Buffer for reconstructing tokens into single string
|
||||||
qboolean cmd_wait = false;
|
qboolean cmd_wait = false;
|
||||||
qboolean cmd_legacy = false;
|
qboolean cmd_legacy = false; // Are we executing current buffer in legacy mode?
|
||||||
int cmd_argc;
|
int cmd_argc;
|
||||||
int cmd_maxargc = 0;
|
int cmd_maxargc = 0;
|
||||||
dstring_t **cmd_argv = 0;
|
dstring_t **cmd_argv = 0;
|
||||||
|
@ -77,6 +86,18 @@ hashtab_t *cmd_hash;
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
/* Quick function to determine if a character is escaped */
|
||||||
|
qboolean
|
||||||
|
escaped (const char *str, int i)
|
||||||
|
{
|
||||||
|
int n, c;
|
||||||
|
if (!i)
|
||||||
|
return 0;
|
||||||
|
for (n = i-1, c = 0; n >= 0 && str[n] == '\\'; n--,c++);
|
||||||
|
return c & 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cmd_Wait_f
|
Cmd_Wait_f
|
||||||
|
|
||||||
|
@ -160,11 +181,11 @@ extract_line (dstring_t *buffer, dstring_t *line)
|
||||||
char *text = buffer->str;
|
char *text = buffer->str;
|
||||||
|
|
||||||
for (i = 0; text[i]; i++) {
|
for (i = 0; text[i]; i++) {
|
||||||
if (text[i] == '\'' && !dquotes)
|
if (text[i] == '\'' && !escaped(text,i) && !dquotes)
|
||||||
squotes^=1;
|
squotes^=1;
|
||||||
if (text[i] == '"' && !squotes)
|
if (text[i] == '"' && !escaped(text,i) && !squotes)
|
||||||
dquotes^=1;
|
dquotes^=1;
|
||||||
if (text[i] == ';' && !squotes && !dquotes)
|
if (text[i] == ';' && !escaped(text,i) && !squotes && !dquotes)
|
||||||
break;
|
break;
|
||||||
if (text[i] == '\n' || text[i] == '\r')
|
if (text[i] == '\n' || text[i] == '\r')
|
||||||
break;
|
break;
|
||||||
|
@ -189,7 +210,8 @@ void
|
||||||
Cbuf_ExecuteBuffer (dstring_t *buffer)
|
Cbuf_ExecuteBuffer (dstring_t *buffer)
|
||||||
{
|
{
|
||||||
dstring_t *buf = dstring_newstr ();
|
dstring_t *buf = dstring_newstr ();
|
||||||
|
dstring_t *temp = cmd_activebuffer; // save old context
|
||||||
|
cmd_activebuffer = buffer;
|
||||||
while (strlen(buffer->str)) {
|
while (strlen(buffer->str)) {
|
||||||
extract_line (buffer, buf);
|
extract_line (buffer, buf);
|
||||||
Cmd_ExecuteString(buf->str, src_command);
|
Cmd_ExecuteString(buf->str, src_command);
|
||||||
|
@ -200,18 +222,16 @@ Cbuf_ExecuteBuffer (dstring_t *buffer)
|
||||||
dstring_clearstr(buf);
|
dstring_clearstr(buf);
|
||||||
}
|
}
|
||||||
dstring_delete (buf);
|
dstring_delete (buf);
|
||||||
|
cmd_activebuffer = temp; // restore old context
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cbuf_Execute (void)
|
Cbuf_Execute (void)
|
||||||
{
|
{
|
||||||
cmd_activebuffer = cmd_legacybuffer; // Put legacy buffer into context
|
Cbuf_ExecuteBuffer (cmd_buffer); // Console buffer gets precedence
|
||||||
cmd_legacy = true;
|
cmd_legacy = true;
|
||||||
Cbuf_ExecuteBuffer (cmd_activebuffer);
|
Cbuf_ExecuteBuffer (cmd_legacybuffer); // Then legacy/stufftext buffer
|
||||||
cmd_legacy = false;
|
cmd_legacy = false;
|
||||||
cmd_activebuffer = cmd_buffer; // Next, do modern filtered buffer
|
|
||||||
Cbuf_ExecuteBuffer (cmd_activebuffer);
|
|
||||||
cmd_activebuffer = cmd_buffer; // The modern buffer should be in context by default
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Cbuf_Execute_Sets
|
Cbuf_Execute_Sets
|
||||||
|
@ -312,7 +332,7 @@ Cmd_Exec_File (const char *path)
|
||||||
f[len] = 0;
|
f[len] = 0;
|
||||||
Qread (file, f, len);
|
Qread (file, f, len);
|
||||||
Qclose (file);
|
Qclose (file);
|
||||||
Cbuf_InsertText (f);
|
Cbuf_InsertTextTo (cmd_buffer, f); // Always insert into console
|
||||||
free (f);
|
free (f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +355,7 @@ Cmd_Exec_f (void)
|
||||||
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cbuf_InsertText (f);
|
Cbuf_InsertTextTo (cmd_buffer, f); // Always insert into console
|
||||||
Hunk_FreeToLowMark (mark);
|
Hunk_FreeToLowMark (mark);
|
||||||
|
|
||||||
if (!Cvar_Command () && (cmd_warncmd->int_val
|
if (!Cvar_Command () && (cmd_warncmd->int_val
|
||||||
|
|
Loading…
Reference in a new issue