mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-29 20:20:43 +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_legacybuffer; // Server stuffcmd buffer with
|
||||
// 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_activebuffer; // Buffer currently being executed
|
||||
|
||||
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
|
||||
|
||||
dstring_t *cmd_backtrace;
|
||||
|
@ -176,7 +178,8 @@ Cmd_LocalFree (void *ele, void *ptr)
|
|||
|
||||
/* Creates a new token */
|
||||
cmd_token_t *
|
||||
Cmd_NewToken (void) {
|
||||
Cmd_NewToken (void)
|
||||
{
|
||||
cmd_token_t *new;
|
||||
|
||||
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
|
||||
new = cmd_recycled;
|
||||
cmd_recycled = new->next;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
new = calloc (1, sizeof (cmd_buffer_t));
|
||||
new->buffer = dstring_newstr ();
|
||||
new->line = dstring_newstr ();
|
||||
|
@ -223,7 +225,8 @@ Cmd_NewBuffer (qboolean ownvars)
|
|||
*/
|
||||
|
||||
void
|
||||
Cmd_FreeBuffer (cmd_buffer_t *free) {
|
||||
Cmd_FreeBuffer (cmd_buffer_t *free)
|
||||
{
|
||||
if (free->ownvars)
|
||||
Hash_DelTable (free->locals); // Local variables are always deadbeef
|
||||
free->subroutine = false;
|
||||
|
@ -249,7 +252,8 @@ Cmd_FreeBuffer (cmd_buffer_t *free) {
|
|||
|
||||
/* Frees an entire linked list (stack) of buffers */
|
||||
void
|
||||
Cmd_FreeStack (cmd_buffer_t *stack) {
|
||||
Cmd_FreeStack (cmd_buffer_t *stack)
|
||||
{
|
||||
cmd_buffer_t *temp;
|
||||
|
||||
for (; stack; stack = temp) {
|
||||
|
@ -262,7 +266,8 @@ Cmd_FreeStack (cmd_buffer_t *stack) {
|
|||
|
||||
/* Creates a new thread */
|
||||
cmd_thread_t *
|
||||
Cmd_NewThread (long int id) {
|
||||
Cmd_NewThread (long int id)
|
||||
{
|
||||
cmd_thread_t *new;
|
||||
|
||||
new = calloc (1, sizeof (cmd_thread_t));
|
||||
|
@ -275,7 +280,8 @@ Cmd_NewThread (long int id) {
|
|||
|
||||
/* Frees a thread */
|
||||
void
|
||||
Cmd_FreeThread (cmd_thread_t *thread) {
|
||||
Cmd_FreeThread (cmd_thread_t *thread)
|
||||
{
|
||||
Cmd_FreeBuffer (thread->cbuf);
|
||||
free (thread);
|
||||
return;
|
||||
|
@ -283,7 +289,8 @@ Cmd_FreeThread (cmd_thread_t *thread) {
|
|||
|
||||
/* Adds a thread to a linked list */
|
||||
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->prev = 0;
|
||||
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 */
|
||||
void
|
||||
Cmd_RemoveThread (cmd_thread_t **list, cmd_thread_t *thread) {
|
||||
Cmd_RemoveThread (cmd_thread_t **list, cmd_thread_t *thread)
|
||||
{
|
||||
if (thread == *list)
|
||||
*list = 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 */
|
||||
|
||||
/* Determines if a character is escaped */
|
||||
inline
|
||||
qboolean
|
||||
inline 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++)
|
||||
;
|
||||
for (n = i - 1, c = 0; n >= 0 && str[n] == '\\'; n--, c++);
|
||||
return c & 1;
|
||||
}
|
||||
|
||||
/* Escapes a list of characters in a dstring */
|
||||
inline
|
||||
void
|
||||
inline void
|
||||
escape (dstring_t *dstr, const char *clist)
|
||||
{
|
||||
int i;
|
||||
|
@ -339,8 +344,7 @@ escape (dstring_t * dstr, const char *clist)
|
|||
}
|
||||
|
||||
/* Unescapes a character and all backslashes preceding it in a dstring */
|
||||
inline
|
||||
int
|
||||
inline int
|
||||
unescape (dstring_t *dstr, int start)
|
||||
{
|
||||
int i;
|
||||
|
@ -436,8 +440,7 @@ Cbuf_ExtractLine (dstring_t * buffer, dstring_t * line, qboolean legacy)
|
|||
else if (!legacy && buffer->str[i] == '}' && !dquotes)
|
||||
braces--;
|
||||
}
|
||||
if (buffer->str[i] == '/' && buffer->str[i + 1] == '/'
|
||||
&& !dquotes) {
|
||||
if (buffer->str[i] == '/' && buffer->str[i + 1] == '/' && !dquotes) {
|
||||
// Filter out comments until newline
|
||||
if ((tmp = strchr (buffer->str + i, '\n')))
|
||||
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
|
||||
dstring_snip (buffer, i, n);
|
||||
i--;
|
||||
}
|
||||
else if ((buffer->str[i] == '\n' || buffer->str[i] == '\r') && !braces) {
|
||||
} else if ((buffer->str[i] == '\n' || buffer->str[i] == '\r')
|
||||
&& !braces) {
|
||||
if (escaped (buffer->str, i)) {
|
||||
dstring_snip (buffer, i - 1, 2);
|
||||
i -= 2;
|
||||
|
@ -490,6 +493,7 @@ Cbuf_ExecuteBuffer (cmd_buffer_t *buffer)
|
|||
|
||||
if (buffer->timeleft) {
|
||||
double newtime = Sys_DoubleTime ();
|
||||
|
||||
buffer->timeleft -= newtime - buffer->lasttime;
|
||||
buffer->lasttime = newtime;
|
||||
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 (buffer->loop) {
|
||||
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));
|
||||
break;
|
||||
}
|
||||
Cbuf_InsertTextTo (buffer, buffer->looptext->str);
|
||||
buffer->loop++;
|
||||
}
|
||||
else
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -569,7 +573,8 @@ Cbuf_ExecuteStack (cmd_buffer_t *buffer)
|
|||
Cbuf_ExecuteBuffer (cur);
|
||||
if (cmd_error || cur->wait)
|
||||
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;
|
||||
temp = cur->next;
|
||||
continue;
|
||||
|
@ -631,7 +636,8 @@ Cbuf_ExecuteSubroutine (cmd_buffer_t *buffer)
|
|||
Cmd_FreeStack (cmd_activebuffer->next);
|
||||
cmd_activebuffer->next = buffer; // Link it in
|
||||
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)
|
||||
buffer->restricted = true;
|
||||
return;
|
||||
|
@ -654,7 +660,8 @@ Cbuf_Execute_Sets (void)
|
|||
dstring_t *buf = dstring_newstr ();
|
||||
|
||||
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])) {
|
||||
Cmd_ExecuteString (buf->str, src_command);
|
||||
} else if (!strncmp (buf->str, "setrom", 6)
|
||||
|
@ -700,8 +707,7 @@ Cmd_StuffCmds_f (void)
|
|||
for (j = i; !((com_cmdline[j] == '+')
|
||||
|| (com_cmdline[j] == '-'
|
||||
&& (j == 0 || com_cmdline[j - 1] == ' '))
|
||||
|| (com_cmdline[j] == 0)); j++)
|
||||
;
|
||||
|| (com_cmdline[j] == 0)); j++);
|
||||
|
||||
c = com_cmdline[j];
|
||||
com_cmdline[j] = 0;
|
||||
|
@ -767,13 +773,16 @@ Cmd_Error (const char *message)
|
|||
/* Returns a value to the previous buffer
|
||||
in the stack, but only if it wants one */
|
||||
void
|
||||
Cmd_Return (const char *value) {
|
||||
if (cmd_activebuffer->prev && cmd_activebuffer->prev->returned == cmd_waiting) {
|
||||
Cmd_Return (const char *value)
|
||||
{
|
||||
if (cmd_activebuffer->prev
|
||||
&& cmd_activebuffer->prev->returned == cmd_waiting) {
|
||||
dstring_clearstr (cmd_activebuffer->prev->retval);
|
||||
dstring_appendstr (cmd_activebuffer->prev->retval, value);
|
||||
cmd_activebuffer->prev->returned = cmd_returned;
|
||||
} 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;
|
||||
i += ret;
|
||||
continue;
|
||||
}
|
||||
else if (str[i] == '}' && !legacy)
|
||||
} else if (str[i] == '}' && !legacy)
|
||||
return -1;
|
||||
else if (str[i] == '\"') {
|
||||
ret = Cmd_EndDoubleQuote (str + i, legacy);
|
||||
|
@ -975,27 +983,21 @@ struct stable_s {
|
|||
char a, b;
|
||||
} stable1[] = {
|
||||
{'f', 0x0D}, // Fake message
|
||||
|
||||
{'[', 0x90}, // Gold braces
|
||||
{']', 0x91},
|
||||
|
||||
{'(', 0x80}, // Scroll bar characters
|
||||
{'=', 0x81},
|
||||
{')', 0x82},
|
||||
{'|', 0x83},
|
||||
|
||||
{'<', 0x9D}, // Vertical line characters
|
||||
{'-', 0x9E},
|
||||
{'>', 0x9F},
|
||||
|
||||
{'.', 0x05}, // White dot
|
||||
|
||||
{'#', 0x0B}, // White block
|
||||
|
||||
{'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
|
||||
|
||||
{'0', 0x92}, // Golden numbers
|
||||
{'1', 0x93},
|
||||
{'2', 0x94},
|
||||
|
@ -1029,8 +1031,7 @@ Cmd_ProcessTags (dstring_t * dstr)
|
|||
if (dstr->str[i] == '<' && !escaped (dstr->str, i)) {
|
||||
close = 0;
|
||||
for (n = 1;
|
||||
dstr->str[i+n] != '>' || escaped (dstr->str, i + n);
|
||||
n++)
|
||||
dstr->str[i + n] != '>' || escaped (dstr->str, i + n); n++)
|
||||
if (dstr->str[i + n] == 0)
|
||||
return;
|
||||
if (dstr->str[i + 1] == '/')
|
||||
|
@ -1089,7 +1090,8 @@ Cmd_ProcessMath (dstring_t * dstr)
|
|||
statement = dstring_newstr ();
|
||||
|
||||
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;
|
||||
if (n < 0) {
|
||||
Cmd_Error ("Unmatched brace in math expression.\n");
|
||||
|
@ -1107,7 +1109,9 @@ Cmd_ProcessMath (dstring_t * dstr)
|
|||
i += strlen (temp) - 1;
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -1180,7 +1184,8 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
|||
braces = 1;
|
||||
for (i = start + 1 + braces;; 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] == '$')) {
|
||||
n = Cmd_ProcessVariablesRecursive (dstr, i);
|
||||
if (n < 0) {
|
||||
|
@ -1189,10 +1194,14 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
|||
i += n - 1;
|
||||
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 *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
|
||||
dstring_snip (dstr, start, i - start + braces);
|
||||
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
|
||||
if (dstr->str[start] == '[') {
|
||||
int val1, val2, res;
|
||||
|
||||
res = Cmd_ProcessIndex (dstr, start, &val1, &val2);
|
||||
if (res < 0)
|
||||
n = -1;
|
||||
else if (val1 >= strlen (copy->str) || val1 < 0)
|
||||
n = 0;
|
||||
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
|
||||
dstring_insert (varname, copy->str+val1, strlen(copy->str)-val1, 0);
|
||||
dstring_insert (varname, copy->str + val1,
|
||||
strlen (copy->str) - val1, 0);
|
||||
} else
|
||||
dstring_appendstr (varname, copy->str);
|
||||
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);
|
||||
n = strlen (varname->str);
|
||||
}
|
||||
|
@ -1230,7 +1243,8 @@ Cmd_ProcessVariablesRecursive (dstring_t * dstr, int start)
|
|||
}
|
||||
}
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@ -1280,7 +1294,8 @@ Cmd_ProcessEmbeddedSingle (dstring_t * dstr, int start)
|
|||
}
|
||||
if (cmd_activebuffer->returned == cmd_waiting) {
|
||||
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;
|
||||
}
|
||||
if (cmd_activebuffer->returned == cmd_returned) {
|
||||
|
@ -1312,7 +1327,8 @@ Cmd_ProcessEmbedded (cmd_token_t *tok, dstring_t * dstr)
|
|||
int i, n;
|
||||
|
||||
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);
|
||||
if (n == -2) {
|
||||
tok->pos = i;
|
||||
|
@ -1401,12 +1417,16 @@ Cmd_Process (void)
|
|||
unsigned int adj = 0;
|
||||
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;
|
||||
if (!Cmd_Argc ()) // No tokens, don't bother
|
||||
return 0;
|
||||
cmd = (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
|
||||
cmd =
|
||||
(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;
|
||||
|
||||
tag_shift = 0;
|
||||
|
@ -1421,8 +1441,8 @@ Cmd_Process (void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Here we edit the composite command line to reflect
|
||||
the changes made to individual tokens. */
|
||||
/* Here we edit the composite command line to reflect the changes made to
|
||||
individual tokens. */
|
||||
dstring_clearstr (cmd_activebuffer->line);
|
||||
dstring_appendstr (cmd_activebuffer->line, cmd_activebuffer->realline->str);
|
||||
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
||||
|
@ -1438,7 +1458,9 @@ Cmd_Process (void)
|
|||
cmd_activebuffer->args[arg] = cmd_activebuffer->argsu[arg] + adj;
|
||||
adj += (str->size - 1) - (org->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;
|
||||
}
|
||||
|
@ -1476,7 +1498,8 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
|||
cmd_argc++;
|
||||
if (cmd_argc > cmd_activebuffer->maxargc) {
|
||||
cmd_activebuffer->argv = realloc (cmd_activebuffer->argv,
|
||||
sizeof (cmd_token_t *) * cmd_argc);
|
||||
sizeof (cmd_token_t *) *
|
||||
cmd_argc);
|
||||
SYS_CHECKMEM (cmd_activebuffer->argv);
|
||||
cmd_activebuffer->argsu = realloc (cmd_activebuffer->argsu,
|
||||
sizeof (int) * cmd_argc);
|
||||
|
@ -1506,7 +1529,8 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
|||
cmd_activebuffer->argv[cmd_argc - 1]->delim = '{';
|
||||
} else
|
||||
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)
|
||||
cmd_activebuffer->argv[cmd_argc - 1]->state = cmd_process;
|
||||
else
|
||||
|
@ -1550,7 +1574,6 @@ Cmd_ExecuteParsed (cmd_source_t src)
|
|||
Cmd_SetLocal (cmd_activebuffer, Cmd_Argv (0), Cmd_Argv (2));
|
||||
return;
|
||||
}
|
||||
|
||||
// check alias
|
||||
|
||||
|
||||
|
@ -1559,10 +1582,12 @@ Cmd_ExecuteParsed (cmd_source_t src)
|
|||
}
|
||||
|
||||
/* 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
|
||||
int ret;
|
||||
|
||||
cmd_activebuffer = cmd_privatebuffer;
|
||||
Cmd_TokenizeString (text, cmd_activebuffer->legacy);
|
||||
if (!Cmd_Argc ()) {
|
||||
|
@ -1842,7 +1867,8 @@ cmd_get_key (void *c, void *unused)
|
|||
return cmd->name;
|
||||
}
|
||||
|
||||
void Cmd_Runalias_f (void)
|
||||
void
|
||||
Cmd_Runalias_f (void)
|
||||
{
|
||||
cmdalias_t *a;
|
||||
|
||||
|
@ -1850,7 +1876,8 @@ void Cmd_Runalias_f (void)
|
|||
|
||||
if (a) {
|
||||
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->restricted = a->restricted;
|
||||
sub->legacy = a->legacy;
|
||||
|
@ -1861,8 +1888,10 @@ void Cmd_Runalias_f (void)
|
|||
Cbuf_ExecuteSubroutine (sub);
|
||||
return;
|
||||
} else {
|
||||
Sys_Printf ("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.");
|
||||
Sys_Printf
|
||||
("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);
|
||||
|
||||
for (a = &cmd_alias; *a != alias; a = &(*a)->next)
|
||||
;
|
||||
for (a = &cmd_alias; *a != alias; a = &(*a)->next);
|
||||
*a = alias->next;
|
||||
|
||||
free ((char *) alias->name);
|
||||
|
@ -1965,6 +1993,7 @@ void
|
|||
Cmd_Wait_f (void)
|
||||
{
|
||||
cmd_buffer_t *cur;
|
||||
|
||||
for (cur = cmd_activebuffer; cur; cur = cur->prev)
|
||||
cur->wait = true;
|
||||
}
|
||||
|
@ -2020,8 +2049,7 @@ Cmd_Help_f (void)
|
|||
name = Cmd_Argv (1);
|
||||
|
||||
for (cmd = cmd_functions; cmd && strcasecmp (name, cmd->name);
|
||||
cmd = cmd->next)
|
||||
;
|
||||
cmd = cmd->next);
|
||||
if (cmd) {
|
||||
Sys_Printf ("%s\n", cmd->description);
|
||||
return;
|
||||
|
@ -2053,21 +2081,21 @@ Cmd_If_f (void)
|
|||
long int num;
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
/* HACK HACK HACK
|
||||
If is set as a pure command, but it needs the first argument
|
||||
to be evaluated. Normally this would mean Cmd_Args is out
|
||||
of sync, but since if uses Cmd_Argsu (4) and no other commands
|
||||
will need these tokens, it is safe.
|
||||
*/
|
||||
/* HACK HACK HACK If is set as a pure command, but it needs the first
|
||||
argument to be evaluated. Normally this would mean Cmd_Args is out of
|
||||
sync, but since if uses Cmd_Argsu (4) and no other commands will need
|
||||
these tokens, it is safe. */
|
||||
ret = Cmd_ProcessToken (cmd_activebuffer->argv[1]);
|
||||
if (ret < 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2089,7 +2117,8 @@ Cmd_If_f (void)
|
|||
/* Executes a block of code while a condition
|
||||
is met */
|
||||
void
|
||||
Cmd_While_f (void) {
|
||||
Cmd_While_f (void)
|
||||
{
|
||||
cmd_buffer_t *sub;
|
||||
|
||||
if (Cmd_Argc () < 3) {
|
||||
|
@ -2101,11 +2130,14 @@ Cmd_While_f (void) {
|
|||
sub->locals = cmd_activebuffer->locals; // Use current local variables
|
||||
sub->loop = true;
|
||||
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 == '\"')
|
||||
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
|
||||
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));
|
||||
Cbuf_ExecuteSubroutine (sub);
|
||||
return;
|
||||
|
@ -2114,11 +2146,13 @@ Cmd_While_f (void) {
|
|||
/* Works exactly like for in C:
|
||||
for {initializer; condition; iterator} {code} */
|
||||
void
|
||||
Cmd_For_f (void) {
|
||||
Cmd_For_f (void)
|
||||
{
|
||||
cmd_buffer_t *sub;
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
@ -2152,7 +2186,8 @@ Cmd_For_f (void) {
|
|||
|
||||
/* Breaks out of a loop buffer */
|
||||
void
|
||||
Cmd_Break_f (void) {
|
||||
Cmd_Break_f (void)
|
||||
{
|
||||
if (cmd_activebuffer->loop) {
|
||||
cmd_activebuffer->loop = false;
|
||||
dstring_clearstr (cmd_activebuffer->buffer);
|
||||
|
@ -2165,12 +2200,15 @@ Cmd_Break_f (void) {
|
|||
|
||||
/* Returns a value to the buffer that requested it */
|
||||
void
|
||||
Cmd_Return_f (void) {
|
||||
Cmd_Return_f (void)
|
||||
{
|
||||
int argc = Cmd_Argc ();
|
||||
const char *val = Cmd_Argv (1);
|
||||
cmd_buffer_t *old = cmd_activebuffer; // save context
|
||||
|
||||
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;
|
||||
}
|
||||
while (cmd_activebuffer->loop) { // We need to get out of any loops
|
||||
|
@ -2183,9 +2221,13 @@ Cmd_Return_f (void) {
|
|||
cmd_activebuffer = old;
|
||||
return;
|
||||
}
|
||||
dstring_clearstr (cmd_activebuffer->buffer); // Clear the buffer out no matter what
|
||||
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
|
||||
dstring_clearstr (cmd_activebuffer->buffer); // Clear the buffer out no
|
||||
// matter what
|
||||
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)
|
||||
Cmd_Return (val);
|
||||
cmd_activebuffer = old;
|
||||
|
@ -2208,6 +2250,7 @@ void
|
|||
Cmd_Detach_f (void)
|
||||
{
|
||||
cmd_thread_t *thread;
|
||||
|
||||
if (Cmd_Restricted ()) {
|
||||
Cmd_Error ("detach: access to restricted command denied");
|
||||
return;
|
||||
|
@ -2222,7 +2265,8 @@ Cmd_Detach_f (void)
|
|||
Cmd_AddThread (&cmd_threads, thread);
|
||||
Cbuf_AddTextTo (thread->cbuf, Cmd_Argv (1));
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -2232,6 +2276,7 @@ Cmd_Killthread_f (void)
|
|||
{
|
||||
long int id;
|
||||
cmd_thread_t *t;
|
||||
|
||||
if (Cmd_Argc () != 2)
|
||||
Cmd_Error ("killthread: invalid number of arguments.\n");
|
||||
id = atol (Cmd_Argv (1));
|
||||
|
@ -2250,15 +2295,22 @@ Cmd_Killthread_f (void)
|
|||
|
||||
/* Generates a random integer between two values */
|
||||
void
|
||||
Cmd_Randint_f (void) {
|
||||
Cmd_Randint_f (void)
|
||||
{
|
||||
int low, high;
|
||||
|
||||
if (Cmd_Argc () != 3) {
|
||||
Cmd_Error ("randint: invalid number of arguments.\n");
|
||||
return;
|
||||
}
|
||||
low = atoi (Cmd_Argv (1));
|
||||
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 */
|
||||
|
@ -2300,6 +2352,7 @@ int
|
|||
Cmd_CollapsePath (char *str)
|
||||
{
|
||||
char *d, *p, *path;
|
||||
|
||||
p = path = str;
|
||||
while (*p) {
|
||||
if (p[0] == '.') {
|
||||
|
@ -2332,7 +2385,8 @@ Cmd_CollapsePath (char *str)
|
|||
p++;
|
||||
}
|
||||
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[0] == '~') {
|
||||
return 0;
|
||||
|
@ -2366,7 +2420,9 @@ Cmd_File_read_f (void)
|
|||
mark = Hunk_LowMark ();
|
||||
contents = (char *) COM_LoadHunkFile (Cmd_Argv (1));
|
||||
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;
|
||||
}
|
||||
Cmd_Return (contents);
|
||||
|
@ -2397,7 +2453,9 @@ Cmd_File_write_f (void)
|
|||
free (path);
|
||||
Sys_DPrintf ("file_write: opening %s/%s\n", com_gamedir, path);
|
||||
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;
|
||||
}
|
||||
Qprintf (file, "%s", Cmd_Argv (2));
|
||||
|
@ -2425,14 +2483,17 @@ Cmd_File_find_f (void)
|
|||
path = strdup (Cmd_Argv (2));
|
||||
if (!Cmd_CollapsePath (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;
|
||||
}
|
||||
free (path);
|
||||
}
|
||||
directory = opendir (va ("%s/%s", com_gamedir, Cmd_Argv (2)));
|
||||
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;
|
||||
}
|
||||
list = dstring_newstr ();
|
||||
|
@ -2526,28 +2587,43 @@ Cmd_Init (void)
|
|||
|
||||
Cmd_AddCommand ("if", Cmd_If_f, "Conditionally execute a set of commands.");
|
||||
Cmd_SetPure ("if");
|
||||
Cmd_AddCommand ("ifnot", Cmd_If_f, "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_AddCommand ("ifnot", Cmd_If_f,
|
||||
"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_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_AddCommand ("break", Cmd_Break_f, "Break out of a loop.");
|
||||
Cmd_AddCommand ("return", Cmd_Return_f, "Return a value to calling buffer.");
|
||||
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 ("return", Cmd_Return_f,
|
||||
"Return a value to calling buffer.");
|
||||
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 ("streq", Cmd_Streq_f, "Returns 1 if $1 and $2 are the same string, 0 otherwise");
|
||||
Cmd_AddCommand ("randint", Cmd_Randint_f,
|
||||
"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 ("file_read", Cmd_File_read_f, "Reads file $1 in the current gamedir and returns its contents.");
|
||||
Cmd_AddCommand ("file_write", Cmd_File_write_f, "Write $2 to the file $1 in the current gamedir");
|
||||
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_AddCommand ("file_read", Cmd_File_read_f,
|
||||
"Reads file $1 in the current gamedir and returns its contents.");
|
||||
Cmd_AddCommand ("file_write", Cmd_File_write_f,
|
||||
"Write $2 to the file $1 in the current gamedir");
|
||||
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_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 ("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 "
|
||||
"display of error messages for unknown commands");
|
||||
|
@ -2555,8 +2631,10 @@ Cmd_Init (void)
|
|||
"maximum number of iterations a loop in GIB can do "
|
||||
"before being forcefully terminated. 0 is infinite.");
|
||||
// Constants for the math interpreter
|
||||
// We don't need to assign the return values to anything because these are never used elsewhere
|
||||
Cvar_Get ("M_PI", "3.1415926535897932384626433832795029", CVAR_ROM, NULL, "Pi");
|
||||
// We don't need to assign the return values to anything because these are
|
||||
// never used elsewhere
|
||||
Cvar_Get ("M_PI", "3.1415926535897932384626433832795029", CVAR_ROM, NULL,
|
||||
"Pi");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue