Add support for reading and writing SPV files.
[pspp] / src / output / spv / spv-dump.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2017, 2018 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include "output/spv/spv.h"
20
21 #include <inttypes.h>
22 #include <stdlib.h>
23
24 #include "data/settings.h"
25 #include "output/pivot-table.h"
26
27 #include "gl/xalloc.h"
28
29 static void
30 indent (int indentation)
31 {
32   for (int i = 0; i < indentation * 2; i++)
33     putchar (' ');
34 }
35
36 void
37 spv_item_dump (const struct spv_item *item, int indentation)
38 {
39   indent (indentation);
40   if (item->label)
41     printf ("\"%s\" ", item->label);
42   if (!item->visible)
43     printf ("(hidden) ");
44
45   switch (item->type)
46     {
47     case SPV_ITEM_HEADING:
48       printf ("heading\n");
49       for (size_t i = 0; i < item->n_children; i++)
50         spv_item_dump (item->children[i], indentation + 1);
51       break;
52
53     case SPV_ITEM_TEXT:
54       printf ("text \"%s\"\n",
55               pivot_value_to_string (item->text, SETTINGS_VALUE_SHOW_DEFAULT,
56                                      SETTINGS_VALUE_SHOW_DEFAULT));
57       break;
58
59     case SPV_ITEM_TABLE:
60       if (item->table)
61         pivot_table_dump (item->table, indentation + 1);
62       else
63         {
64           printf ("unloaded table in %s", item->bin_member);
65           if (item->xml_member)
66             printf (" and %s", item->xml_member);
67           putchar ('\n');
68         }
69       break;
70
71     case SPV_ITEM_GRAPH:
72       printf ("graph\n");
73       break;
74
75     case SPV_ITEM_MODEL:
76       printf ("model\n");
77       break;
78
79     case SPV_ITEM_OBJECT:
80       printf ("object type=\"%s\" uri=\"%s\"\n", item->object_type, item->uri);
81       break;
82     }
83 }