Commit cb00f766 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Improve error messages from configuration parser.

parent 052068bb
......@@ -260,11 +260,13 @@ main(int argc, char **argv)
config_file = "/etc/babeld.conf";
}
if(config_file) {
rc = parse_config_from_file(config_file);
int line;
rc = parse_config_from_file(config_file, &line);
if(rc < 0) {
fprintf(stderr,
"Couldn't parse configuration from file %s.\n",
config_file);
"Couldn't parse configuration from file %s "
"(error at line %d).\n",
config_file, line);
exit(1);
}
} else {
......
......@@ -594,17 +594,37 @@ parse_config(gnc_t gnc, void *closure)
return 1;
}
struct file_state {
FILE *f;
int line;
};
static int
gnc_file(struct file_state *s)
{
int c;
c = fgetc(s->f);
if(c == '\n')
s->line++;
return c;
}
int
parse_config_from_file(char *filename)
parse_config_from_file(const char *filename, int *line_return)
{
FILE *f;
struct file_state s = { NULL, 1 };
int rc;
f = fopen(filename, "r");
if(f == NULL)
s.f = fopen(filename, "r");
if(s.f == NULL) {
*line_return = 0;
return -1;
rc = parse_config((gnc_t)fgetc, f);
fclose(f);
}
rc = parse_config((gnc_t)gnc_file, &s);
fclose(s.f);
*line_return = s.line;
return rc;
}
......
......@@ -34,7 +34,7 @@ struct filter {
struct filter *next;
};
int parse_config_from_file(char *filename);
int parse_config_from_file(const char *filename, int *line_return);
int parse_config_from_string(char *string);
void renumber_filters(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment