From: Ben Pfaff Date: Mon, 3 Nov 2014 00:35:35 +0000 (-0800) Subject: Wow, all of the files now read completely and from the beginning successfully. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5eaa47b6fd68e42f8d5899ea86a65ffc846edfef;p=pspp Wow, all of the files now read completely and from the beginning successfully. --- diff --git a/dump.c b/dump.c index ac51919753..9c53933897 100644 --- a/dump.c +++ b/dump.c @@ -104,7 +104,7 @@ match_u32_assert(uint32_t x, const char *where) static bool match_byte(uint8_t b) { - if (data[pos] == b) + if (pos < n && data[pos] == b) { pos++; return true; @@ -1567,14 +1567,26 @@ dump_title(void) } } +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) { - int i; - printf("fonts: offset=%08x\n", pos); match_byte(0); - for (i = 1; i <= 8; i++) + for (int i = 1; i <= 8; i++) { printf("%08x: font %d, ", pos, i); match_byte_assert(i); @@ -1599,6 +1611,52 @@ dump_fonts(void) putchar('\n'); } + match_u32_assert(240); + pos += 240; + + match_u32_assert(18); + pos += 18; + + if (match_u32(117)) + pos += 117; + else + { + match_u32_assert(142); + pos += 142; + } + + int count = get_u32(); + pos += 4 * count; + + char *encoding = get_string(); + printf("encoding=%s\n", encoding); + + if (!match_u32(0)) + match_u32_assert(UINT32_MAX); + if (!match_byte(0)) + match_byte_assert(1); + match_byte_assert(0); + if (!match_byte(0)) + match_byte_assert(1); + if (!match_byte(0x99) && !match_byte(0x98)) + match_byte_assert(0x97); + match_byte_assert(7); + match_byte_assert(0); + match_byte_assert(0); + if (match_byte('.')) + match_byte_assert(','); + else + { + match_byte_assert(','); + if (!match_byte('.')) + match_byte_assert(' '); + } + match_u32_assert(5); + 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 @@ -1669,23 +1727,19 @@ main(int argc, char *argv[]) } else if (!strcmp(argv[1], "dimensions") || !strcmp(argv[1], "all")) { - { - const char dimensions[] = "-,,,.\0"; - start = try_find_tail(dimensions, sizeof dimensions - 1); - } - - if (!start) - { - const char dimensions[] = "-,,, .\0"; - start = find_tail(dimensions, sizeof dimensions - 1); - } - - pos = start; + pos = 0x27; + dump_title (); + dump_fonts(); dump_dims (); + printf("\n\ndata:\n"); dump_data (); - dump_title (); - if (!strcmp(argv[1], "all")) - dump_fonts(); + if (pos == n - 1) + match_byte_assert (1); + if (pos > n) + { + fprintf (stderr, "%x / %x\n", pos, n); + exit(1); + } exit(0); } else