work on CTABLES
[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/message.h"
22
23 #include "gl/xalloc.h"
24
25 #include "gettext.h"
26 #define _(msgid) gettext (msgid)
27
28 struct ctables
29   {
30     struct pivot_table_look *look;
31
32     /* If this is NULL, zeros are displayed using the normal print format.
33        Otherwise, this string is displayed. */
34     char *zero;
35
36     /* If this is NULL, missing values are displayed using the normal print
37        format.  Otherwise, this string is displayed. */
38     char *missing;
39
40     /* Contains "struct ctables_vlabel" structs.  */
41     struct hmap vlabels;
42
43     bool mrsets_count_duplicates; /* MRSETS. */
44     bool smissing_listwise;       /* SMISSING. */
45     struct variable *base_weight; /* WEIGHT. */
46     double hide_threshold;        /* HIDESMALLCOUNTS. */
47
48     struct ctables_table *tables;
49     size_t n_tables;
50   };
51
52 struct ctables_vlabel
53   {
54     struct hmap_node hmap_node; /* In struct ctables's 'vlabels' hmap. */
55     const char *name;           /* Variable name. */
56
57     /* SETTINGS_VALUE_SHOW_DEFAULT is interpreted as "none". */
58     enum settings_value_show show;
59   };
60
61 struct ctables_postcompute
62   {
63     struct hmap_node hmap_node; /* In struct ctables's 'pcompute' hmap. */
64     const char *name;           /* Name, without leading &. */
65
66     struct ctables_postcompute_expr *expr;
67     char *label;
68     /* XXX FORMAT */
69     bool hide_source_cats;
70   };
71
72 struct ctables_postcompute_expr
73   {
74     enum ctables_postcompute_op
75       {
76         /* Terminals. */
77         CTPET_CAT_NUMBER,
78         CTPET_CAT_STRING,
79         CTPET_CAT_RANGE,
80         CTPET_CAT_MISSING,
81         /* XXX OTHERNM */
82         /* XXX SUBTOTAL and HSUBTOTAL */
83
84         /* Nonterminals. */
85         CTPET_ADD,
86         CTPET_SUB,
87         CTPET_MUL,
88         CTPET_DIV,
89         CTPET_POW,
90       }
91     op;
92
93     union
94       {
95         /* CTPET_CAT_NUMBER, CTPET_NUMBER. */
96         double number;
97
98         /* CTPET_CAT_RANGE.
99
100            XXX what about string ranges? */
101         struct
102           {
103             double low;         /* -DBL_MAX for LO. */
104             double high;        /* DBL_MAX for HIGH. */
105           }
106         range;
107
108         /* CTPET_ADD, CTPET_SUB, CTPET_MUL, CTPET_DIV, CTPET_POW. */
109         struct ctables_postcompute_expr *subs[2];
110       };
111   };
112
113
114 int
115 cmd_ctables (struct lexer *lexer, struct dataset *ds)
116 {
117   
118
119 }
120