return pos ? pos - data : 0;
}
-static size_t
-try_find_tail(const char *target, size_t target_len)
-{
- size_t pos = try_find(target, target_len);
- return pos ? pos + target_len : 0;
-}
-
static size_t
find(const char *target, size_t target_len)
{
return pos;
}
-static size_t
-find_tail(const char *target, size_t target_len)
-{
- size_t pos = try_find_tail(target, target_len);
- if (!pos)
- {
- fprintf (stderr, "not found\n");
- exit(1);
- }
- return pos;
-}
-
size_t pos;
#define XSTR(x) #x
static void
dump_category(int level, int *indexes, int *n_indexes)
{
- dump_value__ (stdout, level, true);
+ for (int i = 0; i <= level; i++)
+ fprintf (stdout, " ");
+ printf ("<category>\n");
+ dump_value__ (stdout, level + 1, true);
match_byte(0);
match_byte(0);
match_byte(0);
}
indexes[(*n_indexes)++] = indx;
}
- if (n_categories > 0)
- printf (", %d subcategories:", n_categories);
- else
- printf (", index %d", indx);
- printf("\n");
+ if (n_categories == 0)
+ {
+ for (int i = 0; i <= level + 1; i++)
+ fprintf (stdout, " ");
+ fprintf (stdout, "<category-index>%d</category-index>\n", indx);
+ }
for (int i = 0; i < n_categories; i++)
dump_category (level + 1, indexes, n_indexes);
+ for (int i = 0; i <= level; i++)
+ fprintf (stdout, " ");
+ printf ("</category>\n");
}
static void
-dump_dim(void)
+dump_dim(int indx)
{
int n_categories;
- printf("next dim\n");
+
+ printf ("<dimension index=\"%d\">\n", indx);
dump_value__ (stdout, 0, false);
/* This byte is usually 0x02 but 0x00 and 0x75 (!) have also been spotted. */
if (!match_byte(0))
match_byte_assert(1);
match_byte_assert(1);
- static int dim_indx = 0;
- match_u32_assert(dim_indx++);
+ match_u32_assert(indx);
n_categories = get_u32();
- printf("%d nested categories\n", n_categories);
int indexes[1024];
int n_indexes = 0;
for (int i = 0; i < n_categories; i++)
dump_category (0, indexes, &n_indexes);
check_permutation(indexes, n_indexes, "categories");
+
+ fprintf (stdout, "</dimension>\n");
}
int n_dims;
dump_dims(void)
{
n_dims = get_u32();
- printf ("%u dimensions\n", n_dims);
for (int i = 0; i < n_dims; i++)
- {
- printf("\n");
- dump_dim ();
- }
+ dump_dim (i);
}
static void
check_permutation(a, n_dims, "dimensions");
int x = get_u32();
- printf ("%d data values, starting at %08x\n", x, pos);
+ printf ("<data>\n");
for (int i = 0; i < x; i++)
{
- printf("%08x, index %d:\n", pos, get_u32());
+ printf (" <datum index=\"%d\">\n", get_u32());
match_u32_assert(0);
- dump_value__(stdout, 0, false);
- putchar('\n');
+ dump_value__(stdout, 1, false);
+ fprintf (stdout, " </datum>\n");
}
+ printf ("</data>\n");
}
static void
dump_title(void)
{
pos = 0x27;
- printf("text:\n");
- dump_value__(stdout, 0, true); putchar('\n');
- printf("subtype:\n");
- dump_value__(stdout, 0, true); putchar('\n');
+ printf ("<title-local>\n");
+ dump_value__(stdout, 0, true);
+ printf ("</title-local>\n");
+
+ printf ("<subtype>\n");
+ dump_value__(stdout, 0, true);
+ printf ("</subtype>\n");
+
match_byte_assert(0x31);
- printf("text_eng:\n");
- dump_value__(stdout, 0, true); putchar('\n');
+
+ printf ("<title-c>\n");
+ dump_value__(stdout, 0, true);
+ printf ("</title-c>\n");
+
match_byte(0);
match_byte_assert(0x58);
if (match_byte(0x31))
{
- printf("caption:\n");
- dump_value__(stdout, 0, false); putchar('\n');
+ printf ("<caption>\n");
+ dump_value__(stdout, 0, false);
+ printf ("</caption>\n");
}
else
match_byte_assert(0x58);
int n_footnotes = get_u32();
- if (n_footnotes >= 20)
+ for (int i = 0; i < n_footnotes; i++)
{
- fprintf(stderr, "%08x: %d footnotes\n", pos - 4, n_footnotes);
- exit(1);
- }
-
- printf("------\n%d footnotes\n", n_footnotes);
- if (n_footnotes < 20)
- {
- for (int i = 0; i < n_footnotes; i++)
+ printf ("<footnote index=\"%d\">\n", i);
+ dump_value__(stdout, 0, false);
+ if (match_byte (0x31))
{
- printf("footnote %d:\n", i);
- dump_value__(stdout, 0, false);
- if (match_byte (0x31))
- {
- /* Custom footnote marker string. */
- match_byte_assert(3);
- get_string();
- match_byte_assert(0x58);
- match_u32_assert(0);
- get_string();
- }
- else
- match_byte_assert (0x58);
- printf("(%d)\n", get_u32());
+ /* Custom footnote marker string. */
+ match_byte_assert(3);
+ get_string();
+ match_byte_assert(0x58);
+ match_u32_assert(0);
+ get_string();
}
+ else
+ match_byte_assert (0x58);
+ printf("(%d)\n", get_u32());
+ printf ("</footnote>\n");
}
}
-static int
-find_dimensions(void)
-{
- {
- const char dimensions[] = "-,,,.\0";
- int x = try_find_tail(dimensions, sizeof dimensions - 1);
- if (x)
- return x;
- }
-
- const char dimensions[] = "-,,, .\0";
- return find_tail(dimensions, sizeof dimensions - 1);
-}
-
static void
dump_fonts(void)
{
- printf("fonts: offset=%08x\n", pos);
match_byte(0);
for (int i = 1; i <= 8; i++)
{
- printf("%08x: font %d, ", pos, i);
+ printf ("<style index=\"%d\"", i);
match_byte_assert(i);
match_byte_assert(0x31);
- printf("%s, ", get_string());
+ 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))
if (!match_u32(0) && !match_u32(1) && !match_u32(2))
match_u32_assert(3);
- printf ("%s, ", get_string());
- printf ("%s, ", get_string());
+ printf (" fgcolor=\"%s\"", get_string());
+ printf (" bgcolor=\"%s\"", get_string());
match_u32_assert(0);
match_u32_assert(0);
match_byte_assert(0);
/* Who knows? Ranges from -1 to 8 with no obvious pattern. */
get_u32();
+
+ printf ("/>\n");
}
match_u32_assert(240);
int count = get_u32();
pos += 4 * count;
- char *encoding = get_string();
- printf("encoding=%s\n", encoding);
+ printf ("<encoding>%s</encoding>\n", get_string ());
if (!match_u32(0))
match_u32_assert(UINT32_MAX);
for (int i = 0; i < 5; i++)
get_string();
pos += get_u32();
- if (pos != find_dimensions())
- fprintf (stderr, "%08x / %08x\n", pos, find_dimensions());
}
int
dump_title ();
dump_fonts();
dump_dims ();
- printf("\n\ndata:\n");
dump_data ();
match_byte (1);
if (pos != n)