jshn: add support for the double datatype
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
49e6e062b8
commit
00a833c5b6
2 changed files with 12 additions and 0 deletions
8
jshn.c
8
jshn.c
|
@ -112,6 +112,9 @@ static int add_json_element(const char *key, json_object *obj)
|
||||||
case json_type_int:
|
case json_type_int:
|
||||||
type = "int";
|
type = "int";
|
||||||
break;
|
break;
|
||||||
|
case json_type_double:
|
||||||
|
type = "double";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -141,6 +144,9 @@ static int add_json_element(const char *key, json_object *obj)
|
||||||
case json_type_int:
|
case json_type_int:
|
||||||
fprintf(stdout, "' %d;\n", json_object_get_int(obj));
|
fprintf(stdout, "' %d;\n", json_object_get_int(obj));
|
||||||
break;
|
break;
|
||||||
|
case json_type_double:
|
||||||
|
fprintf(stdout, "' %lf;\n", json_object_get_double(obj));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
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);
|
new = json_object_new_string(var);
|
||||||
} else if (!strcmp(type, "int")) {
|
} else if (!strcmp(type, "int")) {
|
||||||
new = json_object_new_int(atoi(var));
|
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")) {
|
} else if (!strcmp(type, "boolean")) {
|
||||||
new = json_object_new_boolean(!!atoi(var));
|
new = json_object_new_boolean(!!atoi(var));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -182,6 +182,10 @@ json_add_boolean() {
|
||||||
_json_add_generic boolean "$1" "$2"
|
_json_add_generic boolean "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_add_double() {
|
||||||
|
_json_add_generic double "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
# functions read access to json variables
|
# functions read access to json variables
|
||||||
|
|
||||||
json_load() {
|
json_load() {
|
||||||
|
|
Loading…
Reference in a new issue