X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump2.c;h=15670ecf4bb7c8de1ba8986290fa0fde8f53046f;hb=f926879f4be2b8eca78860e22f00d1001b91c175;hp=af01b408cdc5f77c1ae6021458d1001e1e6473cd;hpb=324edb7f2fc042792ae418618d6b6d04d16a54a3;p=pspp diff --git a/dump2.c b/dump2.c index af01b408cd..15670ecf4b 100644 --- a/dump2.c +++ b/dump2.c @@ -7,6 +7,7 @@ #include #include #include +#include "u8-mbtouc.h" static uint8_t *data; static size_t n, pos; @@ -86,10 +87,25 @@ all_ascii(const uint8_t *p) return true; } +static bool +all_utf8(const uint8_t *p) +{ + size_t len = strlen ((char *) p); + for (size_t ofs = 0, mblen; ofs < len; ofs += mblen) + { + ucs4_t uc; + + mblen = u8_mbtouc (&uc, p + ofs, len - ofs); + if (uc < 32 || uc == 127 || uc == 0xfffd) + return false; + } + return true; +} + static char * get_fixed_string(int len, const char *where) { - if (pos + len > n || !memchr(&data[pos], 0, len) || !all_ascii(&data[pos])) + if (pos + len > n || !memchr(&data[pos], 0, len) || !all_utf8(&data[pos])) { fprintf(stderr, "%s: 0x%x: bad fixed-width string\n", where, pos); exit(1); @@ -190,7 +206,7 @@ dump_raw(FILE *stream, int start, int end, const char *separator) } static void -dump_source(int end, int count, int n_series) +dump_source(int end, int count, int n_series, const char *name) { const union { @@ -219,14 +235,19 @@ dump_source(int end, int count, int n_series) if (pos >= end) return; - printf ("\n %08x: (%d sysmis)", pos, n_sysmis); - printf (" %d", get_u32()); - printf (", \"%s\"\n", get_string()); + match_u32_assert(1); + char *name2 = get_string(); + assert(!strcmp(name, name2)); printf ("\n %08x:", pos); int n_more_series = get_u32(); + if (n_series != n_more_series) + printf("different series counts: %d %d\n", n_series, n_more_series); + assert(n_more_series <= n_series); printf (" %d series to come\n", n_more_series); + int max1 = -1; + int ofs = pos; for (int i = 0; i < n_more_series; i++) { printf ("%08x:", pos); @@ -236,21 +257,45 @@ dump_source(int end, int count, int n_series) { int x = get_u32(); int y = get_u32(); - printf (" (%d,%d)", x, y); + printf (" (%d, %d)", x, y); + if (y > max1) + max1 = y; } printf ("\n"); } printf ("\n%08x:", pos); int n_strings = get_u32(); + assert(n_strings == max1 + 1); printf (" %d strings\n", n_strings); + + char **strings = malloc(n_strings * sizeof *strings); for (int i = 0; i < n_strings; i++) { - int x = get_u32(); + int frequency = get_u32(); char *s = get_string(); - printf ("%d: \"%s\" (%d)\n", i, s, x); + printf ("%d: \"%s\" (%d)\n", i, s, frequency); + strings[i] = s; } printf ("\n"); + + assert (pos == end); + pos = ofs; + printf("Strings:\n"); + for (int i = 0; i < n_more_series; i++) + { + printf (" \"%s\"\n", get_string()); + int n_pairs = get_u32(); + for (int j = 0; j < n_pairs; j++) + { + int x = get_u32(); + //assert (x == j); + int y = get_u32(); + printf (" %d: \"%s\"\n", x, strings[y]); + } + printf ("\n"); + } + pos = end; } int @@ -296,6 +341,7 @@ main(int argc, char **argv) struct source { int offset, count, n_series; + char *name; } sources[n_sources]; for (int i = 0; i < n_sources; i++) @@ -310,6 +356,7 @@ main(int argc, char **argv) sources[i].offset = offset; sources[i].count = count; sources[i].n_series = n_series; + sources[i].name = name; } for (int i = 0; i < n_sources; i++) @@ -319,7 +366,7 @@ main(int argc, char **argv) fprintf (stderr, "pos=0x%x expected=0x%x reading source %d\n", pos, sources[i].offset, i); exit(1); } - dump_source(i + 1 >= n_sources ? n : sources[i + 1].offset, sources[i].count, sources[i].n_series); + dump_source(i + 1 >= n_sources ? n : sources[i + 1].offset, sources[i].count, sources[i].n_series, sources[i].name); } assert(pos == n);