X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump-spo2.c;h=06b3902e3efd22cea75daf343f9906c14892100d;hb=53fb600bd20576419781bbca4c3d3c6be420a599;hp=da9e73191703c859d47aeee0cde8cb21ebcce12e;hpb=ac58a458c37149be22c906539872014766682b27;p=pspp diff --git a/dump-spo2.c b/dump-spo2.c index da9e731917..06b3902e3e 100644 --- a/dump-spo2.c +++ b/dump-spo2.c @@ -249,13 +249,27 @@ all_utf8(const char *p_, size_t len) return true; } +static char * +get_string2(void) +{ + int len = data[pos] + data[pos + 1] * 256; + char *s = xmemdup0(&data[pos + 2], len); + pos += 2 + len; + return s; +} + static char * get_string1(void) { int len = data[pos++]; - char *s = xmemdup0(&data[pos], len); - pos += len; - return s; + if (len == 0xff) + return get_string2(); + else + { + char *s = xmemdup0(&data[pos], len); + pos += len; + return s; + } } static void @@ -272,15 +286,6 @@ match_string1_assert(const char *exp, const char *where) } #define match_string1_assert(x) match_string1_assert(x, WHERE) -static char * -get_string2(void) -{ - int len = data[pos] + data[pos + 1] * 256; - char *s = xmemdup0(&data[pos + 2], len); - pos += 2 + len; - return s; -} - static void match_string2_assert(const char *exp, const char *where) { @@ -302,7 +307,8 @@ get_string4(const char *where) /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/ /*&& all_ascii(&data[pos + 4], data[pos])*/) { - int len = data[pos] + data[pos + 1] * 256; + assert(data[pos + 3] == 0); + int len = data[pos] + data[pos + 1] * 256 + data[pos + 2] * 65536; char *s = malloc(len + 1); memcpy(s, &data[pos + 4], len); @@ -496,16 +502,22 @@ put_safe(const char *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"); + if (match_byte(2)) + { + printf("DspString(%f, \"", get_double()); + printf("%s\")\n", get_string1()); + } + else + { + match_byte_assert(1); + printf ("DspString("); + parse_format(); + printf(" \""); + match_byte_assert(0); + match_byte_assert(1); + put_safe(get_string1()); + printf("\")\n"); + } } static void @@ -554,11 +566,12 @@ static void parse_DspNumber(void) { match_byte_assert(1); + printf("DspNumber("); parse_format(); match_byte_assert(0x80); match_byte(2); printf (" %f", get_double()); - printf (" \"%s\"\n", get_string1()); + printf (" \"%s\")\n", get_string1()); } static void @@ -569,19 +582,22 @@ match_DspNumber(void) parse_DspNumber(); } +static void parse_flexible(void); + +static void +parse_DspCell(void) +{ + match_byte_assert(0); + match_DspSimpleText(); + parse_flexible(); /* DspString or 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); + parse_DspCell(); } static void @@ -615,6 +631,57 @@ match_PMPivotItemTree(void) match_PMModelItemInfo(); } +static void +parse_flexible(void) +{ + if (data[pos] == 0xff && data[pos + 1] == 0xff) + { + match_u16_assert(0xffff); + match_u16_assert(0); + char *heading = get_string2(); + if (!strcmp(heading, "DspCell")) + parse_DspCell(); + else if (!strcmp(heading, "DspNumber")) + parse_DspNumber(); + else if (!strcmp(heading, "DspString")) + parse_DspString(); + else + assert(0); + } + else if (data[pos] == 0x2a && data[pos + 1] == 0x80) + match_DspNumber(); + else if (data[pos] == 0x27 && data[pos + 1] == 0x80) + match_DspCell(); + else if (data[pos] == 0x5 && data[pos + 1] == 0x80) + match_DspString(); + else if ((data[pos] == 0x3c || data[pos] == 0x39) + && data[pos + 1] == 0x80) + { + /* 3c 80 */ + /* 39 80 */ + pos += 2; + parse_format(); +/* match_byte_assert(0x01); + match_byte_assert(0x02); + match_byte_assert(0x0d); */ + } + 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()); + } + else + { + fprintf (stderr, "bad data cell 0x%02x at offset %x\n", + data[pos], pos); + hex_dump (stderr, pos, 64); + assert(0); + } +} + int main(int argc, char *argv[]) { @@ -727,6 +794,7 @@ main(int argc, char *argv[]) match_u32_assert(132); match_zeros_assert(8); match_u32_assert(1); + printf ("0x%x\n", pos); get_string4(); match_byte_assert(0); @@ -801,35 +869,19 @@ main(int argc, char *argv[]) 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(); + while (data[pos] != 1) + { + if (data[pos] == 0) + pos++; + else + parse_flexible(); + } match_byte_assert(1); match_byte_assert(0); puts(get_string1()); - match_u32_assert(0); + if (!match_u32(0)) + match_u32_assert(2); puts(get_string1()); match_byte_assert(0); @@ -840,6 +892,8 @@ main(int argc, char *argv[]) match_byte_assert(1); match_byte_assert(0); + exit (0); + parse_heading("PMPivotItemTree"); match_byte_assert(0); @@ -910,6 +964,11 @@ main(int argc, char *argv[]) pos++; parse_heading("PVViewDimension"); + int i; + for (i = 0; data[pos + i] != 0xff || data[pos + i + 1] != 0xff; i++) + ; + hex_dump(stdout, pos, i); + printf ("%#x: end of successful parse\n", pos); return 0;