Code

liboconfig: Include the filename in error messages.
[collectd.git] / src / liboconfig / parser.y
index ea6ed0a099a2a822bd119dc6c16ebadcad594c25..48b9bf3d764d2b12177382862061d427ad3e2a53 100644 (file)
@@ -30,6 +30,7 @@ extern int yylineno;
 extern char *yytext;
 
 extern oconfig_item_t *ci_root;
+extern char           *c_file;
 %}
 
 %start entire_file
@@ -186,7 +187,15 @@ entire_file:
 %%
 static int yyerror (const char *s)
 {
-       fprintf (stderr, "Error in line %i near `%s': %s\n", yylineno, yytext, s);
+       char *text;
+
+       if (*yytext == '\n')
+               text = "<newline>";
+       else
+               text = yytext;
+
+       fprintf (stderr, "Parse error in file `%s', line %i near `%s': %s\n",
+               c_file, yylineno, text, s);
        return (-1);
 } /* int yyerror */