From 893c0d1c41440bf2a233e5fb69b0aa76c221e876 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 16 Nov 2014 04:51:14 +0100 Subject: mds-kbdc: fix array elements: allow functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/make-tree.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index d32f222..7aff73e 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -209,6 +209,16 @@ while (0) +/** + * Suppress the next `line += strlen(line)` + */ +#define NO_JUMP \ + *end = prev_end_char; \ + end = line; \ + prev_end_char = *end; \ + *end = '\0' + + /** * Take next parameter, which should be a string or numeral, * and store it in the current node @@ -518,18 +528,16 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu in_array = 0; break; } - end = strchrnul(line, ' '); - prev_end_char = *end; - *end = '\0'; { #define node subnode NEW_NODE(string, STRING); - fail_if ((node->string = strdup(line)) == NULL); + NO_JUMP; + CHARS(string); LEAF; + *end = prev_end_char; + line = end; #undef node } - *end = prev_end_char; - line = end; } if (*line == '\0') continue; @@ -676,9 +684,7 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu { #define node subnode NEW_NODE(string, STRING); - end = line; - prev_end_char = *end; - *end = '\0'; + NO_JUMP; CHARS(string); #undef node node->value = (mds_kbdc_tree_t*)subnode; -- cgit v1.2.3-70-g09d2