13 all_ascii(const uint8_t *p, size_t n)
15 for (size_t i = 0; i < n; i++)
16 if (p[i] < 32 || p[i] > 126)
22 try_find(const char *target, size_t target_len)
24 const uint8_t *pos = (const uint8_t *) memmem (data, n, target, target_len);
25 return pos ? pos - data : 0;
29 try_find_tail(const char *target, size_t target_len)
31 size_t pos = try_find(target, target_len);
32 return pos ? pos + target_len : 0;
36 find(const char *target, size_t target_len)
38 size_t pos = try_find(target, target_len);
41 fprintf (stderr, "not found\n");
48 find_tail(const char *target, size_t target_len)
50 size_t pos = try_find_tail(target, target_len);
53 fprintf (stderr, "not found\n");
62 #define STR(x) XSTR(x)
63 #define WHERE __FILE__":" STR(__LINE__)
69 memcpy(&x, &data[pos], 4);
78 memcpy(&x, &data[pos], 8);
93 match_u32_assert(uint32_t x, const char *where)
95 unsigned int y = get_u32();
98 fprintf(stderr, "%s: 0x%x: expected i%u, got i%u\n", where, pos - 4, x, y);
102 #define match_u32_assert(x) match_u32_assert(x, WHERE)
105 match_byte(uint8_t b)
107 if (pos < n && data[pos] == b)
117 match_byte_assert(uint8_t b, const char *where)
121 fprintf(stderr, "%s: 0x%x: expected %02x, got %02x\n", where, pos, b, data[pos]);
125 #define match_byte_assert(b) match_byte_assert(b, WHERE)
128 get_string(const char *where)
131 /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/
132 /*&& all_ascii(&data[pos + 4], data[pos])*/)
134 int len = data[pos] + data[pos + 1] * 256;
135 char *s = malloc(len + 1);
137 memcpy(s, &data[pos + 4], len);
144 fprintf(stderr, "%s: 0x%x: expected string\n", where, pos);
148 #define get_string() get_string(WHERE)
151 dump_value(int level)
153 for (int i = 0; i <= level; i++)
162 char *s1 = get_string();
163 if (match_byte (0x31))
167 printf("(footnote %d) ", get_u32());
168 match_byte_assert (0);
169 match_byte_assert (0);
170 int subn = get_u32 ();
171 printf ("nested %d bytes", subn);
174 else if (match_u32 (2))
176 printf("(special 2)");
177 match_byte_assert(0);
178 match_byte_assert(0);
180 match_byte_assert(0);
181 match_byte_assert(0);
182 int subn = get_u32 ();
183 printf ("nested %d bytes", subn);
189 printf("(special 3)");
190 match_byte_assert(0);
191 match_byte_assert(0);
192 match_byte_assert(1);
193 match_byte_assert(0);
194 int subn = get_u32 ();
195 printf ("nested %d bytes, ", subn);
198 printf ("nested %d bytes, ", subn);
203 match_byte_assert (0x58);
204 char *s2 = get_string();
205 char *s3 = get_string();
207 printf("strings \"%s\", \"%s\" and \"%s\"", s1, s2, s3);
209 printf("string \"%s\" and \"%s\"", s1, s2);
220 else if (match_byte (5))
222 match_byte_assert (0x58);
223 printf ("variable \"%s\"", get_string());
225 if (!match_byte(1) && !match_byte(2))
226 match_byte_assert(3);
232 else if (match_byte (2))
238 match_byte_assert (0x58);
240 value = get_double ();
242 vallab = get_string ();
243 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
244 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
245 if (!match_byte (1) && !match_byte(2))
246 match_byte_assert (3);
255 else if (match_byte (4))
258 char *var, *vallab, *value;
260 match_byte_assert (0x58);
262 vallab = get_string ();
264 if (!match_byte(1) && !match_byte(2))
265 match_byte_assert (3);
266 value = get_string ();
267 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
268 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
274 else if (match_byte (1))
279 if (match_byte (0x31))
283 printf("(footnote %d) ", get_u32());
284 match_byte_assert (0);
285 match_byte_assert (0);
286 int subn = get_u32 ();
287 printf ("nested %d bytes", subn);
292 match_byte_assert (0x58);
294 value = get_double ();
295 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
302 else if (match_byte (0x31))
306 printf("(footnote %d) ", get_u32());
307 match_byte_assert (0);
308 match_byte_assert (0);
309 int subn = get_u32 ();
310 printf ("nested %d bytes", subn);
315 match_u32_assert (0);
316 match_u32_assert (0);
317 int subn = get_u32 ();
318 printf ("nested %d bytes", subn);
321 char *base = get_string();
323 printf ("\"%s\"; %d variables:\n", base, x);
326 for (int i = 0; i < x; i++)
328 dump_value (level+1);
334 for (int i = 0; i < x; i++)
338 for (int j = 0; j <= level; j++)
340 printf("variable %d has %d values:\n", i, y);
341 for (int j = 0; j < y; j++)
345 char *a = get_string();
346 match_byte_assert(0x58);
347 char *b = get_string();
348 char *c = get_string();
349 for (int k = 0; k <= level + 1; k++)
351 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
359 dump_value (level+1);
368 match_byte_assert (0x58);
369 char *base = get_string();
371 printf ("\"%s\" with %d variables:\n", base, x);
374 for (int i = 0; i < x; i++)
376 dump_value (level+1);
382 for (int i = 0; i < x; i++)
386 for (int j = 0; j <= level; j++)
388 printf("variable %d has %d values:\n", i, y);
389 for (int j = 0; j < y; j++)
393 char *a = get_string();
394 match_byte_assert(0x58);
395 char *b = get_string();
396 char *c = get_string();
397 for (int k = 0; k <= level + 1; k++)
399 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
407 dump_value (level+1);
416 dump_dim_value(int level)
418 for (int i = 0; i <= level; i++)
424 if (match_byte (0x31))
427 printf("(footnote %d) ", get_u32());
428 match_byte_assert (0);
429 match_byte_assert (0);
430 int subn = get_u32 ();
431 printf ("nested %d bytes", subn);
435 match_byte_assert (0x58);
437 printf("string \"%s\"", get_string());
439 match_byte_assert (1);
445 else if (match_byte (5))
447 match_byte_assert (0x58);
448 printf ("variable \"%s\"", get_string());
450 match_byte_assert (2);
452 else if (match_byte (2))
458 match_byte_assert (0x58);
460 value = get_double ();
462 vallab = get_string ();
463 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
464 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
466 match_u32_assert (2);
469 else if (match_byte (1))
474 match_byte_assert (0x58);
476 value = get_double ();
477 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
489 match_byte_assert (0x31);
490 match_u32_assert (0);
491 match_u32_assert (0);
493 printf ("nested %d bytes", subn);
495 printf ("; \"%s\", substitutions:", get_string());
496 int total_subs = get_u32();
500 total_subs = (total_subs - 1) + x;
501 match_u32_assert (0);
503 printf (" (total %d)", total_subs);
505 for (int i = 0; i < total_subs; i++)
508 dump_value (level + 1);
514 dump_category(int level)
524 else if (match_u32 (1))
531 else if (match_byte (1))
535 match_u32_assert (1);
541 match_u32_assert (0);
545 int n_categories = get_u32();
546 if (n_categories > 0)
547 printf (", %d subcategories:", n_categories);
549 for (int i = 0; i < n_categories; i++)
550 dump_category (level + 1);
557 printf("next dim\n");
562 match_byte_assert(0x58);
564 printf("string \"%s\": ", get_string());
565 match_byte(1) || match_byte(0);
567 else if (match_byte(5))
569 match_byte_assert(0x58);
570 printf("variable \"%s\": ", get_string());
573 match_byte_assert(3);
575 else if (match_byte(0x31))
580 match_u32_assert (0);
581 match_u32_assert (0);
583 printf ("nested %d bytes", subn);
585 printf ("; \"%s\", substitutions:", get_string());
588 int n_subst = get_u32();
591 printf (" %d", n_subst);
592 total_subs *= n_subst;
595 for (int i = 0; i < total_subs; i++)
605 match_byte_assert (0x58);
606 printf ("\"%s\" with substitutions:", get_string());
609 int n_subst = get_u32();
612 printf (" %d", n_subst);
613 total_subs *= n_subst;
616 for (int i = 0; i < total_subs; i++)
623 /* This byte is usually 0x02 but 0x00 and 0x75 (!) have also been spotted. */
626 if (!match_byte(0) && !match_byte(1))
627 match_byte_assert(2);
631 match_byte_assert(1);
641 n_categories = get_u32();
642 printf("%d nested categories\n", n_categories);
643 for (int i = 0; i < n_categories; i++)
652 printf ("%u dimensions\n", n_dims);
653 for (int i = 0; i < n_dims; i++)
665 for (int i = 0; i < 3 + n_dims; i++)
667 printf ("data intro:");
668 for (int i = 0; i < 3 + n_dims; i++)
672 fprintf (stderr,"data intro (%d dims):", n_dims);
673 for (int i = 0; i < 3+n_dims; i++)
674 fprintf (stderr," %d", get_u32());
675 fprintf(stderr,"\n");
678 printf ("%d data values, starting at %08x\n", x, pos);
679 for (int i = 0; i < x; i++)
681 printf("%08x, index %d:\n", pos, get_u32());
692 if (match_byte (0x31))
699 match_u32_assert (0);
700 int subn = get_u32 ();
701 printf ("nested %d bytes", subn);
704 else if (match_u32 (1))
706 printf("(footnote %d) ", get_u32());
707 match_byte_assert (0);
708 match_byte_assert (0);
709 int subn = get_u32 ();
710 printf ("nested %d bytes", subn);
716 printf("(special 2)");
717 match_byte_assert(0);
718 match_byte_assert(0);
720 match_byte_assert(0);
721 match_byte_assert(0);
722 int subn = get_u32 ();
723 printf ("nested %d bytes", subn);
728 match_byte_assert (0x58);
730 value = get_double ();
731 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
733 else if (match_byte (3))
736 if (match_byte (0x31))
740 match_u32_assert (1);
742 int subn = get_u32 ();
743 printf ("nested %d bytes", subn);
746 else if (match_u32 (1))
748 printf("(footnote %d) ", get_u32());
749 match_byte_assert (0);
750 match_byte_assert (0);
751 int subn = get_u32 ();
752 printf ("nested %d bytes", subn);
755 else if (match_u32 (2))
757 printf("(special 2)");
758 match_byte_assert(0);
759 match_byte_assert(0);
761 match_byte_assert(0);
762 match_byte_assert(0);
763 int subn = get_u32 ();
764 printf ("nested %d bytes", subn);
770 printf("(special 3)");
771 match_byte_assert(0);
772 match_byte_assert(0);
773 match_byte_assert(1);
774 match_byte_assert(0);
775 int subn = get_u32 ();
776 printf ("nested %d bytes, ", subn);
779 printf ("nested %d bytes, ", subn);
784 match_byte_assert (0x58);
786 printf("string \"%s\"", get_string());
789 else if (match_byte (2))
795 match_byte_assert (0x58);
797 value = get_double ();
799 vallab = get_string ();
800 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
801 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
802 if (!match_byte (1) && !match_byte(2))
803 match_byte_assert (3);
805 else if (match_byte (4))
808 char *var, *vallab, *value;
810 match_byte_assert (0x58);
812 vallab = get_string ();
814 if (!match_byte(1) && !match_byte(2))
815 match_byte_assert (3);
816 value = get_string ();
817 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
818 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
820 else if (match_byte (5))
822 match_byte_assert (0x58);
823 printf ("variable \"%s\"", get_string());
825 if (!match_byte(1) && !match_byte(2))
826 match_byte_assert(3);
832 else if (match_byte(0x31))
836 printf("(footnote %d) ", get_u32());
837 match_byte_assert (0);
838 match_byte_assert (0);
839 int subn = get_u32 ();
840 printf ("nested %d bytes", subn);
845 match_u32_assert (0);
846 match_u32_assert (0);
847 int subn = get_u32 ();
848 printf ("nested %d bytes", subn);
851 char *base = get_string();
853 printf ("\"%s\"; %d variables:\n", base, x);
854 for (int i = 0; i < x; i++)
861 for (int j = 0; j <= 0; j++)
863 printf("variable %d has %d values:\n", i, y);
864 for (int j = 0; j < y; j++)
871 if (match_byte (0x31))
878 match_u32_assert (0);
879 int subn = get_u32 ();
880 printf ("nested %d bytes", subn);
883 else if (match_u32 (1))
885 printf("(footnote %d) ", get_u32());
886 match_byte_assert (0);
887 match_byte_assert (0);
888 int subn = get_u32 ();
889 printf ("nested %d bytes", subn);
895 printf("(special 2)");
896 match_byte_assert(0);
897 match_byte_assert(0);
899 match_byte_assert(0);
900 match_byte_assert(0);
901 int subn = get_u32 ();
902 printf ("nested %d bytes", subn);
907 match_byte_assert (0x58);
909 value = get_double ();
910 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
912 else if (match_byte(3))
914 char *a = get_string();
915 match_byte_assert(0x58);
916 char *b = get_string();
917 char *c = get_string();
918 for (int k = 0; k <= 1; k++)
920 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
926 else if (match_byte(5))
928 match_byte_assert (0x58);
929 printf ("variable \"%s\"", get_string());
931 if (!match_byte(1) && !match_byte(2))
932 match_byte_assert(3);
946 match_byte_assert (0x58);
947 char *base = get_string();
949 printf ("\"%s\" with %d variables:\n", base, x);
950 for (int i = 0; i < x; i++)
957 for (int j = 0; j <= 0; j++)
959 printf("variable %d has %d values:\n", i, y);
960 for (int j = 0; j < y; j++)
964 char *a = get_string();
965 match_byte_assert(0x58);
966 char *b = get_string();
967 char *c = get_string();
968 for (int k = 0; k <= 1; k++)
970 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
977 else if (match_byte (1))
982 if (match_byte (0x31))
986 printf("(footnote %d) ", get_u32());
987 match_byte_assert (0);
988 match_byte_assert (0);
989 int subn = get_u32 ();
990 printf ("nested %d bytes", subn);
995 match_byte_assert (0x58);
997 value = get_double ();
998 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1011 dump_title_value(int level)
1013 for (int i = 0; i <= level; i++)
1024 if (match_byte (0x31))
1028 printf("(footnote %d) ", get_u32());
1029 match_byte_assert (0);
1030 match_byte_assert (0);
1031 int subn = get_u32 ();
1032 printf ("nested %d bytes", subn);
1035 else if (match_u32 (2))
1037 printf("(special 2)");
1038 match_byte_assert(0);
1039 match_byte_assert(0);
1041 match_u32_assert(1);
1042 match_byte_assert(0);
1043 match_byte_assert(0);
1044 int subn = get_u32 ();
1045 printf ("nested %d bytes", subn);
1050 match_u32_assert(3);
1051 printf("(special 3)");
1052 match_byte_assert(0);
1053 match_byte_assert(0);
1054 match_byte_assert(1);
1055 match_byte_assert(0);
1056 int subn = get_u32 ();
1057 printf ("nested %d bytes, ", subn);
1060 printf ("nested %d bytes, ", subn);
1065 match_byte_assert (0x58);
1067 printf("string \"%s\"", get_string());
1078 else if (match_byte (5))
1080 if (match_byte (0x31))
1084 printf("(footnote %d) ", get_u32());
1085 match_byte_assert (0);
1086 match_byte_assert (0);
1087 int subn = get_u32 ();
1088 printf ("nested %d bytes", subn);
1093 match_byte_assert (0x58);
1094 printf ("variable \"%s\"", get_string());
1096 if (!match_byte(1) && !match_byte(2))
1097 match_byte_assert(3);
1099 else if (match_byte (2))
1101 unsigned int format;
1105 match_byte_assert (0x58);
1106 format = get_u32 ();
1107 value = get_double ();
1108 var = get_string ();
1109 vallab = get_string ();
1110 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1111 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1112 if (!match_byte (1) && !match_byte(2))
1113 match_byte_assert (3);
1122 else if (match_byte (4))
1124 unsigned int format;
1125 char *var, *vallab, *value;
1127 match_byte_assert (0x58);
1128 format = get_u32 ();
1129 vallab = get_string ();
1130 var = get_string ();
1131 if (!match_byte(1) && !match_byte(2))
1132 match_byte_assert (3);
1133 value = get_string ();
1134 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1135 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1141 else if (match_byte (1))
1143 unsigned int format;
1146 if (match_byte (0x31))
1150 printf("(footnote %d) ", get_u32());
1151 match_byte_assert (0);
1152 match_byte_assert (0);
1153 int subn = get_u32 ();
1154 printf ("nested %d bytes", subn);
1159 match_byte_assert (0x58);
1160 format = get_u32 ();
1161 value = get_double ();
1162 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1169 else if (match_byte (0x31))
1173 printf("(footnote %d) ", get_u32());
1174 match_byte_assert (0);
1175 match_byte_assert (0);
1176 int subn = get_u32 ();
1177 printf ("nested %d bytes", subn);
1180 else if (match_u32 (0))
1182 match_u32_assert (0);
1183 int subn = get_u32 ();
1184 printf ("nested %d bytes", subn);
1189 match_u32_assert(3);
1190 printf("(special 3)");
1191 match_byte_assert(0);
1192 match_byte_assert(0);
1193 match_byte_assert(1);
1194 match_byte_assert(0);
1195 int subn = get_u32 ();
1196 printf ("nested %d bytes, ", subn);
1199 printf ("nested %d bytes, ", subn);
1203 char *base = get_string();
1205 printf ("\"%s\"; %d variables:\n", base, x);
1206 for (int i = 0; i < x; i++)
1212 match_u32_assert(0);
1213 for (int j = 0; j <= level; j++)
1215 printf("variable %d has %d values:\n", i, y);
1216 for (int j = 0; j < y; j++)
1220 char *a = get_string();
1221 match_byte_assert(0x58);
1222 char *b = get_string();
1223 char *c = get_string();
1224 for (int k = 0; k <= level + 1; k++)
1226 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1230 dump_title_value (level+1);
1237 match_byte_assert (0x58);
1238 char *base = get_string();
1240 printf ("\"%s\" with %d variables:\n", base, x);
1241 for (int i = 0; i < x; i++)
1247 match_u32_assert(0);
1248 for (int j = 0; j <= level; j++)
1250 printf("variable %d has %d values:\n", i, y);
1251 for (int j = 0; j < y; j++)
1256 char *a = get_string();
1257 match_byte_assert(0x58);
1258 char *b = get_string();
1259 char *c = get_string();
1260 for (int k = 0; k <= level + 1; k++)
1262 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1265 dump_title_value (level+1);
1273 dump_footnote_value(int level)
1275 for (int i = 0; i <= level; i++)
1285 if (match_byte (0x31))
1289 printf("(footnote %d) ", get_u32());
1290 match_byte_assert (0);
1291 match_byte_assert (0);
1292 int subn = get_u32 ();
1293 printf ("nested %d bytes", subn);
1296 else if (match_u32 (2))
1298 printf("(special 2)");
1299 match_byte_assert(0);
1300 match_byte_assert(0);
1301 match_u32_assert(1);
1302 match_byte_assert(0);
1303 match_byte_assert(0);
1304 int subn = get_u32 ();
1305 printf ("nested %d bytes", subn);
1310 match_u32_assert(3);
1311 printf("(special 3)");
1312 match_byte_assert(0);
1313 match_byte_assert(0);
1314 match_byte_assert(1);
1315 match_byte_assert(0);
1316 int subn = get_u32 ();
1317 printf ("nested %d bytes, ", subn);
1320 printf ("nested %d bytes, ", subn);
1325 match_byte_assert (0x58);
1327 printf("string \"%s\"", get_string());
1328 if (!match_byte (0))
1329 match_byte_assert (1);
1331 else if (match_byte (5))
1333 match_byte_assert (0x58);
1334 printf ("variable \"%s\"", get_string());
1336 if (!match_byte(1) && !match_byte(2))
1337 match_byte_assert(3);
1339 else if (match_byte (2))
1341 unsigned int format;
1345 match_byte_assert (0x58);
1346 format = get_u32 ();
1347 value = get_double ();
1348 var = get_string ();
1349 vallab = get_string ();
1350 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1351 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1352 if (!match_byte (1) && !match_byte(2))
1353 match_byte_assert (3);
1362 else if (match_byte (4))
1364 unsigned int format;
1365 char *var, *vallab, *value;
1367 match_byte_assert (0x58);
1368 format = get_u32 ();
1369 vallab = get_string ();
1370 var = get_string ();
1371 if (!match_byte(1) && !match_byte(2))
1372 match_byte_assert (3);
1373 value = get_string ();
1374 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1375 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1381 else if (match_byte (1))
1383 unsigned int format;
1386 if (match_byte (0x31))
1390 printf("(footnote %d) ", get_u32());
1391 match_byte_assert (0);
1392 match_byte_assert (0);
1393 int subn = get_u32 ();
1394 printf ("nested %d bytes", subn);
1399 match_byte_assert (0x58);
1400 format = get_u32 ();
1401 value = get_double ();
1402 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1404 else if (match_byte (0x31))
1408 printf("(footnote %d) ", get_u32());
1409 match_byte_assert (0);
1410 match_byte_assert (0);
1411 int subn = get_u32 ();
1412 printf ("nested %d bytes", subn);
1417 match_u32_assert (0);
1418 match_u32_assert (0);
1419 int subn = get_u32 ();
1420 printf ("nested %d bytes", subn);
1423 char *base = get_string();
1425 printf ("\"%s\"; %d variables:\n", base, x);
1426 for (int i = 0; i < x; i++)
1432 match_u32_assert(0);
1433 for (int j = 0; j <= level; j++)
1435 printf("variable %d has %d values:\n", i, y);
1436 for (int j = 0; j < y; j++)
1440 char *a = get_string();
1441 match_byte_assert(0x58);
1442 char *b = get_string();
1443 char *c = get_string();
1444 for (int k = 0; k <= level + 1; k++)
1446 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1448 match_byte_assert(0);
1451 dump_footnote_value (level+1);
1459 match_byte_assert (0x58);
1460 char *base = get_string();
1462 printf ("\"%s\" with %d variables:\n", base, x);
1463 for (int i = 0; i < x; i++)
1469 match_u32_assert(0);
1470 for (int j = 0; j <= level; j++)
1472 printf("variable %d has %d values:\n", i, y);
1473 for (int j = 0; j < y; j++)
1477 char *a = get_string();
1478 match_byte_assert(0x58);
1479 char *b = get_string();
1480 char *c = get_string();
1481 for (int k = 0; k <= level + 1; k++)
1483 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1484 match_byte_assert(0);
1487 dump_footnote_value (level+1);
1498 dump_title_value(0); putchar('\n');
1499 dump_title_value(0); putchar('\n');
1500 match_byte_assert(0x31);
1501 dump_title_value(0); putchar('\n');
1503 match_byte_assert(0x58);
1504 if (match_byte(0x31))
1506 dump_footnote_value(0); putchar('\n');
1509 match_byte_assert(0x58);
1512 int n_footnotes = get_u32();
1513 if (n_footnotes >= 20)
1515 fprintf(stderr, "%08x: %d footnotes\n", pos - 4, n_footnotes);
1519 printf("------\n%d footnotes\n", n_footnotes);
1520 if (n_footnotes < 20)
1522 for (int i = 0; i < n_footnotes; i++)
1524 printf("footnote %d:\n", i);
1525 dump_footnote_value(0);
1532 unsigned int format;
1535 if (match_byte (0x31))
1539 printf("(footnote %d) ", get_u32());
1540 match_byte_assert (0);
1541 match_byte_assert (0);
1542 int subn = get_u32 ();
1543 printf ("nested %d bytes", subn);
1548 match_byte_assert (0x58);
1549 format = get_u32 ();
1550 value = get_double ();
1551 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1558 else if (match_byte (0x31))
1560 match_byte_assert(3);
1562 match_byte_assert(0x58);
1563 match_u32_assert(0);
1568 match_byte_assert (0x58);
1569 printf("(%d)\n", get_u32());
1575 find_dimensions(void)
1578 const char dimensions[] = "-,,,.\0";
1579 int x = try_find_tail(dimensions, sizeof dimensions - 1);
1584 const char dimensions[] = "-,,, .\0";
1585 return find_tail(dimensions, sizeof dimensions - 1);
1591 printf("fonts: offset=%08x\n", pos);
1593 for (int i = 1; i <= 8; i++)
1595 printf("%08x: font %d, ", pos, i);
1596 match_byte_assert(i);
1597 match_byte_assert(0x31);
1598 printf("%s, ", get_string());
1599 match_byte_assert(0);
1600 match_byte_assert(0);
1601 if (!match_byte(0x40) && !match_byte(0x20) && !match_byte(0x80) && !match_byte(0x10))
1602 match_byte_assert(0x50);
1603 if (!match_byte(0x41))
1604 match_byte_assert(0x51);
1606 printf ("%s, ", get_string());
1607 printf ("%s, ", get_string());
1608 match_u32_assert(0);
1609 match_u32_assert(0);
1618 match_u32_assert(240);
1621 match_u32_assert(18);
1628 match_u32_assert(142);
1632 int count = get_u32();
1635 char *encoding = get_string();
1636 printf("encoding=%s\n", encoding);
1639 match_u32_assert(UINT32_MAX);
1641 match_byte_assert(1);
1642 match_byte_assert(0);
1644 match_byte_assert(1);
1645 if (!match_byte(0x99) && !match_byte(0x98))
1646 match_byte_assert(0x97);
1647 match_byte_assert(7);
1648 match_byte_assert(0);
1649 match_byte_assert(0);
1650 if (match_byte('.'))
1651 match_byte_assert(',');
1654 match_byte_assert(',');
1655 if (!match_byte('.'))
1656 match_byte_assert(' ');
1658 match_u32_assert(5);
1659 for (int i = 0; i < 5; i++)
1662 if (pos != find_dimensions())
1663 fprintf (stderr, "%08x / %08x\n", pos, find_dimensions());
1667 main(int argc, char *argv[])
1672 if (isatty(STDIN_FILENO))
1674 fprintf(stderr, "redirect stdin from a .bin file\n");
1677 if (fstat(STDIN_FILENO, &s))
1689 if (read(STDIN_FILENO, data, n) != n)
1697 if (!strcmp(argv[1], "title0"))
1700 if (match_byte (0x03)
1701 || (match_byte (0x05) && match_byte (0x58)))
1702 printf ("%s\n", get_string());
1704 printf ("<unknown>\n");
1707 else if (!strcmp(argv[1], "title"))
1712 else if (!strcmp(argv[1], "titleraw"))
1714 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1716 n = find(fonts, sizeof fonts - 1);
1718 else if (!strcmp(argv[1], "fonts"))
1720 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1721 const char styles[] = "\xf0\0\0\0";
1722 start = find(fonts, sizeof fonts - 1);
1723 n = find(styles, sizeof styles - 1);
1725 else if (!strcmp(argv[1], "styles"))
1727 const char styles[] = "\xf0\0\0\0";
1728 const char dimensions[] = "-,,,.\0";
1729 start = find(styles, sizeof styles - 1);
1730 n = find(dimensions, sizeof dimensions - 1) + sizeof dimensions - 1;
1732 else if (!strcmp(argv[1], "dimensions") || !strcmp(argv[1], "all"))
1735 match_byte_assert(1);
1736 match_byte_assert(0);
1737 match_u32_assert(3);
1738 match_byte_assert(1);
1740 match_byte_assert(1);
1741 match_byte_assert(0);
1742 match_byte_assert(0);
1744 match_byte_assert(1);
1746 match_byte_assert(0);
1747 match_byte_assert(0);
1748 match_byte_assert(0);
1752 printf("\n\ndata:\n");
1755 match_byte_assert (1);
1758 fprintf (stderr, "%x / %x\n", pos, n);
1765 fprintf (stderr, "unknown section %s\n", argv[1]);
1772 for (size_t i = start; i < n; )
1779 && i + 4 + data[i] + data[i + 1] * 256 <= n
1780 && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
1782 fputs("\n\"", stdout);
1783 fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stdout);
1784 fputs("\" ", stdout);
1786 i += 4 + data[i] + data[i + 1] * 256;
1788 else if (i + 12 <= n
1789 && data[i + 1] == 40
1791 && data[i + 3] == 0)
1795 memcpy (&d, &data[i + 4], 8);
1796 printf ("F40.%d(%.*f)\n", data[i], data[i], d);
1799 else if (i + 12 <= n
1800 && data[i + 1] == 40
1801 && data[i + 2] == 31
1802 && data[i + 3] == 0)
1806 memcpy (&d, &data[i + 4], 8);
1807 printf ("PCT40.%d(%.*f)\n", data[i], data[i], d);
1811 && (data[i] && data[i] != 88 && data[i] != 0x41)
1816 printf ("i%d ", data[i]);
1821 printf("%02x ", data[i]);