Fixed incorrect handling of - in late args and simplified code

This commit is contained in:
BjossiAlfreds 2021-10-29 03:25:23 +00:00
parent 9de9939fe0
commit ec28387da4

View file

@ -298,74 +298,51 @@ Cbuf_AddEarlyCommands(qboolean clear)
qboolean
Cbuf_AddLateCommands(void)
{
int i, j;
int s;
char *text, *build, c;
int argc;
qboolean ret;
/* build the combined string to parse from */
s = 0;
argc = COM_Argc();
qboolean has_args = false;
char *arg;
int i, argc = COM_Argc();
for (i = 1; i < argc; i++)
{
s += strlen(COM_Argv(i)) + 1;
arg = COM_Argv(i);
if (*arg != '+')
{
continue;
}
if (!s)
{
return false;
}
text = Z_Malloc(s + 1);
text[0] = 0;
for (i = 1; i < argc; i++)
{
strcat(text, COM_Argv(i));
if (i != argc - 1)
{
strcat(text, " ");
}
}
/* pull out the commands */
build = Z_Malloc(s + 1);
build[0] = 0;
for (i = 0; i < s - 1; i++)
{
if (text[i] == '+')
{
has_args = true;
i++;
for (j = i; (text[j] != '+') && (text[j] != '-') && (text[j] != 0); j++)
Cbuf_AddText(arg + 1);
Cbuf_AddText(" ");
/* add the command parameters if any */
while (1)
{
}
c = text[j];
text[j] = 0;
strcat(build, text + i);
strcat(build, "\n");
text[j] = c;
i = j - 1;
}
}
ret = (build[0] != 0);
if (ret)
if (i >= argc)
{
Cbuf_AddText(build);
Cbuf_AddText("\n");
break;
}
Z_Free(text);
Z_Free(build);
arg = COM_Argv(i);
return ret;
if (*arg == '-' || *arg == '+')
{
Cbuf_AddText("\n");
i--; /* i gets incremented again by the outer loop */
break;
}
Cbuf_AddText(arg);
Cbuf_AddText(" ");
i++;
}
}
return has_args;
}
/*