+ const struct variable *v = vl[i];
+
+ struct pivot_value *name = pivot_value_new_variable (v);
+ name->variable.show = SETTINGS_VALUE_SHOW_VALUE;
+ int row = pivot_category_create_leaf (names->root, name);
+
+ int x = 0;
+ if (flags & DF_POSITION)
+ pivot_table_put2 (table, x++, row, pivot_value_new_integer (
+ var_get_dict_index (v) + 1));
+
+ if (flags & DF_LABEL)
+ {
+ const char *label = var_get_label (v);
+ if (label)
+ pivot_table_put2 (table, x, row,
+ pivot_value_new_user_text (label, -1));
+ x++;
+ }
+
+ if (flags & DF_MEASUREMENT_LEVEL)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_text (measure_to_string (var_get_measure (v))));
+
+ if (flags & DF_ROLE)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_text (var_role_to_string (var_get_role (v))));
+
+ if (flags & DF_WIDTH)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_integer (var_get_display_width (v)));
+
+ if (flags & DF_ALIGNMENT)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_text (alignment_to_string (
+ var_get_alignment (v))));
+
+ if (flags & DF_PRINT_FORMAT)
+ {
+ const struct fmt_spec *print = var_get_print_format (v);
+ char s[FMT_STRING_LEN_MAX + 1];
+
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_user_text (fmt_to_string (print, s), -1));
+ }
+
+ if (flags & DF_WRITE_FORMAT)
+ {
+ const struct fmt_spec *write = var_get_write_format (v);
+ char s[FMT_STRING_LEN_MAX + 1];
+
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_user_text (fmt_to_string (write, s), -1));
+ }
+
+ if (flags & DF_MISSING_VALUES)
+ {
+ char *s = mv_to_string (var_get_missing_values (v),
+ var_get_encoding (v));
+ if (s)
+ pivot_table_put2 (
+ table, x, row,
+ pivot_value_new_user_text_nocopy (s));
+
+ x++;
+ }
+ }
+
+ pivot_table_submit (table);
+}
+
+static bool
+any_value_labels (const struct variable **vars, size_t n_vars)
+{
+ for (size_t i = 0; i < n_vars; i++)
+ if (val_labs_count (var_get_value_labels (vars[i])))
+ return true;
+ return false;
+}
+
+static void
+display_value_labels (const struct variable **vars, size_t n_vars)
+{
+ if (!any_value_labels (vars, n_vars))
+ return;
+
+ struct pivot_table *table = pivot_table_create (N_("Value Labels"));
+
+ pivot_dimension_create (table, PIVOT_AXIS_COLUMN,
+ N_("Label"), N_("Label"));
+
+ struct pivot_dimension *values = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Variable Value"));
+ values->root->show_label = true;
+
+ struct pivot_footnote *missing_footnote = pivot_table_create_footnote (
+ table, pivot_value_new_text (N_("User-missing value")));
+
+ for (size_t i = 0; i < n_vars; i++)
+ {
+ const struct val_labs *val_labs = var_get_value_labels (vars[i]);
+ size_t n_labels = val_labs_count (val_labs);
+ if (!n_labels)
+ continue;
+
+ struct pivot_category *group = pivot_category_create_group__ (
+ values->root, pivot_value_new_variable (vars[i]));
+
+ const struct val_lab **labels = val_labs_sorted (val_labs);
+ for (size_t j = 0; j < n_labels; j++)
+ {
+ const struct val_lab *vl = labels[j];
+
+ struct pivot_value *value = pivot_value_new_var_value (
+ vars[i], &vl->value);
+ if (value->type == PIVOT_VALUE_NUMERIC)
+ value->numeric.show = SETTINGS_VALUE_SHOW_VALUE;
+ else
+ value->string.show = SETTINGS_VALUE_SHOW_VALUE;
+ if (var_is_value_missing (vars[i], &vl->value, MV_USER))
+ pivot_value_add_footnote (value, missing_footnote);
+ int row = pivot_category_create_leaf (group, value);
+
+ struct pivot_value *label = pivot_value_new_var_value (
+ vars[i], &vl->value);
+ char *escaped_label = xstrdup (val_lab_get_escaped_label (vl));
+ if (label->type == PIVOT_VALUE_NUMERIC)
+ {
+ free (label->numeric.value_label);
+ label->numeric.value_label = escaped_label;
+ label->numeric.show = SETTINGS_VALUE_SHOW_LABEL;
+ }
+ else
+ {
+ free (label->string.value_label);
+ label->string.value_label = escaped_label;
+ label->string.show = SETTINGS_VALUE_SHOW_LABEL;
+ }
+ pivot_table_put2 (table, 0, row, label);
+ }
+ free (labels);