{
char *keys;
- keys = alloca(var_prefix_len + strlen(prefix) + sizeof("KEYS_") + 1);
- sprintf(keys, "%sKEYS_%s", var_prefix, prefix);
+ keys = alloca(var_prefix_len + strlen(prefix) + sizeof("K_") + 1);
+ sprintf(keys, "%sK_%s", var_prefix, prefix);
return getenv(keys);
}
{
char *tmpname, *varname;
- tmpname = alloca(var_prefix_len + strlen(prefix) + 1 + strlen(*name) + 1 + sizeof("TYPE_"));
+ tmpname = alloca(var_prefix_len + strlen(prefix) + 1 + strlen(*name) + 1 + sizeof("T_"));
sprintf(tmpname, "%s%s_%s", var_prefix, prefix, *name);
*var = getenv(tmpname);
- sprintf(tmpname, "%sTYPE_%s_%s", var_prefix, prefix, *name);
+ sprintf(tmpname, "%sT_%s_%s", var_prefix, prefix, *name);
*type = getenv(tmpname);
- sprintf(tmpname, "%sNAME_%s_%s", var_prefix, prefix, *name);
+ sprintf(tmpname, "%sN_%s_%s", var_prefix, prefix, *name);
varname = getenv(tmpname);
if (varname)
*name = varname;
# cur=$4
local var
- if [ "${4%%[0-9]*}" = "JSON_ARRAY" ]; then
- _json_inc "SEQ_$4" var
+ if [ "${4%%[0-9]*}" = "J_A" ]; then
+ _json_inc "S_$4" var
else
- local name="${2//[^a-zA-Z0-9_]/_}"
- [[ "$name" == "$2" ]] || export -- "${JSON_PREFIX}NAME_${4}_${name}=$2"
- var="$name"
+ var="${2//[^a-zA-Z0-9_]/_}"
+ [[ "$var" == "$2" ]] || export -- "${JSON_PREFIX}N_${4}_${var}=$2"
fi
- local cur_var=
export -- \
"${JSON_PREFIX}${4}_$var=$3" \
- "${JSON_PREFIX}TYPE_${4}_$var=$1"
+ "${JSON_PREFIX}T_${4}_$var=$1"
_jshn_append "JSON_UNSET" "${4}_$var"
- _jshn_append "KEYS_$4" "$var"
+ _jshn_append "K_$4" "$var"
}
_json_add_table() {
_json_get_var cur JSON_CUR
_json_inc JSON_SEQ seq
- local table="JSON_$3$seq"
- _json_set_var "UP_$table" "$cur"
- export -- "${JSON_PREFIX}KEYS_$table="
- unset "${JSON_PREFIX}SEQ_$table"
+ local table="J_$3$seq"
+ _json_set_var "U_$table" "$cur"
+ export -- "${JSON_PREFIX}K_$table="
+ unset "${JSON_PREFIX}S_$table"
_json_set_var JSON_CUR "$table"
_jshn_append "JSON_UNSET" "$table"
local _s_cur
_json_get_var _s_cur JSON_CUR
- _json_get_var "${JSON_PREFIX}JSON_CUR" "UP_$_s_cur"
- unset "${JSON_PREFIX}UP_$_s_cur"
+ _json_get_var "${JSON_PREFIX}JSON_CUR" "U_$_s_cur"
+ unset "${JSON_PREFIX}U_$_s_cur"
}
json_set_namespace() {
_json_get_var unset JSON_UNSET
for tmp in $unset JSON_VAR; do
unset \
- ${JSON_PREFIX}UP_$tmp \
- ${JSON_PREFIX}KEYS_$tmp \
- ${JSON_PREFIX}SEQ_$tmp \
- ${JSON_PREFIX}TYPE_$tmp \
- ${JSON_PREFIX}NAME_$tmp \
+ ${JSON_PREFIX}U_$tmp \
+ ${JSON_PREFIX}K_$tmp \
+ ${JSON_PREFIX}S_$tmp \
+ ${JSON_PREFIX}T_$tmp \
+ ${JSON_PREFIX}N_$tmp \
${JSON_PREFIX}$tmp
done
export -n ${JSON_PREFIX}JSON_SEQ=0
export -- \
${JSON_PREFIX}JSON_CUR="JSON_VAR" \
- ${JSON_PREFIX}KEYS_JSON_VAR=
+ ${JSON_PREFIX}K_JSON_VAR=
}
json_add_object() {
- _json_add_table "$1" object TABLE
+ _json_add_table "$1" object T
}
json_close_object() {
}
json_add_array() {
- _json_add_table "$1" array ARRAY
+ _json_add_table "$1" array A
}
json_close_array() {
local __cur
_json_get_var __cur JSON_CUR
- local __var="${JSON_PREFIX}TYPE_${__cur}_${2//[^a-zA-Z0-9_]/_}"
+ local __var="${JSON_PREFIX}T_${__cur}_${2//[^a-zA-Z0-9_]/_}"
eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
}
else
_json_get_var _tbl_cur JSON_CUR
fi
- local __var="${JSON_PREFIX}KEYS_${_tbl_cur}"
+ local __var="${JSON_PREFIX}K_${_tbl_cur}"
eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
}
}
[[ "$1" == ".." ]] && {
_json_get_var cur JSON_CUR
- _json_get_var cur "UP_$cur"
- unset "${JSON_PREFIX}UP_$cur"
+ _json_get_var cur "U_$cur"
+ unset "${JSON_PREFIX}U_$cur"
_json_set_var JSON_CUR "$cur"
return 0
}
case "$type" in
object|array)
json_get_var cur "$target"
- _json_get_var "${JSON_PREFIX}UP_$cur" JSON_CUR
+ _json_get_var "${JSON_PREFIX}U_$cur" JSON_CUR
_json_set_var JSON_CUR "$cur"
;;
*)