#include <errno.h>
#include <fcntl.h>
#include <float.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
return s;
}
+static void
+match_string1_assert(const char *exp, const char *where)
+{
+ int start = pos;
+ char *act = get_string1();
+ if (strcmp(act, exp))
+ {
+ fprintf(stderr, "%s: 0x%x: expected \"%s\", got \"%s\"\n",
+ where, start, exp, act);
+ exit(1);
+ }
+}
+#define match_string1_assert(x) match_string1_assert(x, WHERE)
+
static char *
get_string2(void)
{
return s;
}
+static void
+match_string2_assert(const char *exp, const char *where)
+{
+ int start = pos;
+ char *act = get_string2();
+ if (strcmp(act, exp))
+ {
+ fprintf(stderr, "%s: 0x%x: expected \"%s\", got \"%s\"\n",
+ where, start, exp, act);
+ exit(1);
+ }
+}
+#define match_string2_assert(x) match_string2_assert(x, WHERE)
+
static char *
get_string(const char *where)
{
}
}
+static void
+parse_heading(const char *name)
+{
+ match_u16_assert(0xffff);
+ match_u16_assert(0);
+ match_string2_assert(name);
+}
+
+static void
+match_zeros_assert(int count)
+{
+ for (int i = 0; i < count; i++)
+ if (data[pos + i])
+ {
+ fprintf (stderr,
+ "%#x: expected %d zeros here but offset %d is %#"PRIx8"\n",
+ pos, count, i, data[pos + i]);
+ exit (1);
+ }
+ pos += count;
+}
+
+static void
+parse_DspString(void)
+{
+ match_byte_assert(1);
+ match_byte_assert(2);
+ match_byte_assert(40);
+ if (!match_byte(0))
+ match_byte_assert(5);
+ match_byte_assert(0);
+ match_byte_assert(1);
+ printf ("DspString(\"%s\")\n", get_string1());
+}
int
main(int argc, char *argv[])
setvbuf (stdout, NULL, _IOLBF, 0);
+ match_byte_assert(4);
+ match_u32_assert(0);
+ match_string1_assert("SPSS Output Document");
+ match_u32_assert(1);
+ match_byte_assert(0x63);
+
+ parse_heading("NavRoot");
+ match_byte_assert(2);
+ match_zeros_assert(32);
+
+ parse_heading("DspSimpleText");
+ match_zeros_assert(10);
+
+ parse_heading("DspString");
+ parse_DspString();
+
+ parse_heading("NavTreeViewItem");
+
+
+ printf ("%#x: end of successful parse\n", pos);
+
return 0;
}