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) ...@@ -34,8 +34,8 @@ sieve_require (list_t slist)
34 status = iterator_create (&itr, slist); 34 status = iterator_create (&itr, slist);
35 if (status) 35 if (status)
36 { 36 {
37 sieve_error ("%s:%d: cannot create iterator: %s", 37 sieve_compile_error (sieve_filename, sieve_line_num,
38 sieve_filename, sieve_line_num, 38 "cannot create iterator: %s",
39 mu_errstring (status)); 39 mu_errstring (status));
40 return; 40 return;
41 } 41 }
...@@ -51,8 +51,9 @@ sieve_require (list_t slist) ...@@ -51,8 +51,9 @@ sieve_require (list_t slist)
51 reg = sieve_action_lookup (s); 51 reg = sieve_action_lookup (s);
52 if (!reg) 52 if (!reg)
53 { 53 {
54 sieve_error ("%s:%d: source for the required action %s is not available", 54 sieve_compile_error (sieve_filename, sieve_line_num,
55 sieve_filename, sieve_line_num, s); 55 "source for the required action %s is not available",
56 s);
56 break; 57 break;
57 } 58 }
58 reg->required = 1; 59 reg->required = 1;
......
...@@ -117,7 +117,7 @@ lex_set_buffer (FILE *fp) ...@@ -117,7 +117,7 @@ lex_set_buffer (FILE *fp)
117 117
118 if (!buf) 118 if (!buf)
119 { 119 {
120 sieve_error ("not enough memory"); 120 sieve_compile_error (sieve_filename, sieve_line_num, "not enough memory");
121 abort (); 121 abort ();
122 } 122 }
123 123
...@@ -218,8 +218,8 @@ push_source (const char *name) ...@@ -218,8 +218,8 @@ push_source (const char *name)
218 218
219 if (stat (name, &st)) 219 if (stat (name, &st))
220 { 220 {
221 sieve_error ("can't stat `%s': %s", name, strerror (errno)); 221 sieve_compile_error (sieve_filename, sieve_line_num,
222 yyerror ("can't include file"); 222 "can't stat `%s': %s", name, strerror (errno));
223 return 1; 223 return 1;
224 } 224 }
225 225
...@@ -232,19 +232,21 @@ push_source (const char *name) ...@@ -232,19 +232,21 @@ push_source (const char *name)
232 { 232 {
233 yyerror ("recursive inclusion"); 233 yyerror ("recursive inclusion");
234 if (ctx->prev) 234 if (ctx->prev)
235 sieve_error ("%s:%d: `%s' already included here", 235 sieve_compile_error (ctx->prev->filename, ctx->prev->line,
236 ctx->prev->filename, ctx->prev->line, name); 236 "`%s' already included here",
237 name);
237 else 238 else
238 sieve_error ("`%s' already included at top level", 239 sieve_compile_error (sieve_filename, sieve_line_num,
239 name); 240 "`%s' already included at top level",
241 name);
240 return 1; 242 return 1;
241 } 243 }
242 244
243 fp = fopen (name, "r"); 245 fp = fopen (name, "r");
244 if (!fp) 246 if (!fp)
245 { 247 {
246 sieve_error ("can't open `%s': %s", name, strerror (errno)); 248 sieve_compile_error (sieve_filename, sieve_line_num,
247 yyerror ("can't include file"); 249 "can't open `%s': %s", name, strerror (errno));
248 return 1; 250 return 1;
249 } 251 }
250 252
...@@ -470,7 +472,8 @@ multiline_begin () ...@@ -470,7 +472,8 @@ multiline_begin ()
470 status = list_create (&string_list); 472 status = list_create (&string_list);
471 if (status) 473 if (status)
472 { 474 {
473 sieve_error ("list_create: %s", mu_errstring (status)); 475 sieve_compile_error (sieve_filename, sieve_line_num,
476 "list_create: %s", mu_errstring (status));
474 exit (1); 477 exit (1);
475 } 478 }
476 } 479 }
......
...@@ -144,20 +144,31 @@ sieve_value_create (sieve_data_type type, void *data) ...@@ -144,20 +144,31 @@ sieve_value_create (sieve_data_type type, void *data)
144 break; 144 break;
145 145
146 default: 146 default:
147 sieve_error ("Invalid data type"); 147 sieve_compile_error (sieve_filename, sieve_line_num, "Invalid data type");
148 abort (); 148 abort ();
149 } 149 }
150 return val; 150 return val;
151 } 151 }
152 152
153 void 153 void
154 sieve_error (const char *fmt, ...) 154 sieve_compile_error (const char *filename, int linenum, const char *fmt, ...)
155 { 155 {
156 va_list ap; 156 va_list ap;
157 157
158 va_start (ap, fmt); 158 va_start (ap, fmt);
159 sieve_error_count++; 159 sieve_error_count++;
160 sieve_machine->error_printer (sieve_machine->data, fmt, ap); 160 sieve_machine->parse_error_printer (sieve_machine->data, filename, linenum,
161 fmt, ap);
162 va_end (ap);
163 }
164
165 void
166 sieve_error (sieve_machine_t *mach, const char *fmt, ...)
167 {
168 va_list ap;
169
170 va_start (ap, fmt);
171 mach->error_printer (mach->data, fmt, ap);
161 va_end (ap); 172 va_end (ap);
162 } 173 }
163 174
...@@ -187,6 +198,15 @@ _sieve_default_error_printer (void *unused, const char *fmt, va_list ap) ...@@ -187,6 +198,15 @@ _sieve_default_error_printer (void *unused, const char *fmt, va_list ap)
187 return mu_verror (fmt, ap); 198 return mu_verror (fmt, ap);
188 } 199 }
189 200
201 int
202 _sieve_default_parse_error (void *unused, const char *filename, int lineno,
203 const char *fmt, va_list ap)
204 {
205 fprintf (stderr, "%s:%d: ", filename, lineno);
206 vfprintf (stderr, fmt, ap);
207 return 0;
208 }
209
190 char * 210 char *
191 sieve_type_str (sieve_data_type type) 211 sieve_type_str (sieve_data_type type)
192 { 212 {
...@@ -304,10 +324,4 @@ sieve_print_tag_list (list_t list, sieve_printf_t printer, void *data) ...@@ -304,10 +324,4 @@ sieve_print_tag_list (list_t list, sieve_printf_t printer, void *data)
304 list_do (list, (list_action_t*) tag_printer, &dbg); 324 list_do (list, (list_action_t*) tag_printer, &dbg);
305 } 325 }
306 326
307 void
308 sieve_set_debug (sieve_machine_t *mach, sieve_printf_t debug, int level)
309 {
310 mach->debug_printer = debug;
311 mach->debug_level = level;
312 }
313 327
......