}
#define match_byte_assert(b) match_byte_assert(b, WHERE)
+static void
+dump_raw(FILE *stream, int start, int end, const char *separator)
+{
+ for (size_t i = start; i < end; )
+ {
+ if (i + 5 <= n
+ && data[i]
+ //&& !data[i + 1]
+ && !data[i + 2]
+ && !data[i + 3]
+ && i + 4 + data[i] + data[i + 1] * 256 <= end
+ && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
+ {
+ fprintf(stream, "%s\"", separator);
+ fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stream);
+ fputs("\" ", stream);
+
+ i += 4 + data[i] + data[i + 1] * 256;
+ }
+ else if (i + 12 <= end
+ && data[i + 1] == 40
+ && data[i + 2] == 5
+ && data[i + 3] == 0)
+ {
+ double d;
+
+ memcpy (&d, &data[i + 4], 8);
+ fprintf (stream, "F40.%d(%.*f)%s", data[i], data[i], d, separator);
+ i += 12;
+ }
+ else if (i + 12 <= end
+ && data[i + 1] == 40
+ && data[i + 2] == 31
+ && data[i + 3] == 0)
+ {
+ double d;
+
+ memcpy (&d, &data[i + 4], 8);
+ fprintf (stream, "PCT40.%d(%.*f)%s", data[i], data[i], d, separator);
+ i += 12;
+ }
+ else if (i + 4 <= end
+ && (data[i] && data[i] != 88 && data[i] != 0x41)
+ && !data[i + 1]
+ && !data[i + 2]
+ && !data[i + 3])
+ {
+ fprintf (stream, "i%d ", data[i]);
+ i += 4;
+ }
+ else
+ {
+ fprintf(stream, "%02x ", data[i]);
+ i++;
+ }
+ }
+
+
+}
+
static char *
get_string(const char *where)
{
}
#define get_string() get_string(WHERE)
+static void
+dump_nested(void)
+{
+ int subn = get_u32 ();
+ fprintf (stderr, "nested %d bytes: ", subn);
+ dump_raw(stderr, pos, pos + subn, "");
+ putc('\n', stderr);
+ pos += subn;
+}
+
static void
dump_value_31(void)
{
get_string();
else
match_u32_assert (0);
- int subn = get_u32 ();
- printf ("nested %d bytes", subn);
- pos += subn;
+ dump_nested();
}
else if (match_u32 (1))
{
printf("(footnote %d) ", get_u32());
match_byte_assert (0);
match_byte_assert (0);
- int subn = get_u32 ();
- printf ("nested %d bytes", subn);
- pos += subn;
+ dump_nested();
}
else if (match_u32 (2))
{
match_u32_assert(1);
match_byte_assert(0);
match_byte_assert(0);
- int subn = get_u32 ();
- printf ("nested %d bytes", subn);
- pos += subn;
+ dump_nested();
}
else
{
match_byte_assert(0);
match_byte_assert(1);
match_byte_assert(0);
- int subn = get_u32 ();
- printf ("nested %d bytes, ", subn);
- pos += subn;
- subn = get_u32 ();
- printf ("nested %d bytes, ", subn);
- pos += subn;
+ dump_nested();
+ dump_nested();
}
}
else
else
start = 0x27;
- for (size_t i = start; i < n; )
- {
- if (i + 5 <= n
- && data[i]
- //&& !data[i + 1]
- && !data[i + 2]
- && !data[i + 3]
- && i + 4 + data[i] + data[i + 1] * 256 <= n
- && all_ascii(&data[i + 4], data[i] + data[i + 1] * 256))
- {
- fputs("\n\"", stdout);
- fwrite(&data[i + 4], 1, data[i] + data[i + 1] * 256, stdout);
- fputs("\" ", stdout);
-
- i += 4 + data[i] + data[i + 1] * 256;
- }
- else if (i + 12 <= n
- && data[i + 1] == 40
- && data[i + 2] == 5
- && data[i + 3] == 0)
- {
- double d;
-
- memcpy (&d, &data[i + 4], 8);
- printf ("F40.%d(%.*f)\n", data[i], data[i], d);
- i += 12;
- }
- else if (i + 12 <= n
- && data[i + 1] == 40
- && data[i + 2] == 31
- && data[i + 3] == 0)
- {
- double d;
-
- memcpy (&d, &data[i + 4], 8);
- printf ("PCT40.%d(%.*f)\n", data[i], data[i], d);
- i += 12;
- }
- else if (i + 4 <= n
- && (data[i] && data[i] != 88 && data[i] != 0x41)
- && !data[i + 1]
- && !data[i + 2]
- && !data[i + 3])
- {
- printf ("i%d ", data[i]);
- i += 4;
- }
- else
- {
- printf("%02x ", data[i]);
- i++;
- }
- }
+ dump_raw(stdout, start, n, "\n");
return 0;
}