Comments are now stripped out when a script is loaded instead of during

execution.
This commit is contained in:
Brian Koropoff 2002-09-10 01:26:02 +00:00
parent d7671d3363
commit 11293819a5
3 changed files with 27 additions and 10 deletions

View File

@ -35,6 +35,7 @@ char GIB_Parse_Match_Brace (const char *str, unsigned int *i);
char GIB_Parse_Match_Backtick (const char *str, unsigned int *i);
char GIB_Parse_Match_Index (const char *str, unsigned int *i);
void GIB_Parse_Strip_Comments (struct cbuf_s *cbuf);
void GIB_Parse_Extract_Line (struct cbuf_s *cbuf);
void GIB_Parse_Tokenize_Line (struct cbuf_s *cbuf);

View File

@ -492,6 +492,7 @@ Cmd_Exec_f (void)
sub->up = cbuf_active;
cbuf_active->state = CBUF_STATE_STACK;
Cbuf_AddText (sub, f);
GIB_Parse_Strip_Comments (sub);
} else
Cbuf_InsertText (cbuf_active, f);
Hunk_FreeToLowMark (mark);

View File

@ -193,6 +193,31 @@ GIB_Parse_Match_Index (const char *str, unsigned int *i)
return '[';
}
void
GIB_Parse_Strip_Comments (struct cbuf_s *cbuf)
{
unsigned int i;
dstring_t *dstr = cbuf->buf;
char c, *n;
for (i = 0; dstr->str[i]; i++) {
if (dstr->str[i] == '\"') {
if ((c = GIB_Parse_Match_Dquote (dstr->str, &i)))
// We don't care about parse errors here.
// Let the parser sort it out later.
return;
} else if (dstr->str[i] == '/' && dstr->str[i+1] == '/') {
if ((n = strchr (dstr->str+i, '\n'))) {
dstring_snip (dstr, i, n-dstr->str-i);
i--;
} else {
dstring_snip (dstr, i, strlen(dstr->str+i));
break;
}
}
}
}
/*
GIB_Parse_Extract_Line
@ -224,16 +249,6 @@ GIB_Parse_Extract_Line (struct cbuf_s *cbuf)
goto PARSE_ERROR;
} else if (dstr->str[i] == '\n' || dstr->str[i] == ';')
break;
else if (dstr->str[i] == '/' && dstr->str[i+1] == '/') {
char *n;
if ((n = strchr (dstr->str+i, '\n'))) {
dstring_snip (dstr, i, n-dstr->str-i);
i--;
} else {
dstring_snip (dstr, i, strlen(dstr->str+i));
break;
}
}
}
if (dstr->str[0]) { // If something is left in the buffer