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++)
661 dump_data_value_31(void)
663 if (match_byte (0x31))
670 match_u32_assert (0);
671 int subn = get_u32 ();
672 printf ("nested %d bytes", subn);
675 else if (match_u32 (1))
677 printf("(footnote %d) ", get_u32());
678 match_byte_assert (0);
679 match_byte_assert (0);
680 int subn = get_u32 ();
681 printf ("nested %d bytes", subn);
684 else if (match_u32 (2))
686 printf("(special 2)");
687 match_byte_assert(0);
688 match_byte_assert(0);
690 match_byte_assert(0);
691 match_byte_assert(0);
692 int subn = get_u32 ();
693 printf ("nested %d bytes", subn);
699 printf("(special 3)");
700 match_byte_assert(0);
701 match_byte_assert(0);
702 match_byte_assert(1);
703 match_byte_assert(0);
704 int subn = get_u32 ();
705 printf ("nested %d bytes, ", subn);
708 printf ("nested %d bytes, ", subn);
713 match_byte_assert (0x58);
721 for (int i = 0; i < 3 + n_dims; i++)
723 printf ("data intro:");
724 for (int i = 0; i < 3 + n_dims; i++)
728 fprintf (stderr,"data intro (%d dims):", n_dims);
729 for (int i = 0; i < 3+n_dims; i++)
730 fprintf (stderr," %d", get_u32());
731 fprintf(stderr,"\n");
734 printf ("%d data values, starting at %08x\n", x, pos);
735 for (int i = 0; i < x; i++)
737 printf("%08x, index %d:\n", pos, get_u32());
748 dump_data_value_31();
750 value = get_double ();
751 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
753 else if (match_byte (3))
756 dump_data_value_31();
758 printf("string \"%s\"", get_string());
761 else if (match_byte (2))
767 match_byte_assert (0x58);
769 value = get_double ();
771 vallab = get_string ();
772 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
773 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
774 if (!match_byte (1) && !match_byte(2))
775 match_byte_assert (3);
777 else if (match_byte (4))
780 char *var, *vallab, *value;
782 match_byte_assert (0x58);
784 vallab = get_string ();
786 if (!match_byte(1) && !match_byte(2))
787 match_byte_assert (3);
788 value = get_string ();
789 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
790 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
792 else if (match_byte (5))
794 match_byte_assert (0x58);
795 printf ("variable \"%s\"", get_string());
797 if (!match_byte(1) && !match_byte(2))
798 match_byte_assert(3);
804 else if (match_byte(0x31))
808 printf("(footnote %d) ", get_u32());
809 match_byte_assert (0);
810 match_byte_assert (0);
811 int subn = get_u32 ();
812 printf ("nested %d bytes", subn);
817 match_u32_assert (0);
818 match_u32_assert (0);
819 int subn = get_u32 ();
820 printf ("nested %d bytes", subn);
823 char *base = get_string();
825 printf ("\"%s\"; %d variables:\n", base, x);
826 for (int i = 0; i < x; i++)
833 for (int j = 0; j <= 0; j++)
835 printf("variable %d has %d values:\n", i, y);
836 for (int j = 0; j < y; j++)
843 if (match_byte (0x31))
850 match_u32_assert (0);
851 int subn = get_u32 ();
852 printf ("nested %d bytes", subn);
855 else if (match_u32 (1))
857 printf("(footnote %d) ", get_u32());
858 match_byte_assert (0);
859 match_byte_assert (0);
860 int subn = get_u32 ();
861 printf ("nested %d bytes", subn);
867 printf("(special 2)");
868 match_byte_assert(0);
869 match_byte_assert(0);
871 match_byte_assert(0);
872 match_byte_assert(0);
873 int subn = get_u32 ();
874 printf ("nested %d bytes", subn);
879 match_byte_assert (0x58);
881 value = get_double ();
882 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
884 else if (match_byte(3))
886 char *a = get_string();
887 match_byte_assert(0x58);
888 char *b = get_string();
889 char *c = get_string();
890 for (int k = 0; k <= 1; k++)
892 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
898 else if (match_byte(5))
900 match_byte_assert (0x58);
901 printf ("variable \"%s\"", get_string());
903 if (!match_byte(1) && !match_byte(2))
904 match_byte_assert(3);
918 match_byte_assert (0x58);
919 char *base = get_string();
921 printf ("\"%s\" with %d variables:\n", base, x);
922 for (int i = 0; i < x; i++)
929 for (int j = 0; j <= 0; j++)
931 printf("variable %d has %d values:\n", i, y);
932 for (int j = 0; j < y; j++)
936 char *a = get_string();
937 match_byte_assert(0x58);
938 char *b = get_string();
939 char *c = get_string();
940 for (int k = 0; k <= 1; k++)
942 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
949 else if (match_byte (1))
954 if (match_byte (0x31))
958 printf("(footnote %d) ", get_u32());
959 match_byte_assert (0);
960 match_byte_assert (0);
961 int subn = get_u32 ();
962 printf ("nested %d bytes", subn);
967 match_byte_assert (0x58);
969 value = get_double ();
970 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
983 dump_title_value_31(int level)
985 if (match_byte (0x31))
989 match_u32_assert (0);
990 int subn = get_u32 ();
991 printf ("nested %d bytes", subn);
994 else if (match_u32 (1))
996 printf("(footnote %d) ", get_u32());
997 match_byte_assert (0);
998 match_byte_assert (0);
999 int subn = get_u32 ();
1000 printf ("nested %d bytes", subn);
1003 else if (match_u32 (2))
1005 printf("(special 2)");
1006 match_byte_assert(0);
1007 match_byte_assert(0);
1009 match_u32_assert(1);
1010 match_byte_assert(0);
1011 match_byte_assert(0);
1012 int subn = get_u32 ();
1013 printf ("nested %d bytes", subn);
1018 match_u32_assert(3);
1019 printf("(special 3)");
1020 match_byte_assert(0);
1021 match_byte_assert(0);
1022 match_byte_assert(1);
1023 match_byte_assert(0);
1024 int subn = get_u32 ();
1025 printf ("nested %d bytes, ", subn);
1028 printf ("nested %d bytes, ", subn);
1033 match_byte_assert (0x58);
1037 dump_title_value(int level)
1039 for (int i = 0; i <= level; i++)
1050 dump_title_value_31(level);
1052 printf("string \"%s\"", get_string());
1063 else if (match_byte (5))
1065 dump_title_value_31(level);
1066 printf ("variable \"%s\"", get_string());
1068 if (!match_byte(1) && !match_byte(2))
1069 match_byte_assert(3);
1071 else if (match_byte (2))
1073 unsigned int format;
1077 match_byte_assert (0x58);
1078 format = get_u32 ();
1079 value = get_double ();
1080 var = get_string ();
1081 vallab = get_string ();
1082 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1083 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1084 if (!match_byte (1) && !match_byte(2))
1085 match_byte_assert (3);
1094 else if (match_byte (4))
1096 unsigned int format;
1097 char *var, *vallab, *value;
1099 match_byte_assert (0x58);
1100 format = get_u32 ();
1101 vallab = get_string ();
1102 var = get_string ();
1103 if (!match_byte(1) && !match_byte(2))
1104 match_byte_assert (3);
1105 value = get_string ();
1106 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1107 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1113 else if (match_byte (1))
1115 unsigned int format;
1118 dump_title_value_31(level);
1119 format = get_u32 ();
1120 value = get_double ();
1121 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1130 dump_title_value_31(level);
1132 char *base = get_string();
1134 printf ("\"%s\" with %d variables:\n", base, x);
1135 for (int i = 0; i < x; i++)
1141 match_u32_assert(0);
1142 for (int j = 0; j <= level; j++)
1144 printf("variable %d has %d values:\n", i, y);
1145 for (int j = 0; j < y; j++)
1150 char *a = get_string();
1151 match_byte_assert(0x58);
1152 char *b = get_string();
1153 char *c = get_string();
1154 for (int k = 0; k <= level + 1; k++)
1156 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1159 dump_title_value (level+1);
1167 dump_footnote_value(int level)
1169 for (int i = 0; i <= level; i++)
1179 if (match_byte (0x31))
1183 printf("(footnote %d) ", get_u32());
1184 match_byte_assert (0);
1185 match_byte_assert (0);
1186 int subn = get_u32 ();
1187 printf ("nested %d bytes", subn);
1190 else if (match_u32 (2))
1192 printf("(special 2)");
1193 match_byte_assert(0);
1194 match_byte_assert(0);
1195 match_u32_assert(1);
1196 match_byte_assert(0);
1197 match_byte_assert(0);
1198 int subn = get_u32 ();
1199 printf ("nested %d bytes", subn);
1204 match_u32_assert(3);
1205 printf("(special 3)");
1206 match_byte_assert(0);
1207 match_byte_assert(0);
1208 match_byte_assert(1);
1209 match_byte_assert(0);
1210 int subn = get_u32 ();
1211 printf ("nested %d bytes, ", subn);
1214 printf ("nested %d bytes, ", subn);
1219 match_byte_assert (0x58);
1221 printf("string \"%s\"", get_string());
1222 if (!match_byte (0))
1223 match_byte_assert (1);
1225 else if (match_byte (5))
1227 match_byte_assert (0x58);
1228 printf ("variable \"%s\"", get_string());
1230 if (!match_byte(1) && !match_byte(2))
1231 match_byte_assert(3);
1233 else if (match_byte (2))
1235 unsigned int format;
1239 match_byte_assert (0x58);
1240 format = get_u32 ();
1241 value = get_double ();
1242 var = get_string ();
1243 vallab = get_string ();
1244 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1245 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1246 if (!match_byte (1) && !match_byte(2))
1247 match_byte_assert (3);
1256 else if (match_byte (4))
1258 unsigned int format;
1259 char *var, *vallab, *value;
1261 match_byte_assert (0x58);
1262 format = get_u32 ();
1263 vallab = get_string ();
1264 var = get_string ();
1265 if (!match_byte(1) && !match_byte(2))
1266 match_byte_assert (3);
1267 value = get_string ();
1268 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1269 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1275 else if (match_byte (1))
1277 unsigned int format;
1280 if (match_byte (0x31))
1284 printf("(footnote %d) ", get_u32());
1285 match_byte_assert (0);
1286 match_byte_assert (0);
1287 int subn = get_u32 ();
1288 printf ("nested %d bytes", subn);
1293 match_byte_assert (0x58);
1294 format = get_u32 ();
1295 value = get_double ();
1296 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1298 else if (match_byte (0x31))
1302 printf("(footnote %d) ", get_u32());
1303 match_byte_assert (0);
1304 match_byte_assert (0);
1305 int subn = get_u32 ();
1306 printf ("nested %d bytes", subn);
1311 match_u32_assert (0);
1312 match_u32_assert (0);
1313 int subn = get_u32 ();
1314 printf ("nested %d bytes", subn);
1317 char *base = get_string();
1319 printf ("\"%s\"; %d variables:\n", base, x);
1320 for (int i = 0; i < x; i++)
1326 match_u32_assert(0);
1327 for (int j = 0; j <= level; j++)
1329 printf("variable %d has %d values:\n", i, y);
1330 for (int j = 0; j < y; j++)
1334 char *a = get_string();
1335 match_byte_assert(0x58);
1336 char *b = get_string();
1337 char *c = get_string();
1338 for (int k = 0; k <= level + 1; k++)
1340 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1342 match_byte_assert(0);
1345 dump_footnote_value (level+1);
1353 match_byte_assert (0x58);
1354 char *base = get_string();
1356 printf ("\"%s\" with %d variables:\n", base, x);
1357 for (int i = 0; i < x; i++)
1363 match_u32_assert(0);
1364 for (int j = 0; j <= level; j++)
1366 printf("variable %d has %d values:\n", i, y);
1367 for (int j = 0; j < y; j++)
1371 char *a = get_string();
1372 match_byte_assert(0x58);
1373 char *b = get_string();
1374 char *c = get_string();
1375 for (int k = 0; k <= level + 1; k++)
1377 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1378 match_byte_assert(0);
1381 dump_footnote_value (level+1);
1392 dump_title_value(0); putchar('\n');
1393 dump_title_value(0); putchar('\n');
1394 match_byte_assert(0x31);
1395 dump_title_value(0); putchar('\n');
1397 match_byte_assert(0x58);
1398 if (match_byte(0x31))
1400 dump_footnote_value(0); putchar('\n');
1403 match_byte_assert(0x58);
1406 int n_footnotes = get_u32();
1407 if (n_footnotes >= 20)
1409 fprintf(stderr, "%08x: %d footnotes\n", pos - 4, n_footnotes);
1413 printf("------\n%d footnotes\n", n_footnotes);
1414 if (n_footnotes < 20)
1416 for (int i = 0; i < n_footnotes; i++)
1418 printf("footnote %d:\n", i);
1419 dump_footnote_value(0);
1426 unsigned int format;
1429 if (match_byte (0x31))
1433 printf("(footnote %d) ", get_u32());
1434 match_byte_assert (0);
1435 match_byte_assert (0);
1436 int subn = get_u32 ();
1437 printf ("nested %d bytes", subn);
1442 match_byte_assert (0x58);
1443 format = get_u32 ();
1444 value = get_double ();
1445 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1452 else if (match_byte (0x31))
1454 match_byte_assert(3);
1456 match_byte_assert(0x58);
1457 match_u32_assert(0);
1462 match_byte_assert (0x58);
1463 printf("(%d)\n", get_u32());
1469 find_dimensions(void)
1472 const char dimensions[] = "-,,,.\0";
1473 int x = try_find_tail(dimensions, sizeof dimensions - 1);
1478 const char dimensions[] = "-,,, .\0";
1479 return find_tail(dimensions, sizeof dimensions - 1);
1485 printf("fonts: offset=%08x\n", pos);
1487 for (int i = 1; i <= 8; i++)
1489 printf("%08x: font %d, ", pos, i);
1490 match_byte_assert(i);
1491 match_byte_assert(0x31);
1492 printf("%s, ", get_string());
1493 match_byte_assert(0);
1494 match_byte_assert(0);
1495 if (!match_byte(0x40) && !match_byte(0x20) && !match_byte(0x80) && !match_byte(0x10))
1496 match_byte_assert(0x50);
1497 if (!match_byte(0x41))
1498 match_byte_assert(0x51);
1500 printf ("%s, ", get_string());
1501 printf ("%s, ", get_string());
1502 match_u32_assert(0);
1503 match_u32_assert(0);
1512 match_u32_assert(240);
1515 match_u32_assert(18);
1522 match_u32_assert(142);
1526 int count = get_u32();
1529 char *encoding = get_string();
1530 printf("encoding=%s\n", encoding);
1533 match_u32_assert(UINT32_MAX);
1535 match_byte_assert(1);
1536 match_byte_assert(0);
1538 match_byte_assert(1);
1539 if (!match_byte(0x99) && !match_byte(0x98))
1540 match_byte_assert(0x97);
1541 match_byte_assert(7);
1542 match_byte_assert(0);
1543 match_byte_assert(0);
1544 if (match_byte('.'))
1545 match_byte_assert(',');
1548 match_byte_assert(',');
1549 if (!match_byte('.'))
1550 match_byte_assert(' ');
1552 match_u32_assert(5);
1553 for (int i = 0; i < 5; i++)
1556 if (pos != find_dimensions())
1557 fprintf (stderr, "%08x / %08x\n", pos, find_dimensions());
1561 main(int argc, char *argv[])
1566 if (isatty(STDIN_FILENO))
1568 fprintf(stderr, "redirect stdin from a .bin file\n");
1571 if (fstat(STDIN_FILENO, &s))
1583 if (read(STDIN_FILENO, data, n) != n)
1591 if (!strcmp(argv[1], "title0"))
1594 if (match_byte (0x03)
1595 || (match_byte (0x05) && match_byte (0x58)))
1596 printf ("%s\n", get_string());
1598 printf ("<unknown>\n");
1601 else if (!strcmp(argv[1], "title"))
1606 else if (!strcmp(argv[1], "titleraw"))
1608 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1610 n = find(fonts, sizeof fonts - 1);
1612 else if (!strcmp(argv[1], "fonts"))
1614 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1615 const char styles[] = "\xf0\0\0\0";
1616 start = find(fonts, sizeof fonts - 1);
1617 n = find(styles, sizeof styles - 1);
1619 else if (!strcmp(argv[1], "styles"))
1621 const char styles[] = "\xf0\0\0\0";
1622 const char dimensions[] = "-,,,.\0";
1623 start = find(styles, sizeof styles - 1);
1624 n = find(dimensions, sizeof dimensions - 1) + sizeof dimensions - 1;
1626 else if (!strcmp(argv[1], "dimensions") || !strcmp(argv[1], "all"))
1629 match_byte_assert(1);
1630 match_byte_assert(0);
1631 match_u32_assert(3);
1632 match_byte_assert(1);
1634 match_byte_assert(1);
1635 match_byte_assert(0);
1636 match_byte_assert(0);
1638 match_byte_assert(1);
1640 match_byte_assert(0);
1641 match_byte_assert(0);
1642 match_byte_assert(0);
1646 printf("\n\ndata:\n");
1649 match_byte_assert (1);
1652 fprintf (stderr, "%x / %x\n", pos, n);
1659 fprintf (stderr, "unknown section %s\n", argv[1]);
1666 for (size_t i = start; i < n; )
1673 && i + 4 + data[i] + data[i + 1] * 256 <= n
1674 && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
1676 fputs("\n\"", stdout);
1677 fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stdout);
1678 fputs("\" ", stdout);
1680 i += 4 + data[i] + data[i + 1] * 256;
1682 else if (i + 12 <= n
1683 && data[i + 1] == 40
1685 && data[i + 3] == 0)
1689 memcpy (&d, &data[i + 4], 8);
1690 printf ("F40.%d(%.*f)\n", data[i], data[i], d);
1693 else if (i + 12 <= n
1694 && data[i + 1] == 40
1695 && data[i + 2] == 31
1696 && data[i + 3] == 0)
1700 memcpy (&d, &data[i + 4], 8);
1701 printf ("PCT40.%d(%.*f)\n", data[i], data[i], d);
1705 && (data[i] && data[i] != 88 && data[i] != 0x41)
1710 printf ("i%d ", data[i]);
1715 printf("%02x ", data[i]);