Lots more details.
[pspp] / dump.c
diff --git a/dump.c b/dump.c
index f6a8b49f4857ba9903dd4a835109a1637a1fff73..8a820d7b86c12ad2ca78b1be232b9993a643cc0a 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -12,6 +12,7 @@
 #include <unistd.h>
 #include "u8-mbtouc.h"
 
+static const char *filename;
 static uint8_t *data;
 static size_t n;
 
@@ -248,24 +249,25 @@ get_end(void)
 }
 
 static void __attribute__((unused))
-hex_dump(int ofs, int n)
+hex_dump(FILE *stream, int ofs, int n)
 {
   for (int i = 0; i < n; i++)
     {
       int c = data[ofs + i];
 #if 1
       if (i && !(i % 16))
-        printf("-");
+        putc('-', stream);
       else
-        printf(" ");
+        putc(' ', stream);
 #endif
-      printf("%02x", c);
+      fprintf(stream, "%02x", c);
     }
   for (int i = 0; i < n; i++)
     {
       int c = data[ofs + i];
-      printf("%c", c >= 32 && c < 127 ? c : '.');
+      putc(c >= 32 && c < 127 ? c : '.', stream);
     }
+  putc('\n', stream);
 }
 
 static char *
@@ -862,7 +864,19 @@ dump_title(void)
         dump_value(stdout, 0);
       else
         match_byte_assert (0x58);
-      get_u32 ();
+      int n = get_u32();
+      if (n >= 0)
+        {
+          /* Appears to be the number of references to a footnote. */
+          printf ("  <references n=\"%d\"/>\n", n);
+        }
+      else if (n == -2)
+        {
+          /* The user deleted the footnote references. */
+          printf ("  <deleted/>\n");
+        }
+      else
+        assert(0);
       printf ("</footnote>\n");
     }
 }
@@ -962,18 +976,21 @@ dump_fonts(void)
       match_be32_assert(1);
       get_be32();
       printf("<settings layer=\"%d\"", get_be32());
-      if (!get_byte())
+      if (!get_bool())
         printf(" skipempty=\"false\"");
-      if (!get_byte())
+      if (!get_bool())
         printf(" showdimensionincorner=\"false\"");
-      if (!get_byte())
+      if (!get_bool())
         printf(" markers=\"numeric\"");
-      if (!get_byte())
+      if (!get_bool())
         printf(" footnoteposition=\"subscript\"");
       get_byte();
       int nbytes = get_be32();
+      int end = pos + nbytes;
       printf("\n");
-      hex_dump(pos, nbytes);
+      while (pos + 4 <= end)
+        printf(" %d", get_be32());
+      pos = end;
       printf("\n");
       pos += nbytes;
       char *notes = get_string_be();
@@ -1003,7 +1020,7 @@ dump_fonts(void)
   const char *locale = get_string();
   printf ("<locale>%s</locale>\n", locale);
 
-  get_u32();            /* Seen: 0, UINT32_MAX, 2, 3, 4, 5, 6, 8, 9, 21, 24. */
+  printf ("<layer>%d</layer>\n", get_u32());
   if (!match_byte(0))
     match_byte_assert(1);
   match_byte_assert(0);
@@ -1024,9 +1041,9 @@ dump_fonts(void)
       if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
         match_byte_assert(0);
     }
-  printf("<format decimal=\"%c\" grouping=\"", decimal);
+  printf("<format decimal=\"%c\"", decimal);
   if (grouping)
-    putchar(grouping);
+    printf(" grouping=\"%c\"", grouping);
   printf("\"/>\n");
   if (match_u32(5))
     {
@@ -1039,22 +1056,22 @@ dump_fonts(void)
   /* The last chunk is an outer envelope that contains two inner envelopes.
      The second inner envelope has some interesting data like the encoding and
      the locale. */
+  int outer_end = get_end();
   if (version == 3)
     {
-      int outer_end = get_end();
-
       /* First inner envelope: byte*33 int[n] int*[n]. */
       int inner_len = get_u32();
       int inner_end = pos + inner_len;
       int array_start = pos + 33;
       match_byte_assert(0);
       pos++;                    /* 0, 1, 10 seen. */
-      match_byte_assert(0);
-      pos++;                    /* 0...11 seen. */
-      if (!match_byte(0) && !match_byte(1) && !match_byte(2))
-        match_byte_assert(3);
-      if (!match_byte(0) && !match_byte(2))
-        match_byte_assert(3);
+      get_bool();
+
+      /* 0=en 1=de 2=es 3=it 5=ko 6=pl 8=zh-tw 10=pt_BR 11=fr */
+      printf("lang=%d ", get_byte());
+
+      printf ("variable_mode=%d\n", get_byte());
+      printf ("value_mode=%d\n", get_byte());
       if (!match_u64(0))
         match_u64_assert(UINT64_MAX);
       match_u32_assert(0);
@@ -1062,17 +1079,40 @@ dump_fonts(void)
       match_u32_assert(0);
       match_u32_assert(0);
       match_byte_assert(0);
-      if (!match_byte(0))
-        match_byte_assert(1);
+      get_bool();
       match_byte_assert(1);
       pos = array_start;
-#if 1
-      printf("widths:");
-      while (pos < inner_end)
-        printf(" %d", get_u32());
-      printf("\n");
-#endif
-      pos = inner_end;;
+
+      assert(get_end() == inner_end);
+      printf("<heights>");
+      int n_heights = get_u32();
+      for (int i = 0; i < n_heights; i++)
+        {
+          if (i)
+            putchar(' ');
+          printf("%d", get_u32());
+        }
+      printf("</heights>\n");
+
+      int n_style_map = get_u32();
+      for (int i = 0; i < n_style_map; i++)
+        {
+          uint64_t cell = get_u64();
+          int style = get_u16();
+          printf("<style-map cell=\"%llu\" style=\"%d\"/>\n", cell, style);
+        }
+
+      int n_styles = get_u32();
+      for (int i = 0; i < n_styles; i++)
+        {
+          printf("<cell-style index=\"%d\"", i);
+          dump_style(stdout);
+          dump_style2(stdout);
+          printf("/>\n");
+        }
+
+      pos = get_end();
+      assert(pos == inner_end);
 
       /* Second inner envelope. */
       assert(get_end() == outer_end);
@@ -1086,18 +1126,15 @@ dump_fonts(void)
       match_byte_assert(0);
 
       printf("<command>%s</command>\n", get_string());
-      printf("<subcommand>%s</subcommand>\n", get_string());
+      printf("<command-local>%s</command-local>\n", get_string());
       printf("<language>%s</language>\n", get_string());
       printf("<charset>%s</charset>\n", get_string());
       printf("<locale>%s</locale>\n", get_string());
 
-      if (!match_byte(0))
-        match_byte_assert(1);
+      get_bool();
       match_byte_assert(0);
-      if (!match_byte(0))
-        match_byte_assert(1);
-      if (!match_byte(0))
-        match_byte_assert(1);
+      get_bool();
+      get_bool();
 
       printf("<epoch2>%d</epoch2>\n", get_u32());
 
@@ -1155,21 +1192,61 @@ dump_fonts(void)
         match_u32_assert(0);
 
       match_byte_assert('.');
-      if (!match_byte(0))
-        match_byte_assert(1);
+      get_bool();
 
       if (pos < outer_end)
         {
-          printf("<seed>%d</seed>\n", get_u32());
+          get_u32();
           match_u32_assert(0);
         }
       assert(pos == outer_end);
 
       pos = outer_end;
     }
-  else
+  else if (outer_end != pos)
     {
-      pos = get_end();
+      pos += 14;
+      printf("<command>%s</command>\n", get_string());
+      printf("<command-local>%s</command-local>\n", get_string());
+      printf("<language>%s</command>\n", get_string());
+      printf("<charset>%s</charset>\n", get_string());
+      printf("<locale>%s</locale>\n", get_string());
+      get_bool();
+      match_byte_assert(0);
+      get_bool();
+      get_bool();
+
+      printf("<epoch2>%d</epoch2>\n", get_u32());
+      int decimal = data[pos];
+      int grouping = data[pos + 1];
+      if (match_byte('.'))
+        {
+          if (!match_byte(',') && !match_byte('\''))
+            match_byte_assert(' ');
+        }
+      else
+        {
+          match_byte_assert(',');
+          if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
+            match_byte_assert(0);
+        }
+      printf("<format decimal=\"%c\"", decimal);
+      if (grouping)
+        printf(" grouping=\"%c\"", grouping);
+      printf("\"/>\n");
+      if (match_u32(5))
+        {
+          for (int i = 0; i < 5; i++)
+            printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
+        }
+      else
+        match_u32_assert(0);
+
+      match_byte_assert('.');
+      get_bool();
+
+      assert(pos == outer_end);
+      pos = outer_end;
     }
 }
 
@@ -1182,10 +1259,11 @@ main(int argc, char *argv[])
       exit (1);
     }
 
-  int fd = open(argv[1], O_RDONLY);
+  filename = argv[1];
+  int fd = open(filename, O_RDONLY);
   if (fd < 0)
     {
-      fprintf (stderr, "%s: open failed (%s)", argv[1], strerror (errno));
+      fprintf (stderr, "%s: open failed (%s)", filename, strerror (errno));
       exit (1);
     }
 
@@ -1217,8 +1295,16 @@ main(int argc, char *argv[])
   assert(version == 1 || version == 3);
 
   match_byte_assert(1);
-  for (int i = 0; i < 4; i++)
-    get_bool();
+  bool number_footnotes = get_bool();
+  printf("<footnote markers=\"%s\"/>\n",
+         number_footnotes ? "number" : "letter");
+  bool rotate_inner_column_labels = get_bool();
+  bool rotate_outer_row_labels = get_bool();
+  printf("x=%d\n", get_bool());
+  printf("<rotate-labels inner-column=\"%s\" outer-row=\"%s\"/>",
+         rotate_inner_column_labels ? "yes" : "no",
+         rotate_outer_row_labels ? "yes" : "no");
+  //fprintf(stderr, "option-number=%d\n", get_u32());
   get_u32();
 
   int min_col_width = get_u32();