X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump-spo2.c;h=da9e73191703c859d47aeee0cde8cb21ebcce12e;hb=ac58a458c37149be22c906539872014766682b27;hp=33671632755321814dcae1ac86a1d78983fbf1cb;hpb=6ca1cdb717c55f8a4b4567285e9b44a8822504c9;p=pspp diff --git a/dump-spo2.c b/dump-spo2.c index 3367163275..da9e731917 100644 --- a/dump-spo2.c +++ b/dump-spo2.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -257,6 +258,20 @@ get_string1(void) return s; } +static void +match_string1_assert(const char *exp, const char *where) +{ + int start = pos; + char *act = get_string1(); + if (strcmp(act, exp)) + { + fprintf(stderr, "%s: 0x%x: expected \"%s\", got \"%s\"\n", + where, start, exp, act); + exit(1); + } +} +#define match_string1_assert(x) match_string1_assert(x, WHERE) + static char * get_string2(void) { @@ -266,8 +281,22 @@ get_string2(void) return s; } +static void +match_string2_assert(const char *exp, const char *where) +{ + int start = pos; + char *act = get_string2(); + if (strcmp(act, exp)) + { + fprintf(stderr, "%s: 0x%x: expected \"%s\", got \"%s\"\n", + where, start, exp, act); + exit(1); + } +} +#define match_string2_assert(x) match_string2_assert(x, WHERE) + static char * -get_string(const char *where) +get_string4(const char *where) { if (1 /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/ @@ -287,7 +316,15 @@ get_string(const char *where) exit(1); } } -#define get_string() get_string(WHERE) +#define get_string4() get_string4(WHERE) + +static char * +get_padded_string(int len) +{ + char *s = xmemdup0(&data[pos], len); + pos += len; + return s; +} static char * get_string_be(const char *where) @@ -406,6 +443,177 @@ format_name (int format, char *buf) } } +static void +parse_format(void) +{ + int d = data[pos++]; + int w = data[pos++]; + int fmt = data[pos++]; + char buf[32]; + printf ("%s%d.%d", format_name(fmt, buf), w, d); +} + +static void +parse_heading(const char *name) +{ + match_u16_assert(0xffff); + match_u16_assert(0); + match_string2_assert(name); +} + +static void +match_zeros_assert(int count, const char *where) +{ + for (int i = 0; i < count; i++) + if (data[pos + i]) + { + fprintf (stderr, + "%s: %#x: expected %d zeros here but offset %d is %#"PRIx8"\n", + where, pos, count, i, data[pos + i]); + exit (1); + } + pos += count; +} +#define match_zeros_assert(count) match_zeros_assert(count, WHERE) + +static void +put_safe(const char *s) +{ + while (*s) + { + if (*s == '\n') + printf ("\\n"); + else if (*s == '\r') + printf ("\\r"); + else if (*s < 0x20 || *s > 0x7e) + printf ("\\x%02"PRIx8, (uint8_t) *s); + else + putchar (*s); + s++; + } +} + +static void +parse_DspString(void) +{ + match_byte_assert(1); + match_byte_assert(2); + match_byte_assert(40); + if (!match_byte(0)) + match_byte_assert(5); + match_byte_assert(0); + match_byte_assert(1); + printf ("DspString(\""); + put_safe(get_string1()); + printf("\")\n"); +} + +static void +match_DspString(void) +{ /* 05 80 */ + match_byte_assert(5); + match_byte_assert(0x80); + parse_DspString(); +} + +static void +match_DspSimpleText(void) +{ /* 03 80 */ + match_byte_assert(3); + match_byte_assert(0x80); + match_zeros_assert(5); + if (!match_byte(0x10)) + match_byte_assert(0); + match_zeros_assert(4); +} + +static void +match_NavTreeViewItem(void) +{ /* 07 80 */ + match_byte_assert(7); + match_byte_assert(0x80); + match_zeros_assert(1); + if (!match_byte(0) && !match_byte(7)) + match_byte_assert(8); + match_zeros_assert(3); + pos++; + match_byte_assert(0); + match_byte_assert(1); + match_zeros_assert(3); + if (!match_byte(0)) + match_byte_assert(1); + match_zeros_assert(5); + match_byte_assert(1); + match_zeros_assert(5); + + put_safe(get_string1()); + putc('\n', stdout); +} + +static void +parse_DspNumber(void) +{ + match_byte_assert(1); + parse_format(); + match_byte_assert(0x80); + match_byte(2); + printf (" %f", get_double()); + printf (" \"%s\"\n", get_string1()); +} + +static void +match_DspNumber(void) +{ + match_byte_assert(0x2a); + match_byte_assert(0x80); + parse_DspNumber(); +} + +static void +match_DspCell(void) +{ /* 27 80 */ + match_byte_assert(0x27); + match_byte_assert(0x80); + match_byte_assert(0); + match_DspSimpleText(); + if (data[pos] == 5) + match_DspString(); + else if (data[pos] == 0x2a) + match_DspNumber(); + else + assert(0); +} + +static void +parse_PMModelItemInfo(void) +{ /* 54 80 */ + match_byte_assert(0); + pos += 1; /* Counter */ + match_zeros_assert(7); + pos += 3; + if (!match_byte(0)) + match_byte_assert(0xe); + match_byte_assert(0); +} + +static void +match_PMModelItemInfo(void) +{ /* 54 80 */ + match_byte_assert(0x54); + match_byte_assert(0x80); + parse_PMModelItemInfo(); + match_DspSimpleText(); + match_DspString(); +} + +static void +match_PMPivotItemTree(void) +{ /* 52 80 */ + match_byte_assert(0x52); + match_byte_assert(0x80); + match_byte_assert(0); + match_PMModelItemInfo(); +} int main(int argc, char *argv[]) @@ -463,5 +671,246 @@ main(int argc, char *argv[]) setvbuf (stdout, NULL, _IOLBF, 0); + match_byte_assert(4); + match_u32_assert(0); + match_string1_assert("SPSS Output Document"); + match_u32_assert(1); + match_byte_assert(0x63); + + parse_heading("NavRoot"); + match_byte_assert(2); + match_zeros_assert(32); + + parse_heading("DspSimpleText"); + match_zeros_assert(10); + + parse_heading("DspString"); + parse_DspString(); + + parse_heading("NavTreeViewItem"); + match_byte_assert(0); + match_u32_assert(0); + match_byte_assert(2); + match_byte_assert(0); + match_byte_assert(1); + match_zeros_assert(9); + match_u32_assert(1); + assert (pos == 0xb0); + + pos += 0x28; + match_zeros_assert(5); + if (match_u32(8500)) + match_u32_assert(11000); + else + { + match_u32_assert(11000); + match_u32_assert(8500); + } + pos = 0x105; + match_string1_assert("(Continued)"); + match_byte_assert(1); + match_byte_assert(1); + match_zeros_assert(3); + 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_heading("NavLog"); + pos = 0x36b; + puts(get_padded_string(32)); + if (!match_u32(80)) + match_u32_assert(132); + match_zeros_assert(8); + match_u32_assert(1); + get_string4(); + match_byte_assert(0); + + parse_heading("NavHead"); + match_byte_assert(2); + match_zeros_assert(24); + match_u32_assert(1); + match_u32_assert(0); + match_DspSimpleText(); + match_DspString(); + match_NavTreeViewItem(); + match_zeros_assert(3); + + parse_heading("NavTitle"); + pos += 33; + match_DspSimpleText(); + match_DspString(); + match_NavTreeViewItem(); + + match_byte_assert(1); + match_byte_assert(1); + match_u32_assert(-19); + match_zeros_assert(12); + match_byte_assert(0xbc); + match_byte_assert(2); + match_zeros_assert(9); + match_byte_assert(0x22); + puts(get_padded_string(32)); + match_u32_assert(80); + match_zeros_assert(8); + match_u32_assert(1); + get_string4(); + match_byte_assert(0); + + parse_heading("NavNote"); + match_byte_assert(2); + match_zeros_assert(8); + match_u32_assert(24); + if (!match_u32(0)) + match_u32_assert(-40); + pos += 8; + match_u32_assert(2); + match_u32_assert(1); + match_DspSimpleText(); + match_DspString(); + match_NavTreeViewItem(); + match_byte_assert(1); + + parse_heading("PTPivotController"); + match_byte_assert(2); + pos += 8; + match_u32_assert(100); + match_u32_assert(100); + match_u32_assert(100); + match_u32_assert(100); + + parse_heading("PVPivotView"); + match_u32_assert(5); + match_byte_assert(0); + + parse_heading("PMPivotModel"); + match_byte_assert(3); + + parse_heading("NDimensional__DspCell"); + match_byte_assert(0); + match_u32_assert(1); + + parse_heading("IndexedCollection"); + match_byte_assert(0); + pos++; + match_zeros_assert(3); + match_byte_assert(1); + match_byte_assert(0); + + parse_heading("DspCell"); + match_byte_assert(0); + match_DspSimpleText(); + + parse_heading("DspNumber"); + parse_DspNumber(); + + match_DspCell(); + match_DspCell(); + match_DspCell(); + match_DspCell(); + match_DspCell(); + match_DspCell(); + match_DspCell(); + while (data[pos] == 0) + pos++; + + match_DspCell(); + match_DspCell(); + while (data[pos] == 0) + pos++; + match_DspCell(); + match_DspCell(); + match_DspCell(); + + match_byte_assert(1); + match_byte_assert(0); + puts(get_string1()); + match_u32_assert(0); + puts(get_string1()); + + match_byte_assert(0); + match_byte_assert(1); + match_byte_assert(0); + match_byte_assert(0); + match_byte_assert(0); + match_byte_assert(1); + match_byte_assert(0); + + parse_heading("PMPivotItemTree"); + match_byte_assert(0); + + parse_heading("AbstractTreeBranch"); + match_byte_assert(0); + + parse_heading("PMModelItemInfo"); + parse_PMModelItemInfo(); + match_DspSimpleText(); + match_DspString(); + + match_u32_assert(7); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(6); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(2); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(2); + match_PMPivotItemTree(); + + match_u32_assert(0); + match_PMPivotItemTree(); + + match_u32_assert(0); + + /* ...unknown... */ + + while (data[pos] != 0xff || data[pos + 1] != 0xff) + pos++; + parse_heading("PVViewDimension"); + + printf ("%#x: end of successful parse\n", pos); + return 0; }