Blame SOURCES/lshw-B.02.18-revert-json.patch

99c025
commit 135a853c60582b14c5b67e5cd988a8062d9896f4
99c025
Author: Lyonel Vincent <lyonel@ezix.org>
99c025
Date:   Fri Apr 28 16:54:42 2017 +0200
99c025
99c025
    Fix JSON output format
99c025
    
99c025
    cf. https://github.com/lyonel/lshw/pull/28
99c025
99c025
diff --git a/src/core/hw.cc b/src/core/hw.cc
99c025
index 68e5912..9defd26 100644
99c025
--- a/src/core/hw.cc
99c025
+++ b/src/core/hw.cc
99c025
@@ -1368,9 +1368,14 @@ string hwNode::asJSON(unsigned level)
99c025
   config = getConfigKeys();
99c025
   resources = getResources("\" value=\"");
99c025
 
99c025
+  if (level == 0)
99c025
+  {
99c025
+    out << "[" << endl;
99c025
+  }
99c025
+
99c025
   if(visible(getClassName()))
99c025
   {
99c025
-    out << "{" << endl;
99c025
+    out << spaces(2*level) << "{" << endl;
99c025
     out << spaces(2*level+2) << "\"id\" : \"" << getId() << "\"," << endl;
99c025
     out << spaces(2*level+2) << "\"class\" : \"" << getClassName() << "\"";
99c025
 
99c025
@@ -1613,20 +1618,13 @@ string hwNode::asJSON(unsigned level)
99c025
     resources.clear();
99c025
   }
99c025
 
99c025
-  
99c025
-  if(countChildren()>0)
99c025
+  for (unsigned int i = 0; i < countChildren(); i++)
99c025
   {
99c025
-    if(visible(getClassName()))
99c025
-      out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;
99c025
-
99c025
-    for (unsigned int i = 0; i < countChildren(); i++)
99c025
+    out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
99c025
+    if (visible(getChild(i)->getClassName()))
99c025
     {
99c025
-      out << spaces(2*level+4) << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
99c025
-      if(visible(getChild(i)->getClassName()) && (i < countChildren()-1)) out << "," << endl;
99c025
+      out << "," << endl;
99c025
     }
99c025
-
99c025
-    if(visible(getClassName()))
99c025
-      out << endl << spaces(2*level+2) << "]";
99c025
   }
99c025
 
99c025
   if(visible(getClassName()))
99c025
@@ -1635,6 +1633,12 @@ string hwNode::asJSON(unsigned level)
99c025
     out << "}";
99c025
   }
99c025
 
99c025
+  if (level == 0)
99c025
+  {
99c025
+    out.seekp(-2, std::ios_base::end);
99c025
+    out << endl << "]" << endl;
99c025
+  }
99c025
+
99c025
   return out.str();
99c025
 }
99c025