#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <time.h>
#include <unistd.h>
#include "u8-mbtouc.h"
}
#define match_u32_assert(x) match_u32_assert(x, WHERE)
+static bool __attribute__((unused))
+match_u64(uint64_t x)
+{
+ if (get_u64() == x)
+ return true;
+ pos -= 8;
+ return false;
+}
+
+static void __attribute__((unused))
+match_u64_assert(uint64_t x, const char *where)
+{
+ unsigned long long int y = get_u64();
+ if (x != y)
+ {
+ fprintf(stderr, "%s: 0x%x: expected u64:%llu, got u64:%llu\n", where, pos - 8, x, y);
+ exit(1);
+ }
+}
+#define match_u64_assert(x) match_u64_assert(x, WHERE)
+
static bool __attribute__((unused))
match_be32(uint32_t x)
{
}
#define match_byte_assert(b) match_byte_assert(b, WHERE)
+static bool
+get_bool(void)
+{
+ if (match_byte(0))
+ return false;
+ match_byte_assert(1);
+ return true;
+}
+
static void
newline(FILE *stream, int pos)
{
int c = data[ofs + i];
#if 1
if (i && !(i % 16))
- fprintf(stderr, "-");
+ printf("-");
else
- fprintf(stderr, " ");
+ printf(" ");
#endif
- fprintf(stderr, "%02x", c);
+ printf("%02x", c);
}
for (int i = 0; i < n; i++)
{
int c = data[ofs + i];
- fprintf(stderr, "%c", c >= 32 && c < 127 ? c : '.');
+ printf("%c", c >= 32 && c < 127 ? c : '.');
}
- fprintf(stderr, "\n");
}
static char *
dump_counted_string(void)
{
- char *s = NULL;
int inner_end = get_end();
+ if (pos == inner_end)
+ return NULL;
+
+ if (match_u32(5))
+ {
+ match_u32_assert(0);
+ match_byte_assert(0x58);
+ }
+ else
+ match_u32_assert(0);
+
+ char *s = NULL;
+ if (match_byte(0x31))
+ s = get_string();
+ else
+ match_byte_assert(0x58);
if (pos != inner_end)
{
- if (match_u32(5))
- {
- match_u32_assert(0);
- match_byte_assert(0x58);
- }
- else
- match_u32_assert(0);
- if (match_byte(0x31))
- s = get_string();
- else
- match_byte_assert(0x58);
- if (pos != inner_end)
- {
- fprintf(stderr, "inner end discrepancy\n");
- exit(1);
- }
+ fprintf(stderr, "inner end discrepancy\n");
+ exit(1);
}
return s;
}
static void
dump_style(FILE *stream)
{
- match_byte(1);
- match_byte(0);
- match_byte(0);
- match_byte(0);
- match_byte_assert(1);
+ if (match_byte(0x58))
+ return;
+
+ match_byte_assert(0x31);
+ if (get_bool())
+ printf (" bold=\"yes\"");
+ if (get_bool())
+ printf (" italic=\"yes\"");
+ if (get_bool())
+ printf (" underline=\"yes\"");
+ if (!get_bool())
+ printf (" show=\"no\"");
char *fg = get_string(); /* foreground */
char *bg = get_string(); /* background */
char *font = get_string(); /* font */
- int size = data[pos];
- if (!match_byte(14))
- match_byte_assert(12); /* size? */
- fprintf(stream, " fgcolor=\"%s\" bgcolor=\"%s\" font=\"%s\" size=\"%d\"",
+ int size = get_byte() * (72. / 96.);
+ fprintf(stream, " fgcolor=\"%s\" bgcolor=\"%s\" font=\"%s\" size=\"%dpt\"",
fg, bg, font, size);
}
+static void
+dump_style2(FILE *stream)
+{
+ if (match_byte(0x58))
+ return;
+
+ match_byte_assert(0x31);
+ uint32_t halign = get_u32();
+ printf (" halign=\"%s\"",
+ halign == 0 ? "center"
+ : halign == 2 ? "left"
+ : halign == 4 ? "right"
+ : halign == 6 ? "decimal"
+ : halign == 0xffffffad ? "mixed"
+ : "<error>");
+ int valign = get_u32();
+ printf (" valign=\"%s\"",
+ valign == 0 ? "center"
+ : valign == 1 ? "top"
+ : valign == 3 ? "bottom"
+ : "<error>");
+ printf (" offset=\"%gpt\"", get_double());
+ int l = get_u16();
+ int r = get_u16();
+ int t = get_u16();
+ int b = get_u16();
+ printf (" margins=\"%d %d %d %d\"", l, r, t, b);
+}
+
static char *
dump_nested_string(FILE *stream)
{
s = dump_counted_string();
if (s)
fprintf(stream, " \"%s\"", s);
- if (match_byte(0x31))
- dump_style(stream);
- else
- match_byte_assert(0x58);
+ dump_style(stream);
match_byte_assert(0x58);
if (pos != outer_end)
{
if (template)
fprintf(stream, " template=\"%s\"", template);
- if (match_byte(0x31))
- dump_style(stream);
- else
- match_byte_assert(0x58);
- if (match_byte(0x31))
- {
- /* Only two SPV files have anything like this, so it's hard to
- generalize. */
- match_u32_assert(0);
- match_u32_assert(0);
- match_u32_assert(0);
- match_u32_assert(0);
- match_byte_assert(1);
- match_byte_assert(0);
- if (!match_byte(8) && !match_byte(1))
- match_byte_assert(2);
- match_byte_assert(0);
- match_byte_assert(8);
- match_byte_assert(0);
- match_byte_assert(10);
- match_byte_assert(0);
- }
- else
- match_byte_assert(0x58);
+ dump_style(stream);
+ dump_style2(stream);
if (pos != outer_end)
{
fprintf(stderr, "outer end discrepancy\n");
printf(" underline=\"true\"");
int halign = get_u32();
- printf("\nhalign=%d\n", halign);
+ printf(" halign=%d", halign);
int valign = get_u32();
- printf("\nvalign=%d\n", valign);
+ printf(" valign=%d", valign);
printf (" fgcolor=\"%s\"", get_string());
printf (" bgcolor=\"%s\"", get_string());
if (!match_byte(0))
match_byte_assert(1);
- match_u32_assert(0);
- char *othercolor = get_string();
- if (othercolor[0])
- printf(" othercolor=\"%s\"", othercolor);
+
+ char *alt_fgcolor = get_string();
+ if (alt_fgcolor[0])
+ printf (" altfg=\"%s\"", alt_fgcolor);
+ char *alt_bgcolor = get_string();
+ if (alt_bgcolor[0])
+ printf (" altbg=\"%s\"", alt_bgcolor);
if (version > 1)
{
- printf("\nfonts:");
+ printf(" margins=\"");
for (int i = 0; i < 4; i++)
- printf(" %2d", get_u32());
- printf("\n");
+ {
+ if (i)
+ putchar(' ');
+ printf("%d", get_u32());
+ }
+ putchar('"');
}
printf ("/>\n");
}
bool grid = get_byte();
pos += 3;
- printf(" <grid show=\"%s\">\n", grid ? "yes" : "no");
+ printf(" <grid show=\"%s\"/>\n", grid ? "yes" : "no");
printf("</borders>\n");
assert(pos == x1_end);
if (!get_byte())
printf(" footnoteposition=\"subscript\"");
get_byte();
- pos += get_be32();
- get_string_be();
+ int nbytes = get_be32();
+ printf("\n");
+ hex_dump(pos, nbytes);
+ printf("\n");
+ pos += nbytes;
+ char *notes = get_string_be();
+ if (notes[0])
+ printf(" notes=\"%s\"", notes);
char *look = get_string_be();
if (look[0])
printf(" look=\"%s\"", look);
}
pos = x3_end;
+ /* Manual column widths, if present. */
int count = get_u32();
- pos += 4 * count;
+ if (count > 0)
+ {
+ printf("<columnwidths>");
+ for (int i = 0; i < count; i++)
+ {
+ if (i)
+ putchar(' ');
+ printf("%d", get_u32());
+ }
+ printf("</columnwidths>\n");
+ }
const char *locale = get_string();
printf ("<locale>%s</locale>\n", locale);
int outer_end = get_end();
/* First inner envelope: byte*33 int[n] int*[n]. */
- pos = get_end();
+ 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);
+ if (!match_u64(0))
+ match_u64_assert(UINT64_MAX);
+ match_u32_assert(0);
+ match_u32_assert(0);
+ match_u32_assert(0);
+ match_u32_assert(0);
+ match_byte_assert(0);
+ if (!match_byte(0))
+ match_byte_assert(1);
+ 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;;
/* Second inner envelope. */
assert(get_end() == outer_end);
match_byte_assert(0);
}
- pos += 8;
- match_byte_assert(1);
+ printf ("small: %g\n", get_double());
+ match_byte_assert(1);
if (outer_end - pos > 6)
{
/* There might be a pair of strings representing a dataset and
printf("<datafile>%s</datafile>\n", get_string());
match_u32_assert(0);
- get_u32();
+
+ time_t date = get_u32();
+ struct tm tm = *localtime(&date);
+ char s[128];
+ strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S %z", &tm);
+ printf("<date>%s</date>\n", s);
+
match_u32_assert(0);
}
}
else
match_u32_assert(0);
- match_byte_assert(0x2e);
+ match_byte_assert('.');
if (!match_byte(0))
match_byte_assert(1);
match_u32_assert(3);
match_byte_assert(1);
- if (!match_byte(0))
- match_byte_assert(1);
-
- /* Offset 8. */
- match_byte_assert(0);
- if (!match_byte(0))
- match_byte_assert(1);
- if (!match_byte(0))
- match_byte_assert(1);
-
- /* Offset 11. */
- pos++;
- match_byte_assert(0);
- match_byte_assert(0);
- match_byte_assert(0);
-
- /* Offset 15. */
- pos++;
- if (!match_byte(0))
- match_byte_assert(1);
- match_byte_assert(0);
- match_byte_assert(0);
-
- /* Offset 19. */
- pos++;
- if (!match_byte(0))
- match_byte_assert(1);
- match_byte_assert(0);
- match_byte_assert(0);
-
- /* Offset 23. */
- pos++;
- if (!match_byte(0))
- match_byte_assert(1);
- match_byte_assert(0);
- match_byte_assert(0);
-
- /* Offset 27. */
- pos++;
- pos++;
- pos++;
- pos++;
+ for (int i = 0; i < 4; i++)
+ if (!match_byte(0))
+ match_byte_assert(1);
+ get_u32();
+
+ int min_col_width = get_u32();
+ int max_col_width = get_u32();
+ int min_row_width = get_u32();
+ int max_row_width = get_u32();
+ printf("<label-width min-col=\"%d\" max-col=\"%d\" min-row=\"%d\" "
+ "max-row=\"%d\"/>\n",
+ min_col_width, max_col_width,
+ min_row_width, max_row_width);
/* Offset 31. */
printf("<tableid>%lld</tableid>", get_u64());