From 29ed52c71c7fb73ecc100c2f1e6e3bbe9fab11d2 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 13 Dec 2014 11:15:35 -0800 Subject: [PATCH] command queueing --- include/cmd.h | 10 ++++-- main/cmd.c | 98 ++++++++++++++++++++++++++++++++++---------------- main/console.c | 10 ++++-- main/inferno.c | 4 ++- 4 files changed, 85 insertions(+), 37 deletions(-) diff --git a/include/cmd.h b/include/cmd.h index 892c082e..b4f1ae1c 100644 --- a/include/cmd.h +++ b/include/cmd.h @@ -13,9 +13,13 @@ void cmd_init(void); void cmd_parse(char *input); // FIXME: make this handle compound statements, add flag for insert/append? void cmd_parsef(char *fmt, ...); /* Add some commands to the queue to be executed */ -void cmd_insert(char *input); -/* Add some commands to the queue to be executed */ -void cmd_append(char *input); +void cmd_enqueue(int insert, char *input); +void cmd_enqueuef(int insert, char *fmt, ...); +#define cmd_append(input) cmd_enqueue(0, (input)) +#define cmd_appendf(...) cmd_enqueue(0, __VA_ARGS__) +#define cmd_insert(input) cmd_enqueue(1, (input)) +#define cmd_insertf(...) cmd_enqueue(1, __VA_ARGS__) + /* Attempt to autocomplete an input string */ char *cmd_complete(char *input); diff --git a/main/cmd.c b/main/cmd.c index df957648..f1d0b8b9 100644 --- a/main/cmd.c +++ b/main/cmd.c @@ -76,8 +76,8 @@ typedef struct cmd_queue_s } cmd_queue_t; /* The list of commands to be executed */ -static cmd_queue_t *cmd_queue_start = NULL; -static cmd_queue_t *cmd_queue_end = NULL; +static cmd_queue_t *cmd_queue_head = NULL; +static cmd_queue_t *cmd_queue_tail = NULL; /* execute a parsed command */ @@ -92,9 +92,11 @@ void cmd_execute(int argc, char **argv) } for (alias = cmd_alias_list; alias; alias = alias->next) { - if (!stricmp(argv[0], alias->name)) - return cmd_parse(alias->value); - //return cmd_insert(alias->value); + if (!stricmp(argv[0], alias->name)) { + cmd_insert(alias->value); + cmd_parse(alias->value); + return; + } } /* Otherwise */ @@ -111,6 +113,7 @@ void cmd_parse(char *input) char *tokens[CMD_MAX_TOKENS]; int num_tokens; int i, l; + int quoted = 0; Assert(input != NULL); @@ -134,7 +137,11 @@ void cmd_parse(char *input) tokens[0] = buffer; for (i=1; i line_start && isspace(*line_end)) - line_end--; - - // Write new null terminator - *(line_end + 1) = 0; - - printf("append: got line: %s\n", line_start); + } while (*input++); + + printf("enqueue: got line: %s\n", line); + + /* make a new queue item, add it to list */ + MALLOC(new, cmd_queue_t, 1); + new->command_line = strdup(line); + new->next = NULL; + + if (!head) + head = new; + if (tail) + tail->next = new; + tail = new; + } + if (insert) { + /* add our list to the head of the main list */ + if (cmd_queue_head) + tail->next = cmd_queue_head; + if (!cmd_queue_tail) + cmd_queue_tail = tail; + + cmd_queue_head = head; + } else { + /* add our list to the tail of the main list */ + if (!cmd_queue_head) + cmd_queue_head = new; + if (cmd_queue_tail) + cmd_queue_tail->next = head; + + cmd_queue_tail = tail; } } +void cmd_enqueuef(int insert, char *fmt, ...){ + va_list arglist; + char buf[CMD_MAX_LENGTH]; + + va_start (arglist, fmt); + vsnprintf (buf, CMD_MAX_LENGTH, fmt, arglist); + va_end (arglist); + + cmd_enqueue(insert, buf); +} + /* Attempt to autocomplete an input string */ char *cmd_complete(char *input) @@ -350,6 +385,7 @@ void cmd_exec(int argc, char **argv) { return; } while (PHYSFSX_gets(f, buf)) { + cmd_append(buf); cmd_parse(buf); } PHYSFS_close(f); diff --git a/main/console.c b/main/console.c index 26be658a..70fe968e 100644 --- a/main/console.c +++ b/main/console.c @@ -22,6 +22,7 @@ #include #endif #include +#include #include "console.h" @@ -1126,8 +1127,13 @@ void con_printf(int priority, char *fmt, ...) if (con_initialized) CON_Out(buffer); - if (text_console_enabled) - { + if (!text_console_enabled) + return; + + if (isatty(fileno(stdout))) { + + + } else { /* Produce a sanitised version and send it to the standard output */ char *p1, *p2; diff --git a/main/inferno.c b/main/inferno.c index 4082deb4..9da02eeb 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -474,8 +474,10 @@ int main(int argc, char *argv[]) if ((t = FindArg("-autoexec"))) cmd_parsef("exec %s", Args[t+1]); - else + else { + cmd_append("exec autoexec.cfg"); cmd_parse("exec autoexec.cfg"); + } if (FindArg("-debug")) con_threshold.value = (float)CON_DEBUG; -- 2.39.2