GIB: White space at the start of a list in a for loop is ignored. The

line where an error occurs in a cbuf is now printed.
This commit is contained in:
Brian Koropoff 2002-08-29 22:12:51 +00:00
parent 9a577c2233
commit b32173db96
3 changed files with 42 additions and 19 deletions

View file

@ -213,18 +213,24 @@ void
Cbuf_Error (const char *class, const char *fmt, ...)
{
dstring_t *message = dstring_newstr();
char *n;
va_list args;
va_start (args, fmt);
dvsprintf (message, fmt, args);
va_end (args);
if ((n = strchr (cbuf_active->line->str, '\n')))
*n = 0;
Sys_Printf (
"Error in command buffer execution\n"
"---------------------------------\n"
"-----------------------------------\n"
"|Error in command buffer execution|\n"
"-----------------------------------\n"
"Type: %s\n"
"Description: %s\n",
"%s\n"
"Near/on line: %s\n",
class,
message->str
message->str,
cbuf_active->line->str
);
cbuf_active->state = CBUF_STATE_ERROR;
dstring_clearstr (cbuf_active->buf);

View file

@ -351,6 +351,7 @@ GIB_For_f (void)
"usage: for variable in list {program}"
);
} else if (GIB_Argv (3)[0]) {
char *ll;
cbuf_t *sub = Cbuf_New (&gib_interp);
GIB_DATA(sub)->type = GIB_BUFFER_LOOP;
GIB_DATA(sub)->locals = GIB_DATA(cbuf_active)->locals;
@ -362,7 +363,10 @@ GIB_For_f (void)
sub->up = cbuf_active;
dstring_appendstr (GIB_DATA(sub)->loop_data, GIB_Argv(3));
dstring_append (GIB_DATA(sub)->loop_data, GIB_Argv(1), strlen(GIB_Argv(1))+1);
GIB_DATA(sub)->loop_list_p = GIB_DATA(sub)->loop_data->str;
ll = GIB_DATA(sub)->loop_data->str;
while (isspace ((byte) *ll))
ll++;
GIB_DATA(sub)->loop_list_p = ll;
GIB_DATA(sub)->loop_var_p = GIB_DATA(sub)->loop_data->str + strlen(GIB_Argv(3))+1;
dstring_appendstr (GIB_DATA(sub)->loop_program, "__for;");
dstring_appendstr (GIB_DATA(sub)->loop_program, GIB_Argv(4));

View file

@ -86,12 +86,14 @@ GIB_Escaped (const char *str, int i)
char
GIB_Parse_Match_Dquote (const char *str, unsigned int *i)
{
unsigned int n = *i;
for ((*i)++; str[*i]; (*i)++) {
if (str[*i] == '\n')
return '\"'; // Newlines should never occur inside quotes, EVER
else if (str[*i] == '\"' && !GIB_Escaped (str, *i))
return 0;
}
*i = n;
return '\"';
}
@ -109,6 +111,7 @@ char
GIB_Parse_Match_Brace (const char *str, unsigned int *i)
{
char c;
unsigned int n = *i;
for ((*i)++; str[*i]; (*i)++) {
if (str[*i] == '\"') {
if ((c = GIB_Parse_Match_Dquote (str, i)))
@ -119,6 +122,7 @@ GIB_Parse_Match_Brace (const char *str, unsigned int *i)
} else if (str[*i] == '}')
return 0;
}
*i = n;
return '{';
}
@ -136,6 +140,7 @@ char
GIB_Parse_Match_Paren (const char *str, unsigned int *i)
{
char c;
unsigned int n = *i;
for ((*i)++; str[*i]; (*i)++) {
if (str[*i] == '(') {
if ((c = GIB_Parse_Match_Paren (str, i)))
@ -143,8 +148,9 @@ GIB_Parse_Match_Paren (const char *str, unsigned int *i)
} else if (str[*i] == ')')
return 0;
else if (str[*i] == '\n') // Newlines in math == bad
return '(';
break;
}
*i = n;
return '(';
}
@ -162,6 +168,7 @@ char
GIB_Parse_Match_Backtick (const char *str, unsigned int *i)
{
char c;
unsigned int n = *i;
for ((*i)++; str[*i]; (*i)++) {
if (str[*i] == '`')
return 0;
@ -170,16 +177,19 @@ GIB_Parse_Match_Backtick (const char *str, unsigned int *i)
return c;
}
}
*i = n;
return '`';
}
char
GIB_Parse_Match_Index (const char *str, unsigned int *i)
{
unsigned int n = *i;
for ((*i)++; str[*i]; (*i)++) {
if (str[*i] == ']')
return 0;
}
*i = n;
return '[';
}
@ -193,7 +203,7 @@ GIB_Parse_Match_Index (const char *str, unsigned int *i)
void
GIB_Parse_Extract_Line (struct cbuf_s *cbuf)
{
int i;
unsigned int i;
char c;
dstring_t *dstr = cbuf->buf;
@ -204,20 +214,14 @@ GIB_Parse_Extract_Line (struct cbuf_s *cbuf)
for (i = 0; dstr->str[i]; i++) {
if (dstr->str[i] == '{') {
if ((c = GIB_Parse_Match_Brace (dstr->str, &i))) {
Cbuf_Error ("parse", "Could not find matching %c", c);
return;
}
if ((c = GIB_Parse_Match_Brace (dstr->str, &i)))
goto PARSE_ERROR;
} else if (dstr->str[i] == '\"') {
if ((c = GIB_Parse_Match_Dquote (dstr->str, &i))) {
Cbuf_Error ("parse", "Could not find matching %c", c);
return;
}
if ((c = GIB_Parse_Match_Dquote (dstr->str, &i)))
goto PARSE_ERROR;
} else if (dstr->str[i] == '`') {
if ((c = GIB_Parse_Match_Backtick (dstr->str, &i))) {
Cbuf_Error ("parse", "Could not find matching %c", c);
return;
}
if ((c = GIB_Parse_Match_Backtick (dstr->str, &i)))
goto PARSE_ERROR;
} else if (dstr->str[i] == '\n' || dstr->str[i] == ';')
break;
else if (dstr->str[i] == '/' && dstr->str[i+1] == '/') {
@ -247,6 +251,15 @@ GIB_Parse_Extract_Line (struct cbuf_s *cbuf)
Cbuf_AddText (cbuf, GIB_DATA(cbuf)->loop_program->str);
return;
PARSE_ERROR: // Extract out the line where the parse error occurred
for (; i && dstr->str[i] != '\n'; i--);
if (dstr->str[i] == '\n')
i++;
dstring_clearstr (cbuf->line);
dstring_appendstr (cbuf->line, dstr->str+i);
Cbuf_Error ("parse", "Could not find match for %c.", c);
}
/*