diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-16 04:44:04 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-16 04:44:04 +0100 |
commit | bd79b0e35ff4159e1c6aed6a4105d8bc9d75f833 (patch) | |
tree | ed981cf2459d4d00239b6c637c5a10addd567a26 /src/mds-kbdc | |
parent | check that the parsing stack is empty when the end of a file has been reached (diff) | |
download | mds-bd79b0e35ff4159e1c6aed6a4105d8bc9d75f833.tar.gz mds-bd79b0e35ff4159e1c6aed6a4105d8bc9d75f833.tar.bz2 mds-bd79b0e35ff4159e1c6aed6a4105d8bc9d75f833.tar.xz |
mds-kbdc: support arrays
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc')
-rw-r--r-- | src/mds-kbdc/make-tree.c | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index 2169342..d00a05a 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -440,7 +440,7 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu const char** keyword_stack = NULL; mds_kbdc_tree_t*** tree_stack = NULL; size_t stack_ptr = 0; - int saved_errno; + int saved_errno, in_array = 0; *result = NULL; *errors = NULL; @@ -499,7 +499,42 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu *end = '\0'; original = line; - if (!strcmp(line, "information")) + redo: + if (in_array) + { + for (;;) + { + while (*line && (*line == ' ')) + line++; + if (*line == '\0') + break; + if (*line == '}') + { + line++; + end = line + strlen(line); + END; + line = end, prev_end_char = '\0'; + stack_ptr--; + 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); + LEAF; +#undef node + } + *end = prev_end_char; + line = end; + } + if (*line == '\0') + continue; + } + else if (!strcmp(line, "information")) { NEW_NODE(information, INFORMATION); NO_PARAMETERS("information"); @@ -649,7 +684,15 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu } else { - /* TODO */ +#define node subnode + NEW_NODE(array, ARRAY); +#define inner elements + BRANCH("}"); +#undef inner +#undef node + in_array = 1; + line++; + goto redo; } } else if (!strcmp(line, "have")) @@ -714,10 +757,15 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu char* end = NULL; NEW_ERROR(0, ERROR, "premature end of file"); while (stack_ptr--) - { - NEW_ERROR(0, NOTE, "missing ‘end %s’", keyword_stack[stack_ptr]); - /* TODO from where? */ - } + /* TODO from where? */ + if (!strcmp(keyword_stack[stack_ptr], "}")) + { + NEW_ERROR(0, NOTE, "missing ‘%s’", keyword_stack[stack_ptr]); + } + else + { + NEW_ERROR(0, NOTE, "missing ‘end %s’", keyword_stack[stack_ptr]); + } } free(pathname); |