diff options
author | Marc Kleine-Budde <mkl@pengutronix.de> | 2015-04-28 14:04:37 +0200 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2015-04-28 15:13:37 +0200 |
commit | 6d58ca4cf725db7e694c376f97de81c69dc5c9d6 (patch) | |
tree | e1ea3bc86961df471185b86bd21914cd47dc9d78 | |
parent | 95a37eb2ecc0a4642df39819e5eb085b1f525cee (diff) | |
download | dt-utils-6d58ca4cf725db7e694c376f97de81c69dc5c9d6.tar.gz dt-utils-6d58ca4cf725db7e694c376f97de81c69dc5c9d6.tar.xz |
barebox-state: fix export of shell variables:
- convert "." in variable names to "_"
- use supplied state name instead of hardcoded "STATE_" as prefix
- let OPT_DUMP_SHELL start after all chars
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | src/barebox-state.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/barebox-state.c b/src/barebox-state.c index f7fa53a..61f8a2d 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -17,6 +17,7 @@ #include <errno.h> #include <fcntl.h> #include <getopt.h> +#include <limits.h> #include <stdarg.h> #include <stdint.h> #include <stdio.h> @@ -1473,7 +1474,7 @@ static struct state *state_get(const char *name) } enum opt { - OPT_DUMP_SHELL = 1, + OPT_DUMP_SHELL = UCHAR_MAX + 1, }; static struct option long_options[] = { @@ -1590,8 +1591,17 @@ int main(int argc, char *argv[]) if (do_dump_shell) { state_for_each_var(state, v) { struct variable_type *vtype; + char *name, *ptr; + int i; + + /* replace "." by "_" to make it var name shell compatible */ + name = strdup(v->name); + ptr = name; + while ((ptr = strchr(ptr, '.'))) + *ptr++ = '_'; + vtype = state_find_type(v->type); - printf("STATE_%s=\"%s\"\n", v->name, vtype->get(v)); + printf("%s_%s=\"%s\"\n", statename, name, vtype->get(v)); } } |