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)
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++)
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);
205 printf("string \"%s\"", get_string());
216 else if (match_byte (5))
218 match_byte_assert (0x58);
219 printf ("variable \"%s\"", get_string());
221 if (!match_byte(1) && !match_byte(2))
222 match_byte_assert(3);
228 else if (match_byte (2))
234 match_byte_assert (0x58);
236 value = get_double ();
238 vallab = get_string ();
239 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
240 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
241 if (!match_byte (1) && !match_byte(2))
242 match_byte_assert (3);
251 else if (match_byte (4))
254 char *var, *vallab, *value;
256 match_byte_assert (0x58);
258 vallab = get_string ();
260 if (!match_byte(1) && !match_byte(2))
261 match_byte_assert (3);
262 value = get_string ();
263 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
264 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
270 else if (match_byte (1))
275 if (match_byte (0x31))
279 printf("(footnote %d) ", get_u32());
280 match_byte_assert (0);
281 match_byte_assert (0);
282 int subn = get_u32 ();
283 printf ("nested %d bytes", subn);
288 match_byte_assert (0x58);
290 value = get_double ();
291 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
298 else if (match_byte (0x31))
302 printf("(footnote %d) ", get_u32());
303 match_byte_assert (0);
304 match_byte_assert (0);
305 int subn = get_u32 ();
306 printf ("nested %d bytes", subn);
311 match_u32_assert (0);
312 match_u32_assert (0);
313 int subn = get_u32 ();
314 printf ("nested %d bytes", subn);
317 char *base = get_string();
319 printf ("\"%s\"; %d variables:\n", base, x);
322 for (int i = 0; i < x; i++)
324 dump_value (level+1);
330 for (int i = 0; i < x; i++)
334 for (int j = 0; j <= level; j++)
336 printf("variable %d has %d values:\n", i, y);
337 for (int j = 0; j < y; j++)
341 char *a = get_string();
342 match_byte_assert(0x58);
343 char *b = get_string();
344 char *c = get_string();
345 for (int k = 0; k <= level + 1; k++)
347 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
355 dump_value (level+1);
364 match_byte_assert (0x58);
365 char *base = get_string();
367 printf ("\"%s\" with %d variables:\n", base, x);
370 for (int i = 0; i < x; i++)
372 dump_value (level+1);
378 for (int i = 0; i < x; i++)
382 for (int j = 0; j <= level; j++)
384 printf("variable %d has %d values:\n", i, y);
385 for (int j = 0; j < y; j++)
389 char *a = get_string();
390 match_byte_assert(0x58);
391 char *b = get_string();
392 char *c = get_string();
393 for (int k = 0; k <= level + 1; k++)
395 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
403 dump_value (level+1);
412 dump_dim_value(int level)
414 for (int i = 0; i <= level; i++)
420 if (match_byte (0x31))
423 printf("(footnote %d) ", get_u32());
424 match_byte_assert (0);
425 match_byte_assert (0);
426 int subn = get_u32 ();
427 printf ("nested %d bytes", subn);
431 match_byte_assert (0x58);
433 printf("string \"%s\"", get_string());
435 match_byte_assert (1);
441 else if (match_byte (5))
443 match_byte_assert (0x58);
444 printf ("variable \"%s\"", get_string());
446 match_byte_assert (2);
448 else if (match_byte (2))
454 match_byte_assert (0x58);
456 value = get_double ();
458 vallab = get_string ();
459 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
460 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
462 match_u32_assert (2);
465 else if (match_byte (1))
470 match_byte_assert (0x58);
472 value = get_double ();
473 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
485 match_byte_assert (0x31);
486 match_u32_assert (0);
487 match_u32_assert (0);
489 printf ("nested %d bytes", subn);
491 printf ("; \"%s\", substitutions:", get_string());
492 int total_subs = get_u32();
496 total_subs = (total_subs - 1) + x;
497 match_u32_assert (0);
499 printf (" (total %d)", total_subs);
501 for (int i = 0; i < total_subs; i++)
504 dump_value (level + 1);
510 dump_category(int level)
520 else if (match_u32 (1))
527 else if (match_byte (1))
531 match_u32_assert (1);
537 match_u32_assert (0);
541 int n_categories = get_u32();
542 if (n_categories > 0)
543 printf (", %d subcategories:", n_categories);
545 for (int i = 0; i < n_categories; i++)
546 dump_category (level + 1);
553 printf("next dim\n");
558 match_byte_assert(0x58);
560 printf("string \"%s\": ", get_string());
561 match_byte(1) || match_byte(0);
563 else if (match_byte(5))
565 match_byte_assert(0x58);
566 printf("variable \"%s\": ", get_string());
569 match_byte_assert(3);
571 else if (match_byte(0x31))
576 match_u32_assert (0);
577 match_u32_assert (0);
579 printf ("nested %d bytes", subn);
581 printf ("; \"%s\", substitutions:", get_string());
584 int n_subst = get_u32();
587 printf (" %d", n_subst);
588 total_subs *= n_subst;
591 for (int i = 0; i < total_subs; i++)
601 match_byte_assert (0x58);
602 printf ("\"%s\" with substitutions:", get_string());
605 int n_subst = get_u32();
608 printf (" %d", n_subst);
609 total_subs *= n_subst;
612 for (int i = 0; i < total_subs; i++)
619 /* This byte is usually 0x02 but 0x00 and 0x75 (!) have also been spotted. */
622 if (!match_byte(0) && !match_byte(1))
623 match_byte_assert(2);
627 match_byte_assert(1);
637 n_categories = get_u32();
638 printf("%d nested categories\n", n_categories);
639 for (int i = 0; i < n_categories; i++)
648 printf ("%u dimensions\n", n_dims);
649 for (int i = 0; i < n_dims; i++)
661 for (int i = 0; i < 3 + n_dims; i++)
663 printf ("data intro:");
664 for (int i = 0; i < 3 + n_dims; i++)
668 fprintf (stderr,"data intro (%d dims):", n_dims);
669 for (int i = 0; i < 3+n_dims; i++)
670 fprintf (stderr," %d", get_u32());
671 fprintf(stderr,"\n");
674 printf ("%d data values, starting at %08x\n", x, pos);
675 for (int i = 0; i < x; i++)
677 printf("%08x, index %d:\n", pos, get_u32());
688 if (match_byte (0x31))
695 match_u32_assert (0);
696 int subn = get_u32 ();
697 printf ("nested %d bytes", subn);
700 else if (match_u32 (1))
702 printf("(footnote %d) ", get_u32());
703 match_byte_assert (0);
704 match_byte_assert (0);
705 int subn = get_u32 ();
706 printf ("nested %d bytes", subn);
712 printf("(special 2)");
713 match_byte_assert(0);
714 match_byte_assert(0);
716 match_byte_assert(0);
717 match_byte_assert(0);
718 int subn = get_u32 ();
719 printf ("nested %d bytes", subn);
724 match_byte_assert (0x58);
726 value = get_double ();
727 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
729 else if (match_byte (3))
732 if (match_byte (0x31))
736 match_u32_assert (1);
738 int subn = get_u32 ();
739 printf ("nested %d bytes", subn);
742 else if (match_u32 (1))
744 printf("(footnote %d) ", get_u32());
745 match_byte_assert (0);
746 match_byte_assert (0);
747 int subn = get_u32 ();
748 printf ("nested %d bytes", subn);
751 else if (match_u32 (2))
753 printf("(special 2)");
754 match_byte_assert(0);
755 match_byte_assert(0);
757 match_byte_assert(0);
758 match_byte_assert(0);
759 int subn = get_u32 ();
760 printf ("nested %d bytes", subn);
766 printf("(special 3)");
767 match_byte_assert(0);
768 match_byte_assert(0);
769 match_byte_assert(1);
770 match_byte_assert(0);
771 int subn = get_u32 ();
772 printf ("nested %d bytes, ", subn);
775 printf ("nested %d bytes, ", subn);
780 match_byte_assert (0x58);
782 printf("string \"%s\"", get_string());
785 else if (match_byte (2))
791 match_byte_assert (0x58);
793 value = get_double ();
795 vallab = get_string ();
796 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
797 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
798 if (!match_byte (1) && !match_byte(2))
799 match_byte_assert (3);
801 else if (match_byte (4))
804 char *var, *vallab, *value;
806 match_byte_assert (0x58);
808 vallab = get_string ();
810 if (!match_byte(1) && !match_byte(2))
811 match_byte_assert (3);
812 value = get_string ();
813 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
814 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
816 else if (match_byte (5))
818 match_byte_assert (0x58);
819 printf ("variable \"%s\"", get_string());
821 if (!match_byte(1) && !match_byte(2))
822 match_byte_assert(3);
828 else if (match_byte(0x31))
832 printf("(footnote %d) ", get_u32());
833 match_byte_assert (0);
834 match_byte_assert (0);
835 int subn = get_u32 ();
836 printf ("nested %d bytes", subn);
841 match_u32_assert (0);
842 match_u32_assert (0);
843 int subn = get_u32 ();
844 printf ("nested %d bytes", subn);
847 char *base = get_string();
849 printf ("\"%s\"; %d variables:\n", base, x);
850 for (int i = 0; i < x; i++)
857 for (int j = 0; j <= 0; j++)
859 printf("variable %d has %d values:\n", i, y);
860 for (int j = 0; j < y; j++)
867 if (match_byte (0x31))
874 match_u32_assert (0);
875 int subn = get_u32 ();
876 printf ("nested %d bytes", subn);
879 else if (match_u32 (1))
881 printf("(footnote %d) ", get_u32());
882 match_byte_assert (0);
883 match_byte_assert (0);
884 int subn = get_u32 ();
885 printf ("nested %d bytes", subn);
891 printf("(special 2)");
892 match_byte_assert(0);
893 match_byte_assert(0);
895 match_byte_assert(0);
896 match_byte_assert(0);
897 int subn = get_u32 ();
898 printf ("nested %d bytes", subn);
903 match_byte_assert (0x58);
905 value = get_double ();
906 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
908 else if (match_byte(3))
910 char *a = get_string();
911 match_byte_assert(0x58);
912 char *b = get_string();
913 char *c = get_string();
914 for (int k = 0; k <= 1; k++)
916 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
922 else if (match_byte(5))
924 match_byte_assert (0x58);
925 printf ("variable \"%s\"", get_string());
927 if (!match_byte(1) && !match_byte(2))
928 match_byte_assert(3);
942 match_byte_assert (0x58);
943 char *base = get_string();
945 printf ("\"%s\" with %d variables:\n", base, x);
946 for (int i = 0; i < x; i++)
953 for (int j = 0; j <= 0; j++)
955 printf("variable %d has %d values:\n", i, y);
956 for (int j = 0; j < y; j++)
960 char *a = get_string();
961 match_byte_assert(0x58);
962 char *b = get_string();
963 char *c = get_string();
964 for (int k = 0; k <= 1; k++)
966 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
973 else if (match_byte (1))
978 if (match_byte (0x31))
982 printf("(footnote %d) ", get_u32());
983 match_byte_assert (0);
984 match_byte_assert (0);
985 int subn = get_u32 ();
986 printf ("nested %d bytes", subn);
991 match_byte_assert (0x58);
993 value = get_double ();
994 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1007 dump_title_value(int level)
1009 for (int i = 0; i <= level; i++)
1020 if (match_byte (0x31))
1024 printf("(footnote %d) ", get_u32());
1025 match_byte_assert (0);
1026 match_byte_assert (0);
1027 int subn = get_u32 ();
1028 printf ("nested %d bytes", subn);
1031 else if (match_u32 (2))
1033 printf("(special 2)");
1034 match_byte_assert(0);
1035 match_byte_assert(0);
1037 match_u32_assert(1);
1038 match_byte_assert(0);
1039 match_byte_assert(0);
1040 int subn = get_u32 ();
1041 printf ("nested %d bytes", subn);
1046 match_u32_assert(3);
1047 printf("(special 3)");
1048 match_byte_assert(0);
1049 match_byte_assert(0);
1050 match_byte_assert(1);
1051 match_byte_assert(0);
1052 int subn = get_u32 ();
1053 printf ("nested %d bytes, ", subn);
1056 printf ("nested %d bytes, ", subn);
1061 match_byte_assert (0x58);
1063 printf("string \"%s\"", get_string());
1074 else if (match_byte (5))
1076 if (match_byte (0x31))
1080 printf("(footnote %d) ", get_u32());
1081 match_byte_assert (0);
1082 match_byte_assert (0);
1083 int subn = get_u32 ();
1084 printf ("nested %d bytes", subn);
1089 match_byte_assert (0x58);
1090 printf ("variable \"%s\"", get_string());
1092 if (!match_byte(1) && !match_byte(2))
1093 match_byte_assert(3);
1095 else if (match_byte (2))
1097 unsigned int format;
1101 match_byte_assert (0x58);
1102 format = get_u32 ();
1103 value = get_double ();
1104 var = get_string ();
1105 vallab = get_string ();
1106 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1107 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1108 if (!match_byte (1) && !match_byte(2))
1109 match_byte_assert (3);
1118 else if (match_byte (4))
1120 unsigned int format;
1121 char *var, *vallab, *value;
1123 match_byte_assert (0x58);
1124 format = get_u32 ();
1125 vallab = get_string ();
1126 var = get_string ();
1127 if (!match_byte(1) && !match_byte(2))
1128 match_byte_assert (3);
1129 value = get_string ();
1130 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1131 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1137 else if (match_byte (1))
1139 unsigned int format;
1142 if (match_byte (0x31))
1146 printf("(footnote %d) ", get_u32());
1147 match_byte_assert (0);
1148 match_byte_assert (0);
1149 int subn = get_u32 ();
1150 printf ("nested %d bytes", subn);
1155 match_byte_assert (0x58);
1156 format = get_u32 ();
1157 value = get_double ();
1158 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1165 else if (match_byte (0x31))
1169 printf("(footnote %d) ", get_u32());
1170 match_byte_assert (0);
1171 match_byte_assert (0);
1172 int subn = get_u32 ();
1173 printf ("nested %d bytes", subn);
1176 else if (match_u32 (0))
1178 match_u32_assert (0);
1179 int subn = get_u32 ();
1180 printf ("nested %d bytes", subn);
1185 match_u32_assert(3);
1186 printf("(special 3)");
1187 match_byte_assert(0);
1188 match_byte_assert(0);
1189 match_byte_assert(1);
1190 match_byte_assert(0);
1191 int subn = get_u32 ();
1192 printf ("nested %d bytes, ", subn);
1195 printf ("nested %d bytes, ", subn);
1199 char *base = get_string();
1201 printf ("\"%s\"; %d variables:\n", base, x);
1202 for (int i = 0; i < x; i++)
1208 match_u32_assert(0);
1209 for (int j = 0; j <= level; j++)
1211 printf("variable %d has %d values:\n", i, y);
1212 for (int j = 0; j < y; j++)
1216 char *a = get_string();
1217 match_byte_assert(0x58);
1218 char *b = get_string();
1219 char *c = get_string();
1220 for (int k = 0; k <= level + 1; k++)
1222 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1226 dump_title_value (level+1);
1233 match_byte_assert (0x58);
1234 char *base = get_string();
1236 printf ("\"%s\" with %d variables:\n", base, x);
1237 for (int i = 0; i < x; i++)
1243 match_u32_assert(0);
1244 for (int j = 0; j <= level; j++)
1246 printf("variable %d has %d values:\n", i, y);
1247 for (int j = 0; j < y; j++)
1252 char *a = get_string();
1253 match_byte_assert(0x58);
1254 char *b = get_string();
1255 char *c = get_string();
1256 for (int k = 0; k <= level + 1; k++)
1258 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1261 dump_title_value (level+1);
1269 dump_footnote_value(int level)
1271 for (int i = 0; i <= level; i++)
1281 if (match_byte (0x31))
1285 printf("(footnote %d) ", get_u32());
1286 match_byte_assert (0);
1287 match_byte_assert (0);
1288 int subn = get_u32 ();
1289 printf ("nested %d bytes", subn);
1292 else if (match_u32 (2))
1294 printf("(special 2)");
1295 match_byte_assert(0);
1296 match_byte_assert(0);
1297 match_u32_assert(1);
1298 match_byte_assert(0);
1299 match_byte_assert(0);
1300 int subn = get_u32 ();
1301 printf ("nested %d bytes", subn);
1306 match_u32_assert(3);
1307 printf("(special 3)");
1308 match_byte_assert(0);
1309 match_byte_assert(0);
1310 match_byte_assert(1);
1311 match_byte_assert(0);
1312 int subn = get_u32 ();
1313 printf ("nested %d bytes, ", subn);
1316 printf ("nested %d bytes, ", subn);
1321 match_byte_assert (0x58);
1323 printf("string \"%s\"", get_string());
1324 if (!match_byte (0))
1325 match_byte_assert (1);
1327 else if (match_byte (5))
1329 match_byte_assert (0x58);
1330 printf ("variable \"%s\"", get_string());
1332 if (!match_byte(1) && !match_byte(2))
1333 match_byte_assert(3);
1335 else if (match_byte (2))
1337 unsigned int format;
1341 match_byte_assert (0x58);
1342 format = get_u32 ();
1343 value = get_double ();
1344 var = get_string ();
1345 vallab = get_string ();
1346 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1347 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1348 if (!match_byte (1) && !match_byte(2))
1349 match_byte_assert (3);
1358 else if (match_byte (4))
1360 unsigned int format;
1361 char *var, *vallab, *value;
1363 match_byte_assert (0x58);
1364 format = get_u32 ();
1365 vallab = get_string ();
1366 var = get_string ();
1367 if (!match_byte(1) && !match_byte(2))
1368 match_byte_assert (3);
1369 value = get_string ();
1370 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1371 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1377 else if (match_byte (1))
1379 unsigned int format;
1382 if (match_byte (0x31))
1386 printf("(footnote %d) ", get_u32());
1387 match_byte_assert (0);
1388 match_byte_assert (0);
1389 int subn = get_u32 ();
1390 printf ("nested %d bytes", subn);
1395 match_byte_assert (0x58);
1396 format = get_u32 ();
1397 value = get_double ();
1398 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1400 else if (match_byte (0x31))
1404 printf("(footnote %d) ", get_u32());
1405 match_byte_assert (0);
1406 match_byte_assert (0);
1407 int subn = get_u32 ();
1408 printf ("nested %d bytes", subn);
1413 match_u32_assert (0);
1414 match_u32_assert (0);
1415 int subn = get_u32 ();
1416 printf ("nested %d bytes", subn);
1419 char *base = get_string();
1421 printf ("\"%s\"; %d variables:\n", base, x);
1422 for (int i = 0; i < x; i++)
1428 match_u32_assert(0);
1429 for (int j = 0; j <= level; j++)
1431 printf("variable %d has %d values:\n", i, y);
1432 for (int j = 0; j < y; j++)
1436 char *a = get_string();
1437 match_byte_assert(0x58);
1438 char *b = get_string();
1439 char *c = get_string();
1440 for (int k = 0; k <= level + 1; k++)
1442 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1444 match_byte_assert(0);
1447 dump_footnote_value (level+1);
1455 match_byte_assert (0x58);
1456 char *base = get_string();
1458 printf ("\"%s\" with %d variables:\n", base, x);
1459 for (int i = 0; i < x; i++)
1465 match_u32_assert(0);
1466 for (int j = 0; j <= level; j++)
1468 printf("variable %d has %d values:\n", i, y);
1469 for (int j = 0; j < y; j++)
1473 char *a = get_string();
1474 match_byte_assert(0x58);
1475 char *b = get_string();
1476 char *c = get_string();
1477 for (int k = 0; k <= level + 1; k++)
1479 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1480 match_byte_assert(0);
1483 dump_footnote_value (level+1);
1494 dump_title_value(0); putchar('\n'); putchar('\n');
1495 dump_title_value(0); putchar('\n'); putchar('\n');
1496 match_byte_assert(0x31);
1497 dump_title_value(0); putchar('\n'); putchar('\n');
1499 match_byte_assert(0x58);
1500 if (match_byte(0x31))
1502 dump_footnote_value(0); putchar('\n');
1505 match_byte_assert(0x58);
1508 int n_footnotes = get_u32();
1509 if (n_footnotes >= 20)
1511 fprintf(stderr, "%08x: %d footnotes\n", pos - 4, n_footnotes);
1515 printf("------\n%d footnotes\n", n_footnotes);
1516 if (n_footnotes < 20)
1518 for (int i = 0; i < n_footnotes; i++)
1520 printf("footnote %d:\n", i);
1521 dump_footnote_value(0);
1528 unsigned int format;
1531 if (match_byte (0x31))
1535 printf("(footnote %d) ", get_u32());
1536 match_byte_assert (0);
1537 match_byte_assert (0);
1538 int subn = get_u32 ();
1539 printf ("nested %d bytes", subn);
1544 match_byte_assert (0x58);
1545 format = get_u32 ();
1546 value = get_double ();
1547 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1554 else if (match_byte (0x31))
1556 match_byte_assert(3);
1558 match_byte_assert(0x58);
1559 match_u32_assert(0);
1564 match_byte_assert (0x58);
1565 printf("(%d)\n", get_u32());
1575 printf("fonts: offset=%08x\n", pos);
1577 for (i = 1; i <= 8; i++)
1579 printf("%08x: font %d, ", pos, i);
1580 match_byte_assert(i);
1581 match_byte_assert(0x31);
1582 printf("%s, ", get_string());
1583 match_byte_assert(0);
1584 match_byte_assert(0);
1585 if (!match_byte(0x40) && !match_byte(0x20) && !match_byte(0x80) && !match_byte(0x10))
1586 match_byte_assert(0x50);
1587 if (!match_byte(0x41))
1588 match_byte_assert(0x51);
1590 printf ("%s, ", get_string());
1591 printf ("%s, ", get_string());
1592 match_u32_assert(0);
1593 match_u32_assert(0);
1605 main(int argc, char *argv[])
1610 if (isatty(STDIN_FILENO))
1612 fprintf(stderr, "redirect stdin from a .bin file\n");
1615 if (fstat(STDIN_FILENO, &s))
1627 if (read(STDIN_FILENO, data, n) != n)
1635 if (!strcmp(argv[1], "title0"))
1638 if (match_byte (0x03)
1639 || (match_byte (0x05) && match_byte (0x58)))
1640 printf ("%s\n", get_string());
1642 printf ("<unknown>\n");
1645 else if (!strcmp(argv[1], "title"))
1650 else if (!strcmp(argv[1], "titleraw"))
1652 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1654 n = find(fonts, sizeof fonts - 1);
1656 else if (!strcmp(argv[1], "fonts"))
1658 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1659 const char styles[] = "\xf0\0\0\0";
1660 start = find(fonts, sizeof fonts - 1);
1661 n = find(styles, sizeof styles - 1);
1663 else if (!strcmp(argv[1], "styles"))
1665 const char styles[] = "\xf0\0\0\0";
1666 const char dimensions[] = "-,,,.\0";
1667 start = find(styles, sizeof styles - 1);
1668 n = find(dimensions, sizeof dimensions - 1) + sizeof dimensions - 1;
1670 else if (!strcmp(argv[1], "dimensions") || !strcmp(argv[1], "all"))
1673 const char dimensions[] = "-,,,.\0";
1674 start = try_find_tail(dimensions, sizeof dimensions - 1);
1679 const char dimensions[] = "-,,, .\0";
1680 start = find_tail(dimensions, sizeof dimensions - 1);
1687 if (!strcmp(argv[1], "all"))
1693 fprintf (stderr, "unknown section %s\n", argv[1]);
1700 for (size_t i = start; i < n; )
1707 && i + 4 + data[i] + data[i + 1] * 256 <= n
1708 && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
1710 fputs("\n\"", stdout);
1711 fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stdout);
1712 fputs("\" ", stdout);
1714 i += 4 + data[i] + data[i + 1] * 256;
1716 else if (i + 12 <= n
1717 && data[i + 1] == 40
1719 && data[i + 3] == 0)
1723 memcpy (&d, &data[i + 4], 8);
1724 printf ("F40.%d(%.*f)\n", data[i], data[i], d);
1727 else if (i + 12 <= n
1728 && data[i + 1] == 40
1729 && data[i + 2] == 31
1730 && data[i + 3] == 0)
1734 memcpy (&d, &data[i + 4], 8);
1735 printf ("PCT40.%d(%.*f)\n", data[i], data[i], d);
1739 && (data[i] && data[i] != 88 && data[i] != 0x41)
1744 printf ("i%d ", data[i]);
1749 printf("%02x ", data[i]);