Do a little work toward dumping the non-"light" tables.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 7 Nov 2014 03:09:51 +0000 (19:09 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 7 Nov 2014 03:09:51 +0000 (19:09 -0800)
.gitignore
Makefile
dump.c
dump2.c [new file with mode: 0644]
notes2 [new file with mode: 0644]

index ad1ca01a94aef3769045f7ab8e3c43548281e22f..4033d25e44d57a24c1845179410ba638da729829 100644 (file)
@@ -7,4 +7,4 @@ dump
 tdump*
 ndump*
 pspp.jnl
-
+dump2
index 5a0f07c4d1bfa4e4f0f36c8ca72f6ced2b15d501..59fcc0beb2393cb02fbd73010a9cc1f98ada0884 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,4 @@
 CFLAGS = -std=gnu99 -Wall -Werror -g -D_GNU_SOURCE=1
+all: dump dump2
 dump: dump.o
+dump2: dump2.o
diff --git a/dump.c b/dump.c
index 4b274808558d52d2a8435f86051de6e6c4980e87..58dbd498b409a1a5edba15fac623f3bbd037078d 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -159,7 +159,7 @@ dump_value(int level)
   match_byte (0);
   if (match_byte (3))
     {
-      get_string();
+      char *s1 = get_string();
       if (match_byte (0x31))
         {
           if (match_u32 (1))
@@ -201,8 +201,12 @@ dump_value(int level)
         }
       else
         match_byte_assert (0x58);
-      get_string();
-      printf("string \"%s\"", get_string());
+      char *s2 = get_string();
+      char *s3 = get_string();
+      if (strcmp(s1, s3))
+        printf("strings \"%s\", \"%s\" and \"%s\"", s1, s2, s3);
+      else
+        printf("string \"%s\" and \"%s\"", s1, s2);
       match_byte (0);
       match_byte (0);
       match_byte (0);
@@ -1491,10 +1495,10 @@ static void
 dump_title(void)
 {
   pos = 0x27;
-  dump_title_value(0); putchar('\n'); putchar('\n');
-  dump_title_value(0); putchar('\n'); putchar('\n');
+  dump_title_value(0); putchar('\n');
+  dump_title_value(0); putchar('\n');
   match_byte_assert(0x31);
-  dump_title_value(0); putchar('\n'); putchar('\n');
+  dump_title_value(0); putchar('\n');
   match_byte(0);
   match_byte_assert(0x58);
   if (match_byte(0x31))
diff --git a/dump2.c b/dump2.c
new file mode 100644 (file)
index 0000000..9eb0f5b
--- /dev/null
+++ b/dump2.c
@@ -0,0 +1,56 @@
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static uint8_t *data;
+static size_t n;
+
+int
+main(int argc, char **argv)
+{
+  size_t start;
+  struct stat s;
+
+  if (isatty(STDIN_FILENO))
+    {
+      fprintf(stderr, "redirect stdin from a .bin file\n");
+      exit(1);
+    }
+  if (fstat(STDIN_FILENO, &s))
+    {
+      perror("fstat");
+      exit(1);
+    }
+  n = s.st_size;
+  data = malloc(n);
+  if (!data)
+    {
+      perror("malloc");
+      exit(1);
+    }
+  if (read(STDIN_FILENO, data, n) != n)
+    {
+      perror("read");
+      exit(1);
+    }
+
+  if (argc < 3)
+    {
+      fprintf(stderr, "bad arguments");
+      exit(1);
+    }
+
+  start = strtol(argv[1], NULL, 0);
+  int end = strtol(argv[2], NULL, 0);
+  for (int pos = start; pos < end; pos += 8)
+    {
+      double d;
+      memcpy(&d, &data[pos], sizeof d);
+      printf("%g\n", d);
+    }
+  return 0;
+}
diff --git a/notes2 b/notes2
new file mode 100644 (file)
index 0000000..0022c6b
--- /dev/null
+++ b/notes2
@@ -0,0 +1,75 @@
+0000: magic number 00 b0 01 00
+0004: file size in bytes
+0008: number of data cells, <N>
+000c: ?
+0010: 58 00 00 00
+0014: "tableData"
+0050: 00 00 00 00 00
+0055: three random-ish bytes that sometimes resemble ASCII and might just be garbage
+0058: "cell"  (note pointer header from 0x10)
+0178: First bytes of data; <N> doubles
+
+
+
+./web/0e2ecc3c2b47dbd86a1bdceb89b8a4d4/00000000085_-4179390934077669371_tableData.bin:
+
+80 cells
+80 cell formats
+80 dimension0categories
+80 dimension0labels
+80 dimension1categories
+80 dimension1labels
+80 dimension2categories
+80 dimension2labels
+80 dimension3categories
+80 dimension3labels
+80 footnotes
+i1 tableData
+
+
+
+
+
+./web/0e2ecc3c2b47dbd86a1bdceb89b8a4d4/00000000013_-4179390934085009405_tableData.bin:
+
+8 cells
+4 formats
+8 dimension0categories
+8 dimension0group0
+8 dimension0group0Label
+8 dimension0labels
+8 dimension1categories
+8 dimension1labels
+i1 tabledata
+i8 cell
+i0 cellFormat
+i0 dimension0categories
+i0 dimension0group0
+i0 dimension0group0Label
+
+
+
+0000: 00 b0 01 00 56 0d
+0010: "X"
+0014: "tableData"
+0055: 14"cell
+0170: 0 1231 1232 1 0 0 0 1 2
+01b8: "cellFormat"
+02d8: 5(40.0) * 8
+0318: "dimension0categories"
+0448: 1 1 2 2 3 3
+0478: "dimension0group0"
+0598: 2 2 2 2 3 3 3 3 3
+05d8: "dimension0group0label"
+06f8: sysmis * 8
+0738: "dimension0labels"
+0858: sysmis * 8
+0898: "dimension1categories"
+09c0: 1 0 1 0 1 0 1
+09f8: "dimension1labels"
+0b18: sysmis * 8
+0b58: i1 i9 "tableData" i8 i4 "cell" i0 i10 "cellFormat" i0 i20 "dimension0categories" i0 i16 "dimension0group0"
+      i0 i21 "dimension0group0Label" i8 i0 i6 i1 i6 i2 i6 i3 i6 i4 i7 i5 i7 i6 i7 i7 i7 i16 "dimension0labels" i8 i0 i0 i1
+      i0 i2 i3 i3 i3 i4 i4 i5 i4 i6 i5 i7  i5 i20 "dimension1categories" i0 i16 "dimension1labels" i8 i0 i1
+      i1 i2 i2 i1 i3 i2 i4 i1 i5 i2 i6 i1 i7 i2 i8 i2 i5 "Valid" i4 i6 "Gender" i4 i9 "Education" i2 i7 "Missing" i2 i7
+      "Minimum" i2 i7 "Maximum" i4 i1 "N" i4 i0