db8a60d9ed17497baa207a0b0912e7fefc44f46a
[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", pivot_value_to_string_defaults (item->text));
55       break;
56
57     case SPV_ITEM_TABLE:
58       if (item->table)
59         pivot_table_dump (item->table, indentation + 1);
60       else
61         {
62           printf ("unloaded table in %s", item->bin_member);
63           if (item->xml_member)
64             printf (" and %s", item->xml_member);
65           putchar ('\n');
66         }
67       break;
68
69     case SPV_ITEM_GRAPH:
70       printf ("graph\n");
71       break;
72
73     case SPV_ITEM_MODEL:
74       printf ("model\n");
75       break;
76
77     case SPV_ITEM_IMAGE:
78       printf ("image in %s\n", item->png_member);
79       break;
80
81     case SPV_ITEM_TREE:
82       printf ("tree\n");
83       break;
84     }
85 }