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

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