X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump-spo2.c;h=d50d861fa428260e4d99bdde812da3517da056c7;hb=6fbf3ec9ce0176ef805a18086b4cfe66df9cfbba;hp=33671632755321814dcae1ac86a1d78983fbf1cb;hpb=6ca1cdb717c55f8a4b4567285e9b44a8822504c9;p=pspp diff --git a/dump-spo2.c b/dump-spo2.c index 3367163275..d50d861fa4 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,6 +281,20 @@ 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) { @@ -406,6 +435,40 @@ format_name (int format, char *buf) } } +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) +{ + for (int i = 0; i < count; i++) + if (data[pos + i]) + { + fprintf (stderr, + "%#x: expected %d zeros here but offset %d is %#"PRIx8"\n", + pos, count, i, data[pos + i]); + exit (1); + } + pos += count; +} + +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(\"%s\")\n", get_string1()); +} int main(int argc, char *argv[]) @@ -463,5 +526,26 @@ 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"); + + + printf ("%#x: end of successful parse\n", pos); + return 0; }