Moved commands from bound keys into a separate buffer, changed the syntax

of for loops to be like that of C, changed math expressions to be
enclosed in #{} instead of #().
This commit is contained in:
Brian Koropoff 2002-04-17 07:05:43 +00:00
parent e677b4acf3
commit 4cb89c69b2
3 changed files with 37 additions and 32 deletions

View file

@ -507,7 +507,7 @@ C_KeyEvent (knum_t key, short unicode, qboolean down)
return; return;
case key_console: case key_console:
if (!con_data.force_commandline) { if (!con_data.force_commandline) {
Cbuf_AddText ("toggleconsole\n"); Cbuf_AddTextTo (cmd_keybindbuffer, "toggleconsole\n");
return; return;
} }
case key_game: case key_game:

View file

@ -68,10 +68,11 @@ each part of QF (console, stufftext, config files and scripts)
that needs one should allocate and maintain its own. that needs one should allocate and maintain its own.
*/ */
cmd_buffer_t *cmd_consolebuffer; // Console buffer cmd_buffer_t *cmd_consolebuffer; // Console buffer
cmd_buffer_t *cmd_legacybuffer; // Server stuffcmd buffer with cmd_buffer_t *cmd_legacybuffer; // Server stuffcmd buffer with
// absolute backwards-compatibility // absolute backwards-compatibility
cmd_buffer_t *cmd_privatebuffer; // Buffer for internal command execution cmd_buffer_t *cmd_privatebuffer; // Buffer for internal command execution
cmd_buffer_t *cmd_activebuffer; // Buffer currently being executed cmd_buffer_t *cmd_keybindbuffer; // Buffer for commands from bound keys
cmd_buffer_t *cmd_activebuffer; // Buffer currently being executed
cmd_buffer_t *cmd_recycled; // Recycled buffers cmd_buffer_t *cmd_recycled; // Recycled buffers
@ -328,11 +329,10 @@ void
Cbuf_Init (void) Cbuf_Init (void)
{ {
cmd_consolebuffer = Cmd_NewBuffer (true); cmd_consolebuffer = Cmd_NewBuffer (true);
cmd_legacybuffer = Cmd_NewBuffer (true); cmd_legacybuffer = Cmd_NewBuffer (true);
cmd_legacybuffer->legacy = true; cmd_legacybuffer->legacy = true;
cmd_privatebuffer = Cmd_NewBuffer (true); cmd_privatebuffer = Cmd_NewBuffer (true);
cmd_keybindbuffer = Cmd_NewBuffer (true);
cmd_activebuffer = cmd_consolebuffer; cmd_activebuffer = cmd_consolebuffer;
@ -539,6 +539,7 @@ Cbuf_ExecuteStack (cmd_buffer_t *buffer)
void void
Cbuf_Execute (void) Cbuf_Execute (void)
{ {
Cbuf_ExecuteStack (cmd_keybindbuffer);
Cbuf_ExecuteStack (cmd_consolebuffer); Cbuf_ExecuteStack (cmd_consolebuffer);
Cbuf_ExecuteStack (cmd_legacybuffer); Cbuf_ExecuteStack (cmd_legacybuffer);
} }
@ -1243,7 +1244,7 @@ int
Cmd_ProcessMath (dstring_t * dstr) Cmd_ProcessMath (dstring_t * dstr)
{ {
dstring_t *statement; dstring_t *statement;
int i, n, paren; int i, n;
float value; float value;
char *temp; char *temp;
int ret = 0; int ret = 0;
@ -1251,21 +1252,12 @@ Cmd_ProcessMath (dstring_t * dstr)
statement = dstring_newstr (); statement = dstring_newstr ();
for (i = 0; i < strlen (dstr->str); i++) { for (i = 0; i < strlen (dstr->str); i++) {
if (dstr->str[i] == '#' && dstr->str[i + 1] == '(' if (dstr->str[i] == '#' && dstr->str[i + 1] == '{'
&& !escaped (dstr->str, i)) { && !escaped (dstr->str, i)) {
paren = 1; n = Cmd_EndBrace (dstr->str+i+1)+1;
for (n = 2;dstr->str[i+n]; n++) { if (n < 0) {
if (dstr->str[i + n] == '(') Cmd_Error ("Unmatched brace in math expression.\n");
paren++;
else if (dstr->str[i + n] == ')') {
paren--;
if (!paren)
break;
}
}
if (paren) {
ret = -1; ret = -1;
Cmd_Error ("Unmatched parenthesis in math expression.\n");
break; break;
} }
/* Copy text between parentheses into a buffer */ /* Copy text between parentheses into a buffer */
@ -1929,20 +1921,33 @@ Cmd_While_f (void) {
void void
Cmd_For_f (void) { Cmd_For_f (void) {
cmd_buffer_t *sub; cmd_buffer_t *sub;
dstring_t *arg1, *init, *cond, *inc;
if (Cmd_Argc() < 4) { if (Cmd_Argc() < 2 || Cmd_Argc() > 3) {
Sys_Printf("Usage: for {initializer} [condition] {commands}\n"); Cmd_Error("Malformed for statement.\n");
return; return;
} }
sub = Cmd_NewBuffer (false); arg1 = dstring_newstr ();
sub->locals = cmd_activebuffer->locals; // Use current local variables init = dstring_newstr ();
sub->loop = true; cond = dstring_newstr ();
dstring_appendstr (sub->looptext, va("ifnot '%s' break\n", Cmd_Argv(2))); inc = dstring_newstr ();
dstring_appendstr (sub->looptext, va("%s\n", Cmd_Argv(4)));
dstring_appendstr (sub->looptext, va("%s", Cmd_Argv(3))); dstring_appendstr (arg1, Cmd_Argv(1));
Cbuf_InsertTextTo (sub, Cmd_Argv(1)); Cbuf_ExtractLine (arg1, init, true);
Cmd_ExecuteSubroutine (sub); Cbuf_ExtractLine (arg1, cond, true);
Cbuf_ExtractLine (arg1, inc, true);
if (!strlen(arg1->str)) {
sub = Cmd_NewBuffer (false);
sub->locals = cmd_activebuffer->locals; // Use current local variables
sub->loop = true;
dstring_appendstr (sub->looptext, va("ifnot '%s' break\n", cond->str));
dstring_appendstr (sub->looptext, va("%s\n", Cmd_Argv(2)));
dstring_appendstr (sub->looptext, va("%s", inc->str));
Cbuf_InsertTextTo (sub, init->str);
Cmd_ExecuteSubroutine (sub);
} else
Cmd_Error("Malformed for statement.\n");
return; return;
} }

View file

@ -400,15 +400,15 @@ Key_Game (knum_t key, short unicode)
if (!keydown[key]) { if (!keydown[key]) {
if (kb[0] == '+') { if (kb[0] == '+') {
snprintf (cmd, sizeof (cmd), "-%s %d\n", kb + 1, key); snprintf (cmd, sizeof (cmd), "-%s %d\n", kb + 1, key);
Cbuf_AddText (cmd); Cbuf_AddTextTo (cmd_keybindbuffer, cmd);
} }
} else if (keydown[key] == 1) { } else if (keydown[key] == 1) {
if (kb[0] == '+') { if (kb[0] == '+') {
snprintf (cmd, sizeof (cmd), "%s %d\n", kb, key); snprintf (cmd, sizeof (cmd), "%s %d\n", kb, key);
Cbuf_AddText (cmd); Cbuf_AddTextTo (cmd_keybindbuffer, cmd);
} else { } else {
snprintf (cmd, sizeof (cmd), "%s\n", kb); snprintf (cmd, sizeof (cmd), "%s\n", kb);
Cbuf_AddText (cmd); Cbuf_AddTextTo (cmd_keybindbuffer, cmd);
} }
} }
return true; return true;