new research
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 31 Dec 2019 05:11:16 +0000 (05:11 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 31 Dec 2019 05:11:16 +0000 (05:11 +0000)
Makefile
dump-float.c [new file with mode: 0644]
dump-spo.c [new file with mode: 0644]
spo-notes [new file with mode: 0644]

index cf5aa787de3e99e0d7adbad3449780114b8ece79..c9a1c7d5517161c42ef6a26b4a445598705ab218 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,10 @@ base_ldflags := $(LDFLAGS)
 parse-xml.o: CFLAGS := $(shell pkg-config --cflags libxml-2.0) $(base_cflags)
 parse-xml: LDFLAGS := $(shell pkg-config --libs libxml-2.0) $(LDFLAGS)
 dump2.o: CFLAGS := $(base_cflags) -Wno-unused
+dump-spo.o: CFLAGS := $(base_cflags) -Wno-unused
 
-all: dump dump2 parse-xml
+all: dump dump2 parse-xml dump-spo
+dump-spo: dump-spo.o u8-mbtouc.o
 dump: dump.o u8-mbtouc.o
 dump2: dump2.o u8-mbtouc.o
 parse-xml: parse-xml.o
diff --git a/dump-float.c b/dump-float.c
new file mode 100644 (file)
index 0000000..9e2d4be
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdint.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+  union
+    {
+      uint8_t b[8];
+      double d;
+    }
+  x = { .b = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0xdd, 0x40 } };
+  printf ("%f\n", x.d);
+  return 0;
+}
diff --git a/dump-spo.c b/dump-spo.c
new file mode 100644 (file)
index 0000000..b481107
--- /dev/null
@@ -0,0 +1,1548 @@
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <float.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+#include "u8-mbtouc.h"
+
+static const char *filename;
+static uint8_t *data;
+static size_t n;
+
+int version;
+
+unsigned int pos;
+
+#define XSTR(x) #x
+#define STR(x) XSTR(x)
+#define WHERE __FILE__":" STR(__LINE__)
+
+static uint8_t
+get_byte(void)
+{
+  return data[pos++];
+}
+
+static unsigned int
+get_u32(void)
+{
+  uint32_t x;
+  memcpy(&x, &data[pos], 4);
+  pos += 4;
+  return x;
+}
+
+static unsigned long long int
+get_u64(void)
+{
+  uint64_t x;
+  memcpy(&x, &data[pos], 8);
+  pos += 8;
+  return x;
+}
+
+static unsigned int
+get_be32(void)
+{
+  uint32_t x;
+  x = (data[pos] << 24) | (data[pos + 1] << 16) | (data[pos + 2] << 8) | data[pos + 3];
+  pos += 4;
+  return x;
+}
+
+static unsigned int
+get_u16(void)
+{
+  uint16_t x;
+  memcpy(&x, &data[pos], 2);
+  pos += 2;
+  return x;
+}
+
+static double
+get_double(void)
+{
+  double x;
+  memcpy(&x, &data[pos], 8);
+  pos += 8;
+  return x;
+}
+
+static double __attribute__((unused))
+get_float(void)
+{
+  float x;
+  memcpy(&x, &data[pos], 4);
+  pos += 4;
+  return x;
+}
+
+static bool
+match_u32(uint32_t x)
+{
+  if (get_u32() == x)
+    return true;
+  pos -= 4;
+  return false;
+}
+
+static void
+match_u32_assert(uint32_t x, const char *where)
+{
+  unsigned int y = get_u32();
+  if (x != y)
+    {
+      fprintf(stderr, "%s: 0x%x: expected i%u, got i%u\n", where, pos - 4, x, y);
+      exit(1);
+    }
+}
+#define match_u32_assert(x) match_u32_assert(x, WHERE)
+
+static bool __attribute__((unused))
+match_u64(uint64_t x)
+{
+  if (get_u64() == x)
+    return true;
+  pos -= 8;
+  return false;
+}
+
+static void __attribute__((unused))
+match_u64_assert(uint64_t x, const char *where)
+{
+  unsigned long long int y = get_u64();
+  if (x != y)
+    {
+      fprintf(stderr, "%s: 0x%x: expected u64:%lu, got u64:%llu\n", where, pos - 8, x, y);
+      exit(1);
+    }
+}
+#define match_u64_assert(x) match_u64_assert(x, WHERE)
+
+static bool __attribute__((unused))
+match_be32(uint32_t x)
+{
+  if (get_be32() == x)
+    return true;
+  pos -= 4;
+  return false;
+}
+
+static void
+match_be32_assert(uint32_t x, const char *where)
+{
+  unsigned int y = get_be32();
+  if (x != y)
+    {
+      fprintf(stderr, "%s: 0x%x: expected be%u, got be%u\n", where, pos - 4, x, y);
+      exit(1);
+    }
+}
+#define match_be32_assert(x) match_be32_assert(x, WHERE)
+
+static bool
+match_byte(uint8_t b)
+{
+  if (pos < n && data[pos] == b)
+    {
+      pos++;
+      return true;
+    }
+  else
+    return false;
+}
+
+static void
+match_byte_assert(uint8_t b, const char *where)
+{
+  if (!match_byte(b))
+    {
+      fprintf(stderr, "%s: 0x%x: expected %02x, got %02x\n", where, pos, b, data[pos]);
+      exit(1);
+    }
+}
+#define match_byte_assert(b) match_byte_assert(b, WHERE)
+
+static bool
+match_bytes(int start, const int *bytes, size_t n_bytes)
+{
+  for (size_t i = 0; i < n_bytes; i++)
+    if (bytes[i] >= 0 && data[start + i] != bytes[i])
+      return false;
+  return true;
+}
+
+static bool
+get_bool(void)
+{
+  if (match_byte(0))
+    return false;
+  match_byte_assert(1);
+  return true;
+}
+
+static bool __attribute__((unused))
+is_ascii(uint8_t p)
+{
+  return (p >= ' ' && p < 127) || p == '\r' || p == '\n' || p == '\t';
+}
+
+static bool __attribute__((unused))
+all_utf8(const char *p_, size_t len)
+{
+  const uint8_t *p = (const uint8_t *) p_;
+  for (size_t ofs = 0, mblen; ofs < len; ofs += mblen)
+    {
+      ucs4_t uc;
+
+      mblen = u8_mbtouc (&uc, p + ofs, len - ofs);
+      if ((uc < 32 && uc != '\n') || uc == 127 || uc == 0xfffd)
+        return false;
+    }
+  return true;
+}
+
+static char *
+get_string(const char *where)
+{
+  if (1
+      /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/
+      /*&& all_ascii(&data[pos + 4], data[pos])*/)
+    {
+      int len = data[pos] + data[pos + 1] * 256;
+      char *s = malloc(len + 1);
+
+      memcpy(s, &data[pos + 4], len);
+      s[len] = 0;
+      pos += 4 + len;
+      return s;
+    }
+  else
+    {
+      fprintf(stderr, "%s: 0x%x: expected string\n", where, pos);
+      exit(1);
+    }
+}
+#define get_string() get_string(WHERE)
+
+static char *
+get_string_be(const char *where)
+{
+  if (1
+      /*data[pos + 1] == 0 && data[pos + 2] == 0 && data[pos + 3] == 0*/
+      /*&& all_ascii(&data[pos + 4], data[pos])*/)
+    {
+      int len = data[pos + 2] * 256 + data[pos + 3];
+      char *s = malloc(len + 1);
+
+      memcpy(s, &data[pos + 4], len);
+      s[len] = 0;
+      pos += 4 + len;
+      return s;
+    }
+  else
+    {
+      fprintf(stderr, "%s: 0x%x: expected string\n", where, pos);
+      exit(1);
+    }
+}
+#define get_string_be() get_string_be(WHERE)
+
+static int
+get_end(void)
+{
+  int len = get_u32();
+  return pos + len;
+}
+
+static void __attribute__((unused))
+hex_dump(FILE *stream, int ofs, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      int c = data[ofs + i];
+      fprintf(stream, " %02x", c);
+    }
+  putc(' ', stream);
+  for (int i = 0; i < n; i++)
+    {
+      int c = data[ofs + i];
+      putc(c >= 32 && c < 127 ? c : '.', stream);
+    }
+  putc('\n', stream);
+}
+
+static void __attribute__((unused))
+char_dump(FILE *stream, int ofs, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      int c = data[ofs + i];
+      putc(c >= 32 && c < 127 ? c : '.', stream);
+    }
+  putc('\n', stream);
+}
+
+static char *
+dump_counted_string(void)
+{
+  int inner_end = get_end();
+  if (pos == inner_end)
+    return NULL;
+
+  if (match_u32(5))
+    {
+      match_u32_assert(0);
+      match_byte_assert(0x58);
+    }
+  else
+    match_u32_assert(0);
+
+  char *s = NULL;
+  if (match_byte(0x31))
+    s = get_string();
+  else
+    match_byte_assert(0x58);
+  if (pos != inner_end)
+    {
+      fprintf(stderr, "inner end discrepancy\n");
+      exit(1);
+    }
+  return s;
+}
+
+static void
+dump_style(FILE *stream)
+{
+  if (match_byte(0x58))
+    return;
+
+  match_byte_assert(0x31);
+  if (get_bool())
+    printf (" bold=\"yes\"");
+  if (get_bool())
+    printf (" italic=\"yes\"");
+  if (get_bool())
+    printf (" underline=\"yes\"");
+  if (!get_bool())
+    printf (" show=\"no\"");
+  char *fg = get_string();     /* foreground */
+  char *bg = get_string();     /* background */
+  char *font = get_string();     /* font */
+  int size = get_byte() * (72. / 96.);
+  fprintf(stream, " fgcolor=\"%s\" bgcolor=\"%s\" font=\"%s\" size=\"%dpt\"",
+          fg, bg, font, size);
+}
+
+static void
+dump_style2(FILE *stream)
+{
+  if (match_byte(0x58))
+    return;
+
+  match_byte_assert(0x31);
+  uint32_t halign = get_u32();
+  printf (" halign=\"%s\"",
+          halign == 0 ? "center"
+          : halign == 2 ? "left"
+          : halign == 4 ? "right"
+          : halign == 6 ? "decimal"
+          : halign == 0xffffffad ? "mixed"
+          : "<error>");
+  int valign = get_u32();
+  printf (" valign=\"%s\"",
+          valign == 0 ? "center"
+          : valign == 1 ? "top"
+          : valign == 3 ? "bottom"
+          : "<error>");
+  printf (" offset=\"%gpt\"", get_double());
+  int l = get_u16();
+  int r = get_u16();
+  int t = get_u16();
+  int b = get_u16();
+  printf (" margins=\"%d %d %d %d\"", l, r, t, b);
+}
+
+static char *
+dump_nested_string(FILE *stream)
+{
+  char *s = NULL;
+
+  match_byte_assert (0);
+  match_byte_assert (0);
+  int outer_end = get_end();
+  s = dump_counted_string();
+  if (s)
+    fprintf(stream, " \"%s\"", s);
+  dump_style(stream);
+  match_byte_assert(0x58);
+  if (pos != outer_end)
+    {
+      fprintf(stderr, "outer end discrepancy\n");
+      exit(1);
+    }
+
+  return s;
+}
+
+static void
+dump_value_modifier(FILE *stream)
+{
+  if (match_byte (0x31))
+    {
+      if (match_u32 (0))
+        {
+          fprintf(stream, "<special0");
+          if (match_u32 (1))
+            {
+              /* Corpus frequencies:
+                 124 "a"
+                 12 "b"
+                 8 "a, b"
+
+                 The given text is appended to the cell in a subscript font.
+              */
+              fprintf(stream, " subscript=\"%s\"", get_string());
+            }
+          else
+            match_u32_assert (0);
+
+          if (version == 1)
+            {
+              /* We only have one SPV file for this version (with many
+                 tables). */
+              match_byte(0);
+              if (!match_u32(1))
+                match_u32_assert(2);
+              match_byte(0);
+              match_byte(0);
+              if (!match_u32(0) && !match_u32(1) && !match_u32(2) && !match_u32(3) && !match_u32(4) && !match_u32(5) && !match_u32(6) && !match_u32(7) && !match_u32(8) && !match_u32(9))
+                match_u32_assert(10);
+              match_byte(0);
+              match_byte(0);
+              fprintf(stream, "/>\n");
+              return;
+            }
+
+          int outer_end = get_end();
+          
+          /* This counted-string appears to be a template string,
+             e.g. "Design\: [:^1:]1 Within Subjects Design\: [:^1:]2". */
+          char *template = dump_counted_string();
+          if (template)
+            fprintf(stream, " template=\"%s\"", template);
+
+          dump_style(stream);
+          dump_style2(stream);
+          if (pos != outer_end)
+            {
+              fprintf(stderr, "outer end discrepancy\n");
+              exit(1);
+            }
+          fprintf(stream, "/>\n");
+        }
+      else
+        {
+          int count = get_u32();
+          fprintf(stream, "<footnote-ref indexes=\"");
+          for (int i = 0; i < count; i++)
+            {
+              if (i)
+                putc(' ', stream);
+              fprintf(stream, "%d", get_u16());
+            }
+          putc('"', stream);
+          match_byte_assert(0);
+          match_byte_assert(0);
+          dump_nested_string(stream);
+          fprintf(stream, "/>\n");
+        }
+    }
+  else
+    match_byte_assert (0x58);
+}
+
+static const char *
+format_to_string (int type)
+{
+  static char tmp[16];
+  switch (type)
+    {
+    case 1: return "A";
+    case 2: return "AHEX";
+    case 3: return "COMMA";
+    case 4: return "DOLLAR";
+    case 5: case 40: return "F";
+    case 6: return "IB";
+    case 7: return "PIBHEX";
+    case 8: return "P";
+    case 9: return "PIB";
+    case 10: return "PK";
+    case 11: return "RB";
+    case 12: return "RBHEX";
+    case 15: return "Z";
+    case 16: return "N";
+    case 17: return "E";
+    case 20: return "DATE";
+    case 21: return "TIME";
+    case 22: return "DATETIME";
+    case 23: return "ADATE";
+    case 24: return "JDATE";
+    case 25: return "DTIME";
+    case 26: return "WKDAY";
+    case 27: return "MONTH";
+    case 28: return "MOYR";
+    case 29: return "QYR";
+    case 30: return "WKYR";
+    case 31: return "PCT";
+    case 32: return "DOT";
+    case 33: return "CCA";
+    case 34: return "CCB";
+    case 35: return "CCC";
+    case 36: return "CCD";
+    case 37: return "CCE";
+    case 38: return "EDATE";
+    case 39: return "SDATE";
+    default:
+      abort();
+      sprintf(tmp, "<%d>", type);
+      return tmp;
+    }
+}
+
+static void
+dump_value(FILE *stream, int level)
+{
+  match_byte(0);
+  match_byte(0);
+  match_byte(0);
+  match_byte(0);
+
+  for (int i = 0; i <= level; i++)
+    fprintf (stream, "    ");
+
+  printf ("%02x: value (%d)\n", pos, data[pos]);
+  if (match_byte (1))
+    {
+      unsigned int format;
+      double value;
+
+      dump_value_modifier(stream);
+      format = get_u32 ();
+      value = get_double ();
+      fprintf (stream, "<number value=\"%.*g\" format=\"%s%d.%d\"/>\n",
+               DBL_DIG, value, format_to_string(format >> 16), (format >> 8) & 0xff, format & 0xff);
+    }
+  else if (match_byte (2))
+    {
+      unsigned int format;
+      char *var, *vallab;
+      double value;
+
+      dump_value_modifier (stream);
+      format = get_u32 ();
+      value = get_double ();
+      var = get_string ();
+      vallab = get_string ();
+      fprintf (stream, "<numeric-datum value=\"%.*g\" format=\"%s%d.%d\"",
+              DBL_DIG, value, format_to_string(format >> 16), (format >> 8) & 0xff, format & 0xff);
+      if (var[0])
+        fprintf (stream, " variable=\"%s\"", var);
+      if (vallab[0])
+        fprintf (stream, " label=\"%s\"", vallab);
+      fprintf (stream, "/>\n");
+      if (!match_byte (1) && !match_byte(2))
+        match_byte_assert (3);
+    }
+  else if (match_byte (3))
+    {
+      char *text =  get_string();
+      dump_value_modifier(stream);
+      char *identifier = get_string();
+      char *text_eng = get_string();
+      fprintf (stream, "<string c=\"%s\"", text_eng);
+      if (identifier[0])
+        fprintf (stream, " identifier=\"%s\"", identifier);
+      if (strcmp(text_eng, text))
+        fprintf (stream, " local=\"%s\"", text);
+      fprintf (stream, "/>\n");
+      if (!match_byte (0))
+        match_byte_assert(1);
+    }
+  else if (match_byte (4))
+    {
+      unsigned int format;
+      char *var, *vallab, *value;
+
+      dump_value_modifier(stream);
+      format = get_u32 ();
+      vallab = get_string ();
+      var = get_string ();
+      if (!match_byte(1) && !match_byte(2))
+        match_byte_assert (3);
+      value = get_string ();
+      fprintf (stream, "<string-datum value=\"%s\" format=\"%s%d.%d\"",
+              value, format_to_string(format >> 16), (format >> 8) & 0xff, format & 0xff);
+      if (var[0])
+        fprintf (stream, " variable=\"%s\"", var);
+      if (vallab[0])
+        fprintf (stream, " label=\"%s\"/>\n", vallab);
+      fprintf (stream, "/>\n");
+    }
+  else if (match_byte (5))
+    {
+      dump_value_modifier(stream);
+      char *name = get_string ();
+      char *label = get_string ();
+      fprintf (stream, "<variable name=\"%s\"", name);
+      if (label[0])
+        fprintf (stream, " label=\"%s\"", label);
+      fprintf (stream, "/>\n");
+      if (!match_byte(1) && !match_byte(2))
+        match_byte_assert(3);
+    }
+  else
+    {
+      printf ("else %#x\n", pos);
+      dump_value_modifier(stream);
+
+      char *base = get_string();
+      int x = get_u32();
+      fprintf (stream, "<template format=\"%s\">\n", base);
+      for (int i = 0; i < x; i++)
+        {
+          int y = get_u32();
+          if (!y)
+            y = 1;
+          else
+            match_u32_assert(0);
+          for (int j = 0; j <= level + 1; j++)
+            fprintf (stream, "    ");
+          fprintf (stream, "<substitution index=\"%d\">\n", i + 1);
+          for (int j = 0; j < y; j++)
+            dump_value (stream, level + 2);
+          for (int j = 0; j <= level + 1; j++)
+            fprintf (stream, "    ");
+          fprintf (stream, "</substitution>\n");
+        }
+      for (int j = 0; j <= level; j++)
+        fprintf (stream, "    ");
+      fprintf (stream, "</template>\n");
+    }
+}
+
+static int
+compare_int(const void *a_, const void *b_)
+{
+  const int *a = a_;
+  const int *b = b_;
+  return *a < *b ? -1 : *a > *b;
+}
+
+static void
+check_permutation(int *a, int n, const char *name)
+{
+  int b[n];
+  memcpy(b, a, n * sizeof *a);
+  qsort(b, n, sizeof *b, compare_int);
+  for (int i = 0; i < n; i++)
+    if (b[i] != i)
+      {
+        fprintf(stderr, "bad %s permutation:", name);
+        for (int i = 0; i < n; i++)
+          fprintf(stderr, " %d", a[i]);
+        putc('\n', stderr);
+        exit(1);
+      }
+}
+
+static void
+dump_category(FILE *stream, int level, int **indexes, int *allocated_indexes,
+              int *n_indexes)
+{
+  for (int i = 0; i <= level; i++)
+    fprintf (stream, "    ");
+  printf ("<category>\n");
+  dump_value (stream, level + 1);
+
+  bool merge = get_bool();
+  match_byte_assert (0);
+  int unindexed = get_bool();
+
+  int x = get_u32 ();
+  pos -= 4;
+  if (!match_u32 (0))
+    match_u32_assert (2);
+
+  int indx = get_u32();
+  int n_categories = get_u32();
+  if (indx == -1)
+    {
+      if (merge)
+        {
+          for (int i = 0; i <= level + 1; i++)
+            fprintf (stream, "    ");
+          fprintf (stream, "<merge/>\n");
+        }
+      assert (unindexed);
+    }
+  else
+    {
+      assert (!merge);
+      assert (!unindexed);
+      assert (x == 2);
+      assert (n_categories == 0);
+      if (*n_indexes >= *allocated_indexes)
+        {
+          *allocated_indexes = *allocated_indexes ? 2 * *allocated_indexes : 16;
+          *indexes = realloc(*indexes, *allocated_indexes * sizeof **indexes);
+        }
+      (*indexes)[(*n_indexes)++] = indx;
+    }
+
+  if (n_categories == 0)
+    {
+      for (int i = 0; i <= level + 1; i++)
+        fprintf (stream, "    ");
+      fprintf (stream, "<category-index>%d</category-index>\n", indx);
+    }
+  for (int i = 0; i < n_categories; i++)
+    dump_category (stream, level + 1, indexes, allocated_indexes, n_indexes);
+  for (int i = 0; i <= level; i++)
+    fprintf (stream, "    ");
+  printf ("</category>\n");
+}
+
+static int
+dump_dim(int indx)
+{
+  int n_categories;
+
+  printf ("<dimension index=\"%d\">\n", indx);
+  dump_value (stdout, 0);
+
+  /* This byte is usually 0 but many other values have been spotted.
+     No visible effect. */
+  pos++;
+
+  /* This byte can cause data to be oddly replicated. */
+  if (!match_byte(0) && !match_byte(1))
+    match_byte_assert(2);
+
+  if (!match_u32(0))
+    match_u32_assert(2);
+
+  bool show_dim_label = get_bool();
+  if (show_dim_label)
+    printf("  <show-dim-label/>\n");
+
+  bool hide_all_labels = get_bool();
+  if (hide_all_labels)
+    printf("  <hide-all-labels/>\n");
+
+  match_byte_assert(1);
+  if (!match_u32(UINT32_MAX))
+    match_u32_assert(indx);
+
+  n_categories = get_u32();
+
+  int *indexes = NULL;
+  int n_indexes = 0;
+  int allocated_indexes = 0;
+  for (int i = 0; i < n_categories; i++)
+    dump_category (stdout, 0, &indexes, &allocated_indexes, &n_indexes);
+  check_permutation(indexes, n_indexes, "categories");
+
+  fprintf (stdout, "</dimension>\n");
+  return n_indexes;
+}
+
+int n_dims;
+static int dim_n_cats[64];
+#define MAX_DIMS (sizeof dim_n_cats / sizeof *dim_n_cats)
+
+static void
+dump_dims(void)
+{
+  n_dims = get_u32();
+  assert(n_dims < MAX_DIMS);
+  for (int i = 0; i < n_dims; i++)
+    dim_n_cats[i] = dump_dim (i);
+}
+
+static void
+dump_data(void)
+{
+  /* The first three numbers add to the number of dimensions. */
+  int l = get_u32();
+  int r = get_u32();
+  int c = n_dims - l - r;
+  match_u32_assert(c);
+
+  /* The next n_dims numbers are a permutation of the dimension numbers. */
+  int a[n_dims];
+  for (int i = 0; i < n_dims; i++)
+    {
+      int dim = get_u32();
+      a[i] = dim;
+
+      const char *name = i < l ? "layer" : i < l + r ? "row" : "column";
+      printf ("<%s dimension=\"%d\"/>\n", name, dim);
+    }
+  check_permutation(a, n_dims, "dimensions");
+
+  int x = get_u32();
+  printf ("<data>\n");
+  for (int i = 0; i < x; i++)
+    {
+      unsigned int indx = get_u32();
+      printf ("    <datum index=\"%d\" coords=", indx);
+
+      int coords[MAX_DIMS];
+      for (int i = n_dims; i-- > 0; )
+        {
+          coords[i] = indx % dim_n_cats[i];
+          indx /= dim_n_cats[i];
+        }
+      for (int i = 0; i < n_dims; i++)
+        printf("%c%d", i ? ',' : '"', coords[i]);
+
+      printf ("\">\n");
+      match_u32_assert(0);
+      if (version == 1)
+        match_byte(0);
+      dump_value(stdout, 1);
+      fprintf (stdout, "    </datum>\n");
+    }
+  printf ("</data>\n");
+}
+
+static void
+dump_title(void)
+{
+  printf ("<title-local>\n");
+  dump_value(stdout, 0);
+  match_byte(1);
+  printf ("</title-local>\n");
+
+  printf ("<subtype>\n");
+  dump_value(stdout, 0);
+  match_byte(1);
+  printf ("</subtype>\n");
+
+  match_byte_assert(0x31);
+
+  printf ("<title-c>\n");
+  dump_value(stdout, 0);
+  match_byte(1);
+  printf ("</title-c>\n");
+
+  if (match_byte(0x31))
+    {
+      printf ("<user-caption>\n");
+      dump_value(stdout, 0);
+      printf ("</user-caption>\n");
+    }
+  else
+    match_byte_assert(0x58);
+  if (match_byte(0x31))
+    {
+      printf ("<caption>\n");
+      dump_value(stdout, 0);
+      printf ("</caption>\n");
+    }
+  else
+    match_byte_assert(0x58);
+
+  int n_footnotes = get_u32();
+  for (int i = 0; i < n_footnotes; i++)
+    {
+      printf ("<footnote index=\"%d\">\n", i);
+      dump_value(stdout, 0);
+      /* Custom footnote marker string. */
+      if (match_byte (0x31))
+        dump_value(stdout, 0);
+      else
+        match_byte_assert (0x58);
+      int n = get_u32();
+      if (n >= 0)
+        {
+          /* Appears to be the number of references to a footnote. */
+          printf ("  <references n=\"%d\"/>\n", n);
+        }
+      else if (n == -2)
+        {
+          /* The user deleted the footnote references. */
+          printf ("  <deleted/>\n");
+        }
+      else
+        assert(0);
+      printf ("</footnote>\n");
+    }
+}
+
+static void
+dump_fonts(void)
+{
+  match_byte(0);
+  for (int i = 1; i <= 8; i++)
+    {
+      printf ("<style index=\"%d\"", i);
+      match_byte_assert(i);
+      match_byte_assert(0x31);
+      printf(" font=\"%s\"", get_string());
+
+      printf(" size=\"%gpt\"", get_float());
+
+      int style = get_u32();
+      if (style & 1)
+        printf(" bold=\"true\"");
+      if (style & 2)
+        printf(" italic=\"true\"");
+
+      bool underline = data[pos++];
+      if (underline)
+        printf(" underline=\"true\"");
+
+      int halign = get_u32();
+      printf(" halign=%d", halign);
+
+      int valign = get_u32();
+      printf(" valign=%d", valign);
+
+      printf (" fgcolor=\"%s\"", get_string());
+      printf (" bgcolor=\"%s\"", get_string());
+
+      if (!match_byte(0))
+        match_byte_assert(1);
+
+      char *alt_fgcolor = get_string();
+      if (alt_fgcolor[0])
+        printf (" altfg=\"%s\"", alt_fgcolor);
+      char *alt_bgcolor = get_string();
+      if (alt_bgcolor[0])
+        printf (" altbg=\"%s\"", alt_bgcolor);
+
+      if (version > 1)
+        {
+          printf(" margins=\"");
+          for (int i = 0; i < 4; i++)
+            {
+              if (i)
+                putchar(' ');
+              printf("%d", get_u32());
+            }
+          putchar('"');
+        }
+
+      printf ("/>\n");
+    }
+
+  int x1 = get_u32();
+  int x1_end = pos + x1;
+  printf("<borders>\n");
+  match_be32_assert(1);
+  int n_borders = get_be32();
+  for (int i = 0; i < n_borders; i++)
+    {
+      int type = get_be32();
+      int stroke = get_be32();
+      int color = get_be32();
+      printf("  <border type=\"%d\" stroke=\"%s\" color=\"#%06x\"/>\n",
+             type,
+             (stroke == 0 ? "none"
+              : stroke == 1 ? "solid"
+              : stroke == 2 ? "dashed"
+              : stroke == 3 ? "thick"
+              : stroke == 4 ? "thin"
+              : stroke == 5 ? "double"
+              : "<error>"),
+             color);
+    }
+  bool grid = get_byte();
+  pos += 3;
+  printf("  <grid show=\"%s\"/>\n", grid ? "yes" : "no");
+  printf("</borders>\n");
+  assert(pos == x1_end);
+
+  int skip = get_u32();
+  assert(skip == 18 || skip == 25);
+  pos += skip;
+
+  int x3 = get_u32();
+  int x3_end = pos + x3;
+  if (version == 3)
+    {
+      match_be32_assert(1);
+      get_be32();
+      printf("<settings layer=\"%d\"", get_be32());
+      if (!get_bool())
+        printf(" skipempty=\"false\"");
+      if (!get_bool())
+        printf(" showdimensionincorner=\"false\"");
+      if (!get_bool())
+        printf(" markers=\"numeric\"");
+      if (!get_bool())
+        printf(" footnoteposition=\"subscript\"");
+      get_byte();
+      int nbytes = get_be32();
+      int end = pos + nbytes;
+      printf("\n");
+      while (pos + 4 <= end)
+        printf(" %d", get_be32());
+      pos = end;
+      printf("\n");
+      pos += nbytes;
+      char *notes = get_string_be();
+      if (notes[0])
+        printf(" notes=\"%s\"", notes);
+      char *look = get_string_be();
+      if (look[0])
+        printf(" look=\"%s\"", look);
+      printf(">\n");
+    }
+  pos = x3_end;
+
+  /* Manual column widths, if present. */
+  int count = get_u32();
+  if (count > 0)
+    {
+      printf("<columnwidths>");
+      for (int i = 0; i < count; i++)
+        {
+          if (i)
+            putchar(' ');
+          printf("%d", get_u32());
+        }
+      printf("</columnwidths>\n");
+    }
+
+  const char *locale = get_string();
+  printf ("<locale>%s</locale>\n", locale);
+
+  printf ("<layer>%d</layer>\n", get_u32());
+  if (!match_byte(0))
+    match_byte_assert(1);
+  if (!match_byte(0))
+    match_byte_assert(1);
+  if (!match_byte(0))
+    match_byte_assert(1);
+  printf("<epoch>%d</epoch>\n", get_u32());
+
+  int decimal = data[pos];
+  int grouping = data[pos + 1];
+  if (match_byte('.'))
+    {
+      if (!match_byte(',') && !match_byte('\''))
+        match_byte_assert(' ');
+    }
+  else
+    {
+      match_byte_assert(',');
+      if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
+        match_byte_assert(0);
+    }
+  printf("<format decimal=\"%c\"", decimal);
+  if (grouping)
+    printf(" grouping=\"%c\"", grouping);
+  printf("\"/>\n");
+  if (match_u32(5))
+    {
+      for (int i = 0; i < 5; i++)
+        printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
+    }
+  else
+    match_u32_assert(0);
+
+  /* The last chunk is an outer envelope that contains two inner envelopes.
+     The second inner envelope has some interesting data like the encoding and
+     the locale. */
+  int outer_end = get_end();
+  if (version == 3)
+    {
+      /* First inner envelope: byte*33 int[n] int*[n]. */
+      int inner_len = get_u32();
+      int inner_end = pos + inner_len;
+      int array_start = pos + 33;
+      match_byte_assert(0);
+      pos++;                    /* 0, 1, 10 seen. */
+      get_bool();
+
+      /* 0=en 1=de 2=es 3=it 5=ko 6=pl 8=zh-tw 10=pt_BR 11=fr */
+      printf("lang=%d ", get_byte());
+
+      printf ("variable_mode=%d\n", get_byte());
+      printf ("value_mode=%d\n", get_byte());
+      if (!match_u64(0))
+        match_u64_assert(UINT64_MAX);
+      match_u32_assert(0);
+      match_u32_assert(0);
+      match_u32_assert(0);
+      match_u32_assert(0);
+      match_byte_assert(0);
+      get_bool();
+      match_byte_assert(1);
+      pos = array_start;
+
+      assert(get_end() == inner_end);
+      printf("<heights>");
+      int n_heights = get_u32();
+      for (int i = 0; i < n_heights; i++)
+        {
+          if (i)
+            putchar(' ');
+          printf("%d", get_u32());
+        }
+      printf("</heights>\n");
+
+      int n_style_map = get_u32();
+      for (int i = 0; i < n_style_map; i++)
+        {
+          uint64_t cell = get_u64();
+          int style = get_u16();
+          printf("<style-map cell=\"%lu\" style=\"%d\"/>\n", cell, style);
+        }
+
+      int n_styles = get_u32();
+      for (int i = 0; i < n_styles; i++)
+        {
+          printf("<cell-style index=\"%d\"", i);
+          dump_style(stdout);
+          dump_style2(stdout);
+          printf("/>\n");
+        }
+
+      pos = get_end();
+      assert(pos == inner_end);
+
+      /* Second inner envelope. */
+      assert(get_end() == outer_end);
+
+      match_byte_assert(1);
+      match_byte_assert(0);
+      if (!match_byte(3) && !match_byte(4))
+        match_byte_assert(5);
+      match_byte_assert(0);
+      match_byte_assert(0);
+      match_byte_assert(0);
+
+      printf("<command>%s</command>\n", get_string());
+      printf("<command-local>%s</command-local>\n", get_string());
+      printf("<language>%s</language>\n", get_string());
+      printf("<charset>%s</charset>\n", get_string());
+      printf("<locale>%s</locale>\n", get_string());
+
+      get_bool();
+      get_bool();
+      get_bool();
+      get_bool();
+
+      printf("<epoch2>%d</epoch2>\n", get_u32());
+
+      if (match_byte('.'))
+        {
+          if (!match_byte(',') && !match_byte('\''))
+            match_byte_assert(' ');
+        }
+      else
+        {
+          match_byte_assert(',');
+          if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
+            match_byte_assert(0);
+        }
+
+      printf ("small: %g\n", get_double());
+
+      match_byte_assert(1);
+      if (outer_end - pos > 6)
+        {
+          /* There might be a pair of strings representing a dataset and
+             datafile name, or there might be a set of custom currency strings.
+             The custom currency strings start with a pair of integers, so we
+             can distinguish these from a string by checking for a null byte; a
+             small 32-bit integer will always contain a null and a text string
+             never will. */
+          int save_pos = pos;
+          int len = get_u32();
+          bool has_dataset = !memchr(&data[pos], '\0', len);
+          pos = save_pos;
+
+          if (has_dataset)
+            {
+              printf("<dataset>%s</dataset>\n", get_string());
+              printf("<datafile>%s</datafile>\n", get_string());
+
+              match_u32_assert(0);
+
+              time_t date = get_u32();
+              struct tm tm = *localtime(&date);
+              char s[128];
+              strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S %z", &tm);
+              printf("<date>%s</date>\n", s);
+
+              match_u32_assert(0);
+            }
+        }
+
+      if (match_u32(5))
+        {
+          for (int i = 0; i < 5; i++)
+            printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
+        }
+      else
+        match_u32_assert(0);
+
+      match_byte_assert('.');
+      get_bool();
+
+      if (pos < outer_end)
+        {
+          get_u32();
+          match_u32_assert(0);
+        }
+      assert(pos == outer_end);
+
+      pos = outer_end;
+    }
+  else if (outer_end != pos)
+    {
+      pos += 14;
+      printf("<command>%s</command>\n", get_string());
+      printf("<command-local>%s</command-local>\n", get_string());
+      printf("<language>%s</command>\n", get_string());
+      printf("<charset>%s</charset>\n", get_string());
+      printf("<locale>%s</locale>\n", get_string());
+      get_bool();
+      match_byte_assert(0);
+      get_bool();
+      get_bool();
+
+      printf("<epoch2>%d</epoch2>\n", get_u32());
+      int decimal = data[pos];
+      int grouping = data[pos + 1];
+      if (match_byte('.'))
+        {
+          if (!match_byte(',') && !match_byte('\''))
+            match_byte_assert(' ');
+        }
+      else
+        {
+          match_byte_assert(',');
+          if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
+            match_byte_assert(0);
+        }
+      printf("<format decimal=\"%c\"", decimal);
+      if (grouping)
+        printf(" grouping=\"%c\"", grouping);
+      printf("\"/>\n");
+      if (match_u32(5))
+        {
+          for (int i = 0; i < 5; i++)
+            printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
+        }
+      else
+        match_u32_assert(0);
+
+      match_byte_assert('.');
+      get_bool();
+
+      assert(pos == outer_end);
+      pos = outer_end;
+    }
+}
+
+int
+main(int argc, char *argv[])
+{
+  if (argc != 2)
+    {
+      fprintf (stderr, "usage: %s FILE.bin", argv[0]);
+      exit (1);
+    }
+
+  filename = argv[1];
+  int fd = open(filename, O_RDONLY);
+  if (fd < 0)
+    {
+      fprintf (stderr, "%s: open failed (%s)", filename, strerror (errno));
+      exit (1);
+    }
+
+  struct stat s;
+  if (fstat(fd, &s))
+    {
+      perror("fstat");
+      exit(1);
+    }
+  n = s.st_size;
+  data = malloc(n);
+  if (!data)
+    {
+      perror("malloc");
+      exit(1);
+    }
+  if (read(fd, data, n) != n)
+    {
+      perror("read");
+      exit(1);
+    }
+  close(fd);
+
+#if 0
+  unsigned int prev_end = 0;
+  for (pos = 0; pos + 50 < n; pos++)
+    {
+      if (data[pos + 0] == 0xff &&
+          data[pos + 1] == 0xff &&
+          data[pos + 2] == 0 &&
+          data[pos + 3] == 0)
+        {
+          int len = data[pos + 4] + (data[pos + 5] << 8);
+          if (len < 3 || pos + len + 6 >= n || !all_utf8 ((char *) &data[pos + 6], len))
+            continue;
+
+          printf ("+%04x %04x...%04x: %-25.*s\n",
+                  pos - prev_end, pos, pos + 6 + len,
+                  len < 50 ? (int) len : 50, &data[pos + 6]);
+          prev_end = pos + 6 + len;
+        }
+    }
+#endif
+#if 0
+  for (pos = 0; pos + 50 < n; pos++)
+    {
+      if (data[pos + 0] == 'L' &&
+          data[pos + 1] == 'o' &&
+          data[pos + 2] == 'g' &&
+          !all_utf8((char *) &data[pos + 3], 1) &&
+          data[pos - 1] != 'v')
+        {
+          //printf ("%04x: ", pos);
+          unsigned int p = pos;
+          while (all_utf8 ((char *) &data[p], 1))
+            p--;
+          hex_dump (stdout, p - 28, 38);
+        }
+    }
+#endif
+  unsigned int prev_end = 0;
+  for (pos = 2; pos + 50 < n; pos++)
+    {
+      static const int cell_prefix[] = {
+        0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x80, 0x01, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+      };
+      size_t cell_prefix_len = sizeof cell_prefix / sizeof *cell_prefix;
+      if (match_bytes(pos, cell_prefix, cell_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x ", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          double d = *(double *) &data[pos + cell_prefix_len - 8];
+          const union
+            {
+              uint8_t b[8];
+              double d;
+            }
+          sysmis = {.b = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff}};
+          if (d == sysmis.d)
+            printf ("cell sysmis\n");
+          else
+            printf ("cell %f\n", d);
+          pos += cell_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      static const int col_prefix[] = {
+        0x11, 0x80, 0x00, -1, 0x00, 0x00, 0x00, 0x01, 0x00
+      };
+      size_t col_prefix_len = sizeof col_prefix / sizeof *col_prefix;
+      if (match_bytes(pos, col_prefix, col_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x ", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          printf ("col %d\n", data[pos + 3]);
+          pos += col_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      static const int heading_prefix[] = {
+        -1, 0x00, 0x00, 0x00, 0x50, 0x80, 0x00, 0x52, 0x80, 0x00, -1, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
+        0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
+        0x00, 0x05, 0x80, 0x01, 0x02, 0x28, 0x05, 0x00, 0x01
+      };
+      size_t heading_prefix_len = sizeof heading_prefix / sizeof *heading_prefix;
+      if (match_bytes(pos, heading_prefix, heading_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x ", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          printf ("heading %d %d\n", data[pos],data[pos + 10]);
+          pos += heading_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      static const int font_prefix[] = {
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0x80, 0x00, 0x01, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xa9,
+        0x80, 0x00, -1, 0x00, -1, 0x00, 0xc8, 0x00, -1, -1, -1, -1, -1,
+        0x00, -1, 0x00, 0x00, 0x00, 0x01, 0x00, 0xf3,
+        0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, -1, -1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x22,
+      };
+      size_t font_prefix_len = sizeof font_prefix / sizeof *font_prefix;
+      if (match_bytes(pos, font_prefix, font_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          printf ("font %d %d %d %d %d %d %d %d %d %d\n",
+                  data[pos + 24], data[pos + 26],
+                  data[pos + 30], data[pos + 31], data[pos + 32],
+                  data[pos + 33], data[pos + 34], data[pos + 36],
+                  data[pos + 58], data[pos + 59]);
+          pos += font_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      static const int table_prefix[] = {
+        0x00, 0x00, 0xed, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x02, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x41, 0x72, 0x69,
+        0x61, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, -1, 0x01, 0x00,
+        0x00,
+      };
+      size_t table_prefix_len = sizeof table_prefix / sizeof *table_prefix;
+      if (match_bytes(pos, table_prefix, table_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          printf ("table %d\n", data[pos + 74]);
+          pos += table_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      static const int dim_prefix[] = {
+        0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, -1,
+        0x00, 0x00, 0x00, 0x00, -1, 0x80, 0x01, 0x02, -1,
+        -1, -1, 0x01,
+      };
+      size_t dim_prefix_len = sizeof dim_prefix / sizeof *dim_prefix;
+      if (match_bytes(pos, dim_prefix, dim_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          printf ("dim %d %d %d %d %d\n", data[pos + 8], data[pos + 13],
+                  data[pos + 17], data[pos + 18], data[pos + 19]);
+          pos += dim_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      static const int dim2_prefix[] = {
+        0x50, 0x80, 0x00, 0x52, 0x80, 0x00, -1, 0x00, 0x00, 0x00, -1, 0, 0, 0,
+        -1, -1, -1, -1
+      };
+      size_t dim2_prefix_len = sizeof dim2_prefix / sizeof *dim2_prefix;
+      if (match_bytes(pos, dim2_prefix, dim2_prefix_len))
+        {
+          if (prev_end != pos)
+            {
+              printf ("%04x", prev_end);
+              hex_dump (stdout, prev_end, pos - prev_end);
+            }
+
+          int16_t x = *(int16_t *) &data[pos + 14];
+          int16_t y = *(int16_t *) &data[pos + 16];
+          printf ("dim2 %d %d %d %d\n", data[pos + 6], data[pos + 10], x, y);
+          pos += dim2_prefix_len - 1;
+          prev_end = pos + 1;
+          continue;
+        }
+
+      if (!is_ascii(data[pos]))
+        continue;
+
+      unsigned int start = pos;
+      unsigned int end = pos + 1;
+      while (is_ascii(data[end]))
+        end++;
+
+      unsigned int len = end - start;
+      if (len < 3)
+        continue;
+
+      unsigned int len2 = data[start - 2] + (data[start - 1] << 8);
+      unsigned int len3 = data[start - 1];
+      int length_bytes;
+      if (len2 && len2 <= len)
+        {
+          length_bytes = 2;
+          len = len2;
+        }
+      else if (len3 && len3 <= len)
+        {
+          length_bytes = 1;
+          len = len3;
+        }
+      else
+        continue;
+      if (len < 3)
+        continue;
+      end = start + len;
+
+      unsigned real_start = start - length_bytes;
+      if (prev_end != real_start)
+        {
+          printf ("%04x ", prev_end);
+          hex_dump (stdout, prev_end, real_start - prev_end);
+        }
+      printf ("%04x \"%.*s\"\n", real_start,
+              (int) end - start, (char *) &data[start]);
+      prev_end = end;
+      pos = end - 1;
+    }
+
+  exit(0);
+
+  return 0;
+}
diff --git a/spo-notes b/spo-notes
new file mode 100644 (file)
index 0000000..32ceb72
--- /dev/null
+++ b/spo-notes
@@ -0,0 +1,305 @@
+Exactly one NavRoot is always present
+
+Exactly one NavHead is present except for .spo files that are (mostly)
+empty, which have none
+
+The Nav* strings only appear once per file, as:
+ffff 0000 xxyy string
+Sometimes there is zero spacing between these.
+
+   1456  01 00 00 00 00 00 00 00 03 80 00 00 00 00 00 00-00 00 00 00 05 80 01 02 28 05 00 01    03 4c 6f 67-               07 80 00 02 00 00........................(....Log......
+      3  01 00 00 00 01 00 00 00 03 80 00 00 00 00 00 00-00 00 00 00 05 80 01 02 28 05 00 01    03 4c 6f 67-               07 80 00 02 00 00........................(....Log......
+     13     00 00 00 00 00 00 00 03 80 00 00 00 00 00 00 00-00 00 00 05 80 01 02 28 05 00 00 00 08 53 50 53-53 20 4c 6f 67 07.......................(.....SPSS Log.
+     13     00 00 00 00 00 00 00 03 80 00 00 00 00 00 00 00-00 00 00 07 80 01 02 28 05 00 00 00 08 53 50 53-53 20 4c 6f 67 09.......................(.....SPSS Log.
+     13  01 00 00 00 00 00 00 00 03 80 00 00 00 00 00 00-00 00 00 00 05 80 01 02 28 05 00 01    08 53 50 53-53 20 4c 6f 67 07........................(....SPSS Log.
+notea.spo/Contents
+
+00000000  02 00 00 00 00 
+                        14 53 50  53 53 20 4f 75 74 70 75  |......SPSS Outpu|
+00000010  74 20 44 6f 63 75 6d 65  6e 74 
+                                        00 00 00 00 ff ff  |t Document......|
+00000020  00 00 
+               07 00 4e 61 76 48  65 61 64 02 
+                                              00 00 00 00  |....NavHead.....|
+00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
+00000040  00 00 00 00 01 00 00 00  
+                                  00 00 00 00 ff ff 00 00  |................|
+00000050  0d 00 44 73 70 53 69 6d  70 6c 65 54 65 78 74 
+                                                       00  |..DspSimpleText.|
+00000060  00 00 00 00 00 
+                        00 00 00  00 ff ff 00 00 
+                                                 09 00 44  |...............D|
+00000070  73 70 53 74 72 69 6e 67  
+                                  01 02 28 05 00 01 
+                                                    0b 46  |spString..(....F|
+00000090  4e 61 76 54 72 65 65 56  69 65 77 49 74 65 6d 
+                                                       00  |NavTreeViewItem.|
+000000a0  00 00 00 00 02 00 01 00  00 00 00 00 00 00 00 00  |................|
+000000b0  01 00 00 00 00 00 
+                           0b 46  72 65 71 75 65 6e 63 69  |.......Frequenci|
+000000c0  65 73 
+               00 00 00 18 00 00  00 d8 ff ff ff de ff ff  |es..............|
+000000d0  ff 18 00 00 00 d8 ff ff  ff 28 00 00 00 28 00 00  |.........(...(..|
+000000e0  00 18 04 00 00 46 1e 00  00 00 00 35 e8 00 34 21  |.....F.....5..4!|
+000000f0  00 00 f8 2a 00 00 01 00  0f 00 01 00 f6 04 00 00  |...*............|
+00000100  f6 04 00 00 f6 04 00 00  f6 04 00 00 00 00 f0 00  |................|
+00000110  00 00 69 32 01 00 
+                           0b 28  43 6f 6e 74 69 6e 75 65  |..i2...(Continue|
+00000120  64 29 
+               00 
+                  b4 00 00 00 7b  5c 72 74 66 31 5c 61 6e  |d).....{\rtf1\an|
+00000130  73 69 5c 61 6e 73 69 63  70 67 31 32 35 32 5c 64  |si\ansicpg1252\d|
+00000140  65 66 66 30 5c 64 65 66  6c 61 6e 67 31 30 33 33  |eff0\deflang1033|
+00000150  7b 5c 66 6f 6e 74 74 62  6c 7b 5c 66 30 5c 66 73  |{\fonttbl{\f0\fs|
+00000160  77 69 73 73 5c 66 70 72  71 32 5c 66 63 68 61 72  |wiss\fprq2\fchar|
+00000170  73 65 74 30 20 41 72 69  61 6c 3b 7d 7d 0d 0a 7b  |set0 Arial;}}..{|
+00000180  5c 63 6f 6c 6f 72 74 62  6c 20 3b 5c 72 65 64 30  |\colortbl ;\red0|
+00000190  5c 67 72 65 65 6e 30 5c  62 6c 75 65 30 3b 7d 0d  |\green0\blue0;}.|
+000001a0  0a 5c 76 69 65 77 6b 69  6e 64 34 5c 75 63 31 5c  |.\viewkind4\uc1\|
+000001b0  70 61 72 64 5c 71 63 5c  63 66 31 5c 66 30 5c 66  |pard\qc\cf1\f0\f|
+000001c0  73 32 30 20 26 5b 50 61  67 65 54 69 74 6c 65 5d  |s20 &[PageTitle]|
+000001d0  0d 0a 5c 70 61 72 20 7d  0d 0a 
+                                        
+                                        00 00
+                                              
+                                              b4 00 00 00  |..\par }........|
+000001e0  7b 5c 72 74 66 31 5c 61  6e 73 69 5c 61 6e 73 69  |{\rtf1\ansi\ansi|
+000001f0  63 70 67 31 32 35 32 5c  64 65 66 66 30 5c 64 65  |cpg1252\deff0\de|
+00000200  66 6c 61 6e 67 31 30 33  33 7b 5c 66 6f 6e 74 74  |flang1033{\fontt|
+00000210  62 6c 7b 5c 66 30 5c 66  73 77 69 73 73 5c 66 70  |bl{\f0\fswiss\fp|
+00000220  72 71 32 5c 66 63 68 61  72 73 65 74 30 20 41 72  |rq2\fcharset0 Ar|
+00000230  69 61 6c 3b 7d 7d 0d 0a  7b 5c 63 6f 6c 6f 72 74  |ial;}}..{\colort|
+00000240  62 6c 20 3b 5c 72 65 64  30 5c 67 72 65 65 6e 30  |bl ;\red0\green0|
+00000250  5c 62 6c 75 65 30 3b 7d  0d 0a 5c 76 69 65 77 6b  |\blue0;}..\viewk|
+00000260  69 6e 64 34 5c 75 63 31  5c 70 61 72 64 5c 71 72  |ind4\uc1\pard\qr|
+00000270  5c 63 66 31 5c 66 30 5c  66 73 32 30 20 50 61 67  |\cf1\f0\fs20 Pag|
+00000280  65 20 26 5b 50 61 67 65  5d 0d 0a 5c 70 61 72 20  |e &[Page]..\par |
+00000290  7d 0d 0a 
+                  
+                  00 00 14 00 ff  ff 00 00 
+                                           
+                                           07 00 4e 61 76  |}............Nav|
+000002a0  52 6f 6f 74 
+                     
+                     02 00 00 00  00 00 00 00 00 00 00 00  |Root............|
+000002b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
+000002c0  00 00 00 00 00 03 80 00  00 00 00 00 00 00 00 00  |................|
+000002d0  00 05 80 01 02 28 00 00  01 
+                                     
+                                     06 4f 75 74 70 75 74  |.....(....Output|
+000002e0  07 80 00 00 00 00 00 0a  00 01 00 00 00 00 00 00  |................|
+000002f0  00 00 00 01 00 00 00 
+                              00  00 00 00 ff ff 00 00 
+                                                       06  |................|
+00000300  00 4e 61 76 4c 6f 67 
+                              02  00 00 00 00 00 00 00 00  |.NavLog.........|
+00000310  18 00 00 00 d8 ff ff ff  b3 02 00 00 45 f9 ff ff  |............E...|
+00000320  01 00 00 00 00 00 00 00  03 80 00 00 00 00 00 00  |................|
+00000330  00 00 00 00 05 80 01 02  28 05 00 01 
+                                              
+                                              03 4c 6f 67  |........(....Log|
+00000340  07 80 00 02 00 00 00 
+                              0f  00 01 00 ff ff 00 00 
+                                                       0a  |................|
+00000350  00 4e 61 76 4f 6c 65 49  74 65 6d 
+                                           
+                                           00 01 00 00 01  |.NavOleItem.....|
+00000360  00 00 00 01 00 00 00 00  00 01 00 00 00 00 00 00  |................|
+00000370  00 00 00 00 01 00 00 00  00 00 00 01 01 f3 ff ff  |................|
+00000380  ff 00 00 00 00 00 00 00  00 00 00 00 00 90 01 00  |................|
+00000390  00 00 00 00 00 00 00 00  
+                                  
+                                  31 43 6f 75 72 69 65 72  |........1Courier|
+000003a0  20 4e 65 77 00 72 00 20  00 4e 00 65 00 77 00 00  | New.r. .N.e.w..|
+000003b0  00 00 00 00 00 00 00 00  00 50 00 00 00 00 00 00  |.........P......|
+000003c0  00 00 00 00 00 01 00 00  00 
+                                     df 14 00 00 7b 5c 72  |.............{\r|
+000003d0  74 66 31 5c 61 6e 73 69  5c 61 6e 73 69 63 70 67  |tf1\ansi\ansicpg|
+000003e0  31 32 35 32 5c 64 65 66  66 30 5c 64 65 66 6c 61  |1252\deff0\defla|
+000003f0  6e 67 31 30 33 33 7b 5c  66 6f 6e 74 74 62 6c 7b  |ng1033{\fonttbl{|
+00000400  5c 66 30 5c 66 6d 6f 64  65 72 6e 5c 66 70 72 71  |\f0\fmodern\fprq|
+00000410  31 5c 66 63 68 61 72 73  65 74 30 20 43 6f 75 72  |1\fcharset0 Cour|
+...
+000018a0  20 0d 0a 5c 70 61 72 20  7d 0d 0a 
+                                           
+                                           00 00 0e 80 02  | ..\par }.......|
+000018b0  00 00 00 00 00 00 00 00  18 00 00 00 23 f9 ff ff  |............#...|
+000018c0  b3 02 00 00 53 f1 ff ff  01 00 00 00 00 00 00 00  |....S...........|
+000018d0  03 80 00 00 00 00 00 00  00 00 00 00 05 80 01 02  |................|
+000018e0  28 05 00 01 
+                     
+                     03 4c 6f 67
+                                  
+                                  07 80 00 02 00 00 00 15  |(....Log........|
+000018f0  00 01 00 13 80 00 01 00  00 02 00 00 00 01 00 00  |................|
+00001900  00 00 00 01 00 00 00 00  00 00 00 00 00 00 01 00  |................|
+00001910  00 00 00 00 00 01 01 0a  00 00 00 00 00 00 00 00  |................|
+00001920  00 00 00 00 00 00 00 90  01 00 00 00 00 00 00 00  |................|
+00001930  00 00 
+               
+               31 43 6f 75 72 69  65 72 20 4e 65 77 00 72  |..1Courier New.r|
+00001940  00 20 00 4e 00 65 00 77  00 00 00 00 00 00 00 00  |. .N.e.w........|
+00001950  00 00 00 50 00 00 00 00  00 00 00 00 00 00 00 01  |...P............|
+00001960  00 00 00 
+                  
+                  69 2b 00 00 7b  5c 72 74 66 31 5c 61 6e  |...i+..{\rtf1\an|
+00001970  73 69 5c 61 6e 73 69 63  70 67 31 32 35 32 5c 64  |si\ansicpg1252\d|
+00001980  65 66 66 30 5c 64 65 66  6c 61 6e 67 31 30 33 33  |eff0\deflang1033|
+00001990  7b 5c 66 6f 6e 74 74 62  6c 7b 5c 66 30 5c 66 6d  |{\fonttbl{\f0\fm|
+000019a0  6f 64 65 72 6e 5c 66 70  72 71 31 5c 66 63 68 61  |odern\fprq1\fcha|
+000019b0  72 73 65 74 30 20 43 6f  75 72 69 65 72 20 4e 65  |rset0 Courier Ne|
+...
+000044c0  63 75 74 65 2e 0d 0a 5c  70 61 72 20 7d 0d 0a 
+                                                       
+                                                       00  |cute...\par }...|
+000044d0  00 0e 80 02 00 00 00 00  00 00 00 00 18 00 00 00  |................|
+000044e0  31 f1 ff ff b3 02 00 00  ee f0 ff ff 01 00 00 00  |1...............|
+000044f0  00 00 00 00 03 80 00 00  00 00 00 00 00 00 00 00  |................|
+00004500  05 80 01 02 28 05 00 01  
+                                  
+                                  03 4c 6f 67 07 80 00 02  |....(....Log....|
+00004510  00 00 00 1a 00 01 00 00  00 00 00 00 00 00 00 01  |................|
+00004520  00 00 00 00 00 00 01 01  0a 00 00 00 00 00 00 00  |................|
+00004530  00 00 00 00 00 00 00 00  90 01 00 00 00 00 00 00  |................|
+00004540  00 00 00 
+                  
+                  31 43 6f 75 72  69 65 72 20 4e 65 77 00  |...1Courier New.|
+00004550  72 00 20 00 4e 00 65 00  77 00 00 00 00 00 00 00  |r. .N.e.w.......|
+00004560  00 00 00 00 50 00 00 00  00 00 00 00 00 00 00 00  |....P...........|
+00004570  01 00 00 00 
+                     
+                     3c 01 00 00  7b 5c 72 74 66 31 5c 61  |....<...{\rtf1\a|
+...
+000046b0  7d 0d 0a 
+                  
+                  00 00 02 00 ff  ff 00 00 
+                                           
+                                           08 00 4e 61 76  |}............Nav|
+000046c0  54 69 74 6c 65 
+                        
+                        02 00 00  00 00 00 00 00 00 18 00  |Title...........|
+000046d0  00 00 cc f0 ff ff 00 04  00 00 b5 f0 ff ff 02 00  |................|
+000046e0  00 00 01 00 00 00 03 80  00 00 00 00 00 00 00 00  |................|
+000046f0  00 00 05 80 01 02 28 00  00 01 
+                                        
+                                        05 54 69 74 6c 65  |......(....Title|
+00004700  07 80 00 08 00 00 00 1f  00 01 00 00 00 00 00 00  |................|
+00004710  00 00 00 01 00 00 00 00  00 
+                                     
+                                     0b 46 72 65 71 75 65  |..........Freque|
+00004720  6e 63 69 65 73 
+                        
+                        01 01 ed  ff ff ff 00 00 00 00 00  |ncies...........|
+00004730  00 00 00 00 00 00 00 bc  02 00 00 00 00 00 00 00  |................|
+00004740  00 00 
+               
+               22 41 72 69 61 6c  00 61 00 6c 00 00 00 00  |.."Arial.a.l....|
+00004750  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
+00004760  00 00 00 50 00 
+                        
+                        00 00 00  00 00 00 00 00 00 00 01  |...P............|
+00004770  00 00 00 
+                  
+                  b2 00 00 00 7b  5c 72 74 66 31 5c 61 6e  |.......{\rtf1\an|
+00004780  73 69 5c 61 6e 73 69 63  70 67 31 32 35 32 5c 64  |si\ansicpg1252\d|
+00004790  65 66 66 30 5c 64 65 66  6c 61 6e 67 31 30 33 33  |eff0\deflang1033|
+000047a0  7b 5c 66 6f 6e 74 74 62  6c 7b 5c 66 30 5c 66 73  |{\fonttbl{\f0\fs|
+000047b0  77 69 73 73 5c 66 70 72  71 32 5c 66 63 68 61 72  |wiss\fprq2\fchar|
+000047c0  73 65 74 30 20 41 72 69  61 6c 3b 7d 7d 0d 0a 7b  |set0 Arial;}}..{|
+000047d0  5c 63 6f 6c 6f 72 74 62  6c 20 3b 5c 72 65 64 30  |\colortbl ;\red0|
+000047e0  5c 67 72 65 65 6e 30 5c  62 6c 75 65 30 3b 7d 0d  |\green0\blue0;}.|
+000047f0  0a 5c 76 69 65 77 6b 69  6e 64 34 5c 75 63 31 5c  |.\viewkind4\uc1\|
+00004800  70 61 72 64 5c 63 66 31  5c 62 5c 66 30 5c 66 73  |pard\cf1\b\f0\fs|
+00004810  32 38 20 46 72 65 71 75  65 6e 63 69 65 73 0d 0a  |28 Frequencies..|
+00004820  5c 70 61 72 20 7d 0d 0a  
+                                  
+                                  00 00 ff ff 00 00 
+                                                    
+                                                    07 00  |\par }..........|
+00004830  4e 61 76 4e 6f 74 65 
+                              
+                              02  00 00 00 00 00 00 00 00  |NavNote.........|
+00004840  18 00 00 00 d8 ff ff ff  00 02 00 00 59 fe ff ff  |............Y...|
+00004850  02 00 00 00 01 00 00 00  03 80 00 00 00 00 00 00  |................|
+00004860  00 00 00 00 05 80 01 02  28 05 00 01 
+                                              
+                                              05 4e 6f 74  |........(....Not|
+00004870  65 73 
+               
+               07 80 00 07 00 00  00 24 00 01 00 00 00 01  |es.......$......|
+00004880  00 00 00 00 00 01 00 00  00 00 00 
+                                           
+                                           0b 46 72 65 71  |............Freq|
+00004890  75 65 6e 63 69 65 73 
+                              01  ff ff 00 00 
+                                              11 00 50 54  |uencies.......PT|
+000048a0  50 69 76 6f 74 43 6f 6e  74 72 6f 6c 6c 65 72 
+                                                       
+                                                       02  |PivotController.|
+000048b0  29 20 69 31 38 28 66 38  64 00 00 00 64 00 00 00  |) i18(f8d...d...|
+000048c0  64 00 00 00 64 00 00 00  ff ff 00 00 
+                                              0b 00 50 56  |d...d.........PV|
+000048d0  50 69 76 6f 74 56 69 65  77 
+                                     04 00 00 00 00 ff ff  |PivotView.......|
+000048e0  00 00 
+               0c 00 50 4d 50 69  76 6f 74 4d 6f 64 65 6c  |....PMPivotModel|
+000048f0  03 ff ff 00 00 
+                        15 00 4e  44 69 6d 65 6e 73 69 6f  |.......NDimensio|
+00004900  6e 61 6c 5f 5f 44 73 70  43 65 6c 6c 
+                                              00 01 00 00  |nal__DspCell....|
+00004910  00 ff ff 00 00 
+                        11 00 49  6e 64 65 78 65 64 43 6f  |.......IndexedCo|
+00004920  6c 6c 65 63 74 69 6f 6e  
+                                  00 0d 00 00 00 01 00 ff  |llection........|
+00004930  ff 00 00 
+                  07 00 44 73 70  43 65 6c 6c 
+                                              00 03 80 00  |.....DspCell....|
+00004940  00 00 00 00 00 00 00 00  00 05 80 01 02 28 05 00  |.............(..|
+00004950  01 
+            
+            12 32 38 20 53 65 70  20 30 37 20 31 33 3a 32  |..28 Sep 07 13:2|
+00004960  38 3a 34 32 32 
+                        
+                        80 00 03  80 00 00 00 00 00 00 00  |8:422...........|
+00004970  00 00 00 05 80 01 02 28  05 00 01 01 20 00 00 32  |.......(.... ..2|
+00004980  80 00 03 80 00 00 00 00  00 00 00 00 00 00 05 80  |................|
+00004990  01 02 28 05 00 01 
+                           
+                           06 3c  6e 6f 6e 65 3e 
+                                                 32 80 00  |..(....<none>2..|
+000049a0  03 80 00 00 00 00 00 00  00 00 00 00 05 80 01 02  |................|
+000049b0  28 05 00 
+                  01 06 3c 6e 6f  6e 65 3e 
+                                           32 80 00 03 80  |(....<none>2....|
+000049c0  00 00 00 00 00 00 00 00  00 00 05 80 01 02 28 05  |..............(.|
+000049d0  00 01 
+               06 3c 6e 6f 6e 65  3e 
+                                     32 80 00 03 80 00 00  |...<none>2......|
+000049e0  00 00 00 00 00 00 00 00  ff ff 00 00 
+                                              09 00 44 73  |..............Ds|
+000049f0  70 4e 75 6d 62 65 72 
+                              01  00 28 05 80 02 00 00 00  |pNumber..(......|
+00004a00  00 00 80 52 40 02 37 34  32 80 00 03 80 00 00 00  |...R@.742.......|
+00004a10  00 00 00 00 00 00 00 05  80 01 02 28 05 00 01 33  |...........(...3|
+00004a20  55 73 65 72 2d 64 65 66  69 6e 65 64 20 6d 69 73  |User-defined mis|
+
+----------------------------------------------------------------------
+
+Output1.spo:
+
+1f33  28 80 00 03 80 00 00 00 00 00 00 00 00 00 00 3d 80 F40.0(01 00 28) 05 80 02 30000.0
+@
+1f52 "30000"
+
+2103  28 80 00 03 80 00 00 00 00 00 00 00 00 00 00 3d 80 F40.1(01 01 28) 05 80 02 66.7
+2122 "66.7"
+
+each cell has the form (where [01] is the number of decimals):
+28 80 00 03 80 00 00 00 00 00 00 00 00 00 00 3d 80 01 0[01] 28 05 80 02 then a double then the string
+each column(?) is preceded by 
+11 80 00 0[345] 00 00 00 01 00
+
+starting around 1c85
+
+16#2134 == 8500
+16#2af8 == 11000