diff options
author | jolsa@redhat.com <jolsa@redhat.com> | 2011-10-31 16:33:47 +0100 |
---|---|---|
committer | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2011-11-24 21:20:27 +0100 |
commit | bf775c23afef014f9e11796741786e032d0ec374 (patch) | |
tree | e207a1c696af27a96e0621a43409fc61140a8d26 | |
parent | ba8c8bd79445a34d24b061cb6fed94578f0af212 (diff) | |
download | latrace-bf775c23afef014f9e11796741786e032d0ec374.tar.gz latrace-bf775c23afef014f9e11796741786e032d0ec374.tar.xz latrace-bf775c23afef014f9e11796741786e032d0ec374.zip |
config: adding value list support
-rw-r--r-- | src/config-bison.y | 17 | ||||
-rw-r--r-- | src/config.c | 15 | ||||
-rw-r--r-- | src/config.h | 13 |
3 files changed, 39 insertions, 6 deletions
diff --git a/src/config-bison.y b/src/config-bison.y index 247a270..c9512ac 100644 --- a/src/config-bison.y +++ b/src/config-bison.y @@ -272,13 +272,26 @@ OPTIONS_DEF OPT_ARGS_STRING_POINTER_LENGTH '=' BOOL list_names_comma: list_names_comma ',' NAME { - if (lt_config_ln_add(&ln_names, $3)) + if (lt_config_ln_add(&ln_names, $3, 0, LT_CONFIG_LN_NAME)) ABORT("failed to add list name"); } | NAME { - if (lt_config_ln_add(&ln_names, $1)) + if (lt_config_ln_add(&ln_names, $1, 0, LT_CONFIG_LN_NAME)) + ABORT("failed to add list name"); +} + +list_values_comma: +list_values_comma ',' VALUE +{ + if (lt_config_ln_add(&ln_names, NULL, $3, LT_CONFIG_LN_VALUE)) + ABORT("failed to add list name"); +} +| +VALUE +{ + if (lt_config_ln_add(&ln_names, NULL, $1, LT_CONFIG_LN_VALUE)) ABORT("failed to add list name"); } diff --git a/src/config.c b/src/config.c index b04ec2c..7b6ecef 100644 --- a/src/config.c +++ b/src/config.c @@ -381,14 +381,25 @@ struct lt_config_opt *lt_config_opt_new(struct lt_config_app *cfg, return opt; } -int lt_config_ln_add(struct lt_list_head *head, char *name) +int lt_config_ln_add(struct lt_list_head *head, + char *name, long val, int type) { struct lt_config_ln *ln = malloc(sizeof(*ln)); if (!ln) return -1; - ln->name = strdup(name); + switch(type) { + case LT_CONFIG_LN_NAME: + ln->name = strdup(name); + break; + case LT_CONFIG_LN_VALUE: + ln->val = val; + break; + } + + ln->type = type; + lt_init_list_head(&ln->list); lt_list_add_tail(&ln->list, head); return 0; diff --git a/src/config.h b/src/config.h index 1ac519e..379c7b8 100644 --- a/src/config.h +++ b/src/config.h @@ -257,9 +257,18 @@ struct lt_config_audit { int init_ok; }; +enum { + LT_CONFIG_LN_NAME, + LT_CONFIG_LN_VALUE, +}; + /* config - list name support */ struct lt_config_ln { - char *name; + union { + char *name; + long val; + }; + int type; struct lt_list_head list; }; @@ -416,7 +425,7 @@ struct lt_symbol* lt_symbol_get(struct lt_config_shared *cfg, struct lt_config_opt *lt_config_opt_new(struct lt_config_app *cfg, int idx, char *sval, long nval); int lt_config_opt_process(struct lt_config_app *cfg, struct lt_list_head *list); -int lt_config_ln_add(struct lt_list_head *head, char *name); +int lt_config_ln_add(struct lt_list_head *head, char *name, long val, int type); int lt_config_ln_fill_buf(struct lt_list_head *head, char *buf, int size); char **lt_config_ln_fill_array(struct lt_list_head *head); |