X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=jshn.c;h=f71e6e685ddcd43117238b40714b4f7140f03cb7;hb=8cee1e552ab281dbbf0f862e4e4e327028c0399b;hp=dc002c1caa0adf0bc8971102b8b86c291076a216;hpb=e16fa068a57318fff073da4a0f8f0535a97fe208;p=project%2Flibubox.git diff --git a/jshn.c b/jshn.c index dc002c1..f71e6e6 100644 --- a/jshn.c +++ b/jshn.c @@ -1,4 +1,24 @@ -#include +/* + * Copyright (C) 2011-2013 Felix Fietkau + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifdef JSONC + #include +#else + #include +#endif + #include #include #include @@ -92,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; } @@ -121,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; } @@ -192,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 {