X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=sh%2Fjshn.sh;h=63d4b094472a2c52ec08015ba023584e4cb4d737;hb=ed9b5c986b06bc90017461f8d0b8f45937a79598;hp=923f2b36318136a51b4f66147ff6f7c4980267be;hpb=fda6079b30a4f47daf95c8b93b9c86afee008f45;p=project%2Flibubox.git diff --git a/sh/jshn.sh b/sh/jshn.sh index 923f2b3..63d4b09 100644 --- a/sh/jshn.sh +++ b/sh/jshn.sh @@ -1,11 +1,11 @@ # functions for parsing and generating json -append() { +jshn_append() { local var="$1" local value="$2" local sep="${3:- }" - eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" + eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" } json_init() { @@ -19,17 +19,19 @@ json_add_generic() { local val="$3" local cur="${4:-$JSON_CUR}" - export ${NO_EXPORT:+-n} -- "${cur}_$var=$val" - export ${NO_EXPORT:+-n} -- "TYPE_${cur}_$var=$type" - append JSON_UNSET "${cur}_$var TYPE_${cur}_$var" - append "KEYS_${cur}" "$var" + export -- "${cur}_$var=$val" + export -- "TYPE_${cur}_$var=$type" + jshn_append JSON_UNSET "${cur}_$var TYPE_${cur}_$var" + jshn_append "KEYS_${cur}" "$var" } json_add_table() { JSON_SEQ=$(($JSON_SEQ + 1)) - append JSON_STACK "$JSON_CUR" + jshn_append JSON_STACK "$JSON_CUR" local table="JSON_TABLE$JSON_SEQ" - export ${NO_EXPORT:+-n} -- "UP_$table=$JSON_CUR" + export -- "UP_$table=$JSON_CUR" + export -- "KEYS_$table=" + jshn_append JSON_UNSET "KEYS_$table UP_$table" JSON_CUR="$table" } @@ -41,7 +43,6 @@ json_add_object() { json_close_object() { local oldstack="$JSON_STACK" - export "KEYS_${JSON_CUR}" JSON_CUR="${JSON_STACK##* }" JSON_STACK="${JSON_STACK% *}" [[ "$oldstack" == "$JSON_STACK" ]] && JSON_STACK= @@ -76,19 +77,19 @@ json_load() { } json_dump() { - jshn -w + jshn "$@" -w } json_get_type() { local dest="$1" local var="$2" - eval "export ${NO_EXPORT:+-n} -- \"$dest=\${TYPE_${JSON_CUR}_$var}\"" + eval "export -- \"$dest=\${TYPE_${JSON_CUR}_$var}\"" } json_get_var() { local dest="$1" local var="$2" - eval "export ${NO_EXPORT:+-n} -- \"$dest=\${${JSON_CUR}_$var}\"" + eval "export -- \"$dest=\${${JSON_CUR}_$var}\"" } json_select() {