Blame SOURCES/0020-clean-up-JSON-output.patch

121cca
From 15565229509455527de9ce7cbb9530e2b31d043b Mon Sep 17 00:00:00 2001
121cca
From: Lyonel Vincent <lyonel@ezix.org>
121cca
Date: Wed, 27 May 2020 01:07:16 +0200
121cca
Subject: [PATCH 20/65] clean-up JSON output
121cca
121cca
---
121cca
 src/core/hw.cc | 29 +++++++++++++++++++++++++----
121cca
 1 file changed, 25 insertions(+), 4 deletions(-)
121cca
121cca
diff --git a/src/core/hw.cc b/src/core/hw.cc
121cca
index ab345fe..6aea7cf 100644
121cca
--- a/src/core/hw.cc
121cca
+++ b/src/core/hw.cc
121cca
@@ -1650,13 +1650,20 @@ string hwNode::asJSON(unsigned level)
121cca
     resources.clear();
121cca
   }
121cca
 
121cca
-  for (unsigned int i = 0; i < countChildren(); i++)
121cca
+  if(!::enabled("output:list") && countChildren()>0)
121cca
   {
121cca
-    out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
121cca
-    if (visible(getChild(i)->getClassName()))
121cca
+    out << "," << endl;
121cca
+    out << spaces(2*level+2);
121cca
+    out << "\"children\" : [";
121cca
+    for (unsigned int i = 0; i < countChildren(); i++)
121cca
     {
121cca
-      out << "," << endl;
121cca
+      out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
121cca
+      if (visible(getChild(i)->getClassName()) && i
121cca
+      {
121cca
+        out << "," << endl;
121cca
+      }
121cca
     }
121cca
+    out << "]";
121cca
   }
121cca
 
121cca
   if(visible(getClassName()))
121cca
@@ -1665,6 +1672,20 @@ string hwNode::asJSON(unsigned level)
121cca
     out << "}";
121cca
   }
121cca
 
121cca
+  if(::enabled("output:list") && countChildren()>0)
121cca
+  {
121cca
+    bool needcomma = visible(getClassName());
121cca
+    for (unsigned int i = 0; i < countChildren(); i++)
121cca
+      {
121cca
+        string json = getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
121cca
+
121cca
+        if(needcomma && strip(json)!="")
121cca
+          out << "," << endl;
121cca
+        out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
121cca
+        needcomma |= strip(json)!="";
121cca
+      }
121cca
+  }
121cca
+
121cca
   if (::enabled("output:list") && level == 0)
121cca
   {
121cca
     out << endl << "]" << endl;
121cca
-- 
121cca
2.33.1
121cca