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/>. */
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/sys-file-reader.h"
32 #include "data/value-labels.h"
33 #include "data/variable.h"
34 #include "data/vector.h"
35 #include "language/command.h"
36 #include "language/data-io/file-handle.h"
37 #include "language/lexer/lexer.h"
38 #include "language/lexer/variable-parser.h"
39 #include "libpspp/array.h"
40 #include "libpspp/hash-functions.h"
41 #include "libpspp/i18n.h"
42 #include "libpspp/message.h"
43 #include "libpspp/misc.h"
44 #include "libpspp/pool.h"
45 #include "libpspp/string-array.h"
46 #include "output/tab.h"
47 #include "output/text-item.h"
48 #include "output/table-item.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)
58 /* Information to include in displaying a dictionary. */
61 DF_DICT_INDEX = 1 << 0,
63 DF_VALUE_LABELS = 1 << 2,
64 DF_VARIABLE_LABELS = 1 << 3,
65 DF_MISSING_VALUES = 1 << 4,
66 DF_AT_ATTRIBUTES = 1 << 5, /* Attributes whose names begin with @. */
67 DF_ATTRIBUTES = 1 << 6, /* All other attributes. */
70 DF_ALIGNMENT = 1 << 9,
72 DF_ALL = (1 << 11) - 1
75 static unsigned int dict_display_mask (const struct dictionary *);
77 static struct table *describe_variable (const struct variable *v, int flags);
79 static void report_encodings (const struct file_handle *,
80 const struct sfm_reader *);
82 /* SYSFILE INFO utility. */
84 cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
86 struct sfm_reader *sfm_reader;
87 struct file_handle *h;
90 struct casereader *reader;
91 struct sfm_read_info info;
100 lex_match (lexer, T_SLASH);
102 if (lex_match_id (lexer, "FILE") || lex_is_string (lexer))
104 lex_match (lexer, T_EQUALS);
107 h = fh_parse (lexer, FH_REF_FILE, NULL);
111 else if (lex_match_id (lexer, "ENCODING"))
113 lex_match (lexer, T_EQUALS);
115 if (!lex_force_string (lexer))
119 encoding = ss_xstrdup (lex_tokss (lexer));
129 lex_sbc_missing ("FILE");
133 sfm_reader = sfm_open (h);
134 if (sfm_reader == NULL)
137 if (encoding && !strcasecmp (encoding, "detect"))
139 report_encodings (h, sfm_reader);
144 reader = sfm_decode (sfm_reader, encoding, &d, &info);
148 casereader_destroy (reader);
150 t = tab_create (2, 11 + (info.product_ext != NULL));
152 tab_vline (t, TAL_GAP, 1, 0, 8);
154 tab_text (t, 0, r, TAB_LEFT, _("File:"));
155 tab_text (t, 1, r++, TAB_LEFT, fh_get_file_name (h));
157 tab_text (t, 0, r, TAB_LEFT, _("Label:"));
159 const char *label = dict_get_label (d);
161 label = _("No label.");
162 tab_text (t, 1, r++, TAB_LEFT, label);
165 tab_text (t, 0, r, TAB_LEFT, _("Created:"));
166 tab_text_format (t, 1, r++, TAB_LEFT, "%s %s by %s",
167 info.creation_date, info.creation_time, info.product);
169 if (info.product_ext)
171 tab_text (t, 0, r, TAB_LEFT, _("Product:"));
172 tab_text (t, 1, r++, TAB_LEFT, info.product_ext);
175 tab_text (t, 0, r, TAB_LEFT, _("Integer Format:"));
176 tab_text (t, 1, r++, TAB_LEFT,
177 info.integer_format == INTEGER_MSB_FIRST ? _("Big Endian")
178 : info.integer_format == INTEGER_LSB_FIRST ? _("Little Endian")
181 tab_text (t, 0, r, TAB_LEFT, _("Real Format:"));
182 tab_text (t, 1, r++, TAB_LEFT,
183 info.float_format == FLOAT_IEEE_DOUBLE_LE ? _("IEEE 754 LE.")
184 : info.float_format == FLOAT_IEEE_DOUBLE_BE ? _("IEEE 754 BE.")
185 : info.float_format == FLOAT_VAX_D ? _("VAX D.")
186 : info.float_format == FLOAT_VAX_G ? _("VAX G.")
187 : info.float_format == FLOAT_Z_LONG ? _("IBM 390 Hex Long.")
190 tab_text (t, 0, r, TAB_LEFT, _("Variables:"));
191 tab_text_format (t, 1, r++, TAB_LEFT, "%zu", dict_get_var_cnt (d));
193 tab_text (t, 0, r, TAB_LEFT, _("Cases:"));
194 if (info.case_cnt == -1)
195 tab_text (t, 1, r, TAB_LEFT, _("Unknown"));
197 tab_text_format (t, 1, r, TAB_LEFT, "%ld", (long int) info.case_cnt);
200 tab_text (t, 0, r, TAB_LEFT, _("Type:"));
201 tab_text (t, 1, r++, TAB_LEFT, _("System File"));
203 tab_text (t, 0, r, TAB_LEFT, _("Weight:"));
205 struct variable *weight_var = dict_get_weight (d);
206 tab_text (t, 1, r++, TAB_LEFT,
208 ? var_get_name (weight_var) : _("Not weighted.")));
211 tab_text (t, 0, r, TAB_LEFT, _("Compression:"));
212 tab_text_format (t, 1, r++, TAB_LEFT,
213 info.compression == SFM_COMP_NONE ? _("None")
214 : info.compression == SFM_COMP_SIMPLE ? "SAV"
217 tab_text (t, 0, r, TAB_LEFT, _("Encoding:"));
218 tab_text (t, 1, r++, TAB_LEFT, dict_get_encoding (d));
222 t = tab_create (3, 1);
223 tab_headers (t, 0, 0, 1, 0);
224 tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable"));
225 tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Description"));
226 tab_text (t, 2, 0, TAB_LEFT | TAT_TITLE, _("Position"));
227 tab_hline (t, TAL_2, 0, 2, 1);
230 for (i = 0; i < dict_get_var_cnt (d); i++)
231 table = table_vpaste (table,
232 describe_variable (dict_get_var (d, i),
233 DF_ALL & ~DF_AT_ATTRIBUTES));
235 table_item_submit (table_item_create (table, NULL /* XXX */));
240 sfm_read_info_destroy (&info);
249 /* DISPLAY utility. */
251 static void display_macros (void);
252 static void display_documents (const struct dictionary *dict);
253 static void display_variables (const struct variable **, size_t, int);
254 static void display_vectors (const struct dictionary *dict, int sorted);
255 static void display_data_file_attributes (struct attrset *, int flags);
258 cmd_display (struct lexer *lexer, struct dataset *ds)
260 /* Whether to sort the list of variables alphabetically. */
263 /* Variables to display. */
265 const struct variable **vl;
267 if (lex_match_id (lexer, "MACROS"))
269 else if (lex_match_id (lexer, "DOCUMENTS"))
270 display_documents (dataset_dict (ds));
271 else if (lex_match_id (lexer, "FILE"))
273 if (!lex_force_match_id (lexer, "LABEL"))
275 if (dict_get_label (dataset_dict (ds)) == NULL)
276 tab_output_text (TAB_LEFT,
277 _("The active dataset does not have a file label."));
279 tab_output_text_format (TAB_LEFT, _("File label: %s"),
280 dict_get_label (dataset_dict (ds)));
286 sorted = lex_match_id (lexer, "SORTED");
288 if (lex_match_id (lexer, "VECTORS"))
290 display_vectors (dataset_dict(ds), sorted);
293 else if (lex_match_id (lexer, "SCRATCH"))
295 dict_get_vars (dataset_dict (ds), &vl, &n, DC_ORDINARY);
305 static const struct subcommand subcommands[] =
307 {"@ATTRIBUTES", DF_ATTRIBUTES | DF_AT_ATTRIBUTES},
308 {"ATTRIBUTES", DF_ATTRIBUTES},
309 {"DICTIONARY", DF_ALL & ~DF_AT_ATTRIBUTES},
310 {"INDEX", DF_DICT_INDEX},
311 {"LABELS", DF_DICT_INDEX | DF_VARIABLE_LABELS},
314 DF_DICT_INDEX | DF_FORMATS | DF_MISSING_VALUES
315 | DF_MEASURE | DF_ROLE | DF_ALIGNMENT | DF_WIDTH},
318 const struct subcommand *sbc;
319 struct dictionary *dict = dataset_dict (ds);
322 for (sbc = subcommands; sbc->name != NULL; sbc++)
323 if (lex_match_id (lexer, sbc->name))
325 flags = sbc->flags & dict_display_mask (dict);
329 lex_match (lexer, T_SLASH);
330 lex_match_id (lexer, "VARIABLES");
331 lex_match (lexer, T_EQUALS);
333 if (lex_token (lexer) != T_ENDCMD)
335 if (!parse_variables_const (lexer, dict, &vl, &n, PV_NONE))
342 dict_get_vars (dict, &vl, &n, 0);
347 sort (vl, n, sizeof *vl,
349 ? compare_var_ptrs_by_name
350 : compare_var_ptrs_by_dict_index), NULL);
351 display_variables (vl, n, flags);
354 msg (SW, _("No variables to display."));
357 if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES))
358 display_data_file_attributes (dict_get_attributes (dataset_dict (ds)),
366 display_macros (void)
368 tab_output_text (TAB_LEFT, _("Macros not supported."));
372 display_documents (const struct dictionary *dict)
374 const struct string_array *documents = dict_get_documents (dict);
376 if (string_array_is_empty (documents))
377 tab_output_text (TAB_LEFT, _("The active dataset dictionary does not "
378 "contain any documents."));
383 tab_output_text (TAB_LEFT | TAT_TITLE,
384 _("Documents in the active dataset:"));
385 for (i = 0; i < dict_get_document_line_cnt (dict); i++)
386 tab_output_text (TAB_LEFT | TAB_FIX, dict_get_document_line (dict, i));
391 count_columns (int flags)
394 if (flags & ~DF_DICT_INDEX)
396 if (flags & DF_DICT_INDEX)
403 position_column (int flags)
406 if (flags & ~DF_DICT_INDEX)
412 display_variables (const struct variable **vl, size_t n, int flags)
419 nc = count_columns (flags);
420 t = tab_create (nc, 1);
421 tab_headers (t, 0, 0, 1, 0);
422 tab_hline (t, TAL_2, 0, nc - 1, 1);
423 tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable"));
424 if (flags & ~DF_DICT_INDEX)
425 tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE,
426 (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS)
427 ? _("Description") : _("Label")));
428 if (flags & DF_DICT_INDEX)
429 tab_text (t, position_column (flags), 0, TAB_LEFT | TAT_TITLE,
433 for (i = 0; i < n; i++)
434 table = table_vpaste (table, describe_variable (vl[i], flags));
437 tab_hline (t, flags & ~DF_DICT_INDEX ? TAL_2 : TAL_1, 0, nc - 1, 1);
440 tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, nc - 1, r - 1);
441 tab_vline (t, TAL_1, 1, 0, r - 1);
443 if (flags & ~DF_DICT_INDEX)
444 tab_vline (t, TAL_1, nc - 1, 0, r - 1);
446 table_item_submit (table_item_create (table, NULL /* XXX */));
450 is_at_name (const char *name)
452 return name[0] == '@' || (name[0] == '$' && name[1] == '@');
456 count_attributes (const struct attrset *set, int flags)
458 struct attrset_iterator i;
459 struct attribute *attr;
463 for (attr = attrset_first (set, &i); attr != NULL;
464 attr = attrset_next (set, &i))
465 if (flags & DF_AT_ATTRIBUTES || !is_at_name (attribute_get_name (attr)))
466 n_attrs += attribute_get_n_values (attr);
470 static struct table *
471 describe_attributes (const struct attrset *set, int flags)
473 struct attribute **attrs;
479 t = tab_create (2, 1 + count_attributes (set, flags));
480 tab_headers (t, 0, 0, 1, 0);
481 tab_box (t, TAL_1, TAL_1, -1, TAL_1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1);
482 tab_hline (t, TAL_1, 0, 1, 1);
483 tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Attribute"));
484 tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Value"));
486 n_attrs = attrset_count (set);
487 attrs = attrset_sorted (set);
488 for (i = 0; i < n_attrs; i++)
490 const struct attribute *attr = attrs[i];
491 const char *name = attribute_get_name (attr);
495 if (!(flags & DF_AT_ATTRIBUTES) && is_at_name (name))
498 n_values = attribute_get_n_values (attr);
499 for (j = 0; j < n_values; j++)
502 tab_text_format (t, 0, r, TAB_LEFT, "%s[%zu]", name, j + 1);
504 tab_text (t, 0, r, TAB_LEFT, name);
505 tab_text (t, 1, r, TAB_LEFT, attribute_get_value (attr, j));
515 display_data_file_attributes (struct attrset *set, int flags)
517 if (count_attributes (set, flags))
518 table_item_submit (table_item_create (describe_attributes (set, flags),
519 _("Custom data file attributes.")));
522 static struct table *
523 describe_value_labels (const struct variable *var)
525 const struct val_labs *val_labs = var_get_value_labels (var);
526 size_t n_labels = val_labs_count (val_labs);
527 const struct val_lab **labels;
531 t = tab_create (2, n_labels + 1);
532 tab_box (t, TAL_1, TAL_1, -1, TAL_1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1);
534 tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Value"));
535 tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Label"));
537 tab_hline (t, TAL_1, 0, 1, 1);
538 tab_vline (t, TAL_1, 1, 0, n_labels);
540 labels = val_labs_sorted (val_labs);
541 for (i = 0; i < n_labels; i++)
543 const struct val_lab *vl = labels[i];
545 tab_value (t, 0, i + 1, TAB_NONE, &vl->value, var, NULL);
546 tab_text (t, 1, i + 1, TAB_LEFT, val_lab_get_escaped_label (vl));
553 /* Puts a description of variable V into table T starting at row
554 R. The variable will be described in the format given by
555 FLAGS. Returns the next row available for use in the
557 static struct table *
558 describe_variable (const struct variable *v, int flags)
565 /* Variable label. */
566 if (flags & DF_VARIABLE_LABELS && var_has_label (v))
568 if (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS))
569 ds_put_format (&s, _("Label: %s\n"), var_get_label (v));
571 ds_put_format (&s, "%s\n", var_get_label (v));
574 /* Print/write format, or print and write formats. */
575 if (flags & DF_FORMATS)
577 const struct fmt_spec *print = var_get_print_format (v);
578 const struct fmt_spec *write = var_get_write_format (v);
579 char str[FMT_STRING_LEN_MAX + 1];
581 if (fmt_equal (print, write))
582 ds_put_format (&s, _("Format: %s\n"), fmt_to_string (print, str));
585 ds_put_format (&s, _("Print Format: %s\n"),
586 fmt_to_string (print, str));
587 ds_put_format (&s, _("Write Format: %s\n"),
588 fmt_to_string (write, str));
592 /* Measurement level, role, display width, alignment. */
593 if (flags & DF_MEASURE)
594 ds_put_format (&s, _("Measure: %s\n"),
595 measure_to_string (var_get_measure (v)));
598 ds_put_format (&s, _("Role: %s\n"), var_role_to_string (var_get_role (v)));
601 if (flags & DF_ALIGNMENT)
602 ds_put_format (&s, _("Display Alignment: %s\n"),
603 alignment_to_string (var_get_alignment (v)));
605 if (flags & DF_WIDTH)
606 ds_put_format (&s, _("Display Width: %d\n"), var_get_display_width (v));
608 /* Missing values if any. */
609 if (flags & DF_MISSING_VALUES && var_has_missing_values (v))
611 const struct missing_values *mv = var_get_missing_values (v);
615 ds_put_cstr (&s, _("Missing Values: "));
617 if (mv_has_range (mv))
620 mv_get_range (mv, &x, &y);
622 ds_put_format (&s, "LOWEST THRU %.*g", DBL_DIG + 1, y);
623 else if (y == HIGHEST)
624 ds_put_format (&s, "%.*g THRU HIGHEST", DBL_DIG + 1, x);
626 ds_put_format (&s, "%.*g THRU %.*g",
631 for (i = 0; i < mv_n_values (mv); i++)
633 const union value *value = mv_get_value (mv, i);
635 ds_put_cstr (&s, "; ");
636 if (var_is_numeric (v))
637 ds_put_format (&s, "%.*g", DBL_DIG + 1, value->f);
640 int width = var_get_width (v);
641 int mv_width = MIN (width, MV_MAX_STRING);
643 ds_put_byte (&s, '"');
644 memcpy (ds_put_uninit (&s, mv_width),
645 value_str (value, width), mv_width);
646 ds_put_byte (&s, '"');
649 ds_put_byte (&s, '\n');
652 ds_chomp_byte (&s, '\n');
654 table = (ds_is_empty (&s)
656 : table_from_string (TAB_LEFT, ds_cstr (&s)));
660 if (flags & DF_VALUE_LABELS && var_has_value_labels (v))
661 table = table_vpaste (table, table_create_nested (describe_value_labels (v)));
663 if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES))
665 struct attrset *attrs = var_get_attributes (v);
667 if (count_attributes (attrs, flags))
668 table = table_vpaste (
669 table, table_create_nested (describe_attributes (attrs, flags)));
673 table = table_from_string (TAB_LEFT, "");
675 table = table_hpaste (table_from_string (0, var_get_name (v)),
676 table_stomp (table));
677 if (flags & DF_DICT_INDEX)
679 char s[INT_BUFSIZE_BOUND (size_t)];
681 sprintf (s, "%zu", var_get_dict_index (v) + 1);
682 table = table_hpaste (table, table_from_string (0, s));
688 /* Display a list of vectors. If SORTED is nonzero then they are
689 sorted alphabetically. */
691 display_vectors (const struct dictionary *dict, int sorted)
693 const struct vector **vl;
700 nvec = dict_get_vector_cnt (dict);
703 msg (SW, _("No vectors defined."));
707 vl = xnmalloc (nvec, sizeof *vl);
709 for (i = 0; i < nvec; i++)
711 vl[i] = dict_get_vector (dict, i);
712 nrow += vector_get_var_cnt (vl[i]);
715 qsort (vl, nvec, sizeof *vl, compare_vector_ptrs_by_name);
717 t = tab_create (4, nrow + 1);
718 tab_headers (t, 0, 0, 1, 0);
719 tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 3, nrow);
720 tab_box (t, -1, -1, -1, TAL_1, 0, 0, 3, nrow);
721 tab_hline (t, TAL_2, 0, 3, 1);
722 tab_text (t, 0, 0, TAT_TITLE | TAB_LEFT, _("Vector"));
723 tab_text (t, 1, 0, TAT_TITLE | TAB_LEFT, _("Position"));
724 tab_text (t, 2, 0, TAT_TITLE | TAB_LEFT, _("Variable"));
725 tab_text (t, 3, 0, TAT_TITLE | TAB_LEFT, _("Print Format"));
728 for (i = 0; i < nvec; i++)
730 const struct vector *vec = vl[i];
733 tab_joint_text (t, 0, row, 0, row + vector_get_var_cnt (vec) - 1,
734 TAB_LEFT, vector_get_name (vl[i]));
736 for (j = 0; j < vector_get_var_cnt (vec); j++)
738 struct variable *var = vector_get_var (vec, j);
739 char fmt_string[FMT_STRING_LEN_MAX + 1];
740 fmt_to_string (var_get_print_format (var), fmt_string);
742 tab_text_format (t, 1, row, TAB_RIGHT, "%zu", j + 1);
743 tab_text (t, 2, row, TAB_LEFT, var_get_name (var));
744 tab_text (t, 3, row, TAB_LEFT, fmt_string);
747 tab_hline (t, TAL_1, 0, 3, row);
755 /* Encoding analysis. */
757 static const char *encoding_names[] = {
758 /* These encodings are from http://encoding.spec.whatwg.org/, as retrieved
759 February 2014. Encodings not supported by glibc and encodings relevant
760 only to HTML have been removed. */
794 /* Added by user request. */
798 #define N_ENCODING_NAMES (sizeof encoding_names / sizeof *encoding_names)
808 recode_strings (struct pool *pool,
809 char **strings, bool *ids, size_t n,
810 const char *encoding)
815 utf8_strings = pool_alloc (pool, n * sizeof *utf8_strings);
816 for (i = 0; i < n; i++)
818 struct substring utf8;
821 error = recode_pedantically ("UTF-8", encoding, ss_cstr (strings[i]),
825 ss_rtrim (&utf8, ss_cstr (" "));
826 utf8.string[utf8.length] = '\0';
828 if (ids[i] && !id_is_plausible (utf8.string, false))
835 utf8_strings[i] = utf8.string;
841 static struct encoding *
842 find_duplicate_encoding (struct encoding *encodings, size_t n_encodings,
843 char **utf8_strings, size_t n_strings,
848 for (e = encodings; e < &encodings[n_encodings]; e++)
855 for (i = 0; i < n_strings; i++)
856 if (strcmp (utf8_strings[i], e->utf8_strings[i]))
867 all_equal (const struct encoding *encodings, size_t n_encodings,
873 s0 = encodings[0].utf8_strings[string_idx];
874 for (i = 1; i < n_encodings; i++)
875 if (strcmp (s0, encodings[i].utf8_strings[string_idx]))
882 equal_prefix (const struct encoding *encodings, size_t n_encodings,
889 s0 = encodings[0].utf8_strings[string_idx];
890 prefix = strlen (s0);
891 for (i = 1; i < n_encodings; i++)
893 const char *si = encodings[i].utf8_strings[string_idx];
896 for (j = 0; j < prefix; j++)
906 while (prefix > 0 && s0[prefix - 1] != ' ')
912 equal_suffix (const struct encoding *encodings, size_t n_encodings,
920 s0 = encodings[0].utf8_strings[string_idx];
921 s0_len = strlen (s0);
923 for (i = 1; i < n_encodings; i++)
925 const char *si = encodings[i].utf8_strings[string_idx];
926 size_t si_len = strlen (si);
931 for (j = 0; j < suffix; j++)
932 if (s0[s0_len - j - 1] != si[si_len - j - 1])
941 while (suffix > 0 && s0[s0_len - suffix] != ' ')
947 report_encodings (const struct file_handle *h, const struct sfm_reader *r)
952 struct encoding encodings[N_ENCODING_NAMES];
953 size_t n_encodings, n_strings, n_unique_strings;
956 struct text_item *text;
960 pool = pool_create ();
961 n_strings = sfm_get_strings (r, pool, &titles, &ids, &strings);
964 for (i = 0; i < N_ENCODING_NAMES; i++)
970 utf8_strings = recode_strings (pool, strings, ids, n_strings,
975 /* Hash utf8_strings. */
977 for (j = 0; j < n_strings; j++)
978 hash = hash_string (utf8_strings[j], hash);
980 /* If there's a duplicate encoding, just mark it. */
981 e = find_duplicate_encoding (encodings, n_encodings,
982 utf8_strings, n_strings, hash);
985 e->encodings |= UINT64_C (1) << i;
989 e = &encodings[n_encodings++];
990 e->encodings = UINT64_C (1) << i;
991 e->utf8_strings = utf8_strings;
996 msg (SW, _("No valid encodings found."));
1001 text = text_item_create_format (
1002 TEXT_ITEM_PARAGRAPH,
1003 _("The following table lists the encodings that can successfully read %s, "
1004 "by specifying the encoding name on the GET command's ENCODING "
1005 "subcommand. Encodings that yield identical text are listed "
1006 "together."), fh_get_name (h));
1007 text_item_submit (text);
1009 t = tab_create (2, n_encodings + 1);
1010 tab_title (t, _("Usable encodings for %s."), fh_get_name (h));
1011 tab_headers (t, 1, 0, 1, 0);
1012 tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 1, n_encodings);
1013 tab_hline (t, TAL_1, 0, 1, 1);
1014 tab_text (t, 0, 0, TAB_RIGHT, "#");
1015 tab_text (t, 1, 0, TAB_LEFT, _("Encodings"));
1016 for (i = 0; i < n_encodings; i++)
1021 for (j = 0; j < 64; j++)
1022 if (encodings[i].encodings & (UINT64_C (1) << j))
1023 ds_put_format (&s, "%s, ", encoding_names[j]);
1024 ds_chomp (&s, ss_cstr (", "));
1026 tab_text_format (t, 0, i + 1, TAB_RIGHT, "%zu", i + 1);
1027 tab_text (t, 1, i + 1, TAB_LEFT, ds_cstr (&s));
1032 n_unique_strings = 0;
1033 for (i = 0; i < n_strings; i++)
1034 if (!all_equal (encodings, n_encodings, i))
1036 if (!n_unique_strings)
1038 pool_destroy (pool);
1042 text = text_item_create_format (
1043 TEXT_ITEM_PARAGRAPH,
1044 _("The following table lists text strings in the file dictionary that "
1045 "the encodings above interpret differently, along with those "
1046 "interpretations."));
1047 text_item_submit (text);
1049 t = tab_create (3, (n_encodings * n_unique_strings) + 1);
1050 tab_title (t, _("%s encoded text strings."), fh_get_name (h));
1051 tab_headers (t, 1, 0, 1, 0);
1052 tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 2, n_encodings * n_unique_strings);
1053 tab_hline (t, TAL_1, 0, 2, 1);
1055 tab_text (t, 0, 0, TAB_LEFT, _("Purpose"));
1056 tab_text (t, 1, 0, TAB_RIGHT, "#");
1057 tab_text (t, 2, 0, TAB_LEFT, _("Text"));
1060 for (i = 0; i < n_strings; i++)
1061 if (!all_equal (encodings, n_encodings, i))
1063 int prefix = equal_prefix (encodings, n_encodings, i);
1064 int suffix = equal_suffix (encodings, n_encodings, i);
1066 tab_joint_text (t, 0, row, 0, row + n_encodings - 1,
1067 TAB_LEFT, titles[i]);
1068 tab_hline (t, TAL_1, 0, 2, row);
1069 for (j = 0; j < n_encodings; j++)
1071 const char *s = encodings[j].utf8_strings[i] + prefix;
1073 tab_text_format (t, 1, row, TAB_RIGHT, "%zu", j + 1);
1074 if (prefix || suffix)
1076 size_t len = strlen (s) - suffix;
1077 struct string entry;
1079 ds_init_empty (&entry);
1081 ds_put_cstr (&entry, "...");
1082 ds_put_substring (&entry, ss_buffer (s, len));
1084 ds_put_cstr (&entry, "...");
1085 tab_text (t, 2, row, TAB_LEFT, ds_cstr (&entry));
1088 tab_text (t, 2, row, TAB_LEFT, s);
1094 pool_destroy (pool);
1098 dict_display_mask (const struct dictionary *d)
1100 size_t n_vars = dict_get_var_cnt (d);
1104 mask = DF_ALL & ~(DF_MEASURE | DF_ROLE | DF_ALIGNMENT | DF_WIDTH);
1105 for (i = 0; i < n_vars; i++)
1107 const struct variable *v = dict_get_var (d, i);
1108 enum val_type val = var_get_type (v);
1109 int width = var_get_width (v);
1111 if (var_get_measure (v) != var_default_measure (val))
1114 if (var_get_role (v) != ROLE_INPUT)
1117 if (var_get_alignment (v) != var_default_alignment (val))
1118 mask |= DF_ALIGNMENT;
1120 if (var_get_display_width (v) != var_default_display_width (width))