more progress!
[pspp] / dump-spo2.c
index bc1e97d57f37136e4911589d227195fd50fc5412..58dbf0539ddb370535ca1c3af431cecde0099cee 100644 (file)
@@ -112,7 +112,8 @@ match_u32_assert(uint32_t x, const char *where)
   unsigned int y = get_u32();
   if (x != y)
     {
-      fprintf(stderr, "%s: 0x%x: expected i%u, got i%u\n", where, pos - 4, x, y);
+      fprintf(stderr, "%s: 0x%x: expected i%u, got i%u: ", where, pos - 4, x, y);
+      hex_dump(stderr, pos - 4, 64);
       exit(1);
     }
 }
@@ -556,8 +557,9 @@ parse_weirdness(void)
   match_byte_assert(1);
   get_u32();
   match_zeros_assert(12);
-  match_byte_assert(0x90);
-  match_byte_assert(1);
+  pos++;                        /* 90 or BC */
+  if (!match_byte(2))
+    match_byte_assert(1);
   match_zeros_assert(5);
   pos++;
   match_zeros_assert(3);
@@ -579,49 +581,55 @@ match_NavTreeViewItem(void)
   match_byte_assert(0);
   if (match_byte(0))
     {
-      match_zeros_assert(7);
+      match_byte_assert(0);
+      if (!match_byte(1))
+        match_byte_assert(0);
+      match_zeros_assert(5);
       if (!match_byte(0))
         match_byte_assert(1);
       match_zeros_assert(5);
       get_string1();
       if (match_byte(1))
         {
-          parse_weirdness();
-          match_byte_assert(0);
-          pos++;
-          match_zeros_assert(11);
-          match_byte_assert(1);
-          match_zeros_assert(3);
-          get_string4();
-          match_byte_assert(0);
-          if (match_byte(0))
+          if (data[pos] == 1)
             {
-              match_zeros_assert(2);
-              if (match_u32(8500))
-                match_u32_assert(11000);
-              else
-                {
-                  match_u32_assert(11000);
-                  match_u32_assert(8500);
-                }
-              pos += 32;
-              get_string1();
-              if (!match_byte(0))
-                match_byte_assert(1);
-              pos++;
-              pos++;
-              pos++;
+              parse_weirdness();
+              match_byte_assert(0);
               pos++;
-              get_string4();                /* page title */
-              match_byte_assert(1);
+              match_zeros_assert(11);
               match_byte_assert(1);
               match_zeros_assert(3);
-              get_string4();                /* page number */
+              get_string4();
               match_byte_assert(0);
-              pos += 2;
-              match_u16_assert(2);
+              if (match_byte(0))
+                {
+                  match_zeros_assert(2);
+                  if (match_u32(8500))
+                    match_u32_assert(11000);
+                  else
+                    {
+                      match_u32_assert(11000);
+                      match_u32_assert(8500);
+                    }
+                  pos += 32;
+                  get_string1();
+                  if (!match_byte(0))
+                    match_byte_assert(1);
+                  pos++;
+                  pos++;
+                  pos++;
+                  pos++;
+                  get_string4();                /* page title */
+                  match_byte_assert(1);
+                  match_byte_assert(1);
+                  match_zeros_assert(3);
+                  get_string4();                /* page number */
+                  match_byte_assert(0);
+                  pos += 2;
+                  match_u16_assert(2);
+                }
+              parse_flexible();
             }
-          parse_flexible();
         }
       else
         match_zeros_assert(3);
@@ -717,7 +725,10 @@ parse_NavHead(void)
   match_byte_assert(2);
   match_zeros_assert(24);
   match_byte_assert(1);
-  match_zeros_assert(7);
+  match_zeros_assert(3);
+  if (!match_byte(1))
+    match_byte_assert(0);
+  match_zeros_assert(3);
   match_DspSimpleText();
   parse_flexible();
 }
@@ -733,7 +744,8 @@ parse_NavOleItem(void)
   match_byte_assert(1);
   match_zeros_assert(10);
   match_byte_assert(1);
-  match_zeros_assert(6);
+  match_zeros_assert(5);
+  get_string1();
   match_byte_assert(1);
   parse_weirdness();
   match_byte_assert(0);
@@ -745,6 +757,86 @@ parse_NavOleItem(void)
   match_byte_assert(0);
 }
 
+static void
+match_NavOleItem(void)
+{                               /* 0e 80 or 12 80*/
+  if (!match_byte(0x12))
+    match_byte_assert(0x0e);
+  match_byte_assert(0x80);
+  parse_NavOleItem();
+}
+
+static void
+parse_NavTitle(void)
+{
+  match_byte_assert(2);
+  match_zeros_assert(8);
+  match_u32_assert(24);
+  get_u32();
+  pos++;
+  if (!match_byte(3))
+    match_byte_assert(4);
+  match_zeros_assert(2);
+  get_u32();
+  match_u32_assert(2);
+  if (!match_u32(2))
+    match_u32_assert(1);
+}
+
+static void
+parse_NavNote(void)
+{
+  match_byte_assert(2);
+  match_zeros_assert(8);
+  match_u32_assert(24);
+  if (!match_u32(0) && !match_u32(0xffffff4b))
+    match_u32_assert(-40);
+  pos += 8;
+  match_u32_assert(2);
+  if (!match_u32(2))
+    match_u32_assert(1);
+}
+
+static void
+parse_PTPivotController(void)
+{
+  match_byte_assert(2);
+  pos += 8;
+  match_u32_assert(100);
+  match_u32_assert(100);
+  match_u32_assert(100);
+  match_u32_assert(100);
+}
+
+static void
+parse_PVPivotView(void)
+{
+  match_byte_assert(5);
+  match_zeros_assert(4);
+}
+
+static void
+parse_NDimensional__DspCell(void)
+{
+  match_byte_assert(0);
+  match_u32_assert(1);
+}
+
+static void
+parse_IndexedCollection(void)
+{
+  match_byte_assert(0);
+  if (match_byte(0))
+    {
+      match_zeros_assert(12);
+    }
+  else
+    {
+      get_u32();
+      match_u16_assert(1);
+    }
+}
+
 static void
 parse_flexible(void)
 {
@@ -763,9 +855,21 @@ parse_flexible(void)
       else if (!strcmp(heading, "NavHead"))
         parse_NavHead();
       else if (!strcmp(heading, "IndexedCollection"))
-        match_zeros_assert(14);
+        parse_IndexedCollection();
       else if (!strcmp(heading, "NavOleItem"))
         parse_NavOleItem();
+      else if (!strcmp(heading, "NavTitle"))
+        parse_NavTitle();
+      else if (!strcmp(heading, "NavNote"))
+        parse_NavNote();
+      else if (!strcmp(heading, "PTPivotController"))
+        parse_PTPivotController();
+      else if (!strcmp(heading, "PVPivotView"))
+        parse_PVPivotView();
+      else if (!strcmp(heading, "PMPivotModel"))
+        match_byte_assert(3);
+      else if (!strcmp(heading, "NDimensional__DspCell"))
+        parse_NDimensional__DspCell();
       else
         {
           fprintf(stderr, "don't know %s at offset 0x%x: ", heading, start);
@@ -799,18 +903,29 @@ parse_flexible(void)
       else if (data[pos] == 0x15 && data[pos + 1] == 0x80)
         {
           /* 15 80 */
-          data += 2;
-          match_byte_assert(2);
-          printf ("15 80(%f", get_double());
-          printf (" %s)\n", get_string1());
+          pos += 2;
+          if (match_byte(2))
+            {
+              printf ("15 80(%f", get_double());
+              printf (" %s)\n", get_string1());
+            }
+          else
+            match_zeros_assert(14);
         }
       else if (data[pos] == 0x9 && data[pos + 1] == 0x80)
         {
           match_NavLog();
         }
+      else if (data[pos] == 0xe || data[pos] == 0x12)
+        match_NavOleItem();
+      else if (data[pos] == 0x11 || data[pos] == 0x13)
+        {
+          pos += 2;
+          match_zeros_assert(14);
+        }
       else
         {
-          fprintf (stderr, "bad record 0x%02x at offset %x\n",
+          fprintf (stderr, "bad record 0x%02x at offset %x",
                    data[pos], pos);
           hex_dump (stderr, pos, 64);
           assert(0);
@@ -964,6 +1079,19 @@ main(int argc, char *argv[])
   parse_flexible();
   parse_flexible();
   parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
+  parse_flexible();
   exit(0);
   puts(get_padded_string(32));
   if (!match_u32(80))