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