mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-06 07:41:17 +00:00
whitespace clean up
This commit is contained in:
parent
e0aa405e76
commit
b9d364d7b7
1 changed files with 407 additions and 329 deletions
318
libs/util/cmd.c
318
libs/util/cmd.c
|
@ -87,14 +87,16 @@ cmd_source_t cmd_source;
|
||||||
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_keybindbuffer; // Buffer for commands from bound keys
|
cmd_buffer_t *cmd_keybindbuffer; // Buffer for commands from bound keys
|
||||||
cmd_buffer_t *cmd_activebuffer; // Buffer currently being executed
|
cmd_buffer_t *cmd_activebuffer; // Buffer currently being executed
|
||||||
|
|
||||||
cmd_buffer_t *cmd_recycled; // Recycled buffers
|
cmd_buffer_t *cmd_recycled; // Recycled buffers
|
||||||
|
|
||||||
|
|
||||||
cmd_thread_t *cmd_threads; // Detached buffers running by themselves
|
cmd_thread_t *cmd_threads; // Detached buffers running by
|
||||||
|
// themselves
|
||||||
long int cmd_threadid; // The id of the last thread + 1
|
long int cmd_threadid; // The id of the last thread + 1
|
||||||
|
|
||||||
dstring_t *cmd_backtrace;
|
dstring_t *cmd_backtrace;
|
||||||
|
@ -176,7 +178,8 @@ Cmd_LocalFree (void *ele, void *ptr)
|
||||||
|
|
||||||
/* Creates a new token */
|
/* Creates a new token */
|
||||||
cmd_token_t *
|
cmd_token_t *
|
||||||
Cmd_NewToken (void) {
|
Cmd_NewToken (void)
|
||||||
|
{
|
||||||
cmd_token_t *new;
|
cmd_token_t *new;
|
||||||
|
|
||||||
new = calloc (1, sizeof (cmd_token_t));
|
new = calloc (1, sizeof (cmd_token_t));
|
||||||
|
@ -197,8 +200,7 @@ Cmd_NewBuffer (qboolean ownvars)
|
||||||
if (cmd_recycled) { // If we have old buffers lying around
|
if (cmd_recycled) { // If we have old buffers lying around
|
||||||
new = cmd_recycled;
|
new = cmd_recycled;
|
||||||
cmd_recycled = new->next;
|
cmd_recycled = new->next;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
new = calloc (1, sizeof (cmd_buffer_t));
|
new = calloc (1, sizeof (cmd_buffer_t));
|
||||||
new->buffer = dstring_newstr ();
|
new->buffer = dstring_newstr ();
|
||||||
new->line = dstring_newstr ();
|
new->line = dstring_newstr ();
|
||||||
|
@ -223,7 +225,8 @@ Cmd_NewBuffer (qboolean ownvars)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
Cmd_FreeBuffer (cmd_buffer_t *free) {
|
Cmd_FreeBuffer (cmd_buffer_t *free)
|
||||||
|
{
|
||||||
if (free->ownvars)
|
if (free->ownvars)
|
||||||
Hash_DelTable (free->locals); // Local variables are always deadbeef
|
Hash_DelTable (free->locals); // Local variables are always deadbeef
|
||||||
free->subroutine = false;
|
free->subroutine = false;
|
||||||
|
@ -249,7 +252,8 @@ Cmd_FreeBuffer (cmd_buffer_t *free) {
|
||||||
|
|
||||||
/* Frees an entire linked list (stack) of buffers */
|
/* Frees an entire linked list (stack) of buffers */
|
||||||
void
|
void
|
||||||
Cmd_FreeStack (cmd_buffer_t *stack) {
|
Cmd_FreeStack (cmd_buffer_t *stack)
|
||||||
|
{
|
||||||
cmd_buffer_t *temp;
|
cmd_buffer_t *temp;
|
||||||
|
|
||||||
for (; stack; stack = temp) {
|
for (; stack; stack = temp) {
|
||||||
|
@ -262,7 +266,8 @@ Cmd_FreeStack (cmd_buffer_t *stack) {
|
||||||
|
|
||||||
/* Creates a new thread */
|
/* Creates a new thread */
|
||||||
cmd_thread_t *
|
cmd_thread_t *
|
||||||
Cmd_NewThread (long int id) {
|
Cmd_NewThread (long int id)
|
||||||
|
{
|
||||||
cmd_thread_t *new;
|
cmd_thread_t *new;
|
||||||
|
|
||||||
new = calloc (1, sizeof (cmd_thread_t));
|
new = calloc (1, sizeof (cmd_thread_t));
|
||||||
|
@ -275,7 +280,8 @@ Cmd_NewThread (long int id) {
|
||||||
|
|
||||||
/* Frees a thread */
|
/* Frees a thread */
|
||||||
void
|
void
|
||||||
Cmd_FreeThread (cmd_thread_t *thread) {
|
Cmd_FreeThread (cmd_thread_t *thread)
|
||||||
|
{
|
||||||
Cmd_FreeBuffer (thread->cbuf);
|
Cmd_FreeBuffer (thread->cbuf);
|
||||||
free (thread);
|
free (thread);
|
||||||
return;
|
return;
|
||||||
|
@ -283,7 +289,8 @@ Cmd_FreeThread (cmd_thread_t *thread) {
|
||||||
|
|
||||||
/* Adds a thread to a linked list */
|
/* Adds a thread to a linked list */
|
||||||
void
|
void
|
||||||
Cmd_AddThread (cmd_thread_t **list, cmd_thread_t *thread) {
|
Cmd_AddThread (cmd_thread_t **list, cmd_thread_t *thread)
|
||||||
|
{
|
||||||
thread->next = *list;
|
thread->next = *list;
|
||||||
thread->prev = 0;
|
thread->prev = 0;
|
||||||
if (*list)
|
if (*list)
|
||||||
|
@ -293,7 +300,8 @@ Cmd_AddThread (cmd_thread_t **list, cmd_thread_t *thread) {
|
||||||
|
|
||||||
/* Removes a thread from a linked list and frees it */
|
/* Removes a thread from a linked list and frees it */
|
||||||
void
|
void
|
||||||
Cmd_RemoveThread (cmd_thread_t **list, cmd_thread_t *thread) {
|
Cmd_RemoveThread (cmd_thread_t **list, cmd_thread_t *thread)
|
||||||
|
{
|
||||||
if (thread == *list)
|
if (thread == *list)
|
||||||
*list = thread->next;
|
*list = thread->next;
|
||||||
if (thread->next)
|
if (thread->next)
|
||||||
|
@ -309,22 +317,19 @@ Cmd_RemoveThread (cmd_thread_t **list, cmd_thread_t *thread) {
|
||||||
/* Escape character functions used by most of the parser */
|
/* Escape character functions used by most of the parser */
|
||||||
|
|
||||||
/* Determines if a character is escaped */
|
/* Determines if a character is escaped */
|
||||||
inline
|
inline qboolean
|
||||||
qboolean
|
|
||||||
escaped (const char *str, int i)
|
escaped (const char *str, int i)
|
||||||
{
|
{
|
||||||
int n, c;
|
int n, c;
|
||||||
|
|
||||||
if (!i)
|
if (!i)
|
||||||
return 0;
|
return 0;
|
||||||
for (n = i - 1, c = 0; n >= 0 && str[n] == '\\'; n--, c++)
|
for (n = i - 1, c = 0; n >= 0 && str[n] == '\\'; n--, c++);
|
||||||
;
|
|
||||||
return c & 1;
|
return c & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Escapes a list of characters in a dstring */
|
/* Escapes a list of characters in a dstring */
|
||||||
inline
|
inline void
|
||||||
void
|
|
||||||
escape (dstring_t *dstr, const char *clist)
|
escape (dstring_t *dstr, const char *clist)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -339,8 +344,7 @@ escape (dstring_t * dstr, const char *clist)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unescapes a character and all backslashes preceding it in a dstring */
|
/* Unescapes a character and all backslashes preceding it in a dstring */
|
||||||
inline
|
inline int
|
||||||
int
|
|
||||||
unescape (dstring_t *dstr, int start)
|
unescape (dstring_t *dstr, int start)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -436,8 +440,7 @@ Cbuf_ExtractLine (dstring_t * buffer, dstring_t * line, qboolean legacy)
|
||||||
else if (!legacy && buffer->str[i] == '}' && !dquotes)
|
else if (!legacy && buffer->str[i] == '}' && !dquotes)
|
||||||
braces--;
|
braces--;
|
||||||
}
|
}
|
||||||
if (buffer->str[i] == '/' && buffer->str[i + 1] == '/'
|
if (buffer->str[i] == '/' && buffer->str[i + 1] == '/' && !dquotes) {
|
||||||
&& !dquotes) {
|
|
||||||
// Filter out comments until newline
|
// Filter out comments until newline
|
||||||
if ((tmp = strchr (buffer->str + i, '\n')))
|
if ((tmp = strchr (buffer->str + i, '\n')))
|
||||||
n = tmp - (buffer->str + i);
|
n = tmp - (buffer->str + i);
|
||||||
|
@ -447,8 +450,8 @@ Cbuf_ExtractLine (dstring_t * buffer, dstring_t * line, qboolean legacy)
|
||||||
n = strlen (buffer->str + i); // snip till \0
|
n = strlen (buffer->str + i); // snip till \0
|
||||||
dstring_snip (buffer, i, n);
|
dstring_snip (buffer, i, n);
|
||||||
i--;
|
i--;
|
||||||
}
|
} else if ((buffer->str[i] == '\n' || buffer->str[i] == '\r')
|
||||||
else if ((buffer->str[i] == '\n' || buffer->str[i] == '\r') && !braces) {
|
&& !braces) {
|
||||||
if (escaped (buffer->str, i)) {
|
if (escaped (buffer->str, i)) {
|
||||||
dstring_snip (buffer, i - 1, 2);
|
dstring_snip (buffer, i - 1, 2);
|
||||||
i -= 2;
|
i -= 2;
|
||||||
|
@ -490,6 +493,7 @@ Cbuf_ExecuteBuffer (cmd_buffer_t *buffer)
|
||||||
|
|
||||||
if (buffer->timeleft) {
|
if (buffer->timeleft) {
|
||||||
double newtime = Sys_DoubleTime ();
|
double newtime = Sys_DoubleTime ();
|
||||||
|
|
||||||
buffer->timeleft -= newtime - buffer->lasttime;
|
buffer->timeleft -= newtime - buffer->lasttime;
|
||||||
buffer->lasttime = newtime;
|
buffer->lasttime = newtime;
|
||||||
if (buffer->timeleft < 0.0)
|
if (buffer->timeleft < 0.0)
|
||||||
|
@ -505,14 +509,14 @@ Cbuf_ExecuteBuffer (cmd_buffer_t *buffer)
|
||||||
if (!strlen (buffer->buffer->str) && buffer->position == cmd_ready) {
|
if (!strlen (buffer->buffer->str) && buffer->position == cmd_ready) {
|
||||||
if (buffer->loop) {
|
if (buffer->loop) {
|
||||||
if (cmd_maxloop->value && buffer->loop > cmd_maxloop->value) {
|
if (cmd_maxloop->value && buffer->loop > cmd_maxloop->value) {
|
||||||
Cmd_Error(va("GIB: Loop lasted longer than %i iterations, forcefully terminating.\n",
|
Cmd_Error (va
|
||||||
|
("GIB: Loop lasted longer than %i iterations, forcefully terminating.\n",
|
||||||
(int) cmd_maxloop->value));
|
(int) cmd_maxloop->value));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Cbuf_InsertTextTo (buffer, buffer->looptext->str);
|
Cbuf_InsertTextTo (buffer, buffer->looptext->str);
|
||||||
buffer->loop++;
|
buffer->loop++;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,7 +573,8 @@ Cbuf_ExecuteStack (cmd_buffer_t *buffer)
|
||||||
Cbuf_ExecuteBuffer (cur);
|
Cbuf_ExecuteBuffer (cur);
|
||||||
if (cmd_error || cur->wait)
|
if (cmd_error || cur->wait)
|
||||||
break;
|
break;
|
||||||
if (cur->subroutine) { // Something was added to the stack, follow it
|
if (cur->subroutine) { // Something was added to the stack,
|
||||||
|
// follow it
|
||||||
cur->subroutine = false;
|
cur->subroutine = false;
|
||||||
temp = cur->next;
|
temp = cur->next;
|
||||||
continue;
|
continue;
|
||||||
|
@ -631,7 +636,8 @@ Cbuf_ExecuteSubroutine (cmd_buffer_t *buffer)
|
||||||
Cmd_FreeStack (cmd_activebuffer->next);
|
Cmd_FreeStack (cmd_activebuffer->next);
|
||||||
cmd_activebuffer->next = buffer; // Link it in
|
cmd_activebuffer->next = buffer; // Link it in
|
||||||
buffer->prev = cmd_activebuffer;
|
buffer->prev = cmd_activebuffer;
|
||||||
cmd_activebuffer->subroutine = true; // Signal that a subroutine is beginning
|
cmd_activebuffer->subroutine = true; // Signal that a subroutine is
|
||||||
|
// beginning
|
||||||
if (cmd_activebuffer->restricted)
|
if (cmd_activebuffer->restricted)
|
||||||
buffer->restricted = true;
|
buffer->restricted = true;
|
||||||
return;
|
return;
|
||||||
|
@ -654,7 +660,8 @@ Cbuf_Execute_Sets (void)
|
||||||
dstring_t *buf = dstring_newstr ();
|
dstring_t *buf = dstring_newstr ();
|
||||||
|
|
||||||
while (strlen (cmd_consolebuffer->buffer->str)) {
|
while (strlen (cmd_consolebuffer->buffer->str)) {
|
||||||
Cbuf_ExtractLine (cmd_consolebuffer->buffer, buf, cmd_consolebuffer->legacy);
|
Cbuf_ExtractLine (cmd_consolebuffer->buffer, buf,
|
||||||
|
cmd_consolebuffer->legacy);
|
||||||
if (!strncmp (buf->str, "set", 3) && isspace ((int) buf->str[3])) {
|
if (!strncmp (buf->str, "set", 3) && isspace ((int) buf->str[3])) {
|
||||||
Cmd_ExecuteString (buf->str, src_command);
|
Cmd_ExecuteString (buf->str, src_command);
|
||||||
} else if (!strncmp (buf->str, "setrom", 6)
|
} else if (!strncmp (buf->str, "setrom", 6)
|
||||||
|
@ -700,8 +707,7 @@ Cmd_StuffCmds_f (void)
|
||||||
for (j = i; !((com_cmdline[j] == '+')
|
for (j = i; !((com_cmdline[j] == '+')
|
||||||
|| (com_cmdline[j] == '-'
|
|| (com_cmdline[j] == '-'
|
||||||
&& (j == 0 || com_cmdline[j - 1] == ' '))
|
&& (j == 0 || com_cmdline[j - 1] == ' '))
|
||||||
|| (com_cmdline[j] == 0)); j++)
|
|| (com_cmdline[j] == 0)); j++);
|
||||||
;
|
|
||||||
|
|
||||||
c = com_cmdline[j];
|
c = com_cmdline[j];
|
||||||
com_cmdline[j] = 0;
|
com_cmdline[j] = 0;
|
||||||
|
@ -767,13 +773,16 @@ Cmd_Error (const char *message)
|
||||||
/* Returns a value to the previous buffer
|
/* Returns a value to the previous buffer
|
||||||
in the stack, but only if it wants one */
|
in the stack, but only if it wants one */
|
||||||
void
|
void
|
||||||
Cmd_Return (const char *value) {
|
Cmd_Return (const char *value)
|
||||||
if (cmd_activebuffer->prev && cmd_activebuffer->prev->returned == cmd_waiting) {
|
{
|
||||||
|
if (cmd_activebuffer->prev
|
||||||
|
&& cmd_activebuffer->prev->returned == cmd_waiting) {
|
||||||
dstring_clearstr (cmd_activebuffer->prev->retval);
|
dstring_clearstr (cmd_activebuffer->prev->retval);
|
||||||
dstring_appendstr (cmd_activebuffer->prev->retval, value);
|
dstring_appendstr (cmd_activebuffer->prev->retval, value);
|
||||||
cmd_activebuffer->prev->returned = cmd_returned;
|
cmd_activebuffer->prev->returned = cmd_returned;
|
||||||
} else
|
} else
|
||||||
Sys_DPrintf ("GIB warning: Return value \"%s\" was unwanted.\n", value);
|
Sys_DPrintf ("GIB warning: Return value \"%s\" was unwanted.\n",
|
||||||
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -947,8 +956,7 @@ Cmd_GetToken (const char *str, qboolean legacy)
|
||||||
return ret;
|
return ret;
|
||||||
i += ret;
|
i += ret;
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (str[i] == '}' && !legacy)
|
||||||
else if (str[i] == '}' && !legacy)
|
|
||||||
return -1;
|
return -1;
|
||||||
else if (str[i] == '\"') {
|
else if (str[i] == '\"') {
|
||||||
ret = Cmd_EndDoubleQuote (str + i, legacy);
|
ret = Cmd_EndDoubleQuote (str + i, legacy);
|
||||||
|
@ -975,27 +983,21 @@ struct stable_s {
|
||||||
char a, b;
|
char a, b;
|
||||||
} stable1[] = {
|
} stable1[] = {
|
||||||
{'f', 0x0D}, // Fake message
|
{'f', 0x0D}, // Fake message
|
||||||
|
|
||||||
{'[', 0x90}, // Gold braces
|
{'[', 0x90}, // Gold braces
|
||||||
{']', 0x91},
|
{']', 0x91},
|
||||||
|
|
||||||
{'(', 0x80}, // Scroll bar characters
|
{'(', 0x80}, // Scroll bar characters
|
||||||
{'=', 0x81},
|
{'=', 0x81},
|
||||||
{')', 0x82},
|
{')', 0x82},
|
||||||
{'|', 0x83},
|
{'|', 0x83},
|
||||||
|
|
||||||
{'<', 0x9D}, // Vertical line characters
|
{'<', 0x9D}, // Vertical line characters
|
||||||
{'-', 0x9E},
|
{'-', 0x9E},
|
||||||
{'>', 0x9F},
|
{'>', 0x9F},
|
||||||
|
|
||||||
{'.', 0x05}, // White dot
|
{'.', 0x05}, // White dot
|
||||||
|
|
||||||
{'#', 0x0B}, // White block
|
{'#', 0x0B}, // White block
|
||||||
|
|
||||||
{'a', 0x7F}, // White arrow.
|
{'a', 0x7F}, // White arrow.
|
||||||
// DO NOT USE <s>a</s> WITH <b> TAG IN ANYTHING SENT TO SERVER. PERIOD.
|
// DO NOT USE <s>a</s> WITH <b> TAG IN ANYTHING SENT TO SERVER.
|
||||||
|
// PERIOD.
|
||||||
{'A', 0x8D}, // Brown arrow
|
{'A', 0x8D}, // Brown arrow
|
||||||
|
|
||||||
{'0', 0x92}, // Golden numbers
|
{'0', 0x92}, // Golden numbers
|
||||||
{'1', 0x93},
|
{'1', 0x93},
|
||||||
{'2', 0x94},
|
{'2', 0x94},
|
||||||
|
@ -1029,8 +1031,7 @@ Cmd_ProcessTags (dstring_t * dstr)
|
||||||
if (dstr->str[i] == '<' && !escaped (dstr->str, i)) {
|
if (dstr->str[i] == '<' && !escaped (dstr->str, i)) {
|
||||||
close = 0;
|
close = 0;
|
||||||
for (n = 1;
|
for (n = 1;
|
||||||
dstr->str[i+n] != '>' || escaped (dstr->str, i + n);
|
dstr->str[i + n] != '>' || escaped (dstr->str, i + n); n++)
|
||||||
n++)
|
|
||||||
if (dstr->str[i + n] == 0)
|
if (dstr->str[i + n] == 0)
|
||||||
return;
|
return;
|
||||||
if (dstr->str[i + 1] == '/')
|
if (dstr->str[i + 1] == '/')
|
||||||
|
@ -1089,7 +1090,8 @@ 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] == '{' && !escaped (dstr->str, i)) {
|
if (dstr->str[i] == '#' && dstr->str[i + 1] == '{'
|
||||||
|
&& !escaped (dstr->str, i)) {
|
||||||
n = Cmd_EndBrace (dstr->str + i + 1) + 1;
|
n = Cmd_EndBrace (dstr->str + i + 1) + 1;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
Cmd_Error ("Unmatched brace in math expression.\n");
|
Cmd_Error ("Unmatched brace in math expression.\n");
|
||||||
|
@ -1107,7 +1109,9 @@ Cmd_ProcessMath (dstring_t * dstr)
|
||||||
i += strlen (temp) - 1;
|
i += strlen (temp) - 1;
|
||||||
} else {
|
} else {
|
||||||
ret = -2;
|
ret = -2;
|
||||||
Cmd_Error (va("Math error: invalid expression %s\n", statement->str));
|
Cmd_Error (va
|
||||||
|
("Math error: invalid expression %s\n",
|
||||||
|
statement->str));
|
||||||
break; // Math evaluation error
|
break; // Math evaluation error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1180,7 +1184,8 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
||||||
braces = 1;
|
braces = 1;
|
||||||
for (i = start + 1 + braces;; i++) {
|
for (i = start + 1 + braces;; i++) {
|
||||||
if (!escaped (dstr->str, i)) {
|
if (!escaped (dstr->str, i)) {
|
||||||
// If we are within braces or two $ appear next to each other, consider it recursive
|
// If we are within braces or two $ appear next to each other,
|
||||||
|
// consider it recursive
|
||||||
if (dstr->str[i] == '$' && (braces || dstr->str[i - 1] == '$')) {
|
if (dstr->str[i] == '$' && (braces || dstr->str[i - 1] == '$')) {
|
||||||
n = Cmd_ProcessVariablesRecursive (dstr, i);
|
n = Cmd_ProcessVariablesRecursive (dstr, i);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
@ -1189,10 +1194,14 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
||||||
i += n - 1;
|
i += n - 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if ((braces && dstr->str[i] == '}') || (!braces && !isalnum((byte)dstr->str[i]) && dstr->str[i] != '_')) {
|
} else if ((braces && dstr->str[i] == '}')
|
||||||
|
|| (!braces && !isalnum ((byte) dstr->str[i])
|
||||||
|
&& dstr->str[i] != '_')) {
|
||||||
dstring_t *varname = dstring_newstr ();
|
dstring_t *varname = dstring_newstr ();
|
||||||
dstring_t *copy = dstring_newstr ();
|
dstring_t *copy = dstring_newstr ();
|
||||||
dstring_insert (varname, dstr->str + start + 1 + braces, i - start - 1 - braces, 0);
|
|
||||||
|
dstring_insert (varname, dstr->str + start + 1 + braces,
|
||||||
|
i - start - 1 - braces, 0);
|
||||||
// Nuke it, even if no match is found
|
// Nuke it, even if no match is found
|
||||||
dstring_snip (dstr, start, i - start + braces);
|
dstring_snip (dstr, start, i - start + braces);
|
||||||
lvar = (cmd_localvar_t *) Hash_Find (cmd_activebuffer->locals,
|
lvar = (cmd_localvar_t *) Hash_Find (cmd_activebuffer->locals,
|
||||||
|
@ -1208,19 +1217,23 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
||||||
dstring_clearstr (varname); // Reuse variable
|
dstring_clearstr (varname); // Reuse variable
|
||||||
if (dstr->str[start] == '[') {
|
if (dstr->str[start] == '[') {
|
||||||
int val1, val2, res;
|
int val1, val2, res;
|
||||||
|
|
||||||
res = Cmd_ProcessIndex (dstr, start, &val1, &val2);
|
res = Cmd_ProcessIndex (dstr, start, &val1, &val2);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
n = -1;
|
n = -1;
|
||||||
else if (val1 >= strlen (copy->str) || val1 < 0)
|
else if (val1 >= strlen (copy->str) || val1 < 0)
|
||||||
n = 0;
|
n = 0;
|
||||||
else if (val2 < strlen (copy->str))
|
else if (val2 < strlen (copy->str))
|
||||||
dstring_insert (varname, copy->str+val1, val2-val1+1, 0);
|
dstring_insert (varname, copy->str + val1,
|
||||||
|
val2 - val1 + 1, 0);
|
||||||
else
|
else
|
||||||
dstring_insert (varname, copy->str+val1, strlen(copy->str)-val1, 0);
|
dstring_insert (varname, copy->str + val1,
|
||||||
|
strlen (copy->str) - val1, 0);
|
||||||
} else
|
} else
|
||||||
dstring_appendstr (varname, copy->str);
|
dstring_appendstr (varname, copy->str);
|
||||||
if (n >= 0) {
|
if (n >= 0) {
|
||||||
escape (varname, "<#\\"); // Preserve backslashes, tags, and math as unprocessed
|
escape (varname, "<#\\"); // Preserve backslashes, tags,
|
||||||
|
// and math as unprocessed
|
||||||
dstring_insertstr (dstr, varname->str, start);
|
dstring_insertstr (dstr, varname->str, start);
|
||||||
n = strlen (varname->str);
|
n = strlen (varname->str);
|
||||||
}
|
}
|
||||||
|
@ -1230,7 +1243,8 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!dstr->str[i] && braces) { // No closing brace
|
if (!dstr->str[i] && braces) { // No closing brace
|
||||||
Cmd_Error ("Unmatched brace in variable substitution expression.\n");
|
Cmd_Error
|
||||||
|
("Unmatched brace in variable substitution expression.\n");
|
||||||
n = -1;
|
n = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1280,7 +1294,8 @@ Cmd_ProcessEmbeddedSingle (dstring_t * dstr, int start)
|
||||||
}
|
}
|
||||||
if (cmd_activebuffer->returned == cmd_waiting) {
|
if (cmd_activebuffer->returned == cmd_waiting) {
|
||||||
cmd_activebuffer->returned = cmd_normal;
|
cmd_activebuffer->returned = cmd_normal;
|
||||||
Cmd_Error ("Embedded command expression did not result in a return value.\n");
|
Cmd_Error
|
||||||
|
("Embedded command expression did not result in a return value.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (cmd_activebuffer->returned == cmd_returned) {
|
if (cmd_activebuffer->returned == cmd_returned) {
|
||||||
|
@ -1312,7 +1327,8 @@ Cmd_ProcessEmbedded (cmd_token_t *tok, dstring_t * dstr)
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
for (i = tok->pos; i < strlen (dstr->str); i++) {
|
for (i = tok->pos; i < strlen (dstr->str); i++) {
|
||||||
if (dstr->str[i] == '~' && dstr->str[i+1] == '{' && !escaped (dstr->str, i)) {
|
if (dstr->str[i] == '~' && dstr->str[i + 1] == '{'
|
||||||
|
&& !escaped (dstr->str, i)) {
|
||||||
n = Cmd_ProcessEmbeddedSingle (dstr, i);
|
n = Cmd_ProcessEmbeddedSingle (dstr, i);
|
||||||
if (n == -2) {
|
if (n == -2) {
|
||||||
tok->pos = i;
|
tok->pos = i;
|
||||||
|
@ -1401,12 +1417,16 @@ Cmd_Process (void)
|
||||||
unsigned int adj = 0;
|
unsigned int adj = 0;
|
||||||
cmd_function_t *cmd;
|
cmd_function_t *cmd;
|
||||||
|
|
||||||
if (cmd_activebuffer->legacy) // Legacy buffers will never require processing, ever
|
if (cmd_activebuffer->legacy) // Legacy buffers will never require
|
||||||
|
// processing, ever
|
||||||
return 0;
|
return 0;
|
||||||
if (!Cmd_Argc ()) // No tokens, don't bother
|
if (!Cmd_Argc ()) // No tokens, don't bother
|
||||||
return 0;
|
return 0;
|
||||||
cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_activebuffer->argv[0]->original->str);
|
cmd =
|
||||||
if (cmd && cmd->pure) // If the function is pure, don't bother processing
|
(cmd_function_t *) Hash_Find (cmd_hash,
|
||||||
|
cmd_activebuffer->argv[0]->original->str);
|
||||||
|
if (cmd && cmd->pure) // If the function is pure, don't
|
||||||
|
// bother processing
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
tag_shift = 0;
|
tag_shift = 0;
|
||||||
|
@ -1421,8 +1441,8 @@ Cmd_Process (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here we edit the composite command line to reflect
|
/* Here we edit the composite command line to reflect the changes made to
|
||||||
the changes made to individual tokens. */
|
individual tokens. */
|
||||||
dstring_clearstr (cmd_activebuffer->line);
|
dstring_clearstr (cmd_activebuffer->line);
|
||||||
dstring_appendstr (cmd_activebuffer->line, cmd_activebuffer->realline->str);
|
dstring_appendstr (cmd_activebuffer->line, cmd_activebuffer->realline->str);
|
||||||
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
||||||
|
@ -1438,7 +1458,9 @@ Cmd_Process (void)
|
||||||
cmd_activebuffer->args[arg] = cmd_activebuffer->argsu[arg] + adj;
|
cmd_activebuffer->args[arg] = cmd_activebuffer->argsu[arg] + adj;
|
||||||
adj += (str->size - 1) - (org->size - 1);
|
adj += (str->size - 1) - (org->size - 1);
|
||||||
dstring_replace (cmd_activebuffer->line, str->str, str->size - 1,
|
dstring_replace (cmd_activebuffer->line, str->str, str->size - 1,
|
||||||
cmd_activebuffer->args[arg] + quotes + (cmd_activebuffer->argv[arg]->delim == '{'), org->size - 1);
|
cmd_activebuffer->args[arg] + quotes +
|
||||||
|
(cmd_activebuffer->argv[arg]->delim == '{'),
|
||||||
|
org->size - 1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1476,7 +1498,8 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
||||||
cmd_argc++;
|
cmd_argc++;
|
||||||
if (cmd_argc > cmd_activebuffer->maxargc) {
|
if (cmd_argc > cmd_activebuffer->maxargc) {
|
||||||
cmd_activebuffer->argv = realloc (cmd_activebuffer->argv,
|
cmd_activebuffer->argv = realloc (cmd_activebuffer->argv,
|
||||||
sizeof (cmd_token_t *) * cmd_argc);
|
sizeof (cmd_token_t *) *
|
||||||
|
cmd_argc);
|
||||||
SYS_CHECKMEM (cmd_activebuffer->argv);
|
SYS_CHECKMEM (cmd_activebuffer->argv);
|
||||||
cmd_activebuffer->argsu = realloc (cmd_activebuffer->argsu,
|
cmd_activebuffer->argsu = realloc (cmd_activebuffer->argsu,
|
||||||
sizeof (int) * cmd_argc);
|
sizeof (int) * cmd_argc);
|
||||||
|
@ -1506,7 +1529,8 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
||||||
cmd_activebuffer->argv[cmd_argc - 1]->delim = '{';
|
cmd_activebuffer->argv[cmd_argc - 1]->delim = '{';
|
||||||
} else
|
} else
|
||||||
cmd_activebuffer->argv[cmd_argc - 1]->delim = ' ';
|
cmd_activebuffer->argv[cmd_argc - 1]->delim = ' ';
|
||||||
dstring_insert (cmd_activebuffer->argv[cmd_argc-1]->original, str + i, len, 0);
|
dstring_insert (cmd_activebuffer->argv[cmd_argc - 1]->original, str + i,
|
||||||
|
len, 0);
|
||||||
if (!legacy && !braces && process)
|
if (!legacy && !braces && process)
|
||||||
cmd_activebuffer->argv[cmd_argc - 1]->state = cmd_process;
|
cmd_activebuffer->argv[cmd_argc - 1]->state = cmd_process;
|
||||||
else
|
else
|
||||||
|
@ -1550,7 +1574,6 @@ Cmd_ExecuteParsed (cmd_source_t src)
|
||||||
Cmd_SetLocal (cmd_activebuffer, Cmd_Argv (0), Cmd_Argv (2));
|
Cmd_SetLocal (cmd_activebuffer, Cmd_Argv (0), Cmd_Argv (2));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check alias
|
// check alias
|
||||||
|
|
||||||
|
|
||||||
|
@ -1559,10 +1582,12 @@ Cmd_ExecuteParsed (cmd_source_t src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Executes a single command in an internal buffer context */
|
/* Executes a single command in an internal buffer context */
|
||||||
int Cmd_ExecuteString (const char *text, cmd_source_t src)
|
int
|
||||||
|
Cmd_ExecuteString (const char *text, cmd_source_t src)
|
||||||
{
|
{
|
||||||
cmd_buffer_t *old = cmd_activebuffer; // Save context
|
cmd_buffer_t *old = cmd_activebuffer; // Save context
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cmd_activebuffer = cmd_privatebuffer;
|
cmd_activebuffer = cmd_privatebuffer;
|
||||||
Cmd_TokenizeString (text, cmd_activebuffer->legacy);
|
Cmd_TokenizeString (text, cmd_activebuffer->legacy);
|
||||||
if (!Cmd_Argc ()) {
|
if (!Cmd_Argc ()) {
|
||||||
|
@ -1842,7 +1867,8 @@ cmd_get_key (void *c, void *unused)
|
||||||
return cmd->name;
|
return cmd->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cmd_Runalias_f (void)
|
void
|
||||||
|
Cmd_Runalias_f (void)
|
||||||
{
|
{
|
||||||
cmdalias_t *a;
|
cmdalias_t *a;
|
||||||
|
|
||||||
|
@ -1850,7 +1876,8 @@ void Cmd_Runalias_f (void)
|
||||||
|
|
||||||
if (a) {
|
if (a) {
|
||||||
int i;
|
int i;
|
||||||
cmd_buffer_t *sub; // Create a new buffer to execute the alias in
|
cmd_buffer_t *sub; // Create a new buffer to execute the
|
||||||
|
// alias in
|
||||||
sub = Cmd_NewBuffer (true);
|
sub = Cmd_NewBuffer (true);
|
||||||
sub->restricted = a->restricted;
|
sub->restricted = a->restricted;
|
||||||
sub->legacy = a->legacy;
|
sub->legacy = a->legacy;
|
||||||
|
@ -1861,8 +1888,10 @@ void Cmd_Runalias_f (void)
|
||||||
Cbuf_ExecuteSubroutine (sub);
|
Cbuf_ExecuteSubroutine (sub);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
Sys_Printf ("BUG: No alias found for registered command. Please report this to the QuakeForge development team.");
|
Sys_Printf
|
||||||
Cmd_Error ("Fatal bug encountered. Execution aborted. Please contact the QuakeForge team.");
|
("BUG: No alias found for registered command. Please report this to the QuakeForge development team.");
|
||||||
|
Cmd_Error
|
||||||
|
("Fatal bug encountered. Execution aborted. Please contact the QuakeForge team.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1947,8 +1976,7 @@ Cmd_UnAlias_f (void)
|
||||||
|
|
||||||
Cmd_RemoveCommand (alias->name);
|
Cmd_RemoveCommand (alias->name);
|
||||||
|
|
||||||
for (a = &cmd_alias; *a != alias; a = &(*a)->next)
|
for (a = &cmd_alias; *a != alias; a = &(*a)->next);
|
||||||
;
|
|
||||||
*a = alias->next;
|
*a = alias->next;
|
||||||
|
|
||||||
free ((char *) alias->name);
|
free ((char *) alias->name);
|
||||||
|
@ -1965,6 +1993,7 @@ void
|
||||||
Cmd_Wait_f (void)
|
Cmd_Wait_f (void)
|
||||||
{
|
{
|
||||||
cmd_buffer_t *cur;
|
cmd_buffer_t *cur;
|
||||||
|
|
||||||
for (cur = cmd_activebuffer; cur; cur = cur->prev)
|
for (cur = cmd_activebuffer; cur; cur = cur->prev)
|
||||||
cur->wait = true;
|
cur->wait = true;
|
||||||
}
|
}
|
||||||
|
@ -2020,8 +2049,7 @@ Cmd_Help_f (void)
|
||||||
name = Cmd_Argv (1);
|
name = Cmd_Argv (1);
|
||||||
|
|
||||||
for (cmd = cmd_functions; cmd && strcasecmp (name, cmd->name);
|
for (cmd = cmd_functions; cmd && strcasecmp (name, cmd->name);
|
||||||
cmd = cmd->next)
|
cmd = cmd->next);
|
||||||
;
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
Sys_Printf ("%s\n", cmd->description);
|
Sys_Printf ("%s\n", cmd->description);
|
||||||
return;
|
return;
|
||||||
|
@ -2053,21 +2081,21 @@ Cmd_If_f (void)
|
||||||
long int num;
|
long int num;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((Cmd_Argc () !=3 && !(Cmd_Argc () >= 5)) || (Cmd_Argc () > 5 && strcmp(Cmd_Argv(3),"else"))) {
|
if ((Cmd_Argc () != 3 && !(Cmd_Argc () >= 5))
|
||||||
|
|| (Cmd_Argc () > 5 && strcmp (Cmd_Argv (3), "else"))) {
|
||||||
Cmd_Error ("Malformed if statement.\n");
|
Cmd_Error ("Malformed if statement.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HACK HACK HACK
|
/* HACK HACK HACK If is set as a pure command, but it needs the first
|
||||||
If is set as a pure command, but it needs the first argument
|
argument to be evaluated. Normally this would mean Cmd_Args is out of
|
||||||
to be evaluated. Normally this would mean Cmd_Args is out
|
sync, but since if uses Cmd_Argsu (4) and no other commands will need
|
||||||
of sync, but since if uses Cmd_Argsu (4) and no other commands
|
these tokens, it is safe. */
|
||||||
will need these tokens, it is safe.
|
|
||||||
*/
|
|
||||||
ret = Cmd_ProcessToken (cmd_activebuffer->argv[1]);
|
ret = Cmd_ProcessToken (cmd_activebuffer->argv[1]);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret == -2)
|
if (ret == -2)
|
||||||
cmd_activebuffer->again = true; // Embedded command needs a return value first
|
cmd_activebuffer->again = true; // Embedded command needs a return
|
||||||
|
// value first
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2089,7 +2117,8 @@ Cmd_If_f (void)
|
||||||
/* Executes a block of code while a condition
|
/* Executes a block of code while a condition
|
||||||
is met */
|
is met */
|
||||||
void
|
void
|
||||||
Cmd_While_f (void) {
|
Cmd_While_f (void)
|
||||||
|
{
|
||||||
cmd_buffer_t *sub;
|
cmd_buffer_t *sub;
|
||||||
|
|
||||||
if (Cmd_Argc () < 3) {
|
if (Cmd_Argc () < 3) {
|
||||||
|
@ -2101,11 +2130,14 @@ Cmd_While_f (void) {
|
||||||
sub->locals = cmd_activebuffer->locals; // Use current local variables
|
sub->locals = cmd_activebuffer->locals; // Use current local variables
|
||||||
sub->loop = true;
|
sub->loop = true;
|
||||||
if (cmd_activebuffer->argv[1]->delim == '{')
|
if (cmd_activebuffer->argv[1]->delim == '{')
|
||||||
dstring_appendstr (sub->looptext, va("ifnot {%s} break\n", Cmd_Argv(1)));
|
dstring_appendstr (sub->looptext,
|
||||||
|
va ("ifnot {%s} break\n", Cmd_Argv (1)));
|
||||||
else if (cmd_activebuffer->argv[1]->delim == '\"')
|
else if (cmd_activebuffer->argv[1]->delim == '\"')
|
||||||
dstring_appendstr (sub->looptext, va("ifnot \"%s\" break\n", Cmd_Argv(1)));
|
dstring_appendstr (sub->looptext,
|
||||||
|
va ("ifnot \"%s\" break\n", Cmd_Argv (1)));
|
||||||
else
|
else
|
||||||
dstring_appendstr (sub->looptext, va("ifnot %s break\n", Cmd_Argv(1)));
|
dstring_appendstr (sub->looptext,
|
||||||
|
va ("ifnot %s break\n", Cmd_Argv (1)));
|
||||||
dstring_appendstr (sub->looptext, Cmd_Argv (2));
|
dstring_appendstr (sub->looptext, Cmd_Argv (2));
|
||||||
Cbuf_ExecuteSubroutine (sub);
|
Cbuf_ExecuteSubroutine (sub);
|
||||||
return;
|
return;
|
||||||
|
@ -2114,11 +2146,13 @@ Cmd_While_f (void) {
|
||||||
/* Works exactly like for in C:
|
/* Works exactly like for in C:
|
||||||
for {initializer; condition; iterator} {code} */
|
for {initializer; condition; iterator} {code} */
|
||||||
void
|
void
|
||||||
Cmd_For_f (void) {
|
Cmd_For_f (void)
|
||||||
|
{
|
||||||
cmd_buffer_t *sub;
|
cmd_buffer_t *sub;
|
||||||
dstring_t *arg1, *init, *cond, *inc;
|
dstring_t *arg1, *init, *cond, *inc;
|
||||||
|
|
||||||
if (Cmd_Argc() < 2 || Cmd_Argc() > 3 || cmd_activebuffer->argv[1]->delim != '{') {
|
if (Cmd_Argc () < 2 || Cmd_Argc () > 3
|
||||||
|
|| cmd_activebuffer->argv[1]->delim != '{') {
|
||||||
Cmd_Error ("Malformed for statement.\n");
|
Cmd_Error ("Malformed for statement.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2152,7 +2186,8 @@ Cmd_For_f (void) {
|
||||||
|
|
||||||
/* Breaks out of a loop buffer */
|
/* Breaks out of a loop buffer */
|
||||||
void
|
void
|
||||||
Cmd_Break_f (void) {
|
Cmd_Break_f (void)
|
||||||
|
{
|
||||||
if (cmd_activebuffer->loop) {
|
if (cmd_activebuffer->loop) {
|
||||||
cmd_activebuffer->loop = false;
|
cmd_activebuffer->loop = false;
|
||||||
dstring_clearstr (cmd_activebuffer->buffer);
|
dstring_clearstr (cmd_activebuffer->buffer);
|
||||||
|
@ -2165,12 +2200,15 @@ Cmd_Break_f (void) {
|
||||||
|
|
||||||
/* Returns a value to the buffer that requested it */
|
/* Returns a value to the buffer that requested it */
|
||||||
void
|
void
|
||||||
Cmd_Return_f (void) {
|
Cmd_Return_f (void)
|
||||||
|
{
|
||||||
int argc = Cmd_Argc ();
|
int argc = Cmd_Argc ();
|
||||||
const char *val = Cmd_Argv (1);
|
const char *val = Cmd_Argv (1);
|
||||||
cmd_buffer_t *old = cmd_activebuffer; // save context
|
cmd_buffer_t *old = cmd_activebuffer; // save context
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
Cmd_Error("GIB: Invalid return statement. Return takes either one argument or none.\n");
|
Cmd_Error
|
||||||
|
("GIB: Invalid return statement. Return takes either one argument or none.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (cmd_activebuffer->loop) { // We need to get out of any loops
|
while (cmd_activebuffer->loop) { // We need to get out of any loops
|
||||||
|
@ -2183,9 +2221,13 @@ Cmd_Return_f (void) {
|
||||||
cmd_activebuffer = old;
|
cmd_activebuffer = old;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dstring_clearstr (cmd_activebuffer->buffer); // Clear the buffer out no matter what
|
dstring_clearstr (cmd_activebuffer->buffer); // Clear the buffer out no
|
||||||
if (!cmd_activebuffer->embedded) // If this isn't an embedded command buffer
|
// matter what
|
||||||
cmd_activebuffer = cmd_activebuffer->prev; // The buffer we want must be two places up on the stack
|
if (!cmd_activebuffer->embedded) // If this isn't an embedded command
|
||||||
|
// buffer
|
||||||
|
cmd_activebuffer = cmd_activebuffer->prev; // The buffer we want must
|
||||||
|
// be two places up on the
|
||||||
|
// stack
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
Cmd_Return (val);
|
Cmd_Return (val);
|
||||||
cmd_activebuffer = old;
|
cmd_activebuffer = old;
|
||||||
|
@ -2208,6 +2250,7 @@ void
|
||||||
Cmd_Detach_f (void)
|
Cmd_Detach_f (void)
|
||||||
{
|
{
|
||||||
cmd_thread_t *thread;
|
cmd_thread_t *thread;
|
||||||
|
|
||||||
if (Cmd_Restricted ()) {
|
if (Cmd_Restricted ()) {
|
||||||
Cmd_Error ("detach: access to restricted command denied");
|
Cmd_Error ("detach: access to restricted command denied");
|
||||||
return;
|
return;
|
||||||
|
@ -2222,7 +2265,8 @@ Cmd_Detach_f (void)
|
||||||
Cmd_AddThread (&cmd_threads, thread);
|
Cmd_AddThread (&cmd_threads, thread);
|
||||||
Cbuf_AddTextTo (thread->cbuf, Cmd_Argv (1));
|
Cbuf_AddTextTo (thread->cbuf, Cmd_Argv (1));
|
||||||
Cbuf_ExecuteStack (thread->cbuf); // Execute it now
|
Cbuf_ExecuteStack (thread->cbuf); // Execute it now
|
||||||
cmd_error = false; // Don't let errors cross into this stack
|
cmd_error = false; // Don't let errors cross into this
|
||||||
|
// stack
|
||||||
Cmd_Return (va ("%li", thread->id));
|
Cmd_Return (va ("%li", thread->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2232,6 +2276,7 @@ Cmd_Killthread_f (void)
|
||||||
{
|
{
|
||||||
long int id;
|
long int id;
|
||||||
cmd_thread_t *t;
|
cmd_thread_t *t;
|
||||||
|
|
||||||
if (Cmd_Argc () != 2)
|
if (Cmd_Argc () != 2)
|
||||||
Cmd_Error ("killthread: invalid number of arguments.\n");
|
Cmd_Error ("killthread: invalid number of arguments.\n");
|
||||||
id = atol (Cmd_Argv (1));
|
id = atol (Cmd_Argv (1));
|
||||||
|
@ -2250,15 +2295,22 @@ Cmd_Killthread_f (void)
|
||||||
|
|
||||||
/* Generates a random integer between two values */
|
/* Generates a random integer between two values */
|
||||||
void
|
void
|
||||||
Cmd_Randint_f (void) {
|
Cmd_Randint_f (void)
|
||||||
|
{
|
||||||
int low, high;
|
int low, high;
|
||||||
|
|
||||||
if (Cmd_Argc () != 3) {
|
if (Cmd_Argc () != 3) {
|
||||||
Cmd_Error ("randint: invalid number of arguments.\n");
|
Cmd_Error ("randint: invalid number of arguments.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
low = atoi (Cmd_Argv (1));
|
low = atoi (Cmd_Argv (1));
|
||||||
high = atoi (Cmd_Argv (2));
|
high = atoi (Cmd_Argv (2));
|
||||||
Cmd_Return (va("%i", (int)(low+(float)rand()/(float)RAND_MAX*(float)(high-low+1))));
|
Cmd_Return (va
|
||||||
|
("%i",
|
||||||
|
(int) (low +
|
||||||
|
(float) rand () / (float) RAND_MAX * (float) (high -
|
||||||
|
low +
|
||||||
|
1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 1 if two strings are equal, zero otherwise */
|
/* Returns 1 if two strings are equal, zero otherwise */
|
||||||
|
@ -2300,6 +2352,7 @@ int
|
||||||
Cmd_CollapsePath (char *str)
|
Cmd_CollapsePath (char *str)
|
||||||
{
|
{
|
||||||
char *d, *p, *path;
|
char *d, *p, *path;
|
||||||
|
|
||||||
p = path = str;
|
p = path = str;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (p[0] == '.') {
|
if (p[0] == '.') {
|
||||||
|
@ -2332,7 +2385,8 @@ Cmd_CollapsePath (char *str)
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if ((!path[0])
|
if ((!path[0])
|
||||||
|| (path[0] == '.' && path[1] == '.' && (path[2] == '/' || path [2] == 0))
|
|| (path[0] == '.' && path[1] == '.'
|
||||||
|
&& (path[2] == '/' || path[2] == 0))
|
||||||
|| (path[strlen (path) - 1] == '/')
|
|| (path[strlen (path) - 1] == '/')
|
||||||
|| path[0] == '~') {
|
|| path[0] == '~') {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2366,7 +2420,9 @@ Cmd_File_read_f (void)
|
||||||
mark = Hunk_LowMark ();
|
mark = Hunk_LowMark ();
|
||||||
contents = (char *) COM_LoadHunkFile (Cmd_Argv (1));
|
contents = (char *) COM_LoadHunkFile (Cmd_Argv (1));
|
||||||
if (!contents) {
|
if (!contents) {
|
||||||
Cmd_Error (va ("file_read: could not open file for reading: %s\n", strerror (errno)));
|
Cmd_Error (va
|
||||||
|
("file_read: could not open file for reading: %s\n",
|
||||||
|
strerror (errno)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cmd_Return (contents);
|
Cmd_Return (contents);
|
||||||
|
@ -2397,7 +2453,9 @@ Cmd_File_write_f (void)
|
||||||
free (path);
|
free (path);
|
||||||
Sys_DPrintf ("file_write: opening %s/%s\n", com_gamedir, path);
|
Sys_DPrintf ("file_write: opening %s/%s\n", com_gamedir, path);
|
||||||
if (!(file = Qopen (va ("%s/%s", com_gamedir, Cmd_Argv (1)), "w"))) {
|
if (!(file = Qopen (va ("%s/%s", com_gamedir, Cmd_Argv (1)), "w"))) {
|
||||||
Cmd_Error (va ("file_write: could not open file for writing: %s\n", strerror (errno)));
|
Cmd_Error (va
|
||||||
|
("file_write: could not open file for writing: %s\n",
|
||||||
|
strerror (errno)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Qprintf (file, "%s", Cmd_Argv (2));
|
Qprintf (file, "%s", Cmd_Argv (2));
|
||||||
|
@ -2425,14 +2483,17 @@ Cmd_File_find_f (void)
|
||||||
path = strdup (Cmd_Argv (2));
|
path = strdup (Cmd_Argv (2));
|
||||||
if (!Cmd_CollapsePath (path)) {
|
if (!Cmd_CollapsePath (path)) {
|
||||||
free (path);
|
free (path);
|
||||||
Cmd_Error ("file_find: access to restricted directory/file denied.\n");
|
Cmd_Error
|
||||||
|
("file_find: access to restricted directory/file denied.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
free (path);
|
free (path);
|
||||||
}
|
}
|
||||||
directory = opendir (va ("%s/%s", com_gamedir, Cmd_Argv (2)));
|
directory = opendir (va ("%s/%s", com_gamedir, Cmd_Argv (2)));
|
||||||
if (!directory) {
|
if (!directory) {
|
||||||
Cmd_Error (va ("file_find: could not open directory: %s\n", strerror (errno)));
|
Cmd_Error (va
|
||||||
|
("file_find: could not open directory: %s\n",
|
||||||
|
strerror (errno)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list = dstring_newstr ();
|
list = dstring_newstr ();
|
||||||
|
@ -2526,28 +2587,43 @@ Cmd_Init (void)
|
||||||
|
|
||||||
Cmd_AddCommand ("if", Cmd_If_f, "Conditionally execute a set of commands.");
|
Cmd_AddCommand ("if", Cmd_If_f, "Conditionally execute a set of commands.");
|
||||||
Cmd_SetPure ("if");
|
Cmd_SetPure ("if");
|
||||||
Cmd_AddCommand ("ifnot", Cmd_If_f, "Conditionally execute a set of commands if the condition is false.");
|
Cmd_AddCommand ("ifnot", Cmd_If_f,
|
||||||
Cmd_AddCommand ("while", Cmd_While_f, "Execute a set of commands while a condition is true.");
|
"Conditionally execute a set of commands if the condition is false.");
|
||||||
|
Cmd_AddCommand ("while", Cmd_While_f,
|
||||||
|
"Execute a set of commands while a condition is true.");
|
||||||
Cmd_SetPure ("while");
|
Cmd_SetPure ("while");
|
||||||
Cmd_AddCommand ("for", Cmd_For_f, "A while loop with initialization and iteration commands.");
|
Cmd_AddCommand ("for", Cmd_For_f,
|
||||||
|
"A while loop with initialization and iteration commands.");
|
||||||
Cmd_SetPure ("for");
|
Cmd_SetPure ("for");
|
||||||
Cmd_AddCommand ("break", Cmd_Break_f, "Break out of a loop.");
|
Cmd_AddCommand ("break", Cmd_Break_f, "Break out of a loop.");
|
||||||
Cmd_AddCommand ("return", Cmd_Return_f, "Return a value to calling buffer.");
|
Cmd_AddCommand ("return", Cmd_Return_f,
|
||||||
Cmd_AddCommand ("lset", Cmd_Lset_f, "Sets the value of a local variable (not cvar).");
|
"Return a value to calling buffer.");
|
||||||
Cmd_AddCommand ("backtrace", Cmd_Backtrace_f, "Show a description of the last GIB error and a backtrace.");
|
Cmd_AddCommand ("lset", Cmd_Lset_f,
|
||||||
|
"Sets the value of a local variable (not cvar).");
|
||||||
|
Cmd_AddCommand ("backtrace", Cmd_Backtrace_f,
|
||||||
|
"Show a description of the last GIB error and a backtrace.");
|
||||||
|
|
||||||
Cmd_AddCommand ("randint", Cmd_Randint_f, "Returns a random integer between $1 and $2");
|
Cmd_AddCommand ("randint", Cmd_Randint_f,
|
||||||
Cmd_AddCommand ("streq", Cmd_Streq_f, "Returns 1 if $1 and $2 are the same string, 0 otherwise");
|
"Returns a random integer between $1 and $2");
|
||||||
|
Cmd_AddCommand ("streq", Cmd_Streq_f,
|
||||||
|
"Returns 1 if $1 and $2 are the same string, 0 otherwise");
|
||||||
Cmd_AddCommand ("strlen", Cmd_Strlen_f, "Returns the length of $1");
|
Cmd_AddCommand ("strlen", Cmd_Strlen_f, "Returns the length of $1");
|
||||||
Cmd_AddCommand ("file_read", Cmd_File_read_f, "Reads file $1 in the current gamedir and returns its contents.");
|
Cmd_AddCommand ("file_read", Cmd_File_read_f,
|
||||||
Cmd_AddCommand ("file_write", Cmd_File_write_f, "Write $2 to the file $1 in the current gamedir");
|
"Reads file $1 in the current gamedir and returns its contents.");
|
||||||
Cmd_AddCommand ("file_find", Cmd_File_find_f, "Finds a file matching pattern $1 in subdirectory $2 of the gamedir.");
|
Cmd_AddCommand ("file_write", Cmd_File_write_f,
|
||||||
Cmd_AddCommand ("eval", Cmd_Eval_f, "Evaluates a command. Useful for callbacks or dynamically generated commands.");
|
"Write $2 to the file $1 in the current gamedir");
|
||||||
Cmd_AddCommand ("legacy", Cmd_Legacy_f, "Adds a command to the legacy buffer");
|
Cmd_AddCommand ("file_find", Cmd_File_find_f,
|
||||||
|
"Finds a file matching pattern $1 in subdirectory $2 of the gamedir.");
|
||||||
|
Cmd_AddCommand ("eval", Cmd_Eval_f,
|
||||||
|
"Evaluates a command. Useful for callbacks or dynamically generated commands.");
|
||||||
|
Cmd_AddCommand ("legacy", Cmd_Legacy_f,
|
||||||
|
"Adds a command to the legacy buffer");
|
||||||
Cmd_SetPure ("legacy");
|
Cmd_SetPure ("legacy");
|
||||||
Cmd_AddCommand ("detach", Cmd_Detach_f, "Starts a thread with an initial program of $1");
|
Cmd_AddCommand ("detach", Cmd_Detach_f,
|
||||||
|
"Starts a thread with an initial program of $1");
|
||||||
Cmd_AddCommand ("killthread", Cmd_Killthread_f, "Kills thread with id $1");
|
Cmd_AddCommand ("killthread", Cmd_Killthread_f, "Kills thread with id $1");
|
||||||
Cmd_AddCommand ("threadstats", Cmd_Threadstats_f, "Shows statistics about threads");
|
Cmd_AddCommand ("threadstats", Cmd_Threadstats_f,
|
||||||
|
"Shows statistics about threads");
|
||||||
|
|
||||||
cmd_warncmd = Cvar_Get ("cmd_warncmd", "0", CVAR_NONE, NULL, "Toggles the "
|
cmd_warncmd = Cvar_Get ("cmd_warncmd", "0", CVAR_NONE, NULL, "Toggles the "
|
||||||
"display of error messages for unknown commands");
|
"display of error messages for unknown commands");
|
||||||
|
@ -2555,8 +2631,10 @@ Cmd_Init (void)
|
||||||
"maximum number of iterations a loop in GIB can do "
|
"maximum number of iterations a loop in GIB can do "
|
||||||
"before being forcefully terminated. 0 is infinite.");
|
"before being forcefully terminated. 0 is infinite.");
|
||||||
// Constants for the math interpreter
|
// Constants for the math interpreter
|
||||||
// We don't need to assign the return values to anything because these are never used elsewhere
|
// We don't need to assign the return values to anything because these are
|
||||||
Cvar_Get ("M_PI", "3.1415926535897932384626433832795029", CVAR_ROM, NULL, "Pi");
|
// never used elsewhere
|
||||||
|
Cvar_Get ("M_PI", "3.1415926535897932384626433832795029", CVAR_ROM, NULL,
|
||||||
|
"Pi");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue