diff options
author | Petr Machata <pmachata@redhat.com> | 2012-01-06 21:10:36 +0100 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-08-29 19:02:06 +0200 |
commit | 21e56081e73310b3409c6d4af1af118fb700c3f8 (patch) | |
tree | e59d58eb0ca45b06a5099ab2d15f91d9b7aa67df /read_config_file.c | |
parent | 2bea8615d97097a334449ee95112c8a59277103e (diff) | |
download | ltrace-21e56081e73310b3409c6d4af1af118fb700c3f8.tar.gz |
Move ARGTYPE_ENUM entries to arg_type_info.u.entries, use type.c in parser
Diffstat (limited to 'read_config_file.c')
-rw-r--r-- | read_config_file.c | 58 |
1 files changed, 19 insertions, 39 deletions
diff --git a/read_config_file.c b/read_config_file.c index fe45894..3d51f6b 100644 --- a/read_config_file.c +++ b/read_config_file.c @@ -541,23 +541,26 @@ parse_alias(char **str, struct arg_type_info **retp, int *ownp) static int parse_enum(char **str, struct arg_type_info *info) { - struct enum_opt { - char *key; - int value; - struct enum_opt *next; - }; - struct enum_opt *list = NULL; - struct enum_opt *p; - int entries = 0; - int ii; - - eat_spaces(str); - (*str)++; // Get past open paren eat_spaces(str); + if (parse_char(str, '(') < 0) + return -1; + + type_init_enum(info); int last_val = 0; - while (**str && **str != ')') { - p = (struct enum_opt *) malloc(sizeof(*p)); + while (1) { + eat_spaces(str); + if (**str == 0 || **str == ')') { + parse_char(str, ')'); + return 0; + } + + /* Field delimiter. XXX should we support the C + * syntax, where the enumeration can end in pending + * comma? */ + if (type_enum_size(info) > 0) + parse_char(str, ','); + eat_spaces(str); char *key = parse_ident(str); if (key == NULL) { @@ -578,32 +581,9 @@ parse_enum(char **str, struct arg_type_info *info) last_val++; } - p->key = key; - p->value = last_val; - p->next = list; - list = p; - ++entries; - - // Skip comma - eat_spaces(str); - if (**str == ',') { - (*str)++; - eat_spaces(str); - } - } - - info->u.enum_info.entries = entries; - info->u.enum_info.keys = (char **) malloc(entries * sizeof(char *)); - info->u.enum_info.values = (int *) malloc(entries * sizeof(int)); - for (ii = 0, p = NULL; list; ++ii, list = list->next) { - if (p != NULL) - free(p); - info->u.enum_info.keys[ii] = list->key; - info->u.enum_info.values[ii] = list->value; - p = list; + if (type_enum_add(info, key, 1, last_val) < 0) + goto err; } - if (p != NULL) - free(p); return 0; } |