dump: Successfully parse all dimensions.
[pspp] / dump.c
diff --git a/dump.c b/dump.c
index ce87e86b2d9b396486b26aa86a9573c6dd36ea55..4d77609cad8c15f7a1c84ef66e1a25ca73e396ac 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -120,19 +120,26 @@ get_string(void)
 }
 
 static void
-dump_category(int level)
+dump_value(int level)
 {
   for (int i = 0; i <= level; i++)
     printf ("    ");
 
-  match_byte (0);
-  match_byte (0);
-  match_byte (0);
-  match_byte (0);
   if (match_byte (3))
     {
       get_string();
-      match_byte_assert (0x58);
+      if (match_byte (0x31))
+        {
+          match_u32 (1);
+          printf("(footnote %d) ", get_u32());
+          match_byte_assert (0);
+          match_byte_assert (0);
+          int subn = get_u32 ();
+          printf ("nested %d bytes", subn);
+          pos += subn;
+        }
+      else
+        match_byte_assert (0x58);
       get_string();
       printf("string \"%s\"", get_string());
       match_byte (0);
@@ -152,6 +159,7 @@ dump_category(int level)
       match_byte (0);
       match_byte (0);
       match_byte (0);
+      match_byte (0);
     }
   else if (match_byte (2))
     {
@@ -168,6 +176,7 @@ dump_category(int level)
               value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
       if (!match_u32 (3))
         match_u32_assert (2);
+      match_byte (0);
     }
   else if (match_byte (1))
     {
@@ -187,21 +196,44 @@ dump_category(int level)
   else
     {
       int subn;
+      int total_subs = 1;
 
+      match_byte (0);
       match_byte_assert (0x31);
       match_u32_assert (0);
       match_u32_assert (0);
       subn = get_u32 ();
       printf ("nested %d bytes", subn);
       pos += subn;
-      printf ("; \"%s\"", get_string());
-      fprintf (stderr, "got %02x\n", data[pos]);
-      match_byte (1);
-      match_byte (0);
-      match_byte (0);
-      match_byte (0);
-      goto next;
+      printf ("; \"%s\", substitutions:", get_string());
+      fprintf (stderr, "substitutions:");
+      for (;;)
+        {
+          int n_subst = get_u32();
+          if (!n_subst)
+            break;
+          printf (" %d", n_subst);
+          fprintf (stderr, " %d", n_subst);
+          total_subs *= n_subst;
+        }
+      putc ('\n', stderr);
+
+      for (int i = 0; i < total_subs; i++)
+        {
+          putc ('\n', stdout);
+          dump_value (level + 1);
+        }
     }
+}
+
+static void
+dump_category(int level)
+{
+  match_byte (0);
+  match_byte (0);
+  match_byte (0);
+  match_byte (0);
+  dump_value (level);
 
   if (match_u32 (2))
     get_u32 ();
@@ -217,7 +249,7 @@ dump_category(int level)
       match_u32_assert (0);
       get_u32 ();
     }
-next:;
+
   int n_categories = get_u32();
   if (n_categories > 0)
     printf (", %d subcategories:", n_categories);
@@ -317,6 +349,16 @@ main(int argc, char *argv[])
 
   if (argc > 1)
     {
+      if (!strcmp(argv[1], "title0"))
+        {
+          pos = 0x27;
+          if (match_byte (0x03)
+              || (match_byte (0x05) && match_byte (0x58)))
+            printf ("%s\n", get_string());
+          else
+            printf ("<unknown>\n");
+          return 0;
+        }
       if (!strcmp(argv[1], "title"))
         {
           const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";