Commit ae09a5a6 ae09a5a6b1893087a8b2fa6285f4439dcb484bb0 by Sergey Poznyakoff

Use sieve_compile_error() to report parse errors.

1 parent 91aa105c
......@@ -34,8 +34,8 @@ sieve_require (list_t slist)
status = iterator_create (&itr, slist);
if (status)
{
sieve_error ("%s:%d: cannot create iterator: %s",
sieve_filename, sieve_line_num,
sieve_compile_error (sieve_filename, sieve_line_num,
"cannot create iterator: %s",
mu_errstring (status));
return;
}
......@@ -51,8 +51,9 @@ sieve_require (list_t slist)
reg = sieve_action_lookup (s);
if (!reg)
{
sieve_error ("%s:%d: source for the required action %s is not available",
sieve_filename, sieve_line_num, s);
sieve_compile_error (sieve_filename, sieve_line_num,
"source for the required action %s is not available",
s);
break;
}
reg->required = 1;
......
......@@ -117,7 +117,7 @@ lex_set_buffer (FILE *fp)
if (!buf)
{
sieve_error ("not enough memory");
sieve_compile_error (sieve_filename, sieve_line_num, "not enough memory");
abort ();
}
......@@ -218,8 +218,8 @@ push_source (const char *name)
if (stat (name, &st))
{
sieve_error ("can't stat `%s': %s", name, strerror (errno));
yyerror ("can't include file");
sieve_compile_error (sieve_filename, sieve_line_num,
"can't stat `%s': %s", name, strerror (errno));
return 1;
}
......@@ -232,19 +232,21 @@ push_source (const char *name)
{
yyerror ("recursive inclusion");
if (ctx->prev)
sieve_error ("%s:%d: `%s' already included here",
ctx->prev->filename, ctx->prev->line, name);
sieve_compile_error (ctx->prev->filename, ctx->prev->line,
"`%s' already included here",
name);
else
sieve_error ("`%s' already included at top level",
name);
sieve_compile_error (sieve_filename, sieve_line_num,
"`%s' already included at top level",
name);
return 1;
}
fp = fopen (name, "r");
if (!fp)
{
sieve_error ("can't open `%s': %s", name, strerror (errno));
yyerror ("can't include file");
sieve_compile_error (sieve_filename, sieve_line_num,
"can't open `%s': %s", name, strerror (errno));
return 1;
}
......@@ -470,7 +472,8 @@ multiline_begin ()
status = list_create (&string_list);
if (status)
{
sieve_error ("list_create: %s", mu_errstring (status));
sieve_compile_error (sieve_filename, sieve_line_num,
"list_create: %s", mu_errstring (status));
exit (1);
}
}
......
......@@ -144,20 +144,31 @@ sieve_value_create (sieve_data_type type, void *data)
break;
default:
sieve_error ("Invalid data type");
sieve_compile_error (sieve_filename, sieve_line_num, "Invalid data type");
abort ();
}
return val;
}
void
sieve_error (const char *fmt, ...)
sieve_compile_error (const char *filename, int linenum, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
sieve_error_count++;
sieve_machine->error_printer (sieve_machine->data, fmt, ap);
sieve_machine->parse_error_printer (sieve_machine->data, filename, linenum,
fmt, ap);
va_end (ap);
}
void
sieve_error (sieve_machine_t *mach, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mach->error_printer (mach->data, fmt, ap);
va_end (ap);
}
......@@ -187,6 +198,15 @@ _sieve_default_error_printer (void *unused, const char *fmt, va_list ap)
return mu_verror (fmt, ap);
}
int
_sieve_default_parse_error (void *unused, const char *filename, int lineno,
const char *fmt, va_list ap)
{
fprintf (stderr, "%s:%d: ", filename, lineno);
vfprintf (stderr, fmt, ap);
return 0;
}
char *
sieve_type_str (sieve_data_type type)
{
......@@ -304,10 +324,4 @@ sieve_print_tag_list (list_t list, sieve_printf_t printer, void *data)
list_do (list, (list_action_t*) tag_printer, &dbg);
}
void
sieve_set_debug (sieve_machine_t *mach, sieve_printf_t debug, int level)
{
mach->debug_printer = debug;
mach->debug_level = level;
}
......