Cbuf_ParseText
Parses Quake console command-line
-Returns size of parsed command-line
+Returns true if command is complete
============
*/
-static size_t Cbuf_ParseText(char **in)
+static qboolean Cbuf_ParseText(char **start, size_t *size)
{
int i = 0;
qboolean quotes = false;
*/
while(!end)
{
- switch ((*in)[i])
+ switch ((*start)[i])
{
case '/':
- if(!quotes && (*in)[i+1] == '/' && (i == 0 || ISWHITESPACE((*in)[i-1])))
+ if(!quotes && (*start)[i+1] == '/' && (i == 0 || ISWHITESPACE((*start)[i-1])))
comment = true;
break;
case 0:
if(!end && cmdsize)
- // Use bit magic to indicate an incomplete (pending) command.
- cmdsize |= (1<<17);
+ return false;
comment = false;
end = true;
break;
if(!comment)
{
- switch ((*in)[i])
+ switch ((*start)[i])
{
case ';':
if(!quotes)
if(!offset)
{
if(!end)
- offset = (char *)&(*in)[i];
- else if ((*in)[i])
+ offset = (char *)&(*start)[i];
+ else if ((*start)[i])
end = false;
}
else
i++;
}
- *in = offset;
+ *start = offset;
+ *size = cmdsize;
- return cmdsize;
+ return true;
}
static cbuf_cmd_t *Cbuf_LinkGet(cbuf_t *cbuf, cbuf_cmd_t *existing)
static void Cbuf_LinkCreate(cmd_state_t *cmd, llist_t *head, cbuf_cmd_t *existing, const char *text)
{
char *in = (char *)&text[0];
+ qboolean complete;
cbuf_t *cbuf = cmd->cbuf;
size_t totalsize = 0, newsize = 0;
cbuf_cmd_t *current = NULL;
* FIXME: Upon reaching a terminator, we make a redundant
* call just to say "it's the end of the input stream".
*/
- newsize = Cbuf_ParseText(&in);
+ complete = Cbuf_ParseText(&in, &newsize);
// Valid command
if(newsize)
List_Move_Tail(¤t->list, head);
}
- if(newsize & (1<<17))
- current->pending = true;
- totalsize += (newsize &= ~(1<<17));
+ current->pending = complete;
+ totalsize += newsize;
strlcpy(¤t->text[current->size], in, newsize + 1);
current->size += newsize;
}