- if (match_byte (0x31))
- {
- if (match_u32 (0))
- {
- match_u32_assert (0);
- int subn = get_u32 ();
- printf ("nested %d bytes", subn);
- pos += subn;
- }
- else if (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_u32_assert(2);
- printf("(special 2)");
- match_byte_assert(0);
- match_byte_assert(0);
- match_u32_assert(1);
- match_byte_assert(0);
- match_byte_assert(0);
- int subn = get_u32 ();
- printf ("nested %d bytes", subn);
- pos += subn;
- }
- }
+ printf ("\">\n");
+ match_u32_assert(0);
+ if (version == 1)
+ match_byte(0);
+ dump_value(stdout, 1);
+ fprintf (stdout, " </datum>\n");
+ }
+ printf ("</data>\n");
+}
+
+static void
+dump_title(void)
+{
+ printf ("<title-local>\n");
+ dump_value(stdout, 0);
+ match_byte(1);
+ printf ("</title-local>\n");
+
+ printf ("<subtype>\n");
+ dump_value(stdout, 0);
+ match_byte(1);
+ printf ("</subtype>\n");
+
+ match_byte_assert(0x31);
+
+ printf ("<title-c>\n");
+ dump_value(stdout, 0);
+ match_byte(1);
+ printf ("</title-c>\n");
+
+ match_byte(0);
+ match_byte_assert(0x58);
+ if (match_byte(0x31))
+ {
+ printf ("<caption>\n");
+ dump_value(stdout, 0);
+ printf ("</caption>\n");
+ }
+ else
+ match_byte_assert(0x58);
+
+ int n_footnotes = get_u32();
+ for (int i = 0; i < n_footnotes; i++)
+ {
+ printf ("<footnote index=\"%d\">\n", i);
+ dump_value(stdout, 0);
+ /* Custom footnote marker string. */
+ if (match_byte (0x31))
+ dump_value(stdout, 0);
+ else
+ match_byte_assert (0x58);
+ get_u32 ();
+ printf ("</footnote>\n");
+ }
+}
+
+static void __attribute__((unused))
+hex_dump(int ofs, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ int c = data[ofs + i];
+#if 0
+ if (i && !(i % 16))
+ fprintf(stderr, "-");
+ else
+ fprintf(stderr, " ");
+#endif
+ fprintf(stderr, "%02x ", c);
+ //fprintf(stderr, "%c", c >= 32 && c < 127 ? c : '.');
+ }
+ fprintf(stderr, "\n");
+}
+
+static void
+dump_fonts(void)
+{
+ match_byte(0);
+ for (int i = 1; i <= 8; i++)
+ {
+ printf ("<style index=\"%d\"", i);
+ match_byte_assert(i);
+ match_byte_assert(0x31);
+ printf(" font=\"%s\"", get_string());
+ match_byte_assert(0);
+ match_byte_assert(0);
+ if (!match_byte(0x40) && !match_byte(0x20) && !match_byte(0x80) && !match_byte(0x10) && !match_byte(0x70))
+ match_byte_assert(0x50);
+ match_byte_assert(0x41);
+ if (!match_u32(0) && !match_u32(1))
+ match_u32_assert(2);
+ match_byte_assert(0);
+
+ /* OK, this seems really unlikely to be totally correct, but it matches my corpus... */
+ if (!match_u32(0) && !match_u32(2))
+ {
+ if (i == 7)
+ match_u32_assert(0xfaad);