Minor improvements.
[pspp] / dump.c
diff --git a/dump.c b/dump.c
index 205167951ca20dab22cf99d3b8143111d5d59abb..3e30ce10f2e7b99857a4560ce55490dfc41bb2f4 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -195,6 +195,15 @@ match_byte_assert(uint8_t b, const char *where)
 }
 #define match_byte_assert(b) match_byte_assert(b, WHERE)
 
+static bool
+get_bool(void)
+{
+  if (match_byte(0))
+    return false;
+  match_byte_assert(1);
+  return true;
+}
+
 static void
 newline(FILE *stream, int pos)
 {
@@ -357,26 +366,27 @@ hex_dump(int ofs, int n)
 static char *
 dump_counted_string(void)
 {
-  char *s = NULL;
   int inner_end = get_end();
+  if (pos == inner_end)
+    return NULL;
+
+  if (match_u32(5))
+    {
+      match_u32_assert(0);
+      match_byte_assert(0x58);
+    }
+  else
+    match_u32_assert(0);
+
+  char *s = NULL;
+  if (match_byte(0x31))
+    s = get_string();
+  else
+    match_byte_assert(0x58);
   if (pos != inner_end)
     {
-      if (match_u32(5))
-        {
-          match_u32_assert(0);
-          match_byte_assert(0x58);
-        }
-      else
-        match_u32_assert(0);
-      if (match_byte(0x31))
-        s = get_string();
-      else
-        match_byte_assert(0x58);
-      if (pos != inner_end)
-        {
-          fprintf(stderr, "inner end discrepancy\n");
-          exit(1);
-        }
+      fprintf(stderr, "inner end discrepancy\n");
+      exit(1);
     }
   return s;
 }
@@ -384,21 +394,55 @@ dump_counted_string(void)
 static void
 dump_style(FILE *stream)
 {
-  match_byte(1);
-  match_byte(0);
-  match_byte(0);
-  match_byte(0);
-  match_byte_assert(1);
+  if (match_byte(0x58))
+    return;
+
+  match_byte_assert(0x31);
+  if (get_bool())
+    printf (" bold=\"yes\"");
+  if (get_bool())
+    printf (" italic=\"yes\"");
+  if (get_bool())
+    printf (" underline=\"yes\"");
+  if (!get_bool())
+    printf (" show=\"no\"");
   char *fg = get_string();     /* foreground */
   char *bg = get_string();     /* background */
   char *font = get_string();     /* font */
-  int size = data[pos];
-  if (!match_byte(14))
-    match_byte_assert(12); /* size? */
-  fprintf(stream, " fgcolor=\"%s\" bgcolor=\"%s\" font=\"%s\" size=\"%d\"",
+  int size = get_byte() * (72. / 96.);
+  fprintf(stream, " fgcolor=\"%s\" bgcolor=\"%s\" font=\"%s\" size=\"%dpt\"",
           fg, bg, font, size);
 }
 
+static void
+dump_style2(FILE *stream)
+{
+  if (match_byte(0x58))
+    return;
+
+  match_byte_assert(0x31);
+  uint32_t halign = get_u32();
+  printf (" halign=\"%s\"",
+          halign == 0 ? "center"
+          : halign == 2 ? "left"
+          : halign == 4 ? "right"
+          : halign == 6 ? "decimal"
+          : halign == 0xffffffad ? "mixed"
+          : "<error>");
+  int valign = get_u32();
+  printf (" valign=\"%s\"",
+          valign == 0 ? "center"
+          : valign == 1 ? "top"
+          : valign == 3 ? "bottom"
+          : "<error>");
+  printf (" offset=\"%gpt\"", get_double());
+  int l = get_u16();
+  int r = get_u16();
+  int t = get_u16();
+  int b = get_u16();
+  printf (" margins=\"%d %d %d %d\"", l, r, t, b);
+}
+
 static char *
 dump_nested_string(FILE *stream)
 {
@@ -410,10 +454,7 @@ dump_nested_string(FILE *stream)
   s = dump_counted_string();
   if (s)
     fprintf(stream, " \"%s\"", s);
-  if (match_byte(0x31))
-    dump_style(stream);
-  else
-    match_byte_assert(0x58);
+  dump_style(stream);
   match_byte_assert(0x58);
   if (pos != outer_end)
     {
@@ -471,30 +512,8 @@ dump_value_modifier(FILE *stream)
           if (template)
             fprintf(stream, " template=\"%s\"", template);
 
-          if (match_byte(0x31))
-            dump_style(stream);
-          else
-            match_byte_assert(0x58);
-          if (match_byte(0x31))
-            {
-              /* Only two SPV files have anything like this, so it's hard to
-                 generalize. */
-              match_u32_assert(0);
-              match_u32_assert(0);
-              match_u32_assert(0);
-              match_u32_assert(0);
-              match_byte_assert(1);
-              match_byte_assert(0);
-              if (!match_byte(8) && !match_byte(1))
-                match_byte_assert(2);
-              match_byte_assert(0);
-              match_byte_assert(8);
-              match_byte_assert(0);
-              match_byte_assert(10);
-              match_byte_assert(0);
-            }
-          else
-            match_byte_assert(0x58);
+          dump_style(stream);
+          dump_style2(stream);
           if (pos != outer_end)
             {
               fprintf(stderr, "outer end discrepancy\n");