X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fsys-file-info.c;h=92ade932ef17384fdde49786ffbf9bee71293d82;hb=d849605f7d1abf4a881faec40572f536859d6c19;hp=05f9be91fbd4224b87f9789597d4a9d09d292f24;hpb=e461291a6df7145e7a870a83f2f10b5839845898;p=pspp diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 05f9be91fb..92ade932ef 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -21,6 +21,7 @@ #include #include +#include "data/any-reader.h" #include "data/attributes.h" #include "data/casereader.h" #include "data/dataset.h" @@ -28,7 +29,6 @@ #include "data/file-handle-def.h" #include "data/format.h" #include "data/missing-values.h" -#include "data/sys-file-reader.h" #include "data/value-labels.h" #include "data/variable.h" #include "data/vector.h" @@ -45,8 +45,10 @@ #include "libpspp/string-array.h" #include "output/tab.h" #include "output/text-item.h" +#include "output/table-item.h" #include "gl/localcharset.h" +#include "gl/intprops.h" #include "gl/minmax.h" #include "gl/xalloc.h" @@ -63,27 +65,33 @@ enum DF_MISSING_VALUES = 1 << 4, DF_AT_ATTRIBUTES = 1 << 5, /* Attributes whose names begin with @. */ DF_ATTRIBUTES = 1 << 6, /* All other attributes. */ - DF_MISC = 1 << 7, - DF_ALL = (1 << 8) - 1 + DF_MEASURE = 1 << 7, + DF_ROLE = 1 << 8, + DF_ALIGNMENT = 1 << 9, + DF_WIDTH = 1 << 10, + DF_ALL = (1 << 11) - 1 }; -static int describe_variable (const struct variable *v, struct tab_table *t, - int r, int pc, int flags); +static unsigned int dict_display_mask (const struct dictionary *); -static void report_encodings (const struct file_handle *, - const struct sfm_reader *); +static struct table *describe_variable (const struct variable *v, int flags); + +static void report_encodings (const struct file_handle *, struct pool *, + char **titles, bool *ids, + char **strings, size_t n_strings); /* SYSFILE INFO utility. */ int cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) { - struct sfm_reader *sfm_reader; + struct any_reader *any_reader; struct file_handle *h; struct dictionary *d; struct tab_table *t; struct casereader *reader; - struct sfm_read_info info; + struct any_read_info info; char *encoding; + struct table *table; int r, i; h = NULL; @@ -123,21 +131,36 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) goto error; } - sfm_reader = sfm_open (h); - if (sfm_reader == NULL) - goto error; + any_reader = any_reader_open (h); + if (!any_reader) + { + free (encoding); + return CMD_FAILURE; + } if (encoding && !strcasecmp (encoding, "detect")) { - report_encodings (h, sfm_reader); + char **titles, **strings; + struct pool *pool; + size_t n_strings; + bool *ids; + + pool = pool_create (); + n_strings = any_reader_get_strings (any_reader, pool, + &titles, &ids, &strings); + any_reader_close (any_reader); + + report_encodings (h, pool, titles, ids, strings, n_strings); fh_unref (h); + pool_destroy (pool); + free (encoding); + return CMD_SUCCESS; } - reader = sfm_decode (sfm_reader, encoding, &d, &info); + reader = any_reader_decode (any_reader, encoding, &d, &info); if (!reader) goto error; - casereader_destroy (reader); t = tab_create (2, 11 + (info.product_ext != NULL)); @@ -191,7 +214,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) r++; tab_text (t, 0, r, TAB_LEFT, _("Type:")); - tab_text (t, 1, r++, TAB_LEFT, _("System File")); + tab_text (t, 1, r++, TAB_LEFT, gettext (info.klass->name)); tab_text (t, 0, r, TAB_LEFT, _("Weight:")); { @@ -203,8 +226,8 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) tab_text (t, 0, r, TAB_LEFT, _("Compression:")); tab_text_format (t, 1, r++, TAB_LEFT, - info.compression == SFM_COMP_NONE ? _("None") - : info.compression == SFM_COMP_SIMPLE ? "SAV" + info.compression == ANY_COMP_NONE ? _("None") + : info.compression == ANY_COMP_SIMPLE ? "SAV" : "ZSAV"); tab_text (t, 0, r, TAB_LEFT, _("Encoding:")); @@ -212,27 +235,26 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) tab_submit (t); - t = tab_create (4, 1 + 2 * dict_get_var_cnt (d)); + t = tab_create (3, 1); tab_headers (t, 0, 0, 1, 0); tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable")); - tab_joint_text (t, 1, 0, 2, 0, TAB_LEFT | TAT_TITLE, _("Description")); - tab_text (t, 3, 0, TAB_LEFT | TAT_TITLE, _("Position")); - tab_hline (t, TAL_2, 0, 3, 1); - for (r = 1, i = 0; i < dict_get_var_cnt (d); i++) - r = describe_variable (dict_get_var (d, i), t, r, 3, - DF_ALL & ~DF_AT_ATTRIBUTES); + tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Description")); + tab_text (t, 2, 0, TAB_LEFT | TAT_TITLE, _("Position")); + tab_hline (t, TAL_2, 0, 2, 1); - tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 3, r); - tab_vline (t, TAL_1, 1, 0, r); - tab_vline (t, TAL_1, 3, 0, r); + table = &t->table; + for (i = 0; i < dict_get_var_cnt (d); i++) + table = table_vpaste (table, + describe_variable (dict_get_var (d, i), + DF_ALL & ~DF_AT_ATTRIBUTES)); - tab_resize (t, -1, r); - tab_submit (t); + table_item_submit (table_item_create (table, NULL /* XXX */, NULL)); dict_destroy (d); fh_unref (h); - sfm_read_info_destroy (&info); + free (encoding); + any_read_info_destroy (&info); return CMD_SUCCESS; error: @@ -306,16 +328,18 @@ cmd_display (struct lexer *lexer, struct dataset *ds) {"LABELS", DF_DICT_INDEX | DF_VARIABLE_LABELS}, {"NAMES", 0}, {"VARIABLES", - DF_DICT_INDEX | DF_FORMATS | DF_MISSING_VALUES | DF_MISC}, + DF_DICT_INDEX | DF_FORMATS | DF_MISSING_VALUES + | DF_MEASURE | DF_ROLE | DF_ALIGNMENT | DF_WIDTH}, {NULL, 0}, }; const struct subcommand *sbc; + struct dictionary *dict = dataset_dict (ds); flags = 0; for (sbc = subcommands; sbc->name != NULL; sbc++) if (lex_match_id (lexer, sbc->name)) { - flags = sbc->flags; + flags = sbc->flags & dict_display_mask (dict); break; } @@ -325,15 +349,14 @@ cmd_display (struct lexer *lexer, struct dataset *ds) if (lex_token (lexer) != T_ENDCMD) { - if (!parse_variables_const (lexer, dataset_dict (ds), &vl, &n, - PV_NONE)) + if (!parse_variables_const (lexer, dict, &vl, &n, PV_NONE)) { free (vl); return CMD_FAILURE; } } else - dict_get_vars (dataset_dict (ds), &vl, &n, 0); + dict_get_vars (dict, &vl, &n, 0); } if (n > 0) @@ -381,49 +404,53 @@ display_documents (const struct dictionary *dict) } } +static int +count_columns (int flags) +{ + int nc = 1; + if (flags & ~DF_DICT_INDEX) + nc++; + if (flags & DF_DICT_INDEX) + nc++; + + return nc; +} + +static int +position_column (int flags) +{ + int pc = 1; + if (flags & ~DF_DICT_INDEX) + pc++; + return pc; +} + static void display_variables (const struct variable **vl, size_t n, int flags) { struct tab_table *t; - int nc; /* Number of columns. */ - int pc; /* `Position column' */ - int r; /* Current row. */ + struct table *table; size_t i; + int nc; - /* One column for the name, - two columns for general description, - one column for dictionary index. */ - nc = 1; - if (flags & ~DF_DICT_INDEX) - nc += 2; - pc = nc; - if (flags & DF_DICT_INDEX) - nc++; - - t = tab_create (nc, n + 5); + nc = count_columns (flags); + t = tab_create (nc, 1); tab_headers (t, 0, 0, 1, 0); tab_hline (t, TAL_2, 0, nc - 1, 1); tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable")); if (flags & ~DF_DICT_INDEX) - tab_joint_text (t, 1, 0, 2, 0, TAB_LEFT | TAT_TITLE, - (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS) - ? _("Description") : _("Label"))); + tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, + (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS) + ? _("Description") : _("Label"))); if (flags & DF_DICT_INDEX) - tab_text (t, pc, 0, TAB_LEFT | TAT_TITLE, _("Position")); + tab_text (t, position_column (flags), 0, TAB_LEFT | TAT_TITLE, + _("Position")); - r = 1; + table = &t->table; for (i = 0; i < n; i++) - r = describe_variable (vl[i], t, r, pc, flags); - tab_hline (t, flags & ~DF_DICT_INDEX ? TAL_2 : TAL_1, 0, nc - 1, 1); - if (flags) - { - tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, nc - 1, r - 1); - tab_vline (t, TAL_1, 1, 0, r - 1); - } - if (flags & ~DF_DICT_INDEX) - tab_vline (t, TAL_1, nc - 1, 0, r - 1); - tab_resize (t, -1, r); - tab_submit (t); + table = table_vpaste (table, describe_variable (vl[i], flags)); + + table_item_submit (table_item_create (table, NULL /* XXX */, NULL)); } static bool @@ -447,13 +474,21 @@ count_attributes (const struct attrset *set, int flags) return n_attrs; } -static void -display_attributes (struct tab_table *t, const struct attrset *set, int flags, - int c, int r) +static struct table * +describe_attributes (const struct attrset *set, int flags) { struct attribute **attrs; + struct tab_table *t; size_t n_attrs; size_t i; + int r = 1; + + t = tab_create (2, 1 + count_attributes (set, flags)); + tab_headers (t, 0, 0, 1, 0); + tab_box (t, TAL_1, TAL_1, -1, TAL_1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1); + tab_hline (t, TAL_1, 0, 1, 1); + tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Attribute")); + tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Value")); n_attrs = attrset_count (set); attrs = attrset_sorted (set); @@ -471,78 +506,73 @@ display_attributes (struct tab_table *t, const struct attrset *set, int flags, for (j = 0; j < n_values; j++) { if (n_values > 1) - tab_text_format (t, c, r, TAB_LEFT, "%s[%zu]", name, j + 1); + tab_text_format (t, 0, r, TAB_LEFT, "%s[%zu]", name, j + 1); else - tab_text (t, c, r, TAB_LEFT, name); - tab_text (t, c + 1, r, TAB_LEFT, attribute_get_value (attr, j)); + tab_text (t, 0, r, TAB_LEFT, name); + tab_text (t, 1, r, TAB_LEFT, attribute_get_value (attr, j)); r++; } } free (attrs); + + return &t->table; } static void display_data_file_attributes (struct attrset *set, int flags) { - struct tab_table *t; - size_t n_attrs; + if (count_attributes (set, flags)) + table_item_submit (table_item_create (describe_attributes (set, flags), + _("Custom data file attributes."), + NULL)); +} - n_attrs = count_attributes (set, flags); - if (!n_attrs) - return; +static struct table * +describe_value_labels (const struct variable *var) +{ + const struct val_labs *val_labs = var_get_value_labels (var); + size_t n_labels = val_labs_count (val_labs); + const struct val_lab **labels; + struct tab_table *t; + size_t i; - t = tab_create (2, n_attrs + 1); - tab_headers (t, 0, 0, 1, 0); + t = tab_create (2, n_labels + 1); tab_box (t, TAL_1, TAL_1, -1, TAL_1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1); - tab_hline (t, TAL_2, 0, 1, 1); - tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Attribute")); - tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Value")); - display_attributes (t, set, flags, 0, 1); - tab_title (t, "Custom data file attributes."); - tab_submit (t); -} -/* Puts a description of variable V into table T starting at row - R. The variable will be described in the format given by - FLAGS. Returns the next row available for use in the - table. */ -static int -describe_variable (const struct variable *v, struct tab_table *t, int r, - int pc, int flags) -{ - size_t n_attrs = 0; - int need_rows; - - /* Make sure that enough rows are allocated. */ - need_rows = 1; - if (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS)) - need_rows += 16; - if (flags & DF_VALUE_LABELS) - need_rows += val_labs_count (var_get_value_labels (v)); - if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES)) - { - n_attrs = count_attributes (var_get_attributes (v), flags); - need_rows += n_attrs; - } - if (r + need_rows > tab_nr (t)) + tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Value")); + tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Label")); + + tab_hline (t, TAL_1, 0, 1, 1); + tab_vline (t, TAL_1, 1, 0, n_labels); + + labels = val_labs_sorted (val_labs); + for (i = 0; i < n_labels; i++) { - int nr = MAX (r + need_rows, tab_nr (t) * 2); - tab_realloc (t, -1, nr); + const struct val_lab *vl = labels[i]; + + tab_value (t, 0, i + 1, TAB_NONE, &vl->value, var, NULL); + tab_text (t, 1, i + 1, TAB_LEFT, val_lab_get_escaped_label (vl)); } + free (labels); - /* Put the name, var label, and position into the first row. */ - tab_text (t, 0, r, TAB_LEFT, var_get_name (v)); - if (flags & DF_DICT_INDEX) - tab_text_format (t, pc, r, 0, "%zu", var_get_dict_index (v) + 1); + return &t->table; +} + +static struct table * +describe_variable_details (const struct variable *v, int flags) +{ + struct table *table; + struct string s; + ds_init_empty (&s); + + /* Variable label. */ if (flags & DF_VARIABLE_LABELS && var_has_label (v)) { if (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS)) - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Label: %s"), var_get_label (v)); + ds_put_format (&s, _("Label: %s\n"), var_get_label (v)); else - tab_joint_text (t, 1, r, 2, r, TAB_LEFT, var_get_label (v)); - r++; + ds_put_format (&s, "%s\n", var_get_label (v)); } /* Print/write format, or print and write formats. */ @@ -550,77 +580,54 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, { const struct fmt_spec *print = var_get_print_format (v); const struct fmt_spec *write = var_get_write_format (v); + char str[FMT_STRING_LEN_MAX + 1]; if (fmt_equal (print, write)) - { - char str[FMT_STRING_LEN_MAX + 1]; - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Format: %s"), fmt_to_string (print, str)); - r++; - } + ds_put_format (&s, _("Format: %s\n"), fmt_to_string (print, str)); else { - char str[FMT_STRING_LEN_MAX + 1]; - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Print Format: %s"), - fmt_to_string (print, str)); - r++; - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Write Format: %s"), - fmt_to_string (write, str)); - r++; + ds_put_format (&s, _("Print Format: %s\n"), + fmt_to_string (print, str)); + ds_put_format (&s, _("Write Format: %s\n"), + fmt_to_string (write, str)); } } - + /* Measurement level, role, display width, alignment. */ - if (flags & DF_MISC) - { - enum var_role role = var_get_role (v); + if (flags & DF_MEASURE) + ds_put_format (&s, _("Measure: %s\n"), + measure_to_string (var_get_measure (v))); - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Measure: %s"), - measure_to_string (var_get_measure (v))); - r++; + if (flags & DF_ROLE) + ds_put_format (&s, _("Role: %s\n"), var_role_to_string (var_get_role (v))); - if (role != ROLE_INPUT) - { - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Role: %s"), var_role_to_string (role)); - r++; - } - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Display Alignment: %s"), - alignment_to_string (var_get_alignment (v))); - r++; + if (flags & DF_ALIGNMENT) + ds_put_format (&s, _("Display Alignment: %s\n"), + alignment_to_string (var_get_alignment (v))); + + if (flags & DF_WIDTH) + ds_put_format (&s, _("Display Width: %d\n"), var_get_display_width (v)); - tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, - _("Display Width: %d"), - var_get_display_width (v)); - r++; - } - /* Missing values if any. */ if (flags & DF_MISSING_VALUES && var_has_missing_values (v)) { const struct missing_values *mv = var_get_missing_values (v); - char buf[128]; - char *cp; int cnt = 0; int i; - cp = stpcpy (buf, _("Missing Values: ")); + ds_put_cstr (&s, _("Missing Values: ")); if (mv_has_range (mv)) { double x, y; mv_get_range (mv, &x, &y); if (x == LOWEST) - cp += sprintf (cp, "LOWEST THRU %.*g", DBL_DIG + 1, y); + ds_put_format (&s, "LOWEST THRU %.*g", DBL_DIG + 1, y); else if (y == HIGHEST) - cp += sprintf (cp, "%.*g THRU HIGHEST", DBL_DIG + 1, x); + ds_put_format (&s, "%.*g THRU HIGHEST", DBL_DIG + 1, x); else - cp += sprintf (cp, "%.*g THRU %.*g", + ds_put_format (&s, "%.*g THRU %.*g", DBL_DIG + 1, x, DBL_DIG + 1, y); cnt++; @@ -629,70 +636,67 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, { const union value *value = mv_get_value (mv, i); if (cnt++ > 0) - cp += sprintf (cp, "; "); + ds_put_cstr (&s, "; "); if (var_is_numeric (v)) - cp += sprintf (cp, "%.*g", DBL_DIG + 1, value->f); + ds_put_format (&s, "%.*g", DBL_DIG + 1, value->f); else { int width = var_get_width (v); int mv_width = MIN (width, MV_MAX_STRING); - *cp++ = '"'; - memcpy (cp, value_str (value, width), mv_width); - cp += mv_width; - *cp++ = '"'; - *cp = '\0'; + ds_put_byte (&s, '"'); + memcpy (ds_put_uninit (&s, mv_width), + value_str (value, width), mv_width); + ds_put_byte (&s, '"'); } } - - tab_joint_text (t, 1, r, 2, r, TAB_LEFT, buf); - r++; + ds_put_byte (&s, '\n'); } + ds_chomp_byte (&s, '\n'); + + table = (ds_is_empty (&s) + ? NULL + : table_from_string (TAB_LEFT, ds_cstr (&s))); + ds_destroy (&s); + /* Value labels. */ if (flags & DF_VALUE_LABELS && var_has_value_labels (v)) - { - const struct val_labs *val_labs = var_get_value_labels (v); - size_t n_labels = val_labs_count (val_labs); - const struct val_lab **labels; - int orig_r = r; - size_t i; + table = table_vpaste (table, table_create_nested (describe_value_labels (v))); -#if 0 - tab_text (t, 1, r, TAB_LEFT, _("Value")); - tab_text (t, 2, r, TAB_LEFT, _("Label")); - r++; -#endif - - tab_hline (t, TAL_1, 1, 2, r); + if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES)) + { + struct attrset *attrs = var_get_attributes (v); - labels = val_labs_sorted (val_labs); - for (i = 0; i < n_labels; i++) - { - const struct val_lab *vl = labels[i]; + if (count_attributes (attrs, flags)) + table = table_vpaste ( + table, table_create_nested (describe_attributes (attrs, flags))); + } - tab_value (t, 1, r, TAB_NONE, &vl->value, v, NULL); - tab_text (t, 2, r, TAB_LEFT, val_lab_get_escaped_label (vl)); - r++; - } - free (labels); + return table ? table : table_from_string (TAB_LEFT, ""); +} - tab_vline (t, TAL_1, 2, orig_r, r - 1); - } +/* Puts a description of variable V into table T starting at row + R. The variable will be described in the format given by + FLAGS. Returns the next row available for use in the + table. */ +static struct table * +describe_variable (const struct variable *v, int flags) +{ + struct table *table; - if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES) && n_attrs) + table = flags & ~DF_DICT_INDEX ? describe_variable_details (v, flags) : NULL; + table = table_hpaste (table_from_string (0, var_get_name (v)), + table ? table_stomp (table) : NULL); + if (flags & DF_DICT_INDEX) { - tab_joint_text (t, 1, r, 2, r, TAB_LEFT, "Custom attributes:"); - r++; + char s[INT_BUFSIZE_BOUND (size_t)]; - display_attributes (t, var_get_attributes (v), flags, 1, r); - r += n_attrs; + sprintf (s, "%zu", var_get_dict_index (v) + 1); + table = table_hpaste (table, table_from_string (0, s)); } - /* Draw a line below the last row of information on this variable. */ - tab_hline (t, TAL_1, 0, tab_nc (t) - 1, r); - - return r; + return table; } /* Display a list of vectors. If SORTED is nonzero then they are @@ -764,10 +768,10 @@ display_vectors (const struct dictionary *dict, int sorted) /* Encoding analysis. */ -/* This list of encodings is taken from http://encoding.spec.whatwg.org/, as - retrieved February 2014. Encodings not supported by glibc and encodings - relevant only to HTML have been removed. */ static const char *encoding_names[] = { + /* These encodings are from http://encoding.spec.whatwg.org/, as retrieved + February 2014. Encodings not supported by glibc and encodings relevant + only to HTML have been removed. */ "utf-8", "windows-1252", "iso-8859-2", @@ -800,6 +804,10 @@ static const char *encoding_names[] = { "iso-2022-jp", "shift_jis", "euc-kr", + + /* Added by user request. */ + "ibm850", + "din_66003", }; #define N_ENCODING_NAMES (sizeof encoding_names / sizeof *encoding_names) @@ -950,22 +958,15 @@ equal_suffix (const struct encoding *encodings, size_t n_encodings, } static void -report_encodings (const struct file_handle *h, const struct sfm_reader *r) +report_encodings (const struct file_handle *h, struct pool *pool, + char **titles, bool *ids, char **strings, size_t n_strings) { - char **titles; - char **strings; - bool *ids; struct encoding encodings[N_ENCODING_NAMES]; - size_t n_encodings, n_strings, n_unique_strings; + size_t n_encodings, n_unique_strings; size_t i, j; struct tab_table *t; - struct text_item *text; - struct pool *pool; size_t row; - pool = pool_create (); - n_strings = sfm_get_strings (r, pool, &titles, &ids, &strings); - n_encodings = 0; for (i = 0; i < N_ENCODING_NAMES; i++) { @@ -1000,20 +1001,15 @@ report_encodings (const struct file_handle *h, const struct sfm_reader *r) if (!n_encodings) { msg (SW, _("No valid encodings found.")); - pool_destroy (pool); return; } - text = text_item_create_format ( - TEXT_ITEM_PARAGRAPH, - _("The following table lists the encodings that can successfully read %s, " - "by specifying the encoding name on the GET command's ENCODING " - "subcommand. Encodings that yield identical text are listed " - "together."), fh_get_name (h)); - text_item_submit (text); - t = tab_create (2, n_encodings + 1); tab_title (t, _("Usable encodings for %s."), fh_get_name (h)); + tab_caption (t, _("Encodings that can successfully read %s (by specifying " + "the encoding name on the GET command's ENCODING " + "subcommand). Encodings that yield identical text are " + "listed together."), fh_get_name (h)); tab_headers (t, 1, 0, 1, 0); tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 1, n_encodings); tab_hline (t, TAL_1, 0, 1, 1); @@ -1029,7 +1025,7 @@ report_encodings (const struct file_handle *h, const struct sfm_reader *r) ds_put_format (&s, "%s, ", encoding_names[j]); ds_chomp (&s, ss_cstr (", ")); - tab_text_format (t, 0, i + 1, TAB_RIGHT, "%d", i + 1); + tab_text_format (t, 0, i + 1, TAB_RIGHT, "%zu", i + 1); tab_text (t, 1, i + 1, TAB_LEFT, ds_cstr (&s)); ds_destroy (&s); } @@ -1040,20 +1036,13 @@ report_encodings (const struct file_handle *h, const struct sfm_reader *r) if (!all_equal (encodings, n_encodings, i)) n_unique_strings++; if (!n_unique_strings) - { - pool_destroy (pool); - return; - } - - text = text_item_create_format ( - TEXT_ITEM_PARAGRAPH, - _("The following table lists text strings in the file dictionary that " - "the encodings above interpret differently, along with those " - "interpretations.")); - text_item_submit (text); + return; t = tab_create (3, (n_encodings * n_unique_strings) + 1); tab_title (t, _("%s encoded text strings."), fh_get_name (h)); + tab_caption (t, _("Text strings in the file dictionary that the previously " + "listed encodings interpret differently, along with the " + "interpretations.")); tab_headers (t, 1, 0, 1, 0); tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 2, n_encodings * n_unique_strings); tab_hline (t, TAL_1, 0, 2, 1); @@ -1076,7 +1065,7 @@ report_encodings (const struct file_handle *h, const struct sfm_reader *r) { const char *s = encodings[j].utf8_strings[i] + prefix; - tab_text_format (t, 1, row, TAB_RIGHT, "%d", j + 1); + tab_text_format (t, 1, row, TAB_RIGHT, "%zu", j + 1); if (prefix || suffix) { size_t len = strlen (s) - suffix; @@ -1096,6 +1085,34 @@ report_encodings (const struct file_handle *h, const struct sfm_reader *r) } } tab_submit (t); +} + +static unsigned int +dict_display_mask (const struct dictionary *d) +{ + size_t n_vars = dict_get_var_cnt (d); + unsigned int mask; + size_t i; + + mask = DF_ALL & ~(DF_MEASURE | DF_ROLE | DF_ALIGNMENT | DF_WIDTH); + for (i = 0; i < n_vars; i++) + { + const struct variable *v = dict_get_var (d, i); + enum val_type val = var_get_type (v); + int width = var_get_width (v); + + if (var_get_measure (v) != var_default_measure (val)) + mask |= DF_MEASURE; + + if (var_get_role (v) != ROLE_INPUT) + mask |= DF_ROLE; + + if (var_get_alignment (v) != var_default_alignment (val)) + mask |= DF_ALIGNMENT; + + if (var_get_display_width (v) != var_default_display_width (width)) + mask |= DF_WIDTH; + } - pool_destroy (pool); + return mask; }