X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump.c;h=e9a068699e005fba3778c5597181c93d0f8a6d4a;hb=368df5e381894c9fa6bb2b51596a1a58b0d869a8;hp=830a5dac1dc3714ea57c2b5429651ff560d66b67;hpb=8f03a15bc9fce38e9651dcb3ce82ba7815ccc9b5;p=pspp
diff --git a/dump.c b/dump.c
index 830a5dac1d..e9a068699e 100644
--- a/dump.c
+++ b/dump.c
@@ -569,33 +569,41 @@ check_permutation(int *a, int n, const char *name)
}
static void
-dump_category(int level, int *indexes, int *n_indexes, int max_indexes)
+dump_category(FILE *stream, int level, int *indexes, int *n_indexes, int max_indexes)
{
for (int i = 0; i <= level; i++)
- fprintf (stdout, " ");
+ fprintf (stream, " ");
printf ("\n");
- dump_value (stdout, level + 1);
- match_byte(1);
- match_byte(0);
- match_byte(0);
- match_byte(0);
+ dump_value (stream, level + 1);
- if (match_u32 (1))
- match_byte (0);
- else if (match_byte (1))
- {
- match_byte (0);
- if (!match_u32 (2))
- match_u32_assert (1);
- match_byte (0);
- }
- else if (!match_u32(2))
- match_u32_assert (0);
+ int merge = data[pos];
+ if (!match_byte(0))
+ match_byte_assert (1);
+ match_byte_assert (0);
+ int unindexed = data[pos];
+ if (!match_byte(0))
+ match_byte_assert (1);
+ if (!match_u32 (0))
+ match_u32_assert (2);
int indx = get_u32();
int n_categories = get_u32();
- if (indx != -1)
+ if (indx == -1)
{
+ if (merge)
+ {
+ for (int i = 0; i <= level + 1; i++)
+ fprintf (stream, " ");
+ fprintf (stream, "\n");
+ }
+ }
+ else
+ {
+ if (merge)
+ {
+ fprintf(stderr, "index not -1 but merged\n");
+ exit(1);
+ }
if (n_categories != 0)
{
fprintf(stderr, "index not -1 but subcategories\n");
@@ -608,16 +616,25 @@ dump_category(int level, int *indexes, int *n_indexes, int max_indexes)
}
indexes[(*n_indexes)++] = indx;
}
+
+ int expected_unindexed = indx == -1;
+ if (unindexed != expected_unindexed)
+ {
+ fprintf(stderr, "unindexed (%d) mismatch with indx (%d)\n",
+ unindexed, indx);
+ exit(1);
+ }
+
if (n_categories == 0)
{
for (int i = 0; i <= level + 1; i++)
- fprintf (stdout, " ");
- fprintf (stdout, "%d\n", indx);
+ fprintf (stream, " ");
+ fprintf (stream, "%d\n", indx);
}
for (int i = 0; i < n_categories; i++)
- dump_category (level + 1, indexes, n_indexes, max_indexes);
+ dump_category (stream, level + 1, indexes, n_indexes, max_indexes);
for (int i = 0; i <= level; i++)
- fprintf (stdout, " ");
+ fprintf (stream, " ");
printf ("\n");
}
@@ -629,7 +646,7 @@ dump_dim(int indx)
printf ("\n", indx);
dump_value (stdout, 0);
- /* This byte is usually 0x02 but many other values have been spotted. */
+ /* This byte is usually 0 but many other values have been spotted. */
pos++;
if (!match_byte(0) && !match_byte(1))
@@ -648,7 +665,7 @@ dump_dim(int indx)
int indexes[2048];
int n_indexes = 0;
for (int i = 0; i < n_categories; i++)
- dump_category (0, indexes, &n_indexes, sizeof indexes / sizeof *indexes);
+ dump_category (stdout, 0, indexes, &n_indexes, sizeof indexes / sizeof *indexes);
check_permutation(indexes, n_indexes, "categories");
fprintf (stdout, "\n");