1
0
This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
ZyXEL_PMG5617GA/package/libs/libjson-c/patches-0.9/010-readable_json_file.patch
2022-11-27 10:16:14 +00:00

144 lines
3.2 KiB
Diff

Index: json-c-0.9/json_object.c
===================================================================
--- json-c-0.9.orig/json_object.c 2014-03-17 09:32:50.418753947 +0800
+++ json-c-0.9/json_object.c 2014-03-17 09:59:20.768001984 +0800
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
+#include <stdbool.h>
#include "debug.h"
#include "printbuf.h"
@@ -23,6 +24,9 @@
#include "json_object.h"
#include "json_object_private.h"
+int level = 0;
+int last_type;
+
#if !HAVE_STRNDUP
char* strndup(const char* str, size_t n);
#endif /* !HAVE_STRNDUP */
@@ -207,23 +211,44 @@
static int json_object_object_to_json_string(struct json_object* jso,
struct printbuf *pb)
{
- int i=0;
+ int i = 0, c = 0;
struct json_object_iter iter;
- sprintbuf(pb, "{");
+
+ sprintbuf(pb, "{\n");
+
+ level++;
/* CAW: scope operator to make ANSI correctness */
/* CAW: switched to json_object_object_foreachC which uses an iterator struct */
- json_object_object_foreachC(jso, iter) {
- if(i) sprintbuf(pb, ",");
- sprintbuf(pb, " \"");
- json_escape_str(pb, iter.key);
- sprintbuf(pb, "\": ");
- if(iter.val == NULL) sprintbuf(pb, "null");
- else iter.val->_to_json_string(iter.val, pb);
- i++;
- }
+ json_object_object_foreachC(jso, iter) {
+ if(i)
+ sprintbuf(pb, ",\n");
+
+ for(c = 0; c < level; c++)
+ sprintbuf(pb, " ");
+
+ sprintbuf(pb, "\"");
+ json_escape_str(pb, iter.key);
+ sprintbuf(pb, "\": ");
+
+ if(iter.val == NULL)
+ sprintbuf(pb, "null");
+ else {
+ last_type = iter.val->o_type;
+ iter.val->_to_json_string(iter.val, pb);
+ }
- return sprintbuf(pb, " }");
+ i++;
+ }
+
+ level--;
+
+ sprintbuf(pb, "\n");
+
+ for(c = 0; c < level; c++)
+ sprintbuf(pb, " ");
+
+ return sprintbuf(pb, "}");
}
#if 0 /* for indirect access, ZyXEL, john */
@@ -246,7 +271,7 @@
{
int i=0;
struct json_object_iter iter;
- sprintbuf(pb, "{");
+ sprintbuf(pb, "{")\n;
/* CAW: scope operator to make ANSI correctness */
/* CAW: switched to json_object_object_foreachC which uses an iterator struct */
@@ -494,18 +519,46 @@
static int json_object_array_to_json_string(struct json_object* jso,
struct printbuf *pb)
{
- int i;
- sprintbuf(pb, "[");
+ int i, c;
+
+ sprintbuf(pb, "[\n");
+
+ level++;
+
for(i=0; i < json_object_array_length(jso); i++) {
struct json_object *val;
- if(i) { sprintbuf(pb, ", "); }
- else { sprintbuf(pb, " "); }
-
+ if(i) {
+ sprintbuf(pb, ", \n");
+ }
+#if 0
+ else {
+ sprintbuf(pb, " ");
+ }
+#endif
val = json_object_array_get_idx(jso, i);
- if(val == NULL) { sprintbuf(pb, "null"); }
- else { val->_to_json_string(val, pb); }
+ if(val == NULL){
+ sprintbuf(pb, "null");
+ }
+ else {
+ for(c = 0; c < level; c++)
+ sprintbuf(pb, " ");
+
+ val->_to_json_string(val, pb);
+ }
+ }
+
+ sprintbuf(pb, "\n");
+
+ level--;
+
+ for(c = 0; c < level; c++) {
+ if(c == level)
+ sprintbuf(pb, " ");
+ else
+ sprintbuf(pb, " ");
}
- return sprintbuf(pb, " ]");
+
+ return sprintbuf(pb, "]");
}
#if 0 /* for indirect access, ZyXEL, john */