some more type decls
[pspp] / src / language / stats / ctables.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2021 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 "language/command.h"
20 #include "language/lexer/lexer.h"
21 #include "libpspp/hmap.h"
22 #include "libpspp/message.h"
23 #include "output/pivot-table.h"
24
25 #include "gl/xalloc.h"
26
27 #include "gettext.h"
28 #define _(msgid) gettext (msgid)
29
30 struct ctables
31   {
32     struct pivot_table_look *look;
33
34     /* If this is NULL, zeros are displayed using the normal print format.
35        Otherwise, this string is displayed. */
36     char *zero;
37
38     /* If this is NULL, missing values are displayed using the normal print
39        format.  Otherwise, this string is displayed. */
40     char *missing;
41
42     /* Contains "struct ctables_vlabel" structs.  */
43     struct hmap vlabels;
44
45     bool mrsets_count_duplicates; /* MRSETS. */
46     bool smissing_listwise;       /* SMISSING. */
47     struct variable *base_weight; /* WEIGHT. */
48     double hide_threshold;        /* HIDESMALLCOUNTS. */
49
50     struct ctables_table *tables;
51     size_t n_tables;
52   };
53
54 struct ctables_vlabel
55   {
56     struct hmap_node hmap_node; /* In struct ctables's 'vlabels' hmap. */
57     const char *name;           /* Variable name. */
58
59     /* SETTINGS_VALUE_SHOW_DEFAULT is interpreted as "none". */
60     enum settings_value_show show;
61   };
62
63 struct ctables_postcompute
64   {
65     struct hmap_node hmap_node; /* In struct ctables's 'pcompute' hmap. */
66     const char *name;           /* Name, without leading &. */
67
68     struct ctables_postcompute_expr *expr;
69     char *label;
70     /* XXX FORMAT */
71     bool hide_source_cats;
72   };
73
74 struct ctables_postcompute_expr
75   {
76     enum ctables_postcompute_op
77       {
78         /* Terminals. */
79         CTPO_CAT_NUMBER,
80         CTPO_CAT_STRING,
81         CTPO_CAT_RANGE,
82         CTPO_CAT_MISSING,
83         /* XXX OTHERNM */
84         /* XXX SUBTOTAL and HSUBTOTAL */
85
86         /* Nonterminals. */
87         CTPO_ADD,
88         CTPO_SUB,
89         CTPO_MUL,
90         CTPO_DIV,
91         CTPO_POW,
92       }
93     op;
94
95     union
96       {
97         /* CTPO_CAT_NUMBER, CTPO_NUMBER. */
98         double number;
99
100         /* CTPO_CAT_RANGE.
101
102            XXX what about string ranges? */
103         struct
104           {
105             double low;         /* -DBL_MAX for LO. */
106             double high;        /* DBL_MAX for HIGH. */
107           }
108         range;
109
110         /* CTPO_ADD, CTPO_SUB, CTPO_MUL, CTPO_DIV, CTPO_POW. */
111         struct ctables_postcompute_expr *subs[2];
112       };
113   };
114
115 struct ctables_table
116   {
117     struct ctables_axis *axes[PIVOT_N_AXES];
118
119
120   };
121
122 struct ctables_axis
123   {
124     enum ctables_axis_op
125       {
126         /* Terminals. */
127         CTAO_VAR,
128         CTAO_MRSET,
129
130         /* Nonterminals. */
131         CTAO_CONCAT,            /* + */
132         CTAO_NEST,              /* > */
133       }
134     op;
135
136     union
137       {
138         /* Terminals. */
139         struct
140           {
141             union
142               {
143                 struct variable *var;
144                 struct mrset *mrset;
145               };
146
147             bool scale;
148             struct ctables_summary *summaries;
149             size_t n_summaries;
150           };
151
152         /* Nonterminals. */
153         struct ctables_axis *subs[2];
154       };
155   };
156
157 struct ctables_summary
158   {
159     enum ctables_summary_function
160       {
161         /* All variables. */
162         CTSF_COUNT,
163         CTSF_ECOUNT,
164         CTSF_ROWPCT_COUNT,
165         CTSF_COLPCT_COUNT,
166         CTSF_TABLEPCT_COUNT,
167         CTSF_SUBTABLEPCT_COUNT,
168         CTSF_LAYERPCT_COUNT,
169         CTSF_LAYERROWPCT_COUNT,
170         CTSF_LAYERCOLPCT_COUNT,
171         CTSF_ROWPCT_VALIDN,
172         CTSF_COLPCT_VALIDN,
173         CTSF_TABLEPCT_VALIDN,
174         CTSF_SUBTABLEPCT_VALIDN,
175         CTSF_LAYERPCT_VALIDN,
176         CTSF_LAYERROWPCT_VALIDN,
177         CTSF_LAYERCOLPCT_VALIDN,
178         CTSF_ROWPCT_TOTALN,
179         CTSF_COLPCT_TOTALN,
180         CTSF_TABLEPCT_TOTALN,
181         CTSF_SUBTABLEPCT_TOTALN,
182         CTSF_LAYERPCT_TOTALN,
183         CTSF_LAYERROWPCT_TOTALN,
184         CTSF_LAYERCOLPCT_TOTALN,
185
186         /* Scale variables, totals, and subtotals. */
187         CTSF_MAXIMUM,
188         CTSF_MEAN,
189         CTSF_MEDIAN,
190         CTSF_MINIMUM,
191         CTSF_MISSING,
192         CTSF_MODE,
193         CTSF_PTILE,
194         CTSF_RANGE,
195         CTSF_SEMAN,
196         CTSF_STDDEV,
197         CTSF_SUM,
198         CSTF_TOTALN,
199         CTSF_ETOTALN,
200         CTSF_VALIDN,
201         CTSF_EVALIDN,
202         CTSF_VARIANCE,
203         CTSF_ROWPCT_SUM,
204         CTSF_COLPCT_SUM,
205         CTSF_TABLEPCT_SUM,
206         CTSF_SUBTABLEPCT_SUM,
207         CTSF_LAYERPCT_SUM,
208         CTSF_LAYERROWPCT_SUM,
209         CTSF_LAYERCOLPCT_SUM,
210
211         /* Multiple response sets. */
212         CTSF_ROWPCT_RESPONSES,
213         CTSF_COLPCT_RESPONSES,
214         CTSF_TABLEPCT_RESPONSES,
215         CTSF_SUBTABLEPCT_RESPONSES,
216         CTSF_LAYERPCT_RESPONSES,
217         CTSF_LAYERROWPCT_RESPONSES,
218         CTSF_LAYERCOLPCT_RESPONSES,
219         CTSF_ROWPCT_RESPONSES_COUNT,
220         CTSF_COLPCT_RESPONSES_COUNT,
221         CTSF_TABLEPCT_RESPONSES_COUNT,
222         CTSF_SUBTABLEPCT_RESPONSES_COUNT,
223         CTSF_LAYERPCT_RESPONSES_COUNT,
224         CTSF_LAYERROWPCT_RESPONSES_COUNT,
225         CTSF_LAYERCOLPCT_RESPONSES_COUNT,
226         CTSF_ROWPCT_COUNT_RESPONSES,
227         CTSF_COLPCT_COUNT_RESPONSES,
228         CTSF_TABLEPCT_COUNT_RESPONSES,
229         CTSF_SUBTABLEPCT_COUNT_RESPONSES,
230         CTSF_LAYERPCT_COUNT_RESPONSES,
231         CTSF_LAYERROWPCT_COUNT_RESPONSES,
232         CTSF_LAYERCOLPCT_COUNT_RESPONSES,
233       }
234     function;
235
236     char *label;
237     struct fmt_spec format;     /* XXX extra CTABLES formats */
238   };
239
240 int
241 cmd_ctables (struct lexer *lexer, struct dataset *ds)
242 {
243   
244
245 }
246