]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cmd: Add comments to better explain the overly complicated cbuf system, to aid later...
authorCloudwalk <cloudwalk009@gmail.com>
Tue, 25 May 2021 03:21:50 +0000 (23:21 -0400)
committerCloudwalk <cloudwalk009@gmail.com>
Tue, 25 May 2021 03:21:50 +0000 (23:21 -0400)
cmd.c

diff --git a/cmd.c b/cmd.c
index fba45672c5a341bb3d70b12c144b29ee8c4fb489..525be466796515ca4ae98f96e183aebe5b4afbd0 100644 (file)
--- 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(&current, &in);
 
                // Valid command
                if(newsize)
                {
+                       // current will match existing if the input line hasn't terminated yet
                        if(current != existing)
                        {
                                current->source = cmd;