11 #include "u8-mbtouc.h"
19 all_ascii(const uint8_t *p, size_t n)
21 for (size_t i = 0; i < n; i++)
22 if (p[i] < 32 || p[i] > 126)
28 try_find(const char *target, size_t target_len)
30 const uint8_t *pos = (const uint8_t *) memmem (data, n, target, target_len);
31 return pos ? pos - data : 0;
35 find(const char *target, size_t target_len)
37 size_t pos = try_find(target, target_len);
40 fprintf (stderr, "not found\n");
49 #define STR(x) XSTR(x)
50 #define WHERE __FILE__":" STR(__LINE__)
62 memcpy(&x, &data[pos], 4);
67 static unsigned long long int
71 memcpy(&x, &data[pos], 8);
80 x = (data[pos] << 24) | (data[pos + 1] << 16) | (data[pos + 2] << 8) | data[pos + 3];
89 memcpy(&x, &data[pos], 2);
98 memcpy(&x, &data[pos], 8);
103 static double __attribute__((unused))
107 memcpy(&x, &data[pos], 4);
113 match_u32(uint32_t x)
122 match_u32_assert(uint32_t x, const char *where)
124 unsigned int y = get_u32();
127 fprintf(stderr, "%s: 0x%x: expected i%u, got i%u\n", where, pos - 4, x, y);
131 #define match_u32_assert(x) match_u32_assert(x, WHERE)
133 static bool __attribute__((unused))
134 match_u64(uint64_t x)
142 static void __attribute__((unused))
143 match_u64_assert(uint64_t x, const char *where)
145 unsigned long long int y = get_u64();
148 fprintf(stderr, "%s: 0x%x: expected u64:%llu, got u64:%llu\n", where, pos - 8, x, y);
152 #define match_u64_assert(x) match_u64_assert(x, WHERE)
154 static bool __attribute__((unused))
155 match_be32(uint32_t x)
164 match_be32_assert(uint32_t x, const char *where)
166 unsigned int y = get_be32();
169 fprintf(stderr, "%s: 0x%x: expected be%u, got be%u\n", where, pos - 4, x, y);
173 #define match_be32_assert(x) match_be32_assert(x, WHERE)
176 match_byte(uint8_t b)
178 if (pos < n && data[pos] == b)
188 match_byte_assert(uint8_t b, const char *where)
192 fprintf(stderr, "%s: 0x%x: expected %02x, got %02x\n", where, pos, b, data[pos]);
196 #define match_byte_assert(b) match_byte_assert(b, WHERE)
199 newline(FILE *stream, int pos)
201 fprintf(stream, "\n%08x: ", pos);
205 dump_raw(FILE *stream, int start, int end)
207 for (size_t i = start; i < end; )
214 && i + 4 + data[i] + data[i + 1] * 256 <= end
215 && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
218 fprintf(stream, "\"");
219 fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stream);
220 fputs("\" ", stream);
222 i += 4 + data[i] + data[i + 1] * 256;
224 else if (i + 12 <= end
231 memcpy (&d, &data[i + 4], 8);
232 fprintf (stream, "F40.%d(%.*f)", data[i], data[i], d);
236 else if (i + 12 <= end
243 memcpy (&d, &data[i + 4], 8);
244 fprintf (stream, "PCT40.%d(%.*f)", data[i], data[i], d);
248 else if (i + 4 <= end
249 && (data[i] && data[i] != 88 && data[i] != 0x41)
254 fprintf (stream, "i%d ", data[i]);
259 fprintf(stream, "%02x ", data[i]);
267 static bool __attribute__((unused))
268 all_utf8(const char *p_)
270 const uint8_t *p = (const uint8_t *) p_;
271 size_t len = strlen ((char *) p);
272 for (size_t ofs = 0, mblen; ofs < len; ofs += mblen)
276 mblen = u8_mbtouc (&uc, p + ofs, len - ofs);
277 if ((uc < 32 && uc != '\n') || uc == 127 || uc == 0xfffd)
284 get_string(const char *where)
287 /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/
288 /*&& all_ascii(&data[pos + 4], data[pos])*/)
290 int len = data[pos] + data[pos + 1] * 256;
291 char *s = malloc(len + 1);
293 memcpy(s, &data[pos + 4], len);
300 fprintf(stderr, "%s: 0x%x: expected string\n", where, pos);
304 #define get_string() get_string(WHERE)
307 get_string_be(const char *where)
310 /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/
311 /*&& all_ascii(&data[pos + 4], data[pos])*/)
313 int len = data[pos + 2] * 256 + data[pos + 3];
314 char *s = malloc(len + 1);
316 memcpy(s, &data[pos + 4], len);
323 fprintf(stderr, "%s: 0x%x: expected string\n", where, pos);
327 #define get_string_be() get_string_be(WHERE)
336 static void __attribute__((unused))
337 hex_dump(int ofs, int n)
339 for (int i = 0; i < n; i++)
341 int c = data[ofs + i];
350 for (int i = 0; i < n; i++)
352 int c = data[ofs + i];
353 printf("%c", c >= 32 && c < 127 ? c : '.');
358 dump_counted_string(void)
361 int inner_end = get_end();
362 if (pos != inner_end)
367 match_byte_assert(0x58);
371 if (match_byte(0x31))
374 match_byte_assert(0x58);
375 if (pos != inner_end)
377 fprintf(stderr, "inner end discrepancy\n");
385 dump_style(FILE *stream)
387 for (int i = 0; i < 4; i++)
388 printf (" %d", get_byte());
389 char *fg = get_string(); /* foreground */
390 char *bg = get_string(); /* background */
391 char *font = get_string(); /* font */
392 int size = get_byte() * (72. / 96.);
393 fprintf(stream, " fgcolor=\"%s\" bgcolor=\"%s\" font=\"%s\" size=\"%dpt\"",
398 dump_nested_string(FILE *stream)
402 match_byte_assert (0);
403 match_byte_assert (0);
404 int outer_end = get_end();
405 s = dump_counted_string();
407 fprintf(stream, " \"%s\"", s);
408 if (match_byte(0x31))
411 match_byte_assert(0x58);
412 match_byte_assert(0x58);
413 if (pos != outer_end)
415 fprintf(stderr, "outer end discrepancy\n");
423 dump_value_modifier(FILE *stream)
425 if (match_byte (0x31))
429 fprintf(stream, "<special0");
432 /* Corpus frequencies:
437 The given text is appended to the cell in a subscript font.
439 fprintf(stream, " subscript=\"%s\"", get_string());
442 match_u32_assert (0);
446 /* We only have one SPV file for this version (with many
453 if (!match_u32(0) && !match_u32(1) && !match_u32(2) && !match_u32(3) && !match_u32(4) && !match_u32(5) && !match_u32(6) && !match_u32(7) && !match_u32(8) && !match_u32(9))
454 match_u32_assert(10);
457 fprintf(stream, "/>\n");
461 int outer_end = get_end();
463 /* This counted-string appears to be a template string,
464 e.g. "Design\: [:^1:]1 Within Subjects Design\: [:^1:]2". */
465 char *template = dump_counted_string();
467 fprintf(stream, " template=\"%s\"", template);
469 if (match_byte(0x31))
472 match_byte_assert(0x58);
473 if (match_byte(0x31))
475 uint32_t halign = get_u32();
476 printf (" halign=\"%s\"",
477 halign == 0 ? "center"
478 : halign == 2 ? "left"
479 : halign == 4 ? "right"
480 : halign == 6 ? "decimal"
481 : halign == 0xffffffad ? "mixed"
483 int valign = get_u32();
484 printf (" valign=\"%s\"",
485 valign == 0 ? "center"
486 : valign == 1 ? "top"
487 : valign == 3 ? "bottom"
489 printf (" %g", get_double());
494 printf (" margins=\"%d %d %d %d\"", l, r, t, b);
497 match_byte_assert(0x58);
498 if (pos != outer_end)
500 fprintf(stderr, "outer end discrepancy\n");
503 fprintf(stream, "/>\n");
507 int count = get_u32();
508 fprintf(stream, "<footnote-ref indexes=\"");
509 for (int i = 0; i < count; i++)
513 fprintf(stream, "%d", get_u16());
516 match_byte_assert(0);
517 match_byte_assert(0);
518 dump_nested_string(stream);
519 fprintf(stream, "/>\n");
523 match_byte_assert (0x58);
527 format_to_string (int type)
533 case 2: return "AHEX";
534 case 3: return "COMMA";
535 case 4: return "DOLLAR";
536 case 5: case 40: return "F";
538 case 7: return "PIBHEX";
540 case 9: return "PIB";
541 case 10: return "PK";
542 case 11: return "RB";
543 case 12: return "RBHEX";
547 case 20: return "DATE";
548 case 21: return "TIME";
549 case 22: return "DATETIME";
550 case 23: return "ADATE";
551 case 24: return "JDATE";
552 case 25: return "DTIME";
553 case 26: return "WKDAY";
554 case 27: return "MONTH";
555 case 28: return "MOYR";
556 case 29: return "QYR";
557 case 30: return "WKYR";
558 case 31: return "PCT";
559 case 32: return "DOT";
560 case 33: return "CCA";
561 case 34: return "CCB";
562 case 35: return "CCC";
563 case 36: return "CCD";
564 case 37: return "CCE";
565 case 38: return "EDATE";
566 case 39: return "SDATE";
569 sprintf(tmp, "<%d>", type);
575 dump_value(FILE *stream, int level)
582 for (int i = 0; i <= level; i++)
583 fprintf (stream, " ");
590 dump_value_modifier(stream);
592 value = get_double ();
593 fprintf (stream, "<number value=\"%.*g\" format=\"%s%d.%d\"/>\n",
594 DBL_DIG, value, format_to_string(format >> 16), (format >> 8) & 0xff, format & 0xff);
596 else if (match_byte (2))
602 dump_value_modifier (stream);
604 value = get_double ();
606 vallab = get_string ();
607 fprintf (stream, "<numeric-datum value=\"%.*g\" format=\"%s%d.%d\"",
608 DBL_DIG, value, format_to_string(format >> 16), (format >> 8) & 0xff, format & 0xff);
610 fprintf (stream, " variable=\"%s\"", var);
612 fprintf (stream, " label=\"%s\"", vallab);
613 fprintf (stream, "/>\n");
614 if (!match_byte (1) && !match_byte(2))
615 match_byte_assert (3);
617 else if (match_byte (3))
619 char *text = get_string();
620 dump_value_modifier(stream);
621 char *identifier = get_string();
622 char *text_eng = get_string();
623 fprintf (stream, "<string c=\"%s\"", text_eng);
625 fprintf (stream, " identifier=\"%s\"", identifier);
626 if (strcmp(text_eng, text))
627 fprintf (stream, " local=\"%s\"", text);
628 fprintf (stream, "/>\n");
630 match_byte_assert(1);
632 else if (match_byte (4))
635 char *var, *vallab, *value;
637 dump_value_modifier(stream);
639 vallab = get_string ();
641 if (!match_byte(1) && !match_byte(2))
642 match_byte_assert (3);
643 value = get_string ();
644 fprintf (stream, "<string-datum value=\"%s\" format=\"%s%d.%d\"",
645 value, format_to_string(format >> 16), (format >> 8) & 0xff, format & 0xff);
647 fprintf (stream, " variable=\"%s\"", var);
649 fprintf (stream, " label=\"%s\"/>\n", vallab);
650 fprintf (stream, "/>\n");
652 else if (match_byte (5))
654 dump_value_modifier(stream);
655 char *name = get_string ();
656 char *label = get_string ();
657 fprintf (stream, "<variable name=\"%s\"", name);
659 fprintf (stream, " label=\"%s\"", label);
660 fprintf (stream, "/>\n");
661 if (!match_byte(1) && !match_byte(2))
662 match_byte_assert(3);
666 dump_value_modifier(stream);
668 char *base = get_string();
670 fprintf (stream, "<template format=\"%s\">\n", base);
671 for (int i = 0; i < x; i++)
678 for (int j = 0; j <= level + 1; j++)
679 fprintf (stream, " ");
680 fprintf (stream, "<substitution index=\"%d\">\n", i + 1);
681 for (int j = 0; j < y; j++)
682 dump_value (stream, level + 2);
683 for (int j = 0; j <= level + 1; j++)
684 fprintf (stream, " ");
685 fprintf (stream, "</substitution>\n");
687 for (int j = 0; j <= level; j++)
688 fprintf (stream, " ");
689 fprintf (stream, "</template>\n");
694 compare_int(const void *a_, const void *b_)
698 return *a < *b ? -1 : *a > *b;
702 check_permutation(int *a, int n, const char *name)
705 memcpy(b, a, n * sizeof *a);
706 qsort(b, n, sizeof *b, compare_int);
707 for (int i = 0; i < n; i++)
710 fprintf(stderr, "bad %s permutation:", name);
711 for (int i = 0; i < n; i++)
712 fprintf(stderr, " %d", a[i]);
719 dump_category(FILE *stream, int level, int **indexes, int *allocated_indexes,
722 for (int i = 0; i <= level; i++)
723 fprintf (stream, " ");
724 printf ("<category>\n");
725 dump_value (stream, level + 1);
727 int merge = data[pos];
729 match_byte_assert (1);
731 match_byte_assert (0);
733 int unindexed = data[pos];
735 match_byte_assert (1);
740 match_u32_assert (2);
742 int indx = get_u32();
743 int n_categories = get_u32();
748 for (int i = 0; i <= level + 1; i++)
749 fprintf (stream, " ");
750 fprintf (stream, "<merge/>\n");
757 fprintf(stderr, "index not -1 but merged\n");
762 fprintf(stderr, "index not -1 but x != 2\n");
765 if (n_categories != 0)
767 fprintf(stderr, "index not -1 but subcategories\n");
770 if (*n_indexes >= *allocated_indexes)
772 *allocated_indexes = *allocated_indexes ? 2 * *allocated_indexes : 16;
773 *indexes = realloc(*indexes, *allocated_indexes * sizeof **indexes);
775 (*indexes)[(*n_indexes)++] = indx;
778 int expected_unindexed = indx == -1;
779 if (unindexed != expected_unindexed)
781 fprintf(stderr, "unindexed (%d) mismatch with indx (%d)\n",
786 if (n_categories == 0)
788 for (int i = 0; i <= level + 1; i++)
789 fprintf (stream, " ");
790 fprintf (stream, "<category-index>%d</category-index>\n", indx);
792 for (int i = 0; i < n_categories; i++)
793 dump_category (stream, level + 1, indexes, allocated_indexes, n_indexes);
794 for (int i = 0; i <= level; i++)
795 fprintf (stream, " ");
796 printf ("</category>\n");
804 printf ("<dimension index=\"%d\">\n", indx);
805 dump_value (stdout, 0);
807 /* This byte is usually 0 but many other values have been spotted. */
810 if (!match_byte(0) && !match_byte(1))
811 match_byte_assert(2);
815 match_byte_assert(1);
817 match_byte_assert(1);
818 match_byte_assert(1);
819 if (!match_u32(UINT32_MAX))
820 match_u32_assert(indx);
821 n_categories = get_u32();
825 int allocated_indexes = 0;
826 for (int i = 0; i < n_categories; i++)
827 dump_category (stdout, 0, &indexes, &allocated_indexes, &n_indexes);
828 check_permutation(indexes, n_indexes, "categories");
830 fprintf (stdout, "</dimension>\n");
835 static int dim_n_cats[64];
836 #define MAX_DIMS (sizeof dim_n_cats / sizeof *dim_n_cats)
842 assert(n_dims < MAX_DIMS);
843 for (int i = 0; i < n_dims; i++)
844 dim_n_cats[i] = dump_dim (i);
850 /* The first three numbers add to the number of dimensions. */
853 int c = n_dims - l - r;
856 /* The next n_dims numbers are a permutation of the dimension numbers. */
858 for (int i = 0; i < n_dims; i++)
863 const char *name = i < l ? "layer" : i < l + r ? "row" : "column";
864 printf ("<%s dimension=\"%d\"/>\n", name, dim);
866 check_permutation(a, n_dims, "dimensions");
870 for (int i = 0; i < x; i++)
872 unsigned int indx = get_u32();
873 printf (" <datum index=\"%d\" coords=", indx);
875 int coords[MAX_DIMS];
876 for (int i = n_dims; i-- > 0; )
878 coords[i] = indx % dim_n_cats[i];
879 indx /= dim_n_cats[i];
881 for (int i = 0; i < n_dims; i++)
882 printf("%c%d", i ? ',' : '"', coords[i]);
888 dump_value(stdout, 1);
889 fprintf (stdout, " </datum>\n");
891 printf ("</data>\n");
897 printf ("<title-local>\n");
898 dump_value(stdout, 0);
900 printf ("</title-local>\n");
902 printf ("<subtype>\n");
903 dump_value(stdout, 0);
905 printf ("</subtype>\n");
907 match_byte_assert(0x31);
909 printf ("<title-c>\n");
910 dump_value(stdout, 0);
912 printf ("</title-c>\n");
914 if (match_byte(0x31))
916 printf ("<user-caption>\n");
917 dump_value(stdout, 0);
918 printf ("</user-caption>\n");
921 match_byte_assert(0x58);
922 if (match_byte(0x31))
924 printf ("<caption>\n");
925 dump_value(stdout, 0);
926 printf ("</caption>\n");
929 match_byte_assert(0x58);
931 int n_footnotes = get_u32();
932 for (int i = 0; i < n_footnotes; i++)
934 printf ("<footnote index=\"%d\">\n", i);
935 dump_value(stdout, 0);
936 /* Custom footnote marker string. */
937 if (match_byte (0x31))
938 dump_value(stdout, 0);
940 match_byte_assert (0x58);
942 printf ("</footnote>\n");
950 for (int i = 1; i <= 8; i++)
952 printf ("<style index=\"%d\"", i);
953 match_byte_assert(i);
954 match_byte_assert(0x31);
955 printf(" font=\"%s\"", get_string());
957 printf(" size=\"%gpt\"", get_float());
959 int style = get_u32();
961 printf(" bold=\"true\"");
963 printf(" italic=\"true\"");
965 bool underline = data[pos++];
967 printf(" underline=\"true\"");
969 int halign = get_u32();
970 printf(" halign=%d", halign);
972 int valign = get_u32();
973 printf(" valign=%d", valign);
975 printf (" fgcolor=\"%s\"", get_string());
976 printf (" bgcolor=\"%s\"", get_string());
979 match_byte_assert(1);
981 char *alt_fgcolor = get_string();
983 printf (" altfg=\"%s\"", alt_fgcolor);
984 char *alt_bgcolor = get_string();
986 printf (" altbg=\"%s\"", alt_bgcolor);
990 printf(" margins=\"");
991 for (int i = 0; i < 4; i++)
995 printf("%d", get_u32());
1004 int x1_end = pos + x1;
1005 printf("<borders>\n");
1006 match_be32_assert(1);
1007 int n_borders = get_be32();
1008 for (int i = 0; i < n_borders; i++)
1010 int type = get_be32();
1011 int stroke = get_be32();
1012 int color = get_be32();
1013 printf(" <border type=\"%d\" stroke=\"%s\" color=\"#%06x\"/>\n",
1015 (stroke == 0 ? "none"
1016 : stroke == 1 ? "solid"
1017 : stroke == 2 ? "dashed"
1018 : stroke == 3 ? "thick"
1019 : stroke == 4 ? "thin"
1020 : stroke == 5 ? "double"
1024 bool grid = get_byte();
1026 printf(" <grid show=\"%s\"/>\n", grid ? "yes" : "no");
1027 printf("</borders>\n");
1028 assert(pos == x1_end);
1030 int skip = get_u32();
1031 assert(skip == 18 || skip == 25);
1035 int x3_end = pos + x3;
1038 match_be32_assert(1);
1040 printf("<settings layer=\"%d\"", get_be32());
1042 printf(" skipempty=\"false\"");
1044 printf(" showdimensionincorner=\"false\"");
1046 printf(" markers=\"numeric\"");
1048 printf(" footnoteposition=\"subscript\"");
1050 int nbytes = get_be32();
1052 hex_dump(pos, nbytes);
1055 char *notes = get_string_be();
1057 printf(" notes=\"%s\"", notes);
1058 char *look = get_string_be();
1060 printf(" look=\"%s\"", look);
1065 /* Manual column widths, if present. */
1066 int count = get_u32();
1069 printf("<columnwidths>");
1070 for (int i = 0; i < count; i++)
1074 printf("%d", get_u32());
1076 printf("</columnwidths>\n");
1079 const char *locale = get_string();
1080 printf ("<locale>%s</locale>\n", locale);
1082 get_u32(); /* Seen: 0, UINT32_MAX, 2, 3, 4, 5, 6, 8, 9, 21, 24. */
1084 match_byte_assert(1);
1085 match_byte_assert(0);
1087 match_byte_assert(1);
1088 printf("<epoch>%d</epoch>\n", get_u32());
1090 int decimal = data[pos];
1091 int grouping = data[pos + 1];
1092 if (match_byte('.'))
1094 if (!match_byte(',') && !match_byte('\''))
1095 match_byte_assert(' ');
1099 match_byte_assert(',');
1100 if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
1101 match_byte_assert(0);
1103 printf("<format decimal=\"%c\" grouping=\"", decimal);
1109 for (int i = 0; i < 5; i++)
1110 printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
1113 match_u32_assert(0);
1115 /* The last chunk is an outer envelope that contains two inner envelopes.
1116 The second inner envelope has some interesting data like the encoding and
1120 int outer_end = get_end();
1122 /* First inner envelope: byte*33 int[n] int*[n]. */
1123 int inner_len = get_u32();
1124 int inner_end = pos + inner_len;
1125 int array_start = pos + 33;
1126 match_byte_assert(0);
1127 pos++; /* 0, 1, 10 seen. */
1128 match_byte_assert(0);
1129 pos++; /* 0...11 seen. */
1130 if (!match_byte(0) && !match_byte(1) && !match_byte(2))
1131 match_byte_assert(3);
1132 if (!match_byte(0) && !match_byte(2))
1133 match_byte_assert(3);
1135 match_u64_assert(UINT64_MAX);
1136 match_u32_assert(0);
1137 match_u32_assert(0);
1138 match_u32_assert(0);
1139 match_u32_assert(0);
1140 match_byte_assert(0);
1142 match_byte_assert(1);
1143 match_byte_assert(1);
1147 while (pos < inner_end)
1148 printf(" %d", get_u32());
1153 /* Second inner envelope. */
1154 assert(get_end() == outer_end);
1156 match_byte_assert(1);
1157 match_byte_assert(0);
1158 if (!match_byte(3) && !match_byte(4))
1159 match_byte_assert(5);
1160 match_byte_assert(0);
1161 match_byte_assert(0);
1162 match_byte_assert(0);
1164 printf("<command>%s</command>\n", get_string());
1165 printf("<subcommand>%s</subcommand>\n", get_string());
1166 printf("<language>%s</language>\n", get_string());
1167 printf("<charset>%s</charset>\n", get_string());
1168 printf("<locale>%s</locale>\n", get_string());
1171 match_byte_assert(1);
1172 match_byte_assert(0);
1174 match_byte_assert(1);
1176 match_byte_assert(1);
1178 printf("<epoch2>%d</epoch2>\n", get_u32());
1180 if (match_byte('.'))
1182 if (!match_byte(',') && !match_byte('\''))
1183 match_byte_assert(' ');
1187 match_byte_assert(',');
1188 if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
1189 match_byte_assert(0);
1192 printf ("small: %g\n", get_double());
1194 match_byte_assert(1);
1195 if (outer_end - pos > 6)
1197 /* There might be a pair of strings representing a dataset and
1198 datafile name, or there might be a set of custom currency strings.
1199 The custom currency strings start with a pair of integers, so we
1200 can distinguish these from a string by checking for a null byte; a
1201 small 32-bit integer will always contain a null and a text string
1204 int len = get_u32();
1205 bool has_dataset = !memchr(&data[pos], '\0', len);
1210 printf("<dataset>%s</dataset>\n", get_string());
1211 printf("<datafile>%s</datafile>\n", get_string());
1213 match_u32_assert(0);
1215 time_t date = get_u32();
1216 struct tm tm = *localtime(&date);
1218 strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S %z", &tm);
1219 printf("<date>%s</date>\n", s);
1221 match_u32_assert(0);
1227 for (int i = 0; i < 5; i++)
1228 printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
1231 match_u32_assert(0);
1233 match_byte_assert('.');
1235 match_byte_assert(1);
1237 if (pos < outer_end)
1239 printf("<seed>%d</seed>\n", get_u32());
1240 match_u32_assert(0);
1242 assert(pos == outer_end);
1253 main(int argc, char *argv[])
1258 if (isatty(STDIN_FILENO))
1260 fprintf(stderr, "redirect stdin from a .bin file\n");
1263 if (fstat(STDIN_FILENO, &s))
1275 if (read(STDIN_FILENO, data, n) != n)
1283 fprintf (stderr, "usage: %s TYPE < .bin", argv[0]);
1287 if (!strcmp(argv[1], "title0"))
1290 if (match_byte (0x03)
1291 || (match_byte (0x05) && match_byte (0x58)))
1292 printf ("%s\n", get_string());
1294 printf ("<unknown>\n");
1297 else if (!strcmp(argv[1], "title"))
1303 else if (!strcmp(argv[1], "titleraw"))
1305 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1307 n = find(fonts, sizeof fonts - 1);
1309 else if (!strcmp(argv[1], "fonts"))
1311 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1312 const char styles[] = "\xf0\0\0\0";
1313 start = find(fonts, sizeof fonts - 1);
1314 n = find(styles, sizeof styles - 1);
1316 else if (!strcmp(argv[1], "styles"))
1318 const char styles[] = "\xf0\0\0\0";
1319 const char dimensions[] = "-,,,.\0";
1320 start = find(styles, sizeof styles - 1);
1321 n = find(dimensions, sizeof dimensions - 1) + sizeof dimensions - 1;
1323 else if (!strcmp(argv[1], "dimensions") || !strcmp(argv[1], "all"))
1326 match_byte_assert(1);
1327 match_byte_assert(0);
1329 /* This might be a version number of some kind, because value 1 seems
1330 to only appear in an SPV file that also required its own weird
1331 special cases in dump_value_modifier(). */
1332 version = get_u32();
1335 match_u32_assert(3);
1337 match_byte_assert(1);
1338 for (int i = 0; i < 4; i++)
1340 match_byte_assert(1);
1343 int min_col_width = get_u32();
1344 int max_col_width = get_u32();
1345 int min_row_width = get_u32();
1346 int max_row_width = get_u32();
1347 printf("<label-width min-col=\"%d\" max-col=\"%d\" min-row=\"%d\" "
1348 "max-row=\"%d\"/>\n",
1349 min_col_width, max_col_width,
1350 min_row_width, max_row_width);
1353 printf("<tableid>%lld</tableid>", get_u64());
1362 fprintf (stderr, "%x / %x\n", pos, n);
1367 else if (!strcmp(argv[1], "raw"))
1371 dump_raw(stdout, start, n);
1375 fprintf (stderr, "unknown section %s\n", argv[1]);