From 8d7449d26f55e22592ecd51e7d6e11edaa2868f4 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Mon, 4 Jan 2021 09:15:01 +0100 Subject: [PATCH] add list_of_lists to config and more error messages --- src/lib-config/iconfig.h | 2 ++ src/lib-config/parse.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib-config/iconfig.h b/src/lib-config/iconfig.h index 92662d8d..bb1e7f47 100644 --- a/src/lib-config/iconfig.h +++ b/src/lib-config/iconfig.h @@ -62,6 +62,8 @@ struct _CONFIG_REC { GIOChannel *handle; int tmp_indent_level; /* indentation position */ int tmp_last_lf; /* last character was a line feed */ + + int list_of_lists : 1; /* list of lists allowed */ }; /* Open configuration. The file is created if it doesn't exist, unless diff --git a/src/lib-config/parse.c b/src/lib-config/parse.c index e4ff1abb..91a78781 100644 --- a/src/lib-config/parse.c +++ b/src/lib-config/parse.c @@ -170,8 +170,10 @@ static GTokenType config_parse_symbol(CONFIG_REC *rec, CONFIG_NODE *node) case '{': /* block */ - if (key == NULL && node->type != NODE_TYPE_LIST) + if (key == NULL && node->type != NODE_TYPE_LIST) { + g_scanner_error(rec->scanner, "Missing key"); return G_TOKEN_ERROR; + } newnode = config_node_section(rec, node, key, NODE_TYPE_BLOCK); config_parse_loop(rec, newnode, (GTokenType) '}'); @@ -186,8 +188,11 @@ static GTokenType config_parse_symbol(CONFIG_REC *rec, CONFIG_NODE *node) case '(': /* list */ - if (key == NULL) + if (key == NULL && !rec->list_of_lists) { + g_scanner_error(rec->scanner, "List of lists not allowed"); return G_TOKEN_ERROR; + } + newnode = config_node_section(rec, node, key, NODE_TYPE_LIST); config_parse_loop(rec, newnode, (GTokenType) ')'); g_free_not_null(key);