diff options
author | pommicket <pommicket@gmail.com> | 2025-09-13 23:33:13 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-13 23:33:13 -0400 |
commit | 64c5d7ab942d8f4589f43909497ae07cc69231d0 (patch) | |
tree | 45ea4e09315bc60a74f15899b1dfa923af657dd2 /pom.c | |
parent | 5a7bce1f14ac3daecb295a2b0aa6c94d8a485921 (diff) |
Check for duplicates
Diffstat (limited to 'pom.c')
-rw-r--r-- | pom.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -926,7 +926,29 @@ parser_finish(struct parser *parser) { #endif } qsort(items, items_count, sizeof *items, conf_item_cmp_qsort); - // TODO: check for duplicates + for (size_t i = 0; i + 1 < items_count; i++) { + struct conf_item *item1 = &items[i]; + struct conf_item *item2 = &items[i+1]; + if (strcmp(item1->key, item2->key) != 0) { + // OK + continue; + } + uint64_t min_line, max_line; + if (item1->line < item2->line) { + min_line = item1->line; + max_line = item2->line; + } else { + min_line = item2->line; + max_line = item1->line; + } + parser->line_number = max_line; + parser_error(parser, "Re-definition of %s (previously defined on line %" PRIu64 ")", + item1->key, min_line); + } + if (parser->errors.count) { + conf_free(conf); + return NULL; + } pom_conf *root = conf_calloc(conf, 1, sizeof *root); if (!root) goto out_of_memory; |