From 2439a77d0c4f77420edb04e77be6aa664b85f842 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 3 Nov 2010 06:36:19 +0100 Subject: json.sh, test.json: initial commit --- json.sh | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.json | 5 +++ 2 files changed, 114 insertions(+) create mode 100755 json.sh create mode 100644 test.json diff --git a/json.sh b/json.sh new file mode 100755 index 00000000..1c734b94 --- /dev/null +++ b/json.sh @@ -0,0 +1,109 @@ +#! /bin/sh +set -euf + +# TODO check json first + +normalize_json() { + sed -rn ' + 1s/^/cat<&2 + #echo `echo "$key_stack" | head -n 1` >&2 + pop_key # TODO check if is %%%MAKEJSONOBJ%%% + set -- `print_key` + #echo object: $1 >&2; set | sed -rn "s/^($1_[a-zA-Z]+)_VALUE=(.*)/\1/p" >&2 + json_set OBJ "`set | sed -rn "s/^($1_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" +} +begin_json_array() { :; } +end_json_array() { :; } +json_push_key() { + push_key "`echo -n "$1" | base64 -d`" +} +json_set_key() { + pop_key + json_push_key "$1" +} +json_set() { + ##echo "`print_key`$1=$2 (`echo -n $2 | base64 -d`)" >&2 + #echo "`print_key`TYPE=$1" >&2 + #echo "`print_key`VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 + eval "`print_key`_TYPE=$1" + eval "`print_key`_VALUE=\"$2\"" +} + +push_key() { + key="${key+${key}_}$1" + #key_stack="$1 +#$key_stack" +} +pop_key() { + key="`echo $key | sed 's/_[^_]\+$//'`" + #key_stack="`echo "$key_stack" | sed 1d`" +} +print_key() { + ##echo \<`echo print_key: $key`, `echo "$key_stack" | tac | tr '\n' _`\> >&2 + #echo "$key_stack" | tac | tr '\n' _ + echo -n "$key" +} + +json() { + #eval echo "\"\$`echo -n JSON "$@" | tr "$IFS" _`\" | base64 -d" + NAME="`echo -n JSON "$@" | tr "$IFS" _`" + eval "TYPE=\"\$${NAME}_TYPE\"" + + echo -n "$TYPE $NAME: " + case "$TYPE" in + (OBJ) + eval echo -n \$${NAME}_VALUE + ;; + #set | sed -rn "s/^(${NAME})_([a-zA-Z]+)[a-zA-Z_]*_VALUE=(.*)/\1_\2/p" | + # sort | uniq | tr \\n \ ;; + (*) #echo -n "$VALUE";; + #eval "VALUE=\"\$(echo -n \"\$${NAME}_VALUE\" | base64 -d)\"" + eval echo -n \"\$${NAME}_VALUE\" | base64 -d + esac + echo +} + +key='JSON' +#key_stack='JSON' +meh="`cat`" +echo "$meh" +#echo "$meh" | normalize_json | json_to_sh; exit +eval "`echo "$meh" | normalize_json | json_to_sh`" +#echo ==== +#set | grep '^JSON[A-Za-z_]*=' +#echo ==== +json +json a +json b +json c +json c ca +json c cb + +echo READY. +#### End of file. diff --git a/test.json b/test.json new file mode 100644 index 00000000..7da5175d --- /dev/null +++ b/test.json @@ -0,0 +1,5 @@ +{ + "a": "1", + "b": 2, + "c": { "ca": 11, "cb": [1, 2, 3] } +} -- cgit v1.2.3 From 1b9f91da01ae46d7d316c676ce2c121dd2a9588f Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 3 Nov 2010 16:26:00 +0100 Subject: json.sh: renamed types like STR -> string --- json.sh | 81 +++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/json.sh b/json.sh index 1c734b94..8297a853 100755 --- a/json.sh +++ b/json.sh @@ -3,6 +3,8 @@ set -euf # TODO check json first +# XXX json_key is something like PWD^^ + normalize_json() { sed -rn ' 1s/^/cat<&2 - #echo `echo "$key_stack" | head -n 1` >&2 + #echo end_json_object: $json_key >&2 pop_key # TODO check if is %%%MAKEJSONOBJ%%% - set -- `print_key` - #echo object: $1 >&2; set | sed -rn "s/^($1_[a-zA-Z]+)_VALUE=(.*)/\1/p" >&2 - json_set OBJ "`set | sed -rn "s/^($1_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" + #echo obj: $1 `set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"` >&2 + #json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" + json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)=(.*)/\1/p"`" } begin_json_array() { :; } end_json_array() { :; } @@ -48,62 +49,68 @@ json_set_key() { json_push_key "$1" } json_set() { - ##echo "`print_key`$1=$2 (`echo -n $2 | base64 -d`)" >&2 - #echo "`print_key`TYPE=$1" >&2 - #echo "`print_key`VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 - eval "`print_key`_TYPE=$1" - eval "`print_key`_VALUE=\"$2\"" + ##echo "typeof_$json_key=$1" >&2 + ##echo "${json_key}_VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 + #eval "${json_key}_TYPE=$1" + #eval "${json_key}_VALUE=\"$2\"" + eval "typeof_${json_key}=$1" + eval "${json_key}=\"$2\"" } push_key() { - key="${key+${key}_}$1" - #key_stack="$1 -#$key_stack" + json_key="${json_key+${json_key}_}$1" } pop_key() { - key="`echo $key | sed 's/_[^_]\+$//'`" - #key_stack="`echo "$key_stack" | sed 1d`" -} -print_key() { - ##echo \<`echo print_key: $key`, `echo "$key_stack" | tac | tr '\n' _`\> >&2 - #echo "$key_stack" | tac | tr '\n' _ - echo -n "$key" + json_key="`echo $json_key | sed 's/_[^_]\+$//'`" } json() { - #eval echo "\"\$`echo -n JSON "$@" | tr "$IFS" _`\" | base64 -d" - NAME="`echo -n JSON "$@" | tr "$IFS" _`" - eval "TYPE=\"\$${NAME}_TYPE\"" + #eval echo "\"\$`echo -n "$json_key" "$@" | tr "$IFS" _`\" | base64 -d" + NAME="`echo -n "$json_key" "$@" | tr "$IFS" _`" + #eval "TYPE=\"\$${NAME}_TYPE\"" + eval "TYPE=\"\$typeof_$NAME\"" echo -n "$TYPE $NAME: " case "$TYPE" in - (OBJ) - eval echo -n \$${NAME}_VALUE + (object) + #eval echo -n \$${NAME}_VALUE + eval echo -n \$$NAME ;; #set | sed -rn "s/^(${NAME})_([a-zA-Z]+)[a-zA-Z_]*_VALUE=(.*)/\1_\2/p" | # sort | uniq | tr \\n \ ;; (*) #echo -n "$VALUE";; #eval "VALUE=\"\$(echo -n \"\$${NAME}_VALUE\" | base64 -d)\"" - eval echo -n \"\$${NAME}_VALUE\" | base64 -d + #eval echo -n \"\$${NAME}_VALUE\" | base64 -d + eval echo -n \$${NAME} | base64 -d esac echo } -key='JSON' -#key_stack='JSON' -meh="`cat`" -echo "$meh" -#echo "$meh" | normalize_json | json_to_sh; exit -eval "`echo "$meh" | normalize_json | json_to_sh`" -#echo ==== -#set | grep '^JSON[A-Za-z_]*=' -#echo ==== +read_json() { + json_key="${1-JSON}" + #meh="`cat`" + #echo "$meh" + ##echo "$meh" | normalize_json | json_to_sh; exit + #eval "`echo "$meh" | normalize_json | json_to_sh`" + eval "`normalize_json | json_to_sh`" +} + +# TODO print_json x, print_json x ca ... to print as json + +read_json x +echo ==== +set | egrep "^(typeof_)?$json_key[A-Za-z_]*=" +echo ==== json json a json b json c json c ca json c cb +json d +#echo ==== +#echo $JSON_VALUE +#echo $JSON_c_cb_VALUE | base64 -d; echo echo READY. #### End of file. -- cgit v1.2.3 From 38bc33d7b4750540afcd67a37cfb00da3357b053 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 3 Nov 2010 16:26:41 +0100 Subject: test.json: bump --- test.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.json b/test.json index 7da5175d..a0406039 100644 --- a/test.json +++ b/test.json @@ -1,5 +1,6 @@ { "a": "1", "b": 2, - "c": { "ca": 11, "cb": [1, 2, 3] } + "c": { "ca": 11, "cb": [1, 2, 3, "42"] }, + "d": {} } -- cgit v1.2.3 From d42b585a1e8dfaf8184021a4664bbbe2b3fc10a9 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 31 Jul 2011 04:16:20 +0200 Subject: translate.google: fix encoding --- util/bin/translate.google | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/bin/translate.google b/util/bin/translate.google index 943675f4..1a1be6b6 100755 --- a/util/bin/translate.google +++ b/util/bin/translate.google @@ -33,6 +33,8 @@ done -d "hl=\${hl-en}" \\ -d "layout=\${layout-2}" \\ -d "eotf=\${eotf-1}" \\ + -d "ie=UTF-8" \\ + -d "oe=UTF-8" \\ -d "sl=\${sl-auto}" \\ -d "tl=\${tl-en}" \\ -d "text=\$text" \\ -- cgit v1.2.3 From 952f5b160a95a2eee616116f250aa8921deed934 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 31 Jul 2011 04:24:11 +0200 Subject: sh-json -> json/sh --- Makefile | 19 --------- json.sh | 116 ------------------------------------------------------ json/sh/Makefile | 19 +++++++++ json/sh/json.sh | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ json/sh/test.json | 6 +++ test.json | 6 --- 6 files changed, 141 insertions(+), 141 deletions(-) delete mode 100644 Makefile delete mode 100755 json.sh create mode 100644 json/sh/Makefile create mode 100755 json/sh/json.sh create mode 100644 json/sh/test.json delete mode 100644 test.json diff --git a/Makefile b/Makefile deleted file mode 100644 index 188e6ca2..00000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -DIST = debian - -.PHONY: infest all -all: select-target - -infest: - make -C infest - -install-core: - core/$(DIST) - -noise: - make -C noise infest -streams: - make -C streams -monitoring: - make -C Monitoring debian -zoneminder: - make -C zoneminder fix it so hard diff --git a/json.sh b/json.sh deleted file mode 100755 index 8297a853..00000000 --- a/json.sh +++ /dev/null @@ -1,116 +0,0 @@ -#! /bin/sh -set -euf - -# TODO check json first - -# XXX json_key is something like PWD^^ - -normalize_json() { - sed -rn ' - 1s/^/cat<&2 - pop_key # TODO check if is %%%MAKEJSONOBJ%%% - #echo obj: $1 `set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"` >&2 - #json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" - json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)=(.*)/\1/p"`" -} -begin_json_array() { :; } -end_json_array() { :; } -json_push_key() { - push_key "`echo -n "$1" | base64 -d`" -} -json_set_key() { - pop_key - json_push_key "$1" -} -json_set() { - ##echo "typeof_$json_key=$1" >&2 - ##echo "${json_key}_VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 - #eval "${json_key}_TYPE=$1" - #eval "${json_key}_VALUE=\"$2\"" - eval "typeof_${json_key}=$1" - eval "${json_key}=\"$2\"" -} - -push_key() { - json_key="${json_key+${json_key}_}$1" -} -pop_key() { - json_key="`echo $json_key | sed 's/_[^_]\+$//'`" -} - -json() { - #eval echo "\"\$`echo -n "$json_key" "$@" | tr "$IFS" _`\" | base64 -d" - NAME="`echo -n "$json_key" "$@" | tr "$IFS" _`" - #eval "TYPE=\"\$${NAME}_TYPE\"" - eval "TYPE=\"\$typeof_$NAME\"" - - echo -n "$TYPE $NAME: " - case "$TYPE" in - (object) - #eval echo -n \$${NAME}_VALUE - eval echo -n \$$NAME - ;; - #set | sed -rn "s/^(${NAME})_([a-zA-Z]+)[a-zA-Z_]*_VALUE=(.*)/\1_\2/p" | - # sort | uniq | tr \\n \ ;; - (*) #echo -n "$VALUE";; - #eval "VALUE=\"\$(echo -n \"\$${NAME}_VALUE\" | base64 -d)\"" - #eval echo -n \"\$${NAME}_VALUE\" | base64 -d - eval echo -n \$${NAME} | base64 -d - esac - echo -} - -read_json() { - json_key="${1-JSON}" - #meh="`cat`" - #echo "$meh" - ##echo "$meh" | normalize_json | json_to_sh; exit - #eval "`echo "$meh" | normalize_json | json_to_sh`" - eval "`normalize_json | json_to_sh`" -} - -# TODO print_json x, print_json x ca ... to print as json - -read_json x -echo ==== -set | egrep "^(typeof_)?$json_key[A-Za-z_]*=" -echo ==== -json -json a -json b -json c -json c ca -json c cb -json d -#echo ==== -#echo $JSON_VALUE -#echo $JSON_c_cb_VALUE | base64 -d; echo - -echo READY. -#### End of file. diff --git a/json/sh/Makefile b/json/sh/Makefile new file mode 100644 index 00000000..188e6ca2 --- /dev/null +++ b/json/sh/Makefile @@ -0,0 +1,19 @@ +DIST = debian + +.PHONY: infest all +all: select-target + +infest: + make -C infest + +install-core: + core/$(DIST) + +noise: + make -C noise infest +streams: + make -C streams +monitoring: + make -C Monitoring debian +zoneminder: + make -C zoneminder fix it so hard diff --git a/json/sh/json.sh b/json/sh/json.sh new file mode 100755 index 00000000..8297a853 --- /dev/null +++ b/json/sh/json.sh @@ -0,0 +1,116 @@ +#! /bin/sh +set -euf + +# TODO check json first + +# XXX json_key is something like PWD^^ + +normalize_json() { + sed -rn ' + 1s/^/cat<&2 + pop_key # TODO check if is %%%MAKEJSONOBJ%%% + #echo obj: $1 `set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"` >&2 + #json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"`" + json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)=(.*)/\1/p"`" +} +begin_json_array() { :; } +end_json_array() { :; } +json_push_key() { + push_key "`echo -n "$1" | base64 -d`" +} +json_set_key() { + pop_key + json_push_key "$1" +} +json_set() { + ##echo "typeof_$json_key=$1" >&2 + ##echo "${json_key}_VALUE=\"$2\"" >&2 # (`echo -n $2 | base64 -d`)" >&2 + #eval "${json_key}_TYPE=$1" + #eval "${json_key}_VALUE=\"$2\"" + eval "typeof_${json_key}=$1" + eval "${json_key}=\"$2\"" +} + +push_key() { + json_key="${json_key+${json_key}_}$1" +} +pop_key() { + json_key="`echo $json_key | sed 's/_[^_]\+$//'`" +} + +json() { + #eval echo "\"\$`echo -n "$json_key" "$@" | tr "$IFS" _`\" | base64 -d" + NAME="`echo -n "$json_key" "$@" | tr "$IFS" _`" + #eval "TYPE=\"\$${NAME}_TYPE\"" + eval "TYPE=\"\$typeof_$NAME\"" + + echo -n "$TYPE $NAME: " + case "$TYPE" in + (object) + #eval echo -n \$${NAME}_VALUE + eval echo -n \$$NAME + ;; + #set | sed -rn "s/^(${NAME})_([a-zA-Z]+)[a-zA-Z_]*_VALUE=(.*)/\1_\2/p" | + # sort | uniq | tr \\n \ ;; + (*) #echo -n "$VALUE";; + #eval "VALUE=\"\$(echo -n \"\$${NAME}_VALUE\" | base64 -d)\"" + #eval echo -n \"\$${NAME}_VALUE\" | base64 -d + eval echo -n \$${NAME} | base64 -d + esac + echo +} + +read_json() { + json_key="${1-JSON}" + #meh="`cat`" + #echo "$meh" + ##echo "$meh" | normalize_json | json_to_sh; exit + #eval "`echo "$meh" | normalize_json | json_to_sh`" + eval "`normalize_json | json_to_sh`" +} + +# TODO print_json x, print_json x ca ... to print as json + +read_json x +echo ==== +set | egrep "^(typeof_)?$json_key[A-Za-z_]*=" +echo ==== +json +json a +json b +json c +json c ca +json c cb +json d +#echo ==== +#echo $JSON_VALUE +#echo $JSON_c_cb_VALUE | base64 -d; echo + +echo READY. +#### End of file. diff --git a/json/sh/test.json b/json/sh/test.json new file mode 100644 index 00000000..a0406039 --- /dev/null +++ b/json/sh/test.json @@ -0,0 +1,6 @@ +{ + "a": "1", + "b": 2, + "c": { "ca": 11, "cb": [1, 2, 3, "42"] }, + "d": {} +} diff --git a/test.json b/test.json deleted file mode 100644 index a0406039..00000000 --- a/test.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "a": "1", - "b": 2, - "c": { "ca": 11, "cb": [1, 2, 3, "42"] }, - "d": {} -} -- cgit v1.2.3 From 3d4169bb993d741d66e734294afe889e0fa0d0ca Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 31 Jul 2011 04:25:17 +0200 Subject: move top-level Makefile back^_^ --- Makefile | 19 +++++++++++++++++++ json/sh/Makefile | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 Makefile delete mode 100644 json/sh/Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..188e6ca2 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +DIST = debian + +.PHONY: infest all +all: select-target + +infest: + make -C infest + +install-core: + core/$(DIST) + +noise: + make -C noise infest +streams: + make -C streams +monitoring: + make -C Monitoring debian +zoneminder: + make -C zoneminder fix it so hard diff --git a/json/sh/Makefile b/json/sh/Makefile deleted file mode 100644 index 188e6ca2..00000000 --- a/json/sh/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -DIST = debian - -.PHONY: infest all -all: select-target - -infest: - make -C infest - -install-core: - core/$(DIST) - -noise: - make -C noise infest -streams: - make -C streams -monitoring: - make -C Monitoring debian -zoneminder: - make -C zoneminder fix it so hard -- cgit v1.2.3