#include "libpspp/assertion.h"
#include "libpspp/hmap.h"
#include "libpspp/message.h"
+#include "libpspp/string-array.h"
#include "output/pivot-table.h"
#include "gl/minmax.h"
return true;
}
+struct ctables_freqtab
+ {
+ struct variable **vars;
+ size_t n_vars;
+
+ struct hmap data; /* Contains "struct freq"s. */
+ };
+
+static struct string_array
+nest_fts (struct string_array sa0, struct string_array sa1)
+{
+ if (!sa0.n)
+ return sa1;
+ else if (!sa1.n)
+ return sa0;
+
+ struct string_array sa = STRING_ARRAY_INITIALIZER;
+ for (size_t i = 0; i < sa0.n; i++)
+ for (size_t j = 0; j < sa1.n; j++)
+ string_array_append_nocopy (&sa, xasprintf ("%s, %s",
+ sa0.strings[i],
+ sa1.strings[j]));
+ string_array_destroy (&sa0);
+ string_array_destroy (&sa1);
+ return sa;
+}
+
+static struct string_array
+enumerate_fts (const struct ctables_axis *a)
+{
+ struct string_array sa = STRING_ARRAY_INITIALIZER;
+ if (!a)
+ return sa;
+
+ switch (a->op)
+ {
+ case CTAO_VAR:
+ string_array_append (&sa, ctables_var_name (&a->var));
+ break;
+
+ case CTAO_STACK:
+ sa = enumerate_fts (a->subs[0]);
+ struct string_array sa2 = enumerate_fts (a->subs[1]);
+ for (size_t i = 0; i < sa2.n; i++)
+ string_array_append_nocopy (&sa, sa2.strings[i]);
+ free (sa2.strings);
+ break;
+
+ case CTAO_NEST:
+ return nest_fts (enumerate_fts (a->subs[0]),
+ enumerate_fts (a->subs[1]));
+ }
+ return sa;
+}
+
+static void
+ctables_execute (struct ctables *ct)
+{
+ for (size_t i = 0; i < ct->n_tables; i++)
+ {
+ struct ctables_table *t = &ct->tables[i];
+ struct string_array sa = enumerate_fts (t->axes[PIVOT_AXIS_ROW]);
+ sa = nest_fts (sa, enumerate_fts (t->axes[PIVOT_AXIS_COLUMN]));
+ sa = nest_fts (sa, enumerate_fts (t->axes[PIVOT_AXIS_LAYER]));
+ for (size_t i = 0; i < sa.n; i++)
+ puts (sa.strings[i]);
+ putc ('\n', stdout);
+ string_array_destroy (&sa);
+ }
+}
+
int
cmd_ctables (struct lexer *lexer, struct dataset *ds)
{
}
while (lex_token (lexer) != T_ENDCMD);
+
+ ctables_execute (ct);
ctables_destroy (ct);
return CMD_SUCCESS;