Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-08-12 01:29:23 +0400
committerFelix Fietkau <nbd@openwrt.org>2011-08-12 01:29:23 +0400
commitec56b91662f7ba5bc305e7210b4ea0d4da1dc58f (patch)
tree25e3f4ac3b5c83025e99b11ce6882afd10dba209 /sh
parentbdf717425a8f21e7abf6c45b36fe294b1fea58c5 (diff)
jshn: clear more variables on json_init, fix adding array elements
Diffstat (limited to 'sh')
-rw-r--r--sh/jshn.sh16
1 files changed, 12 insertions, 4 deletions
diff --git a/sh/jshn.sh b/sh/jshn.sh
index 63d4b09..7389f8c 100644
--- a/sh/jshn.sh
+++ b/sh/jshn.sh
@@ -10,7 +10,7 @@ jshn_append() {
json_init() {
[ -n "$JSON_UNSET" ] && eval "unset $JSON_UNSET"
- export -- JSON_SEQ=0 JSON_STACK= JSON_CUR="JSON_VAR" JSON_UNSET=
+ export -- JSON_SEQ=0 JSON_STACK= JSON_CUR="JSON_VAR" JSON_UNSET="" KEYS_JSON_VAR= TYPE_JSON_VAR=
}
json_add_generic() {
@@ -19,6 +19,12 @@ json_add_generic() {
local val="$3"
local cur="${4:-$JSON_CUR}"
+ [ "${cur%%[0-9]*}" = "JSON_ARRAY" ] && {
+ eval "local aseq=\"\${SEQ_$cur}\""
+ var=$(( ${aseq:-0} + 1 ))
+ export -- "SEQ_$cur=$var"
+ }
+
export -- "${cur}_$var=$val"
export -- "TYPE_${cur}_$var=$type"
jshn_append JSON_UNSET "${cur}_$var TYPE_${cur}_$var"
@@ -26,18 +32,20 @@ json_add_generic() {
}
json_add_table() {
+ local TYPE="$1"
JSON_SEQ=$(($JSON_SEQ + 1))
jshn_append JSON_STACK "$JSON_CUR"
- local table="JSON_TABLE$JSON_SEQ"
+ local table="JSON_$TYPE$JSON_SEQ"
export -- "UP_$table=$JSON_CUR"
export -- "KEYS_$table="
jshn_append JSON_UNSET "KEYS_$table UP_$table"
+ [ "$TYPE" = "ARRAY" ] && jshn_append JSON_UNSET "SEQ_$table"
JSON_CUR="$table"
}
json_add_object() {
local cur="$JSON_CUR"
- json_add_table
+ json_add_table TABLE
json_add_generic object "$1" "$JSON_CUR" "$cur"
}
@@ -50,7 +58,7 @@ json_close_object() {
json_add_array() {
local cur="$JSON_CUR"
- json_add_table
+ json_add_table ARRAY
json_add_generic array "$1" "$JSON_CUR" "$cur"
}