From: Ben Pfaff Date: Wed, 12 Nov 2014 06:31:18 +0000 (-0800) Subject: dump: All output into pseudo-XML. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fae52d40322a80fe485e2f70eba05170cd091fd;p=pspp dump: All output into pseudo-XML. --- diff --git a/dump.c b/dump.c index e1446edeb8..64ddcfdda8 100644 --- a/dump.c +++ b/dump.c @@ -26,13 +26,6 @@ try_find(const char *target, size_t target_len) return pos ? pos - data : 0; } -static size_t -try_find_tail(const char *target, size_t target_len) -{ - size_t pos = try_find(target, target_len); - return pos ? pos + target_len : 0; -} - static size_t find(const char *target, size_t target_len) { @@ -45,18 +38,6 @@ find(const char *target, size_t target_len) return pos; } -static size_t -find_tail(const char *target, size_t target_len) -{ - size_t pos = try_find_tail(target, target_len); - if (!pos) - { - fprintf (stderr, "not found\n"); - exit(1); - } - return pos; -} - size_t pos; #define XSTR(x) #x @@ -524,7 +505,10 @@ check_permutation(int *a, int n, const char *name) static void dump_category(int level, int *indexes, int *n_indexes) { - dump_value__ (stdout, level, true); + for (int i = 0; i <= level; i++) + fprintf (stdout, " "); + printf ("\n"); + dump_value__ (stdout, level + 1, true); match_byte(0); match_byte(0); match_byte(0); @@ -552,20 +536,25 @@ dump_category(int level, int *indexes, int *n_indexes) } indexes[(*n_indexes)++] = indx; } - if (n_categories > 0) - printf (", %d subcategories:", n_categories); - else - printf (", index %d", indx); - printf("\n"); + if (n_categories == 0) + { + for (int i = 0; i <= level + 1; i++) + fprintf (stdout, " "); + fprintf (stdout, "%d\n", indx); + } for (int i = 0; i < n_categories; i++) dump_category (level + 1, indexes, n_indexes); + for (int i = 0; i <= level; i++) + fprintf (stdout, " "); + printf ("\n"); } static void -dump_dim(void) +dump_dim(int indx) { int n_categories; - printf("next dim\n"); + + printf ("\n", indx); dump_value__ (stdout, 0, false); /* This byte is usually 0x02 but 0x00 and 0x75 (!) have also been spotted. */ @@ -580,16 +569,16 @@ dump_dim(void) if (!match_byte(0)) match_byte_assert(1); match_byte_assert(1); - static int dim_indx = 0; - match_u32_assert(dim_indx++); + match_u32_assert(indx); n_categories = get_u32(); - printf("%d nested categories\n", n_categories); int indexes[1024]; int n_indexes = 0; for (int i = 0; i < n_categories; i++) dump_category (0, indexes, &n_indexes); check_permutation(indexes, n_indexes, "categories"); + + fprintf (stdout, "\n"); } int n_dims; @@ -597,12 +586,8 @@ static void dump_dims(void) { n_dims = get_u32(); - printf ("%u dimensions\n", n_dims); for (int i = 0; i < n_dims; i++) - { - printf("\n"); - dump_dim (); - } + dump_dim (i); } static void @@ -620,93 +605,78 @@ dump_data(void) check_permutation(a, n_dims, "dimensions"); int x = get_u32(); - printf ("%d data values, starting at %08x\n", x, pos); + printf ("\n"); for (int i = 0; i < x; i++) { - printf("%08x, index %d:\n", pos, get_u32()); + printf (" \n", get_u32()); match_u32_assert(0); - dump_value__(stdout, 0, false); - putchar('\n'); + dump_value__(stdout, 1, false); + fprintf (stdout, " \n"); } + printf ("\n"); } static void dump_title(void) { pos = 0x27; - printf("text:\n"); - dump_value__(stdout, 0, true); putchar('\n'); - printf("subtype:\n"); - dump_value__(stdout, 0, true); putchar('\n'); + printf ("\n"); + dump_value__(stdout, 0, true); + printf ("\n"); + + printf ("\n"); + dump_value__(stdout, 0, true); + printf ("\n"); + match_byte_assert(0x31); - printf("text_eng:\n"); - dump_value__(stdout, 0, true); putchar('\n'); + + printf ("\n"); + dump_value__(stdout, 0, true); + printf ("\n"); + match_byte(0); match_byte_assert(0x58); if (match_byte(0x31)) { - printf("caption:\n"); - dump_value__(stdout, 0, false); putchar('\n'); + printf ("\n"); + dump_value__(stdout, 0, false); + printf ("\n"); } else match_byte_assert(0x58); int n_footnotes = get_u32(); - if (n_footnotes >= 20) + for (int i = 0; i < n_footnotes; i++) { - fprintf(stderr, "%08x: %d footnotes\n", pos - 4, n_footnotes); - exit(1); - } - - printf("------\n%d footnotes\n", n_footnotes); - if (n_footnotes < 20) - { - for (int i = 0; i < n_footnotes; i++) + printf ("\n", i); + dump_value__(stdout, 0, false); + if (match_byte (0x31)) { - printf("footnote %d:\n", i); - dump_value__(stdout, 0, false); - if (match_byte (0x31)) - { - /* Custom footnote marker string. */ - match_byte_assert(3); - get_string(); - match_byte_assert(0x58); - match_u32_assert(0); - get_string(); - } - else - match_byte_assert (0x58); - printf("(%d)\n", get_u32()); + /* Custom footnote marker string. */ + match_byte_assert(3); + get_string(); + match_byte_assert(0x58); + match_u32_assert(0); + get_string(); } + else + match_byte_assert (0x58); + printf("(%d)\n", get_u32()); + printf ("\n"); } } -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) { - printf("fonts: offset=%08x\n", pos); match_byte(0); for (int i = 1; i <= 8; i++) { - printf("%08x: font %d, ", pos, i); + printf ("