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 dump_data_value_31();
845 value = get_double ();
846 printf (" value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
848 else if (match_byte(3))
850 char *a = get_string();
851 match_byte_assert(0x58);
852 char *b = get_string();
853 char *c = get_string();
854 for (int k = 0; k <= 1; k++)
856 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
862 else if (match_byte(5))
864 match_byte_assert (0x58);
865 printf ("variable \"%s\"", get_string());
867 if (!match_byte(1) && !match_byte(2))
868 match_byte_assert(3);
882 match_byte_assert (0x58);
883 char *base = get_string();
885 printf ("\"%s\" with %d variables:\n", base, x);
886 for (int i = 0; i < x; i++)
893 for (int j = 0; j <= 0; j++)
895 printf("variable %d has %d values:\n", i, y);
896 for (int j = 0; j < y; j++)
900 char *a = get_string();
901 match_byte_assert(0x58);
902 char *b = get_string();
903 char *c = get_string();
904 for (int k = 0; k <= 1; k++)
906 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
913 else if (match_byte (1))
918 dump_data_value_31();
920 value = get_double ();
921 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
934 dump_title_value_31(int level)
936 if (match_byte (0x31))
940 match_u32_assert (0);
941 int subn = get_u32 ();
942 printf ("nested %d bytes", subn);
945 else if (match_u32 (1))
947 printf("(footnote %d) ", get_u32());
948 match_byte_assert (0);
949 match_byte_assert (0);
950 int subn = get_u32 ();
951 printf ("nested %d bytes", subn);
954 else if (match_u32 (2))
956 printf("(special 2)");
957 match_byte_assert(0);
958 match_byte_assert(0);
961 match_byte_assert(0);
962 match_byte_assert(0);
963 int subn = get_u32 ();
964 printf ("nested %d bytes", subn);
970 printf("(special 3)");
971 match_byte_assert(0);
972 match_byte_assert(0);
973 match_byte_assert(1);
974 match_byte_assert(0);
975 int subn = get_u32 ();
976 printf ("nested %d bytes, ", subn);
979 printf ("nested %d bytes, ", subn);
984 match_byte_assert (0x58);
988 dump_title_value(int level)
990 for (int i = 0; i <= level; i++)
1001 dump_title_value_31(level);
1003 printf("string \"%s\"", get_string());
1014 else if (match_byte (5))
1016 dump_title_value_31(level);
1017 printf ("variable \"%s\"", get_string());
1019 if (!match_byte(1) && !match_byte(2))
1020 match_byte_assert(3);
1022 else if (match_byte (2))
1024 unsigned int format;
1028 match_byte_assert (0x58);
1029 format = get_u32 ();
1030 value = get_double ();
1031 var = get_string ();
1032 vallab = get_string ();
1033 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1034 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1035 if (!match_byte (1) && !match_byte(2))
1036 match_byte_assert (3);
1045 else if (match_byte (4))
1047 unsigned int format;
1048 char *var, *vallab, *value;
1050 match_byte_assert (0x58);
1051 format = get_u32 ();
1052 vallab = get_string ();
1053 var = get_string ();
1054 if (!match_byte(1) && !match_byte(2))
1055 match_byte_assert (3);
1056 value = get_string ();
1057 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1058 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1064 else if (match_byte (1))
1066 unsigned int format;
1069 dump_title_value_31(level);
1070 format = get_u32 ();
1071 value = get_double ();
1072 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1081 dump_title_value_31(level);
1083 char *base = get_string();
1085 printf ("\"%s\" with %d variables:\n", base, x);
1086 for (int i = 0; i < x; i++)
1092 match_u32_assert(0);
1093 for (int j = 0; j <= level; j++)
1095 printf("variable %d has %d values:\n", i, y);
1096 for (int j = 0; j < y; j++)
1101 char *a = get_string();
1102 match_byte_assert(0x58);
1103 char *b = get_string();
1104 char *c = get_string();
1105 for (int k = 0; k <= level + 1; k++)
1107 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1110 dump_title_value (level+1);
1118 dump_footnote_value(int level)
1120 for (int i = 0; i <= level; i++)
1130 if (match_byte (0x31))
1134 printf("(footnote %d) ", get_u32());
1135 match_byte_assert (0);
1136 match_byte_assert (0);
1137 int subn = get_u32 ();
1138 printf ("nested %d bytes", subn);
1141 else if (match_u32 (2))
1143 printf("(special 2)");
1144 match_byte_assert(0);
1145 match_byte_assert(0);
1146 match_u32_assert(1);
1147 match_byte_assert(0);
1148 match_byte_assert(0);
1149 int subn = get_u32 ();
1150 printf ("nested %d bytes", subn);
1155 match_u32_assert(3);
1156 printf("(special 3)");
1157 match_byte_assert(0);
1158 match_byte_assert(0);
1159 match_byte_assert(1);
1160 match_byte_assert(0);
1161 int subn = get_u32 ();
1162 printf ("nested %d bytes, ", subn);
1165 printf ("nested %d bytes, ", subn);
1170 match_byte_assert (0x58);
1172 printf("string \"%s\"", get_string());
1173 if (!match_byte (0))
1174 match_byte_assert (1);
1176 else if (match_byte (5))
1178 match_byte_assert (0x58);
1179 printf ("variable \"%s\"", get_string());
1181 if (!match_byte(1) && !match_byte(2))
1182 match_byte_assert(3);
1184 else if (match_byte (2))
1186 unsigned int format;
1190 match_byte_assert (0x58);
1191 format = get_u32 ();
1192 value = get_double ();
1193 var = get_string ();
1194 vallab = get_string ();
1195 printf ("value %g format %d(%d.%d) var \"%s\" vallab \"%s\"",
1196 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1197 if (!match_byte (1) && !match_byte(2))
1198 match_byte_assert (3);
1207 else if (match_byte (4))
1209 unsigned int format;
1210 char *var, *vallab, *value;
1212 match_byte_assert (0x58);
1213 format = get_u32 ();
1214 vallab = get_string ();
1215 var = get_string ();
1216 if (!match_byte(1) && !match_byte(2))
1217 match_byte_assert (3);
1218 value = get_string ();
1219 printf ("value \"%s\" format %d(%d.%d) var \"%s\" vallab \"%s\"",
1220 value, format >> 16, (format >> 8) & 0xff, format & 0xff, var, vallab);
1226 else if (match_byte (1))
1228 unsigned int format;
1231 if (match_byte (0x31))
1235 printf("(footnote %d) ", get_u32());
1236 match_byte_assert (0);
1237 match_byte_assert (0);
1238 int subn = get_u32 ();
1239 printf ("nested %d bytes", subn);
1244 match_byte_assert (0x58);
1245 format = get_u32 ();
1246 value = get_double ();
1247 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1249 else if (match_byte (0x31))
1253 printf("(footnote %d) ", get_u32());
1254 match_byte_assert (0);
1255 match_byte_assert (0);
1256 int subn = get_u32 ();
1257 printf ("nested %d bytes", subn);
1262 match_u32_assert (0);
1263 match_u32_assert (0);
1264 int subn = get_u32 ();
1265 printf ("nested %d bytes", subn);
1268 char *base = get_string();
1270 printf ("\"%s\"; %d variables:\n", base, x);
1271 for (int i = 0; i < x; i++)
1277 match_u32_assert(0);
1278 for (int j = 0; j <= level; j++)
1280 printf("variable %d has %d values:\n", i, y);
1281 for (int j = 0; j < y; j++)
1285 char *a = get_string();
1286 match_byte_assert(0x58);
1287 char *b = get_string();
1288 char *c = get_string();
1289 for (int k = 0; k <= level + 1; k++)
1291 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1293 match_byte_assert(0);
1296 dump_footnote_value (level+1);
1304 match_byte_assert (0x58);
1305 char *base = get_string();
1307 printf ("\"%s\" with %d variables:\n", base, x);
1308 for (int i = 0; i < x; i++)
1314 match_u32_assert(0);
1315 for (int j = 0; j <= level; j++)
1317 printf("variable %d has %d values:\n", i, y);
1318 for (int j = 0; j < y; j++)
1322 char *a = get_string();
1323 match_byte_assert(0x58);
1324 char *b = get_string();
1325 char *c = get_string();
1326 for (int k = 0; k <= level + 1; k++)
1328 printf ("\"%s\", \"%s\", \"%s\"", a, b, c);
1329 match_byte_assert(0);
1332 dump_footnote_value (level+1);
1343 dump_title_value(0); putchar('\n');
1344 dump_title_value(0); putchar('\n');
1345 match_byte_assert(0x31);
1346 dump_title_value(0); putchar('\n');
1348 match_byte_assert(0x58);
1349 if (match_byte(0x31))
1351 dump_footnote_value(0); putchar('\n');
1354 match_byte_assert(0x58);
1357 int n_footnotes = get_u32();
1358 if (n_footnotes >= 20)
1360 fprintf(stderr, "%08x: %d footnotes\n", pos - 4, n_footnotes);
1364 printf("------\n%d footnotes\n", n_footnotes);
1365 if (n_footnotes < 20)
1367 for (int i = 0; i < n_footnotes; i++)
1369 printf("footnote %d:\n", i);
1370 dump_footnote_value(0);
1377 unsigned int format;
1380 if (match_byte (0x31))
1384 printf("(footnote %d) ", get_u32());
1385 match_byte_assert (0);
1386 match_byte_assert (0);
1387 int subn = get_u32 ();
1388 printf ("nested %d bytes", subn);
1393 match_byte_assert (0x58);
1394 format = get_u32 ();
1395 value = get_double ();
1396 printf ("value %g format %d(%d.%d)", value, format >> 16, (format >> 8) & 0xff, format & 0xff);
1403 else if (match_byte (0x31))
1405 match_byte_assert(3);
1407 match_byte_assert(0x58);
1408 match_u32_assert(0);
1413 match_byte_assert (0x58);
1414 printf("(%d)\n", get_u32());
1420 find_dimensions(void)
1423 const char dimensions[] = "-,,,.\0";
1424 int x = try_find_tail(dimensions, sizeof dimensions - 1);
1429 const char dimensions[] = "-,,, .\0";
1430 return find_tail(dimensions, sizeof dimensions - 1);
1436 printf("fonts: offset=%08x\n", pos);
1438 for (int i = 1; i <= 8; i++)
1440 printf("%08x: font %d, ", pos, i);
1441 match_byte_assert(i);
1442 match_byte_assert(0x31);
1443 printf("%s, ", get_string());
1444 match_byte_assert(0);
1445 match_byte_assert(0);
1446 if (!match_byte(0x40) && !match_byte(0x20) && !match_byte(0x80) && !match_byte(0x10))
1447 match_byte_assert(0x50);
1448 if (!match_byte(0x41))
1449 match_byte_assert(0x51);
1451 printf ("%s, ", get_string());
1452 printf ("%s, ", get_string());
1453 match_u32_assert(0);
1454 match_u32_assert(0);
1463 match_u32_assert(240);
1466 match_u32_assert(18);
1473 match_u32_assert(142);
1477 int count = get_u32();
1480 char *encoding = get_string();
1481 printf("encoding=%s\n", encoding);
1484 match_u32_assert(UINT32_MAX);
1486 match_byte_assert(1);
1487 match_byte_assert(0);
1489 match_byte_assert(1);
1490 if (!match_byte(0x99) && !match_byte(0x98))
1491 match_byte_assert(0x97);
1492 match_byte_assert(7);
1493 match_byte_assert(0);
1494 match_byte_assert(0);
1495 if (match_byte('.'))
1496 match_byte_assert(',');
1499 match_byte_assert(',');
1500 if (!match_byte('.'))
1501 match_byte_assert(' ');
1503 match_u32_assert(5);
1504 for (int i = 0; i < 5; i++)
1507 if (pos != find_dimensions())
1508 fprintf (stderr, "%08x / %08x\n", pos, find_dimensions());
1512 main(int argc, char *argv[])
1517 if (isatty(STDIN_FILENO))
1519 fprintf(stderr, "redirect stdin from a .bin file\n");
1522 if (fstat(STDIN_FILENO, &s))
1534 if (read(STDIN_FILENO, data, n) != n)
1542 if (!strcmp(argv[1], "title0"))
1545 if (match_byte (0x03)
1546 || (match_byte (0x05) && match_byte (0x58)))
1547 printf ("%s\n", get_string());
1549 printf ("<unknown>\n");
1552 else if (!strcmp(argv[1], "title"))
1557 else if (!strcmp(argv[1], "titleraw"))
1559 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1561 n = find(fonts, sizeof fonts - 1);
1563 else if (!strcmp(argv[1], "fonts"))
1565 const char fonts[] = "\x01\x31\x09\0\0\0SansSerif";
1566 const char styles[] = "\xf0\0\0\0";
1567 start = find(fonts, sizeof fonts - 1);
1568 n = find(styles, sizeof styles - 1);
1570 else if (!strcmp(argv[1], "styles"))
1572 const char styles[] = "\xf0\0\0\0";
1573 const char dimensions[] = "-,,,.\0";
1574 start = find(styles, sizeof styles - 1);
1575 n = find(dimensions, sizeof dimensions - 1) + sizeof dimensions - 1;
1577 else if (!strcmp(argv[1], "dimensions") || !strcmp(argv[1], "all"))
1580 match_byte_assert(1);
1581 match_byte_assert(0);
1582 match_u32_assert(3);
1583 match_byte_assert(1);
1585 match_byte_assert(1);
1586 match_byte_assert(0);
1587 match_byte_assert(0);
1589 match_byte_assert(1);
1591 match_byte_assert(0);
1592 match_byte_assert(0);
1593 match_byte_assert(0);
1597 printf("\n\ndata:\n");
1600 match_byte_assert (1);
1603 fprintf (stderr, "%x / %x\n", pos, n);
1610 fprintf (stderr, "unknown section %s\n", argv[1]);
1617 for (size_t i = start; i < n; )
1624 && i + 4 + data[i] + data[i + 1] * 256 <= n
1625 && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
1627 fputs("\n\"", stdout);
1628 fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stdout);
1629 fputs("\" ", stdout);
1631 i += 4 + data[i] + data[i + 1] * 256;
1633 else if (i + 12 <= n
1634 && data[i + 1] == 40
1636 && data[i + 3] == 0)
1640 memcpy (&d, &data[i + 4], 8);
1641 printf ("F40.%d(%.*f)\n", data[i], data[i], d);
1644 else if (i + 12 <= n
1645 && data[i + 1] == 40
1646 && data[i + 2] == 31
1647 && data[i + 3] == 0)
1651 memcpy (&d, &data[i + 4], 8);
1652 printf ("PCT40.%d(%.*f)\n", data[i], data[i], d);
1656 && (data[i] && data[i] != 88 && data[i] != 0x41)
1661 printf ("i%d ", data[i]);
1666 printf("%02x ", data[i]);