X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=dump.c;h=a7bd6c2c14dcbde968f2a05dd4a54bfc9d6aa5a4;hb=2cc609b8d02f7fe9f9d4eb32e5aca08dd59ee1cd;hp=44a1158af4cb869857a6ab325c4eac2f4ab8cedd;hpb=9f11a65bf50d984fc435f29095a35833a58d17b3;p=pspp diff --git a/dump.c b/dump.c index 44a1158af4..a7bd6c2c14 100644 --- a/dump.c +++ b/dump.c @@ -204,11 +204,26 @@ dump_value_31(void) match_byte_assert (0x58); } -static void dump_value(int level); +static void dump_substs(void (*dump)(int level), int level); +static void dump_value__(int level, bool match1); + +static void +dump_value__with_preskip(int level) +{ + match_byte(0); + match_byte(0); + match_byte(0); + match_byte(0); + dump_value__ (level, false); + putchar('\n'); +} static void dump_value__(int level, bool match1) { + for (int i = 0; i <= level; i++) + printf (" "); + if (match_byte (3)) { char *s1 = get_string(); @@ -276,88 +291,20 @@ dump_value__(int level, bool match1) match_byte (1); } else - { - dump_value_31(); - char *base = get_string(); - - int x = get_u32(); - printf ("\"%s\" with %d variables:\n", base, x); - if (match_u32(0)) - { - for (int i = 0; i < x; i++) - { - dump_value (level+1); - putchar('\n'); - } - } - else - { - for (int i = 0; i < x; i++) - { - int y = get_u32(); - match_u32_assert(0); - for (int j = 0; j <= level; j++) - printf (" "); - printf("variable %d has %d values:\n", i, y); - for (int j = 0; j < y; j++) - { - match_byte(0); - if (match_byte(3)) - { - char *a = get_string(); - match_byte_assert(0x58); - char *b = get_string(); - char *c = get_string(); - for (int k = 0; k <= level + 1; k++) - printf (" "); - printf ("\"%s\", \"%s\", \"%s\"", a, b, c); - } - else - dump_value (level+1); - - match_byte(0); - match_byte(0); - match_byte(0); - match_byte(0); - putchar('\n'); - } - } - } - } + dump_substs(dump_value__with_preskip, level + 1); } static void -dump_value(int level) +dump_category(int level) { - for (int i = 0; i <= level; i++) - printf (" "); - match_byte (0); match_byte (0); match_byte (0); match_byte (0); - dump_value__(level, true); + dump_value__ (level, true); match_byte(0); match_byte(0); match_byte(0); -} - -static void -dump_dim_value(int level) -{ - for (int i = 0; i <= level; i++) - printf (" "); - - if (data[pos] == 3 || data[pos] == 5) - dump_value__(level, true); - else - dump_value(level); -} - -static void -dump_category(int level) -{ - dump_value (level); if (match_u32 (1)) match_byte (0); @@ -381,12 +328,14 @@ dump_category(int level) dump_category (level + 1); } +static void dump_title_value(int level); + static void dump_dim(void) { int n_categories; printf("next dim\n"); - dump_dim_value(0); + dump_title_value(0); /* This byte is usually 0x02 but 0x00 and 0x75 (!) have also been spotted. */ pos++; @@ -397,15 +346,9 @@ dump_dim(void) match_u32_assert(2); if (!match_byte(0)) match_byte_assert(1); - match_byte(0); - match_byte(0); - match_byte(0); - match_byte(0); get_u32(); match_byte(0); match_byte(0); - match_byte(0); - match_byte(0); n_categories = get_u32(); printf("%d nested categories\n", n_categories); for (int i = 0; i < n_categories; i++) @@ -461,10 +404,8 @@ dump_data_value(int level) match_byte(0); match_byte(0); match_byte(0); - if (data[pos] == 1 || data[pos] == 2 || data[pos] == 3 || data[pos] == 4) + if (data[pos] <= 5) dump_value__(0, false); - else if (data[pos] == 5) - dump_value (0); else dump_substs (dump_data_value, level + 1); } @@ -507,32 +448,12 @@ dump_title_value(int level) match_byte (0); match_byte (0); match_byte (0); - if (data[pos] == 1 || data[pos] == 2 || data[pos] == 3 || data[pos] == 4) - dump_value(level); - else if (data[pos] == 5) + if (data[pos] <= 5) dump_value__(level, true); else dump_substs(dump_title_value, level + 1); } -static void -dump_footnote_value(int level) -{ - for (int i = 0; i <= level; i++) - printf (" "); - - match_byte (0); - match_byte (0); - match_byte (0); - match_byte (0); - if (data[pos] == 2 || data[pos] == 4) - dump_value(level); - else if (data[pos] == 1 || data[pos] == 3 || data[pos] == 5) - dump_value__(level, false); - else - dump_substs(dump_footnote_value, level + 1); -} - static void dump_title(void) { @@ -545,7 +466,7 @@ dump_title(void) match_byte_assert(0x58); if (match_byte(0x31)) { - dump_footnote_value(0); putchar('\n'); + dump_data_value(0); putchar('\n'); } else match_byte_assert(0x58); @@ -564,11 +485,7 @@ dump_title(void) for (int i = 0; i < n_footnotes; i++) { printf("footnote %d:\n", i); - dump_footnote_value(0); - match_byte(0); - match_byte(0); - match_byte(0); - match_byte(0); + dump_data_value(0); if (match_byte (0x31)) { /* Custom footnote marker string. */ @@ -765,8 +682,7 @@ main(int argc, char *argv[]) dump_dims (); printf("\n\ndata:\n"); dump_data (); - if (pos == n - 1) - match_byte_assert (1); + match_byte (1); if (pos != n) { fprintf (stderr, "%x / %x\n", pos, n);