Tools: Fix C_struct printing

Fix issues with structs in arrays, format arrays to not wrap lines, pad
hex digits

Change-Id: Iff2c80a4220c8d103bfd8e3081b1738195f84862
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/tools/modules/c_struct.py b/tools/modules/c_struct.py
index 89c02b2..e75db6d 100644
--- a/tools/modules/c_struct.py
+++ b/tools/modules/c_struct.py
@@ -69,6 +69,10 @@
     for f in self._fields:
         if f.to_bytes() != bytes(f.get_size()):
             fields_string += _pad_lines(".{} = {},".format(f.name, f.get_value_str()), pad)
+            fields_string += "\n"
+    fields_string = fields_string[:-1]
+    if not fields_string:
+        return "{}"
     string += fields_string
     string += "\n}"
     return string
@@ -339,11 +343,17 @@
         if self.to_bytes() != bytes(self.get_size()):
             string += "{\n"
             m_string = ""
-            for m in self._members:
-                m_string += m.get_value_str() + ", "
+            for idx,m in enumerate(self._members):
+                tmp = m.get_value_str() + ", "
+                m_string += tmp
+                if m_string[-3:] == "}, " or idx % 8 == 7:
+                    m_string = m_string[:-1] + "\n"
+            m_string = m_string[:-1]
             string += _pad_lines(m_string, pad)
             string += "\n}"
-        return string
+            return string
+        else:
+            return "{}"
 
     def __str__(self):
         string = "{} {}".format(self.c_type, self.name)
@@ -417,7 +427,8 @@
         return self._size
 
     def get_value_str(self):
-        return hex(self.value) if self.value else hex(0)
+        value = self.value or 0
+        return f"0x{value:02x}"
 
     def __str__(self):
         string = "{} {}".format(self.c_type, self.name)