jshn: add support for the double datatype
authorFelix Fietkau <nbd@openwrt.org>
Sat, 16 Mar 2013 23:50:03 +0000 (00:50 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 16 Mar 2013 23:50:03 +0000 (00:50 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
jshn.c
sh/jshn.sh

diff --git a/jshn.c b/jshn.c
index 781861deda534602b560f138151534da55b91e31..f71e6e685ddcd43117238b40714b4f7140f03cb7 100644 (file)
--- a/jshn.c
+++ b/jshn.c
@@ -112,6 +112,9 @@ static int add_json_element(const char *key, json_object *obj)
        case json_type_int:
                type = "int";
                break;
+       case json_type_double:
+               type = "double";
+               break;
        default:
                return -1;
        }
@@ -141,6 +144,9 @@ static int add_json_element(const char *key, json_object *obj)
        case json_type_int:
                fprintf(stdout, "' %d;\n", json_object_get_int(obj));
                break;
+       case json_type_double:
+               fprintf(stdout, "' %lf;\n", json_object_get_double(obj));
+               break;
        default:
                return -1;
        }
@@ -212,6 +218,8 @@ static void jshn_add_object_var(json_object *obj, bool array, const char *prefix
                new = json_object_new_string(var);
        } else if (!strcmp(type, "int")) {
                new = json_object_new_int(atoi(var));
+       } else if (!strcmp(type, "double")) {
+               new = json_object_new_double(strtod(var, NULL));
        } else if (!strcmp(type, "boolean")) {
                new = json_object_new_boolean(!!atoi(var));
        } else {
index 1d9fc8084466444a95a4b379813233e154ac8ce7..b4bb1e13a8cc12e849d702a97fba1c06241d01ce 100644 (file)
@@ -182,6 +182,10 @@ json_add_boolean() {
        _json_add_generic boolean "$1" "$2"
 }
 
+json_add_double() {
+       _json_add_generic double "$1" "$2"
+}
+
 # functions read access to json variables
 
 json_load() {