Do a little work toward dumping the non-"light" tables.
[pspp] / dump2.c
1 #include <stdbool.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/stat.h>
7 #include <unistd.h>
8
9 static uint8_t *data;
10 static size_t n;
11
12 int
13 main(int argc, char **argv)
14 {
15   size_t start;
16   struct stat s;
17
18   if (isatty(STDIN_FILENO))
19     {
20       fprintf(stderr, "redirect stdin from a .bin file\n");
21       exit(1);
22     }
23   if (fstat(STDIN_FILENO, &s))
24     {
25       perror("fstat");
26       exit(1);
27     }
28   n = s.st_size;
29   data = malloc(n);
30   if (!data)
31     {
32       perror("malloc");
33       exit(1);
34     }
35   if (read(STDIN_FILENO, data, n) != n)
36     {
37       perror("read");
38       exit(1);
39     }
40
41   if (argc < 3)
42     {
43       fprintf(stderr, "bad arguments");
44       exit(1);
45     }
46
47   start = strtol(argv[1], NULL, 0);
48   int end = strtol(argv[2], NULL, 0);
49   for (int pos = start; pos < end; pos += 8)
50     {
51       double d;
52       memcpy(&d, &data[pos], sizeof d);
53       printf("%g\n", d);
54     }
55   return 0;
56 }