From 3afaf3d8f7617beed427c96e544ab177fabadaa4 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 24 Jun 2020 00:16:51 +0200 Subject: Simplify config_parse_header --- shared/config-parser.c | 22 ++++++++-------------- shared/config-parser.h | 3 +-- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'shared') diff --git a/shared/config-parser.c b/shared/config-parser.c index 1c9979e..8dedbe5 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -35,6 +35,8 @@ get_line(char **pos) assert_return(pos && *pos, NULL); + eat_whitespace_and_comments(pos); + begin = *pos; while (isspace(*begin)) begin++; @@ -325,7 +327,6 @@ config_parse_line(const char *filename, char **buf, assert_return(buf && *buf && kvmap && rkey && rkeyname && rvalue, false); - eat_whitespace_and_comments(buf); line = get_line(buf); if (!line) return false; @@ -467,27 +468,20 @@ error: } bool -config_parse_header(const char *filename, const char *title, char **buf) +config_parse_header(const char *title, char **buf) { char *line; - assert_return(!empty_str(filename) && !empty_str(title) && buf && *buf, false); - - eat_whitespace_and_comments(buf); + assert_return(!empty_str(title) && buf && *buf, false); line = get_line(buf); - if (!line) { - error("%s: missing header in configuration file", filename); - return false; - } else { + if (line) { char titlehdr[strlen(title) + 3]; sprintf(titlehdr, "[%s]", title); - if (!streq(line, titlehdr)) { - error("%s: incorrect header in configuration file", filename); - return false; - } + if (streq(line, titlehdr)) + return true; } - return true; + return false; } diff --git a/shared/config-parser.h b/shared/config-parser.h index 3a117a3..4b2103f 100644 --- a/shared/config-parser.h +++ b/shared/config-parser.h @@ -53,7 +53,6 @@ bool config_parse_line(const char *filename, char **buf, int *rkey, const char **rkeyname, struct cfg_value *rvalue); -bool config_parse_header(const char *filename, - const char *title, char **buf); +bool config_parse_header(const char *title, char **buf); #endif -- cgit v1.2.3