summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d927093)
raw | patch | inline | side by side (parent: d927093)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 24 Mar 2008 11:06:49 +0000 (12:06 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 24 Mar 2008 11:13:44 +0000 (12:13 +0100) |
As collectd now supports more than one config file, this is more
convenient.
A module-global variable is used for that purpose. If no filename is
available (e.g. if the user uses oconfig_parse_fh() directly), a string
like "<fd#X>" is used instead, where X is replaced by the file descriptor.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
convenient.
A module-global variable is used for that purpose. If no filename is
available (e.g. if the user uses oconfig_parse_fh() directly), a string
like "<fd#X>" is used instead, where X is replaced by the file descriptor.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/liboconfig/oconfig.c | patch | blob | history | |
src/liboconfig/parser.y | patch | blob | history |
index db9285b3cf47052581405dcfce2d69170d0c587f..8cc3c8abc616b640e0d45a1eb672c60d2d47df1d 100644 (file)
--- a/src/liboconfig/oconfig.c
+++ b/src/liboconfig/oconfig.c
extern FILE *yyin;
oconfig_item_t *ci_root;
+char *c_file;
static void yyset_in (FILE *fd)
{
int status;
oconfig_item_t *ret;
+ char file[10];
+
yyset_in (fh);
+ if (NULL == c_file) {
+ int status;
+
+ status = snprintf (file, sizeof (file), "<fd#%d>", fileno (fh));
+
+ if ((status < 0) || (status >= sizeof (file))) {
+ c_file = "<unknown>";
+ }
+ else {
+ file[sizeof (file) - 1] = '\0';
+ c_file = file;
+ }
+ }
+
status = yyparse ();
if (status != 0)
{
return (NULL);
}
+ c_file = NULL;
+
ret = ci_root;
ci_root = NULL;
yyset_in ((FILE *) 0);
FILE *fh;
oconfig_item_t *ret;
+ c_file = file;
+
fh = fopen (file, "r");
if (fh == NULL)
{
ret = oconfig_parse_fh (fh);
fclose (fh);
+ c_file = NULL;
+
return (ret);
} /* oconfig_item_t *oconfig_parse_file */
index ea6ed0a099a2a822bd119dc6c16ebadcad594c25..48b9bf3d764d2b12177382862061d427ad3e2a53 100644 (file)
--- a/src/liboconfig/parser.y
+++ b/src/liboconfig/parser.y
extern char *yytext;
extern oconfig_item_t *ci_root;
+extern char *c_file;
%}
%start 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 */