From 4f2644f354184d5febc1aa8f37e987eca03f7f25 Mon Sep 17 00:00:00 2001 From: pommicket Date: Mon, 15 Sep 2025 14:06:17 -0400 Subject: More tests; fix locations --- pom.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pom.c') diff --git a/pom.c b/pom.c index 37afeca..78eb41b 100644 --- a/pom.c +++ b/pom.c @@ -799,6 +799,7 @@ parse_line(struct parser *parser) { check_if_key_is_valid(parser, current_section); return; } + uint64_t start_line_number = parser->line_number; size_t equals_idx; for (size_t i = 0; ; i++) { if (line[i] == '=') { @@ -847,7 +848,7 @@ parse_line(struct parser *parser) { if (!item) return; item->key = key_idx; item->value = value_idx; - item->line = parser->line_number; + item->line = start_line_number; } static void @@ -1385,11 +1386,23 @@ pom_conf_has(const pom_conf *conf, const char *key) { bool pom_conf_location(const pom_conf *conf, const char *key, const char **file, uint64_t *line) { struct conf_item *item = conf_get_item(conf, key); + bool found; + size_t i; if (item) { if (file) *file = item->file; if (line) *line = item->line; return true; + } else if ((i = conf_binary_search_sections(conf, key, 0, &found)), found) { + // pick an item from this section + const struct conf_section *section = &conf->sections[i]; + if (section->conf.items_count == 0) + goto fail; + const struct conf_item *item = §ion->conf.items[0]; + if (file) *file = item->file; + if (line) *line = item->line; + return true; } else { + fail: if (file) *file = NULL; if (line) *line = 0; return false; -- cgit v1.2.3