1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
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.
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.
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/>. */
23 #include "data/any-reader.h"
24 #include "data/attributes.h"
25 #include "data/casereader.h"
26 #include "data/dataset.h"
27 #include "data/dictionary.h"
28 #include "data/file-handle-def.h"
29 #include "data/format.h"
30 #include "data/missing-values.h"
31 #include "data/value-labels.h"
32 #include "data/variable.h"
33 #include "data/vector.h"
34 #include "language/command.h"
35 #include "language/data-io/file-handle.h"
36 #include "language/lexer/lexer.h"
37 #include "language/lexer/variable-parser.h"
38 #include "libpspp/array.h"
39 #include "libpspp/hash-functions.h"
40 #include "libpspp/i18n.h"
41 #include "libpspp/message.h"
42 #include "libpspp/misc.h"
43 #include "libpspp/pool.h"
44 #include "libpspp/string-array.h"
45 #include "output/pivot-table.h"
46 #include "output/text-item.h"
47 #include "output/table-item.h"
49 #include "gl/count-one-bits.h"
50 #include "gl/localcharset.h"
51 #include "gl/intprops.h"
52 #include "gl/minmax.h"
53 #include "gl/xalloc.h"
56 #define _(msgid) gettext (msgid)
57 #define N_(msgid) (msgid)
59 /* Information to include in displaying a dictionary. */
66 DF_MEASUREMENT_LEVEL = 1 << 3,
69 DF_ALIGNMENT = 1 << 6,
70 DF_PRINT_FORMAT = 1 << 7,
71 DF_WRITE_FORMAT = 1 << 8,
72 DF_MISSING_VALUES = 1 << 9,
73 #define DF_ALL_VARIABLE ((1 << 10) - 1)
75 /* Value labels table. */
76 DF_VALUE_LABELS = 1 << 10,
78 /* Attribute table. */
79 DF_AT_ATTRIBUTES = 1 << 11, /* Attributes whose names begin with @. */
80 DF_ATTRIBUTES = 1 << 12, /* All other attributes. */
83 static void display_variables (const struct variable **, size_t, int flags);
84 static void display_value_labels (const struct variable **, size_t);
85 static void display_attributes (const struct attrset *,
86 const struct variable **, size_t, int flags);
88 static void report_encodings (const struct file_handle *, struct pool *,
89 char **titles, bool *ids,
90 char **strings, size_t n_strings);
93 add_row (struct pivot_table *table, const char *attribute,
94 struct pivot_value *value)
96 int row = pivot_category_create_leaf (table->dimensions[0]->root,
97 pivot_value_new_text (attribute));
99 pivot_table_put1 (table, row, value);
102 /* SYSFILE INFO utility. */
104 cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
106 struct any_reader *any_reader;
107 struct file_handle *h;
108 struct dictionary *d;
109 struct casereader *reader;
110 struct any_read_info info;
117 lex_match (lexer, T_SLASH);
119 if (lex_match_id (lexer, "FILE") || lex_is_string (lexer))
121 lex_match (lexer, T_EQUALS);
124 h = fh_parse (lexer, FH_REF_FILE, NULL);
128 else if (lex_match_id (lexer, "ENCODING"))
130 lex_match (lexer, T_EQUALS);
132 if (!lex_force_string (lexer))
136 encoding = ss_xstrdup (lex_tokss (lexer));
146 lex_sbc_missing ("FILE");
150 any_reader = any_reader_open (h);
157 if (encoding && !strcasecmp (encoding, "detect"))
159 char **titles, **strings;
164 pool = pool_create ();
165 n_strings = any_reader_get_strings (any_reader, pool,
166 &titles, &ids, &strings);
167 any_reader_close (any_reader);
169 report_encodings (h, pool, titles, ids, strings, n_strings);
177 reader = any_reader_decode (any_reader, encoding, &d, &info);
180 casereader_destroy (reader);
182 struct pivot_table *table = pivot_table_create (N_("File Information"));
183 pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Attribute"));
185 add_row (table, N_("File"),
186 pivot_value_new_user_text (fh_get_file_name (h), -1));
188 const char *label = dict_get_label (d);
189 add_row (table, N_("Label"),
190 label ? pivot_value_new_user_text (label, -1) : NULL);
192 add_row (table, N_("Created"),
193 pivot_value_new_user_text_nocopy (
194 xasprintf ("%s %s by %s", info.creation_date,
195 info.creation_time, info.product)));
197 if (info.product_ext)
198 add_row (table, N_("Product"),
199 pivot_value_new_user_text (info.product_ext, -1));
201 add_row (table, N_("Integer Format"),
202 pivot_value_new_text (
203 info.integer_format == INTEGER_MSB_FIRST ? N_("Big Endian")
204 : info.integer_format == INTEGER_LSB_FIRST ? N_("Little Endian")
207 add_row (table, N_("Real Format"),
208 pivot_value_new_text (
209 info.float_format == FLOAT_IEEE_DOUBLE_LE ? N_("IEEE 754 LE.")
210 : info.float_format == FLOAT_IEEE_DOUBLE_BE ? N_("IEEE 754 BE.")
211 : info.float_format == FLOAT_VAX_D ? N_("VAX D.")
212 : info.float_format == FLOAT_VAX_G ? N_("VAX G.")
213 : info.float_format == FLOAT_Z_LONG ? N_("IBM 390 Hex Long.")
216 add_row (table, N_("Variables"),
217 pivot_value_new_integer (dict_get_var_cnt (d)));
219 add_row (table, N_("Cases"),
221 ? pivot_value_new_text (N_("Unknown"))
222 : pivot_value_new_integer (info.case_cnt)));
224 add_row (table, N_("Type"),
225 pivot_value_new_text (info.klass->name));
227 struct variable *weight_var = dict_get_weight (d);
228 add_row (table, N_("Weight"),
230 ? pivot_value_new_variable (weight_var)
231 : pivot_value_new_text (N_("Not weighted"))));
233 add_row (table, N_("Compression"),
234 (info.compression == ANY_COMP_NONE
235 ? pivot_value_new_text (N_("None"))
236 : pivot_value_new_user_text (
237 info.compression == ANY_COMP_SIMPLE ? "SAV" : "ZSAV", -1)));
239 add_row (table, N_("Encoding"),
240 pivot_value_new_user_text (dict_get_encoding (d), -1));
242 pivot_table_submit (table);
244 size_t n_vars = dict_get_var_cnt (d);
245 const struct variable **vars = xnmalloc (n_vars, sizeof *vars);
246 for (size_t i = 0; i < dict_get_var_cnt (d); i++)
247 vars[i] = dict_get_var (d, i);
248 display_variables (vars, n_vars, DF_ALL_VARIABLE);
249 display_value_labels (vars, n_vars);
250 display_attributes (dict_get_attributes (dataset_dict (ds)),
251 vars, n_vars, DF_ATTRIBUTES);
257 any_read_info_destroy (&info);
266 /* DISPLAY utility. */
268 static void display_macros (void);
269 static void display_documents (const struct dictionary *dict);
270 static void display_vectors (const struct dictionary *dict, int sorted);
273 cmd_display (struct lexer *lexer, struct dataset *ds)
275 /* Whether to sort the list of variables alphabetically. */
278 /* Variables to display. */
280 const struct variable **vl;
282 if (lex_match_id (lexer, "MACROS"))
284 else if (lex_match_id (lexer, "DOCUMENTS"))
285 display_documents (dataset_dict (ds));
286 else if (lex_match_id (lexer, "FILE"))
288 if (!lex_force_match_id (lexer, "LABEL"))
291 const char *label = dict_get_label (dataset_dict (ds));
293 struct pivot_table *table = pivot_table_create (N_("File Label"));
294 pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Label"),
296 pivot_table_put1 (table, 0,
297 (label ? pivot_value_new_user_text (label, -1)
298 : pivot_value_new_text (N_("(none)"))));
299 pivot_table_submit (table);
305 sorted = lex_match_id (lexer, "SORTED");
307 if (lex_match_id (lexer, "VECTORS"))
309 display_vectors (dataset_dict(ds), sorted);
312 else if (lex_match_id (lexer, "SCRATCH"))
314 dict_get_vars (dataset_dict (ds), &vl, &n, DC_ORDINARY);
324 static const struct subcommand subcommands[] =
326 {"@ATTRIBUTES", DF_ATTRIBUTES | DF_AT_ATTRIBUTES},
327 {"ATTRIBUTES", DF_ATTRIBUTES},
328 {"DICTIONARY", (DF_NAME | DF_POSITION | DF_LABEL
329 | DF_MEASUREMENT_LEVEL | DF_ROLE | DF_WIDTH
330 | DF_ALIGNMENT | DF_PRINT_FORMAT
331 | DF_WRITE_FORMAT | DF_MISSING_VALUES
333 {"INDEX", DF_NAME | DF_POSITION},
334 {"LABELS", DF_NAME | DF_POSITION | DF_LABEL},
336 {"VARIABLES", (DF_NAME | DF_POSITION | DF_PRINT_FORMAT
337 | DF_WRITE_FORMAT | DF_MISSING_VALUES)},
340 const struct subcommand *sbc;
341 struct dictionary *dict = dataset_dict (ds);
344 for (sbc = subcommands; sbc->name != NULL; sbc++)
345 if (lex_match_id (lexer, sbc->name))
351 lex_match (lexer, T_SLASH);
352 lex_match_id (lexer, "VARIABLES");
353 lex_match (lexer, T_EQUALS);
355 if (lex_token (lexer) != T_ENDCMD)
357 if (!parse_variables_const (lexer, dict, &vl, &n, PV_NONE))
364 dict_get_vars (dict, &vl, &n, 0);
369 sort (vl, n, sizeof *vl, (sorted
370 ? compare_var_ptrs_by_name
371 : compare_var_ptrs_by_dict_index), NULL);
373 int variable_flags = flags & DF_ALL_VARIABLE;
375 display_variables (vl, n, variable_flags);
377 if (flags & DF_VALUE_LABELS)
378 display_value_labels (vl, n);
380 int attribute_flags = flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES);
382 display_attributes (dict_get_attributes (dataset_dict (ds)),
383 vl, n, attribute_flags);
386 msg (SW, _("No variables to display."));
395 display_macros (void)
397 msg (SW, _("Macros not supported."));
401 display_documents (const struct dictionary *dict)
403 struct pivot_table *table = pivot_table_create (N_("Documents"));
404 struct pivot_dimension *d = pivot_dimension_create (
405 table, PIVOT_AXIS_COLUMN, N_("Documents"), N_("Document"));
406 d->hide_all_labels = true;
408 const struct string_array *documents = dict_get_documents (dict);
410 pivot_table_put1 (table, 0, pivot_value_new_text (N_("(none)")));
413 struct string s = DS_EMPTY_INITIALIZER;
414 for (size_t i = 0; i < documents->n; i++)
417 ds_put_byte (&s, '\n');
418 ds_put_cstr (&s, documents->strings[i]);
420 pivot_table_put1 (table, 0,
421 pivot_value_new_user_text_nocopy (ds_steal_cstr (&s)));
424 pivot_table_submit (table);
428 display_variables (const struct variable **vl, size_t n, int flags)
430 struct pivot_table *table = pivot_table_create (N_("Variables"));
432 struct pivot_dimension *attributes = pivot_dimension_create (
433 table, PIVOT_AXIS_COLUMN, N_("Attributes"));
440 static const struct heading headings[] = {
441 { DF_POSITION, N_("Position") },
442 { DF_LABEL, N_("Label") },
443 { DF_MEASUREMENT_LEVEL, N_("Measurement Level") },
444 { DF_ROLE, N_("Role") },
445 { DF_WIDTH, N_("Width") },
446 { DF_ALIGNMENT, N_("Alignment") },
447 { DF_PRINT_FORMAT, N_("Print Format") },
448 { DF_WRITE_FORMAT, N_("Write Format") },
449 { DF_MISSING_VALUES, N_("Missing Values") },
451 for (size_t i = 0; i < sizeof headings / sizeof *headings; i++)
452 if (flags & headings[i].flag)
453 pivot_category_create_leaf (attributes->root,
454 pivot_value_new_text (headings[i].title));
456 struct pivot_dimension *names = pivot_dimension_create (
457 table, PIVOT_AXIS_ROW, N_("Name"));
458 names->root->show_label = true;
460 for (size_t i = 0; i < n; i++)
462 const struct variable *v = vl[i];
464 struct pivot_value *name = pivot_value_new_variable (v);
465 name->variable.show = SETTINGS_VALUE_SHOW_VALUE;
466 int row = pivot_category_create_leaf (names->root, name);
469 if (flags & DF_POSITION)
470 pivot_table_put2 (table, x++, row, pivot_value_new_integer (
471 var_get_dict_index (v) + 1));
473 if (flags & DF_LABEL)
475 const char *label = var_get_label (v);
477 pivot_table_put2 (table, x, row,
478 pivot_value_new_user_text (label, -1));
482 if (flags & DF_MEASUREMENT_LEVEL)
485 pivot_value_new_text (measure_to_string (var_get_measure (v))));
490 pivot_value_new_text (var_role_to_string (var_get_role (v))));
492 if (flags & DF_WIDTH)
495 pivot_value_new_integer (var_get_display_width (v)));
497 if (flags & DF_ALIGNMENT)
500 pivot_value_new_text (alignment_to_string (
501 var_get_alignment (v))));
503 if (flags & DF_PRINT_FORMAT)
505 const struct fmt_spec *print = var_get_print_format (v);
506 char s[FMT_STRING_LEN_MAX + 1];
510 pivot_value_new_user_text (fmt_to_string (print, s), -1));
513 if (flags & DF_WRITE_FORMAT)
515 const struct fmt_spec *write = var_get_write_format (v);
516 char s[FMT_STRING_LEN_MAX + 1];
520 pivot_value_new_user_text (fmt_to_string (write, s), -1));
523 if (flags & DF_MISSING_VALUES)
525 char *s = mv_to_string (var_get_missing_values (v),
526 var_get_encoding (v));
530 pivot_value_new_user_text_nocopy (s));
536 pivot_table_submit (table);
540 any_value_labels (const struct variable **vars, size_t n_vars)
542 for (size_t i = 0; i < n_vars; i++)
543 if (val_labs_count (var_get_value_labels (vars[i])))
549 display_value_labels (const struct variable **vars, size_t n_vars)
551 if (!any_value_labels (vars, n_vars))
554 struct pivot_table *table = pivot_table_create (N_("Value Labels"));
556 pivot_dimension_create (table, PIVOT_AXIS_COLUMN,
557 N_("Label"), N_("Label"));
559 struct pivot_dimension *values = pivot_dimension_create (
560 table, PIVOT_AXIS_ROW, N_("Variable Value"));
561 values->root->show_label = true;
563 struct pivot_footnote *missing_footnote = pivot_table_create_footnote (
564 table, pivot_value_new_text (N_("User-missing value")));
566 for (size_t i = 0; i < n_vars; i++)
568 const struct val_labs *val_labs = var_get_value_labels (vars[i]);
569 size_t n_labels = val_labs_count (val_labs);
573 struct pivot_category *group = pivot_category_create_group__ (
574 values->root, pivot_value_new_variable (vars[i]));
576 const struct val_lab **labels = val_labs_sorted (val_labs);
577 for (size_t j = 0; j < n_labels; j++)
579 const struct val_lab *vl = labels[j];
581 struct pivot_value *value = pivot_value_new_var_value (
582 vars[i], &vl->value);
583 if (value->type == PIVOT_VALUE_NUMERIC)
584 value->numeric.show = SETTINGS_VALUE_SHOW_VALUE;
586 value->string.show = SETTINGS_VALUE_SHOW_VALUE;
587 if (var_is_value_missing (vars[i], &vl->value, MV_USER))
588 pivot_value_add_footnote (value, missing_footnote);
589 int row = pivot_category_create_leaf (group, value);
591 struct pivot_value *label = pivot_value_new_var_value (
592 vars[i], &vl->value);
593 char *escaped_label = xstrdup (val_lab_get_escaped_label (vl));
594 if (label->type == PIVOT_VALUE_NUMERIC)
596 free (label->numeric.value_label);
597 label->numeric.value_label = escaped_label;
598 label->numeric.show = SETTINGS_VALUE_SHOW_LABEL;
602 free (label->string.value_label);
603 label->string.value_label = escaped_label;
604 label->string.show = SETTINGS_VALUE_SHOW_LABEL;
606 pivot_table_put2 (table, 0, row, label);
610 pivot_table_submit (table);
614 is_at_name (const char *name)
616 return name[0] == '@' || (name[0] == '$' && name[1] == '@');
620 count_attributes (const struct attrset *set, int flags)
622 struct attrset_iterator i;
623 struct attribute *attr;
627 for (attr = attrset_first (set, &i); attr != NULL;
628 attr = attrset_next (set, &i))
629 if (flags & DF_AT_ATTRIBUTES || !is_at_name (attribute_get_name (attr)))
630 n_attrs += attribute_get_n_values (attr);
635 display_attrset (struct pivot_table *table, struct pivot_value *set_name,
636 const struct attrset *set, int flags)
638 size_t n_total = count_attributes (set, flags);
641 pivot_value_destroy (set_name);
645 struct pivot_category *group = pivot_category_create_group__ (
646 table->dimensions[1]->root, set_name);
648 size_t n_attrs = attrset_count (set);
649 struct attribute **attrs = attrset_sorted (set);
650 for (size_t i = 0; i < n_attrs; i++)
652 const struct attribute *attr = attrs[i];
653 const char *name = attribute_get_name (attr);
655 if (!(flags & DF_AT_ATTRIBUTES) && is_at_name (name))
658 size_t n_values = attribute_get_n_values (attr);
659 for (size_t j = 0; j < n_values; j++)
661 int row = pivot_category_create_leaf (
664 ? pivot_value_new_user_text_nocopy (xasprintf (
665 "%s[%zu]", name, j + 1))
666 : pivot_value_new_user_text (name, -1)));
667 pivot_table_put2 (table, 0, row,
668 pivot_value_new_user_text (
669 attribute_get_value (attr, j), -1));
676 display_attributes (const struct attrset *dict_attrset,
677 const struct variable **vars, size_t n_vars, int flags)
679 struct pivot_table *table = pivot_table_create (
680 N_("Variable and Dataset Attributes"));
682 pivot_dimension_create (table, PIVOT_AXIS_COLUMN,
683 N_("Value"), N_("Value"));
685 struct pivot_dimension *variables = pivot_dimension_create (
686 table, PIVOT_AXIS_ROW, N_("Variable and Name"));
687 variables->root->show_label = true;
689 display_attrset (table, pivot_value_new_text (N_("(dataset)")),
690 dict_attrset, flags);
691 for (size_t i = 0; i < n_vars; i++)
692 display_attrset (table, pivot_value_new_variable (vars[i]),
693 var_get_attributes (vars[i]), flags);
695 if (pivot_table_is_empty (table))
696 pivot_table_destroy (table);
698 pivot_table_submit (table);
701 /* Display a list of vectors. If SORTED is nonzero then they are
702 sorted alphabetically. */
704 display_vectors (const struct dictionary *dict, int sorted)
706 size_t n_vectors = dict_get_vector_cnt (dict);
709 msg (SW, _("No vectors defined."));
713 const struct vector **vectors = xnmalloc (n_vectors, sizeof *vectors);
714 for (size_t i = 0; i < n_vectors; i++)
715 vectors[i] = dict_get_vector (dict, i);
717 qsort (vectors, n_vectors, sizeof *vectors, compare_vector_ptrs_by_name);
719 struct pivot_table *table = pivot_table_create (N_("Vectors"));
720 pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Attributes"),
721 N_("Variable"), N_("Print Format"));
722 struct pivot_dimension *vector_dim = pivot_dimension_create (
723 table, PIVOT_AXIS_ROW, N_("Vector and Position"));
724 vector_dim->root->show_label = true;
726 for (size_t i = 0; i < n_vectors; i++)
728 const struct vector *vec = vectors[i];
730 struct pivot_category *group = pivot_category_create_group__ (
731 vector_dim->root, pivot_value_new_user_text (
732 vector_get_name (vectors[i]), -1));
734 for (size_t j = 0; j < vector_get_var_cnt (vec); j++)
736 struct variable *var = vector_get_var (vec, j);
738 int row = pivot_category_create_leaf (
739 group, pivot_value_new_integer (j + 1));
741 pivot_table_put2 (table, 0, row, pivot_value_new_variable (var));
742 char fmt_string[FMT_STRING_LEN_MAX + 1];
743 fmt_to_string (var_get_print_format (var), fmt_string);
744 pivot_table_put2 (table, 1, row,
745 pivot_value_new_user_text (fmt_string, -1));
749 pivot_table_submit (table);
754 /* Encoding analysis. */
756 static const char *encoding_names[] = {
757 /* These encodings are from http://encoding.spec.whatwg.org/, as retrieved
758 February 2014. Encodings not supported by glibc and encodings relevant
759 only to HTML have been removed. */
793 /* Added by user request. */
797 #define N_ENCODING_NAMES (sizeof encoding_names / sizeof *encoding_names)
807 recode_strings (struct pool *pool,
808 char **strings, bool *ids, size_t n,
809 const char *encoding)
814 utf8_strings = pool_alloc (pool, n * sizeof *utf8_strings);
815 for (i = 0; i < n; i++)
817 struct substring utf8;
820 error = recode_pedantically ("UTF-8", encoding, ss_cstr (strings[i]),
824 ss_rtrim (&utf8, ss_cstr (" "));
825 utf8.string[utf8.length] = '\0';
827 if (ids[i] && !id_is_plausible (utf8.string, false))
834 utf8_strings[i] = utf8.string;
840 static struct encoding *
841 find_duplicate_encoding (struct encoding *encodings, size_t n_encodings,
842 char **utf8_strings, size_t n_strings,
847 for (e = encodings; e < &encodings[n_encodings]; e++)
854 for (i = 0; i < n_strings; i++)
855 if (strcmp (utf8_strings[i], e->utf8_strings[i]))
866 all_equal (const struct encoding *encodings, size_t n_encodings,
872 s0 = encodings[0].utf8_strings[string_idx];
873 for (i = 1; i < n_encodings; i++)
874 if (strcmp (s0, encodings[i].utf8_strings[string_idx]))
881 equal_prefix (const struct encoding *encodings, size_t n_encodings,
888 s0 = encodings[0].utf8_strings[string_idx];
889 prefix = strlen (s0);
890 for (i = 1; i < n_encodings; i++)
892 const char *si = encodings[i].utf8_strings[string_idx];
895 for (j = 0; j < prefix; j++)
905 while (prefix > 0 && s0[prefix - 1] != ' ')
911 equal_suffix (const struct encoding *encodings, size_t n_encodings,
919 s0 = encodings[0].utf8_strings[string_idx];
920 s0_len = strlen (s0);
922 for (i = 1; i < n_encodings; i++)
924 const char *si = encodings[i].utf8_strings[string_idx];
925 size_t si_len = strlen (si);
930 for (j = 0; j < suffix; j++)
931 if (s0[s0_len - j - 1] != si[si_len - j - 1])
940 while (suffix > 0 && s0[s0_len - suffix] != ' ')
946 report_encodings (const struct file_handle *h, struct pool *pool,
947 char **titles, bool *ids, char **strings, size_t n_strings)
949 struct encoding encodings[N_ENCODING_NAMES];
950 size_t n_encodings, n_unique_strings;
953 for (size_t i = 0; i < N_ENCODING_NAMES; i++)
959 utf8_strings = recode_strings (pool, strings, ids, n_strings,
964 /* Hash utf8_strings. */
966 for (size_t j = 0; j < n_strings; j++)
967 hash = hash_string (utf8_strings[j], hash);
969 /* If there's a duplicate encoding, just mark it. */
970 e = find_duplicate_encoding (encodings, n_encodings,
971 utf8_strings, n_strings, hash);
974 e->encodings |= UINT64_C (1) << i;
978 e = &encodings[n_encodings++];
979 e->encodings = UINT64_C (1) << i;
980 e->utf8_strings = utf8_strings;
985 msg (SW, _("No valid encodings found."));
989 /* Table of valid encodings. */
990 struct pivot_table *table = pivot_table_create__ (
991 pivot_value_new_text_format (N_("Usable encodings for %s."),
993 table->caption = pivot_value_new_text_format (
994 N_("Encodings that can successfully read %s (by specifying the encoding "
995 "name on the GET command's ENCODING subcommand). Encodings that "
996 "yield identical text are listed together."),
999 pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Encodings"),
1001 struct pivot_dimension *number = pivot_dimension_create__ (
1002 table, PIVOT_AXIS_ROW, pivot_value_new_user_text ("#", -1));
1003 number->root->show_label = true;
1005 for (size_t i = 0; i < n_encodings; i++)
1007 struct string s = DS_EMPTY_INITIALIZER;
1008 for (size_t j = 0; j < 64; j++)
1009 if (encodings[i].encodings & (UINT64_C (1) << j))
1010 ds_put_format (&s, "%s, ", encoding_names[j]);
1011 ds_chomp (&s, ss_cstr (", "));
1013 int row = pivot_category_create_leaf (number->root,
1014 pivot_value_new_integer (i + 1));
1016 table, 0, row, pivot_value_new_user_text_nocopy (ds_steal_cstr (&s)));
1018 pivot_table_submit (table);
1020 n_unique_strings = 0;
1021 for (size_t i = 0; i < n_strings; i++)
1022 if (!all_equal (encodings, n_encodings, i))
1024 if (!n_unique_strings)
1027 /* Table of alternative interpretations. */
1028 table = pivot_table_create__ (
1029 pivot_value_new_text_format (N_("%s Encoded Text Strings"),
1031 table->caption = pivot_value_new_text (
1032 N_("Text strings in the file dictionary that the previously listed "
1033 "encodings interpret differently, along with the interpretations."));
1035 pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Text"), N_("Text"));
1037 number = pivot_dimension_create__ (table, PIVOT_AXIS_ROW,
1038 pivot_value_new_user_text ("#", -1));
1039 number->root->show_label = true;
1040 for (size_t i = 0; i < n_encodings; i++)
1041 pivot_category_create_leaf (number->root,
1042 pivot_value_new_integer (i + 1));
1044 struct pivot_dimension *purpose = pivot_dimension_create (
1045 table, PIVOT_AXIS_ROW, N_("Purpose"));
1046 purpose->root->show_label = true;
1048 for (size_t i = 0; i < n_strings; i++)
1049 if (!all_equal (encodings, n_encodings, i))
1051 int prefix = equal_prefix (encodings, n_encodings, i);
1052 int suffix = equal_suffix (encodings, n_encodings, i);
1054 int purpose_idx = pivot_category_create_leaf (
1055 purpose->root, pivot_value_new_user_text (titles[i], -1));
1057 for (size_t j = 0; j < n_encodings; j++)
1059 const char *s = encodings[j].utf8_strings[i] + prefix;
1061 if (prefix || suffix)
1063 size_t len = strlen (s) - suffix;
1064 struct string entry;
1066 ds_init_empty (&entry);
1068 ds_put_cstr (&entry, "...");
1069 ds_put_substring (&entry, ss_buffer (s, len));
1071 ds_put_cstr (&entry, "...");
1073 pivot_table_put3 (table, 0, j, purpose_idx,
1074 pivot_value_new_user_text_nocopy (
1075 ds_steal_cstr (&entry)));
1078 pivot_table_put3 (table, 0, j, purpose_idx,
1079 pivot_value_new_user_text (s, -1));
1083 pivot_table_submit (table);