From: Cloudwalk Date: Tue, 25 May 2021 03:21:50 +0000 (-0400) Subject: cmd: Add comments to better explain the overly complicated cbuf system, to aid later... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fe71303c11d6378634b5cae0277650a41c5fe320;p=xonotic%2Fdarkplaces.git cmd: Add comments to better explain the overly complicated cbuf system, to aid later rewriting --- diff --git a/cmd.c b/cmd.c index fba45672..525be466 100644 --- a/cmd.c +++ b/cmd.c @@ -198,6 +198,11 @@ static cmd_input_t *Cmd_AllocInputNode(void) return node; } + +// Cloudwalk FIXME: The entire design of this thing is overly complicated. +// We could very much safely have one input node per line whether or not +// the command was terminated. We don't need to split up input nodes per command +// executed. static size_t Cmd_ParseInput (cmd_input_t **output, char **input) { size_t pos, cmdsize = 0, start = 0; @@ -284,6 +289,7 @@ static size_t Cmd_ParseInput (cmd_input_t **output, char **input) if(!*output) *output = Cmd_AllocInputNode(); + // Append, since this input line hasn't closed yet. if((*output)->pending) offset = (*output)->length; @@ -296,6 +302,11 @@ static size_t Cmd_ParseInput (cmd_input_t **output, char **input) } strlcpy(&(*output)->text[offset], &(*input)[start], cmdsize + 1); + + /* + * If we were still looking ahead by the time we broke from the loop, the command input + * hasn't terminated yet and we're still expecting more, so keep this node open for appending later. + */ (*output)->pending = !lookahead; } @@ -316,12 +327,14 @@ static void Cbuf_LinkCreate(cmd_state_t *cmd, llist_t *head, cmd_input_t *existi // Slide the pointer down until we reach the end while(*in) { + // Check if the current node is still accepting input (input line hasn't terminated) current = Cbuf_LinkGet(cbuf, existing); newsize = Cmd_ParseInput(¤t, &in); // Valid command if(newsize) { + // current will match existing if the input line hasn't terminated yet if(current != existing) { current->source = cmd;