#include "libpspp/str.h"
#include "libpspp/stringi-map.h"
#include "libpspp/stringi-set.h"
-#include "output/tab.h"
+#include "output/pivot-table.h"
#include "gl/xalloc.h"
#include "gettext.h"
+#define N_(msgid) msgid
#define _(msgid) gettext (msgid)
static bool parse_group (struct lexer *, struct dictionary *, enum mrset_type);
enum mrset_type type)
{
const char *subcommand_name = type == MRSET_MD ? "MDGROUP" : "MCGROUP";
- struct mrset *mrset;
- bool labelsource_varlabel;
- bool has_value;
- mrset = xzalloc (sizeof *mrset);
+ struct mrset *mrset = XZALLOC (struct mrset);
mrset->type = type;
mrset->cat_source = MRSET_VARLABELS;
- labelsource_varlabel = false;
- has_value = false;
+ bool labelsource_varlabel = false;
+ bool has_value = false;
+
+ int vars_start = 0;
+ int vars_end = 0;
+ int value_ofs = 0;
+ int labelsource_start = 0;
+ int labelsource_end = 0;
+ int label_start = 0;
+ int label_end = 0;
while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
{
if (lex_match_id (lexer, "NAME"))
{
- if (!lex_force_match (lexer, T_EQUALS) || !lex_force_id (lexer)
- || !mrset_is_valid_name (lex_tokcstr (lexer),
- dict_get_encoding (dict), true))
+ if (!lex_force_match (lexer, T_EQUALS) || !lex_force_id (lexer))
goto error;
+ char *error = mrset_is_valid_name__ (lex_tokcstr (lexer),
+ dict_get_encoding (dict));
+ if (error)
+ {
+ lex_error (lexer, "%s", error);
+ free (error);
+ goto error;
+ }
free (mrset->name);
mrset->name = xstrdup (lex_tokcstr (lexer));
goto error;
free (mrset->vars);
+ vars_start = lex_ofs (lexer);
if (!parse_variables (lexer, dict, &mrset->vars, &mrset->n_vars,
PV_SAME_TYPE | PV_NO_SCRATCH))
goto error;
+ vars_end = lex_ofs (lexer) - 1;
if (mrset->n_vars < 2)
{
- msg (SE, _("VARIABLES specified only variable %s on %s, but "
- "at least two variables are required."),
+ lex_ofs_error (lexer, vars_start, vars_end,
+ _("VARIABLES specified only variable %s on %s, but "
+ "at least two variables are required."),
var_get_name (mrset->vars[0]), subcommand_name);
goto error;
}
}
else if (lex_match_id (lexer, "LABEL"))
{
+ label_start = lex_ofs (lexer) - 1;
if (!lex_force_match (lexer, T_EQUALS) || !lex_force_string (lexer))
goto error;
+ label_end = lex_ofs (lexer);
free (mrset->label);
mrset->label = ss_xstrdup (lex_tokss (lexer));
}
else if (type == MRSET_MD && lex_match_id (lexer, "LABELSOURCE"))
{
- if (!lex_force_match (lexer, T_EQUALS)
- || !lex_force_match_id (lexer, "VARLABEL"))
+ if (!lex_force_match_phrase (lexer, "=VARLABEL"))
goto error;
labelsource_varlabel = true;
+ labelsource_start = lex_ofs (lexer) - 3;
+ labelsource_end = lex_ofs (lexer) - 1;
}
else if (type == MRSET_MD && lex_match_id (lexer, "VALUE"))
{
goto error;
has_value = true;
+ value_ofs = lex_ofs (lexer);
if (lex_is_number (lexer))
{
if (!lex_is_integer (lexer))
{
- msg (SE, _("Numeric VALUE must be an integer."));
+ lex_error (lexer, _("Numeric VALUE must be an integer."));
goto error;
}
value_destroy (&mrset->counted, mrset->width);
value_destroy (&mrset->counted, mrset->width);
value_init (&mrset->counted, width);
- memcpy (value_str_rw (&mrset->counted, width), s, width);
+ memcpy (mrset->counted.s, s, width);
mrset->width = width;
free (s);
{
if (mrset->width == 0)
{
- msg (SE, _("MDGROUP subcommand for group %s specifies a string "
- "VALUE, but the variables specified for this group "
- "are numeric."),
- mrset->name);
+ lex_ofs_error (lexer, value_ofs, value_ofs,
+ _("MDGROUP subcommand for group %s specifies a "
+ "string VALUE, but the variables specified for "
+ "this group are numeric."),
+ mrset->name);
goto error;
}
else {
}
if (mrset->width > min_width)
{
- msg (SE, _("VALUE string on MDGROUP subcommand for group "
- "%s is %d bytes long, but it must be no longer "
- "than the narrowest variable in the group, "
- "which is %s with a width of %d bytes."),
- mrset->name, mrset->width,
- var_get_name (shortest_var), min_width);
+ lex_ofs_error (lexer, value_ofs, value_ofs,
+ _("VALUE string on MDGROUP subcommand for "
+ "group %s is %d bytes long, but it must be "
+ "no longer than the narrowest variable in "
+ "the group, which is %s with a width of "
+ "%d bytes."),
+ mrset->name, mrset->width,
+ var_get_name (shortest_var), min_width);
goto error;
}
}
{
if (mrset->width != 0)
{
- msg (SE, _("MDGROUP subcommand for group %s specifies a string "
- "VALUE, but the variables specified for this group "
- "are numeric."),
+ lex_ofs_error (lexer, value_ofs, value_ofs,
+ _("MDGROUP subcommand for group %s specifies a "
+ "string VALUE, but the variables specified for "
+ "this group are numeric."),
mrset->name);
goto error;
}
if (labelsource_varlabel)
{
if (mrset->cat_source != MRSET_COUNTEDVALUES)
- msg (SW, _("MDGROUP subcommand for group %s specifies "
- "LABELSOURCE=VARLABEL but not "
- "CATEGORYLABELS=COUNTEDVALUES. "
- "Ignoring LABELSOURCE."),
+ lex_ofs_msg (lexer, SW, labelsource_start, labelsource_end,
+ _("MDGROUP subcommand for group %s specifies "
+ "LABELSOURCE=VARLABEL but not "
+ "CATEGORYLABELS=COUNTEDVALUES. "
+ "Ignoring LABELSOURCE."),
mrset->name);
else if (mrset->label)
- msg (SW, _("MDGROUP subcommand for group %s specifies both LABEL "
- "and LABELSOURCE, but only one of these subcommands "
- "may be used at a time. Ignoring LABELSOURCE."),
- mrset->name);
+ {
+ msg (SW, _("MDGROUP subcommand for group %s specifies both "
+ "LABEL and LABELSOURCE, but only one of these "
+ "subcommands may be used at a time. "
+ "Ignoring LABELSOURCE."),
+ mrset->name);
+ lex_ofs_msg (lexer, SN, label_start, label_end,
+ _("Here is the %s setting."), "LABEL");
+ lex_ofs_msg (lexer, SN, labelsource_start, labelsource_end,
+ _("Here is the %s setting."), "LABELSOURCE");
+ }
else
{
size_t i;
if (other_name == NULL)
stringi_map_insert (&seen, label, name);
else
- msg (SW, _("Variables %s and %s specified as part of "
- "multiple dichotomy group %s have the same "
- "variable label. Categories represented by "
- "these variables will not be distinguishable "
- "in output."),
- other_name, name, mrset->name);
+ lex_ofs_msg (lexer, SW, vars_start, vars_end,
+ _("Variables %s and %s specified as part of "
+ "multiple dichotomy group %s have the same "
+ "variable label. Categories represented by "
+ "these variables will not be distinguishable "
+ "in output."),
+ other_name, name, mrset->name);
}
}
stringi_map_destroy (&seen);
val_labs = var_get_value_labels (var);
label = val_labs_find (val_labs, &value);
if (label == NULL)
- msg (SW, _("Variable %s specified as part of multiple "
- "dichotomy group %s (which has "
- "CATEGORYLABELS=COUNTEDVALUES) has no value label "
- "for its counted value. This category will not "
- "be distinguishable in output."),
+ lex_ofs_msg (lexer, SW, vars_start, vars_end,
+ _("Variable %s specified as part of multiple "
+ "dichotomy group %s (which has "
+ "CATEGORYLABELS=COUNTEDVALUES) has no value "
+ "label for its counted value. This category "
+ "will not be distinguishable in output."),
name, mrset->name);
else
{
if (other_name == NULL)
stringi_map_insert (&seen, label, name);
else
- msg (SW, _("Variables %s and %s specified as part of "
- "multiple dichotomy group %s (which has "
- "CATEGORYLABELS=COUNTEDVALUES) have the same "
- "value label for the the group's counted "
- "value. These categories will not be "
- "distinguishable in output."),
- other_name, name, mrset->name);
+ lex_ofs_msg (lexer, SW, vars_start, vars_end,
+ _("Variables %s and %s specified as part of "
+ "multiple dichotomy group %s (which has "
+ "CATEGORYLABELS=COUNTEDVALUES) have the same "
+ "value label for the group's counted "
+ "value. These categories will not be "
+ "distinguishable in output."),
+ other_name, name, mrset->name);
}
}
stringi_map_destroy (&seen);
if (!c->warned && utf8_strcasecmp (c->label, label))
{
char *s = data_out (value, var_get_encoding (var),
- var_get_print_format (var));
+ var_get_print_format (var),
+ settings_get_fmt_settings ());
c->warned = true;
- msg (SW, _("Variables specified on MCGROUP should "
- "have the same categories, but %s and %s "
- "(and possibly others) in multiple "
- "category group %s have different "
- "value labels for value %s."),
- c->var_name, name, mrset->name, s);
+ lex_ofs_msg (lexer, SW, vars_start, vars_end,
+ _("Variables specified on MCGROUP should "
+ "have the same categories, but %s and "
+ "%s (and possibly others) in multiple "
+ "category group %s have different "
+ "value labels for value %s."),
+ c->var_name, name, mrset->name, s);
free (s);
}
goto found;
parse_mrset_names (struct lexer *lexer, struct dictionary *dict,
struct stringi_set *mrset_names)
{
- if (!lex_force_match_id (lexer, "NAME")
- || !lex_force_match (lexer, T_EQUALS))
+ if (!lex_force_match_phrase (lexer, "NAME="))
return false;
stringi_set_init (mrset_names);
return false;
if (dict_lookup_mrset (dict, lex_tokcstr (lexer)) == NULL)
{
- msg (SE, _("No multiple response set named %s."),
- lex_tokcstr (lexer));
+ lex_error (lexer, _("No multiple response set named %s."),
+ lex_tokcstr (lexer));
stringi_set_destroy (mrset_names);
return false;
}
static bool
parse_display (struct lexer *lexer, struct dictionary *dict)
{
- struct string details, var_names;
struct stringi_set mrset_names_set;
- char **mrset_names;
- struct tab_table *table;
- size_t i, n;
-
if (!parse_mrset_names (lexer, dict, &mrset_names_set))
return false;
- n = stringi_set_count (&mrset_names_set);
+ size_t n = stringi_set_count (&mrset_names_set);
if (n == 0)
{
if (dict_get_n_mrsets (dict) == 0)
- msg (SN, _("The active dataset dictionary does not contain any "
- "multiple response sets."));
+ lex_next_msg (lexer, SN, -1, -1,
+ _("The active dataset dictionary does not contain any "
+ "multiple response sets."));
stringi_set_destroy (&mrset_names_set);
return true;
}
- table = tab_create (3, n + 1);
- tab_headers (table, 0, 0, 1, 0);
- tab_box (table, TAL_1, TAL_1, TAL_1, TAL_1, 0, 0, 2, n);
- tab_hline (table, TAL_2, 0, 2, 1);
- tab_title (table, "%s", _("Multiple Response Sets"));
- tab_text (table, 0, 0, TAB_EMPH | TAB_LEFT, _("Name"));
- tab_text (table, 1, 0, TAB_EMPH | TAB_LEFT, _("Variables"));
- tab_text (table, 2, 0, TAB_EMPH | TAB_LEFT, _("Details"));
-
- ds_init_empty (&details);
- ds_init_empty (&var_names);
- mrset_names = stringi_set_get_sorted_array (&mrset_names_set);
- for (i = 0; i < n; i++)
+ struct pivot_table *table = pivot_table_create (
+ N_("Multiple Response Sets"));
+
+ pivot_dimension_create (
+ table, PIVOT_AXIS_COLUMN, N_("Attributes"),
+ N_("Label"), N_("Encoding"), N_("Counted Value"), N_("Member Variables"));
+
+ struct pivot_dimension *mrsets = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Name"));
+ mrsets->root->show_label = true;
+
+ char **mrset_names = stringi_set_get_sorted_array (&mrset_names_set);
+ for (size_t i = 0; i < n; i++)
{
const struct mrset *mrset = dict_lookup_mrset (dict, mrset_names[i]);
- const int row = i + 1;
- size_t j;
-
- /* Details. */
- ds_clear (&details);
- ds_put_format (&details, "%s\n", (mrset->type == MRSET_MD
- ? _("Multiple dichotomy set")
- : _("Multiple category set")));
+
+ int row = pivot_category_create_leaf (
+ mrsets->root, pivot_value_new_user_text (mrset->name, -1));
+
if (mrset->label != NULL)
- ds_put_format (&details, "%s: %s\n", _("Label"), mrset->label);
+ pivot_table_put2 (table, 0, row,
+ pivot_value_new_user_text (mrset->label, -1));
+
+ pivot_table_put2 (table, 1, row,
+ pivot_value_new_text (mrset->type == MRSET_MD
+ ? _("Dichotomies")
+ : _("Categories")));
+
if (mrset->type == MRSET_MD)
- {
- if (mrset->label != NULL || mrset->label_from_var_label)
- ds_put_format (&details, "%s: %s\n", _("Label source"),
- (mrset->label_from_var_label
- ? _("First variable label among variables")
- : _("Provided by user")));
- ds_put_format (&details, "%s: ", _("Counted value"));
- if (mrset->width == 0)
- ds_put_format (&details, "%.0f\n", mrset->counted.f);
- else
- {
- const uint8_t *raw = value_str (&mrset->counted, mrset->width);
- char *utf8 = recode_string ("UTF-8", dict_get_encoding (dict),
- CHAR_CAST (const char *, raw),
- mrset->width);
- ds_put_format (&details, "`%s'\n", utf8);
- free (utf8);
- }
- ds_put_format (&details, "%s: %s\n", _("Category label source"),
- (mrset->cat_source == MRSET_VARLABELS
- ? _("Variable labels")
- : _("Value labels of counted value")));
- }
+ pivot_table_put2 (table, 2, row,
+ pivot_value_new_value (
+ &mrset->counted, mrset->width,
+ &F_8_0, dict_get_encoding (dict)));
/* Variable names. */
- ds_clear (&var_names);
- for (j = 0; j < mrset->n_vars; j++)
+ struct string var_names = DS_EMPTY_INITIALIZER;
+ for (size_t j = 0; j < mrset->n_vars; j++)
ds_put_format (&var_names, "%s\n", var_get_name (mrset->vars[j]));
-
- tab_text (table, 0, row, TAB_LEFT, mrset_names[i]);
- tab_text (table, 1, row, TAB_LEFT, ds_cstr (&var_names));
- tab_text (table, 2, row, TAB_LEFT, ds_cstr (&details));
+ ds_chomp_byte (&var_names, '\n');
+ pivot_table_put2 (table, 3, row,
+ pivot_value_new_user_text_nocopy (
+ ds_steal_cstr (&var_names)));
}
free (mrset_names);
- ds_destroy (&var_names);
- ds_destroy (&details);
stringi_set_destroy (&mrset_names_set);
- tab_submit (table);
+ pivot_table_submit (table);
return true;
}