char line[MAX_INPUTLINE];
char preprocessed[MAX_INPUTLINE];
char *firstchar;
- qboolean quotes, comment;
+ qboolean quotes;
+ char *comment;
// LordHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes
cmd_tokenizebufferpos = 0;
text = (char *)cmd_text.data;
quotes = false;
- comment = false;
+ comment = NULL;
for (i=0 ; i < cmd_text.cursize ; i++)
{
if(!comment)
else
{
if(text[i] == '/' && text[i + 1] == '/' && (i == 0 || ISWHITESPACE(text[i-1])))
- comment = true;
+ comment = &text[i];
if(text[i] == ';')
break; // don't break if inside a quoted string or comment
}
}
else
{
- memcpy (line, text, i);
- line[i] = 0;
+ memcpy (line, text, comment ? (comment - text) : i);
+ line[comment ? (comment - text) : i] = 0;
}
// delete the text from the command buffer and move remaining commands down
}
// execute the command line
- firstchar = line + strspn(line, " \t");
+ firstchar = line;
+ while(*firstchar && ISWHITESPACE(*firstchar))
+ ++firstchar;
if(
- (strncmp(firstchar, "alias", 5) || (firstchar[5] != ' ' && firstchar[5] != '\t'))
+ (strncmp(firstchar, "alias", 5) || !ISWHITESPACE(firstchar[5]))
&&
- (strncmp(firstchar, "bind", 4) || (firstchar[4] != ' ' && firstchar[4] != '\t'))
+ (strncmp(firstchar, "bind", 4) || !ISWHITESPACE(firstchar[4]))
&&
- (strncmp(firstchar, "in_bind", 7) || (firstchar[7] != ' ' && firstchar[7] != '\t'))
+ (strncmp(firstchar, "in_bind", 7) || !ISWHITESPACE(firstchar[7]))
)
{
Cmd_PreprocessString( line, preprocessed, sizeof(preprocessed), NULL );
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
c = Cmd_Argc();
- for (i=2 ; i< c ; i++)
+ for (i=2 ; i < c ; i++)
{
- strlcat (cmd, Cmd_Argv(i), sizeof (cmd));
- if (i != c)
+ if (i != 2)
strlcat (cmd, " ", sizeof (cmd));
+ strlcat (cmd, Cmd_Argv(i), sizeof (cmd));
}
strlcat (cmd, "\n", sizeof (cmd));
static char varval[MAX_INPUTLINE];
const char *varstr;
char *varfunc;
+static char asis[] = "asis"; // just to suppress const char warnings
if(varlen >= MAX_INPUTLINE)
varlen = MAX_INPUTLINE - 1;
varstr = Cmd_GetDirectCvarValue(varname, alias, &is_multiple);
if(is_multiple)
if(!varfunc)
- varfunc = "asis";
+ varfunc = asis;
}
if(!varstr)
}
for (alias = cmd_alias; alias; alias = alias->next)
{
+ // procede here a bit differently as an alias value always got a final \n
if (!matchpattern_with_separator(alias->name, partial, true, "", false))
- if (!matchpattern_with_separator(alias->value, partial, true, "", false))
+ if (!matchpattern_with_separator(alias->value, partial, true, "\n", false)) // when \n is as separator wildcards don't match it
continue;
- Con_Printf("alias ^5%s^7: %s", alias->name, alias->value);
+ Con_Printf("alias ^5%s^7: %s", alias->name, alias->value); // do not print an extra \n
count++;
}
Con_Printf("%i result%s\n\n", count, (count > 1) ? "s" : "");