#include "libpspp/ll.h"
#include "libpspp/message.h"
#include "libpspp/misc.h"
-#include "output/tab.h"
-#include "output/table-item.h"
+#include "output/pivot-table.h"
#include "gl/intprops.h"
#include "gl/minmax.h"
#include "gl/xmalloca.h"
#include "gettext.h"
+#define N_(msgid) msgid
#define _(msgid) gettext (msgid)
enum numbering
grouper = casegrouper_create_splits (proc_open (ds), dict);
while (casegrouper_get_next_group (grouper, &group))
{
- struct ccase *ccase;
- struct table *t;
-
- ccase = casereader_peek (group, 0);
- if (ccase != NULL)
+ struct ccase *c = casereader_peek (group, 0);
+ if (c != NULL)
{
- output_split_file_values (ds, ccase);
- case_unref (ccase);
+ output_split_file_values (ds, c);
+ case_unref (c);
}
group = casereader_project (group, &sc);
- if (lcmd->numbering == format_numbered)
- group = casereader_create_arithmetic_sequence (group, 1, 1);
group = casereader_select (group, lcmd->first - 1,
(lcmd->last != LONG_MAX ? lcmd->last
: CASENUMBER_MAX), lcmd->step);
- if (lcmd->numbering == format_numbered)
- {
- struct fmt_spec fmt;
- size_t col;
- int width;
+ struct pivot_table *table = pivot_table_create (N_("Data List"));
+ table->show_values = table->show_variables = SETTINGS_VALUE_SHOW_VALUE;
- width = lcmd->last == LONG_MAX ? 5 : intlog10 (lcmd->last);
- fmt = fmt_for_output (FMT_F, width, 0);
- col = caseproto_get_n_widths (casereader_get_proto (group)) - 1;
+ struct pivot_dimension *variables = pivot_dimension_create (
+ table, PIVOT_AXIS_COLUMN, N_("Variables"));
+ for (int i = 0; i < lcmd->n_variables; i++)
+ pivot_category_create_leaf (
+ variables->root, pivot_value_new_variable (lcmd->v_variables[i]));
- t = table_from_casereader (group, col, _("Case Number"), &fmt);
- }
+ struct pivot_dimension *cases = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Case Number"));
+ if (lcmd->numbering == format_numbered)
+ cases->root->show_label = true;
else
- t = NULL;
+ cases->hide_all_labels = true;
- for (i = 0; i < lcmd->n_variables; i++)
+ casenumber case_num = lcmd->first;
+ for (; (c = casereader_read (group)) != NULL; case_unref (c))
{
- const struct variable *var = lcmd->v_variables[i];
- struct table *c;
-
- c = table_from_casereader (group, i, var_get_name (var),
- var_get_print_format (var));
- t = table_hpaste (t, c);
+ int case_idx = pivot_category_create_leaf (
+ cases->root, pivot_value_new_integer (case_num));
+ case_num += lcmd->step;
+
+ for (int i = 0; i < lcmd->n_variables; i++)
+ pivot_table_put2 (table, i, case_idx,
+ pivot_value_new_var_value (
+ lcmd->v_variables[i], case_data_idx (c, i)));
}
-
casereader_destroy (group);
- table_item_submit (table_item_create (t, "Data List", NULL));
+ pivot_table_submit (table);
}
ok = casegrouper_destroy (grouper);
ok = proc_commit (ds) && ok;
- subcase_destroy (&sc);
+ subcase_uninit (&sc);
free (lcmd->v_variables);
return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
while (lex_token (lexer) != T_ENDCMD)
{
lex_match (lexer, T_SLASH);
- if (lex_match_id (lexer, "VARIABLES") )
+ if (lex_match_id (lexer, "VARIABLES"))
{
lex_match (lexer, T_EQUALS);
- if (! parse_variables_const (lexer, dict, &cmd.v_variables, &cmd.n_variables, 0 ))
+ if (! parse_variables_const (lexer, dict, &cmd.v_variables, &cmd.n_variables, 0))
{
msg (SE, _("No variables specified."));
return CMD_FAILURE;
}
}
- else if (lex_match_id (lexer, "FORMAT") )
+ else if (lex_match_id (lexer, "FORMAT"))
{
lex_match (lexer, T_EQUALS);
- if (lex_match_id (lexer, "NUMBERED") )
+ if (lex_match_id (lexer, "NUMBERED"))
{
cmd.numbering = format_numbered;
}
- else if (lex_match_id (lexer, "UNNUMBERED") )
+ else if (lex_match_id (lexer, "UNNUMBERED"))
{
cmd.numbering = format_unnumbered;
}
lex_get (lexer);
}
}
- else if (! parse_variables_const (lexer, dict, &cmd.v_variables, &cmd.n_variables, 0 ))
+ else if (! parse_variables_const (lexer, dict, &cmd.v_variables, &cmd.n_variables, 0))
{
return CMD_FAILURE;
}
}
-
+
/* Verify arguments. */
if (cmd.first > cmd.last)
if (cmd.first < 1)
{
- msg (SW, _("The first case (%ld) to list is less than 1. The value is "
- "being reset to 1."), cmd.first);
+ msg (SW, _("The first case (%ld) to list is numbered less than 1. "
+ "The value is being reset to 1."), cmd.first);
cmd.first = 1;
}
if (cmd.last < 1)
{
- msg (SW, _("The last case (%ld) to list is less than 1. The value is "
- "being reset to 1."), cmd.last);
+ msg (SW, _("The last case (%ld) to list is numbered less than 1. "
+ "The value is being reset to 1."), cmd.last);
cmd.last = 1;
}