diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-24 00:16:51 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-24 00:16:51 +0200 |
commit | 3afaf3d8f7617beed427c96e544ab177fabadaa4 (patch) | |
tree | 2e21acbbd074029da9a51e667ecc38fbcedeabf8 /shared | |
parent | 460b10553ac898232bfc5444e335dfa938690d1b (diff) |
Simplify config_parse_header
Diffstat (limited to 'shared')
-rw-r--r-- | shared/config-parser.c | 22 | ||||
-rw-r--r-- | shared/config-parser.h | 3 |
2 files changed, 9 insertions, 16 deletions
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 |