X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fsys-file-info.c;h=a0e608623290ff3b90fde776c5f21c64d4c665a6;hb=35717813005e999b6b807fc3f4bd6bb2d770f301;hp=b9e0a85c48c27b972529069d40c7861a055d14e4;hpb=649c202d57d7d5d8bb87be5b72839cd56ca4ca0b;p=pspp diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index b9e0a85c48..a0e6086232 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -13,7 +13,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - #include #include @@ -21,6 +20,7 @@ #include #include +#include "data/any-reader.h" #include "data/attributes.h" #include "data/casereader.h" #include "data/dataset.h" @@ -28,7 +28,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" @@ -47,6 +46,7 @@ #include "output/text-item.h" #include "output/table-item.h" +#include "gl/count-one-bits.h" #include "gl/localcharset.h" #include "gl/intprops.h" #include "gl/minmax.h" @@ -54,44 +54,53 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +#define N_(msgid) (msgid) /* Information to include in displaying a dictionary. */ -enum +enum { - DF_DICT_INDEX = 1 << 0, - DF_FORMATS = 1 << 1, - DF_VALUE_LABELS = 1 << 2, - DF_VARIABLE_LABELS = 1 << 3, - DF_MISSING_VALUES = 1 << 4, - DF_AT_ATTRIBUTES = 1 << 5, /* Attributes whose names begin with @. */ - DF_ATTRIBUTES = 1 << 6, /* All other attributes. */ - DF_MEASURE = 1 << 7, - DF_ROLE = 1 << 8, - DF_ALIGNMENT = 1 << 9, - DF_WIDTH = 1 << 10, - DF_ALL = (1 << 11) - 1 + /* Variable table. */ + DF_NAME = 1 << 0, + DF_POSITION = 1 << 1, + DF_LABEL = 1 << 2, + DF_MEASUREMENT_LEVEL = 1 << 3, + DF_ROLE = 1 << 4, + DF_WIDTH = 1 << 5, + DF_ALIGNMENT = 1 << 6, + DF_PRINT_FORMAT = 1 << 7, + DF_WRITE_FORMAT = 1 << 8, + DF_MISSING_VALUES = 1 << 9, +#define DF_ALL_VARIABLE ((1 << 10) - 1) + + /* Value labels table. */ + DF_VALUE_LABELS = 1 << 10, + + /* Attribute table. */ + DF_AT_ATTRIBUTES = 1 << 11, /* Attributes whose names begin with @. */ + DF_ATTRIBUTES = 1 << 12, /* All other attributes. */ }; -static unsigned int dict_display_mask (const struct dictionary *); - -static struct table *describe_variable (const struct variable *v, int flags); +static void display_variables (const struct variable **, size_t, int flags); +static void display_value_labels (const struct variable **, size_t); +static void display_attributes (const struct attrset *, + const struct variable **, size_t, int flags); -static void report_encodings (const struct file_handle *, - const struct sfm_reader *); +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; + int r; h = NULL; encoding = NULL; @@ -130,27 +139,41 @@ 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)); r = 0; - tab_vline (t, TAL_GAP, 1, 0, 8); - + tab_text (t, 0, r, TAB_LEFT, _("File:")); tab_text (t, 1, r++, TAB_LEFT, fh_get_file_name (h)); @@ -198,7 +221,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:")); { @@ -210,8 +233,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:")); @@ -219,25 +242,20 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) tab_submit (t); - t = tab_create (3, 1); - tab_headers (t, 0, 0, 1, 0); - tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable")); - 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); - - 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)); - - table_item_submit (table_item_create (table, NULL /* XXX */)); + size_t n_vars = dict_get_var_cnt (d); + const struct variable **vars = xnmalloc (n_vars, sizeof *vars); + for (size_t i = 0; i < dict_get_var_cnt (d); i++) + vars[i] = dict_get_var (d, i); + display_variables (vars, n_vars, DF_ALL_VARIABLE); + display_value_labels (vars, n_vars); + display_attributes (dict_get_attributes (dataset_dict (ds)), + vars, n_vars, DF_ATTRIBUTES); - dict_destroy (d); + dict_unref (d); fh_unref (h); - sfm_read_info_destroy (&info); + free (encoding); + any_read_info_destroy (&info); return CMD_SUCCESS; error: @@ -250,9 +268,7 @@ error: static void display_macros (void); static void display_documents (const struct dictionary *dict); -static void display_variables (const struct variable **, size_t, int); static void display_vectors (const struct dictionary *dict, int sorted); -static void display_data_file_attributes (struct attrset *, int flags); int cmd_display (struct lexer *lexer, struct dataset *ds) @@ -290,29 +306,32 @@ cmd_display (struct lexer *lexer, struct dataset *ds) display_vectors (dataset_dict(ds), sorted); return CMD_SUCCESS; } - else if (lex_match_id (lexer, "SCRATCH")) + else if (lex_match_id (lexer, "SCRATCH")) { dict_get_vars (dataset_dict (ds), &vl, &n, DC_ORDINARY); - flags = 0; + flags = DF_NAME; } - else + else { - struct subcommand + struct subcommand { const char *name; int flags; }; - static const struct subcommand subcommands[] = + static const struct subcommand subcommands[] = { {"@ATTRIBUTES", DF_ATTRIBUTES | DF_AT_ATTRIBUTES}, {"ATTRIBUTES", DF_ATTRIBUTES}, - {"DICTIONARY", DF_ALL & ~DF_AT_ATTRIBUTES}, - {"INDEX", DF_DICT_INDEX}, - {"LABELS", DF_DICT_INDEX | DF_VARIABLE_LABELS}, - {"NAMES", 0}, - {"VARIABLES", - DF_DICT_INDEX | DF_FORMATS | DF_MISSING_VALUES - | DF_MEASURE | DF_ROLE | DF_ALIGNMENT | DF_WIDTH}, + {"DICTIONARY", (DF_NAME | DF_POSITION | DF_LABEL + | DF_MEASUREMENT_LEVEL | DF_ROLE | DF_WIDTH + | DF_ALIGNMENT | DF_PRINT_FORMAT + | DF_WRITE_FORMAT | DF_MISSING_VALUES + | DF_VALUE_LABELS)}, + {"INDEX", DF_NAME | DF_POSITION}, + {"LABELS", DF_NAME | DF_POSITION | DF_LABEL}, + {"NAMES", DF_NAME}, + {"VARIABLES", (DF_NAME | DF_POSITION | DF_PRINT_FORMAT + | DF_WRITE_FORMAT | DF_MISSING_VALUES)}, {NULL, 0}, }; const struct subcommand *sbc; @@ -322,7 +341,7 @@ cmd_display (struct lexer *lexer, struct dataset *ds) for (sbc = subcommands; sbc->name != NULL; sbc++) if (lex_match_id (lexer, sbc->name)) { - flags = sbc->flags & dict_display_mask (dict); + flags = sbc->flags; break; } @@ -342,21 +361,28 @@ cmd_display (struct lexer *lexer, struct dataset *ds) dict_get_vars (dict, &vl, &n, 0); } - if (n > 0) + if (n > 0) { - sort (vl, n, sizeof *vl, - (sorted - ? compare_var_ptrs_by_name - : compare_var_ptrs_by_dict_index), NULL); - display_variables (vl, n, flags); + sort (vl, n, sizeof *vl, (sorted + ? compare_var_ptrs_by_name + : compare_var_ptrs_by_dict_index), NULL); + + int variable_flags = flags & DF_ALL_VARIABLE; + if (variable_flags) + display_variables (vl, n, variable_flags); + + if (flags & DF_VALUE_LABELS) + display_value_labels (vl, n); + + int attribute_flags = flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES); + if (attribute_flags) + display_attributes (dict_get_attributes (dataset_dict (ds)), + vl, n, attribute_flags); } else msg (SW, _("No variables to display.")); - free (vl); - if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES)) - display_data_file_attributes (dict_get_attributes (dataset_dict (ds)), - flags); + free (vl); } return CMD_SUCCESS; @@ -387,302 +413,228 @@ display_documents (const struct dictionary *dict) } } -static int -count_columns (int flags) +static void +display_variables (const struct variable **vl, size_t n, int flags) { - int nc = 1; - if (flags & ~DF_DICT_INDEX) - nc++; - if (flags & DF_DICT_INDEX) - nc++; + int nc = count_one_bits (flags); + struct tab_table *t = tab_create (nc, n + 1); + tab_title (t, "%s", _("Variables")); + tab_headers (t, 0, 0, 1, 0); + tab_hline (t, TAL_2, 0, nc - 1, 1); - return nc; -} + struct heading + { + int flag; + const char *title; + }; + static const struct heading headings[] = { + { DF_NAME, N_("Name") }, + { DF_POSITION, N_("Position") }, + { DF_LABEL, N_("Label") }, + { DF_MEASUREMENT_LEVEL, N_("Measurement Level") }, + { DF_ROLE, N_("Role") }, + { DF_WIDTH, N_("Width") }, + { DF_ALIGNMENT, N_("Alignment") }, + { DF_PRINT_FORMAT, N_("Print Format") }, + { DF_WRITE_FORMAT, N_("Write Format") }, + { DF_MISSING_VALUES, N_("Missing Values") }, + }; + for (size_t i = 0, x = 0; i < sizeof headings / sizeof *headings; i++) + if (flags & headings[i].flag) + tab_text (t, x++, 0, TAB_LEFT | TAT_TITLE, gettext (headings[i].title)); -static int -position_column (int flags) -{ - int pc = 1; - if (flags & ~DF_DICT_INDEX) - pc++; - return pc; + for (size_t i = 0; i < n; i++) + { + const struct variable *v = vl[i]; + size_t y = i + 1; + size_t x = 0; + if (flags & DF_NAME) + tab_text (t, x++, y, TAB_LEFT, var_get_name (v)); + if (flags & DF_POSITION) + { + char s[INT_BUFSIZE_BOUND (size_t)]; + + sprintf (s, "%zu", var_get_dict_index (v) + 1); + tab_text (t, x++, y, TAB_LEFT, s); + } + if (flags & DF_LABEL) + { + const char *label = var_get_label (v); + if (label) + tab_text (t, x, y, TAB_LEFT, label); + x++; + } + if (flags & DF_MEASUREMENT_LEVEL) + tab_text (t, x++, y, TAB_LEFT, + gettext (measure_to_string (var_get_measure (v)))); + if (flags & DF_ROLE) + tab_text (t, x++, y, TAB_LEFT, + gettext (var_role_to_string (var_get_role (v)))); + if (flags & DF_WIDTH) + { + char s[INT_BUFSIZE_BOUND (int)]; + sprintf (s, "%d", var_get_display_width (v)); + tab_text (t, x++, y, TAB_RIGHT, s); + } + if (flags & DF_ALIGNMENT) + tab_text (t, x++, y, TAB_LEFT, + gettext (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]; + + tab_text (t, x++, y, TAB_LEFT, fmt_to_string (print, s)); + } + if (flags & DF_WRITE_FORMAT) + { + const struct fmt_spec *write = var_get_write_format (v); + char s[FMT_STRING_LEN_MAX + 1]; + + tab_text (t, x++, y, TAB_LEFT, fmt_to_string (write, s)); + } + if (flags & DF_MISSING_VALUES) + { + const struct missing_values *mv = var_get_missing_values (v); + + char *s = mv_to_string (mv, var_get_encoding (v)); + if (s) + { + tab_text (t, x, y, TAB_LEFT, s); + free (s); + } + x++; + + assert (x == nc); + } + } + + tab_submit (t); } static void -display_variables (const struct variable **vl, size_t n, int flags) +display_value_labels (const struct variable **vars, size_t n_vars) { - struct tab_table *t; - struct table *table; - size_t i; - int nc; - - nc = count_columns (flags); - t = tab_create (nc, 1); + size_t n_value_labels = 0; + for (size_t i = 0; i < n_vars; i++) + n_value_labels += val_labs_count (var_get_value_labels (vars[i])); + if (!n_value_labels) + return; + + struct tab_table *t = tab_create (3, n_value_labels + 1); + tab_title (t, "%s", _("Value Labels")); tab_headers (t, 0, 0, 1, 0); - tab_hline (t, TAL_2, 0, nc - 1, 1); + tab_hline (t, TAL_2, 0, 2, 1); tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable")); - if (flags & ~DF_DICT_INDEX) - 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, position_column (flags), 0, TAB_LEFT | TAT_TITLE, - _("Position")); - - table = &t->table; - for (i = 0; i < n; i++) - table = table_vpaste (table, describe_variable (vl[i], flags)); + tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Value")); + tab_text (t, 2, 0, TAB_LEFT | TAT_TITLE, _("Label")); -#if 0 - tab_hline (t, flags & ~DF_DICT_INDEX ? TAL_2 : TAL_1, 0, nc - 1, 1); - if (flags) + int y = 1; + for (size_t i = 0; i < n_vars; i++) { - tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, nc - 1, r - 1); - tab_vline (t, TAL_1, 1, 0, r - 1); + 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; + + tab_joint_text (t, 0, y, 0, y + (n_labels - 1), TAB_LEFT, + var_get_name (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]; + + tab_value (t, 1, y, TAB_NONE, &vl->value, vars[i], NULL); + tab_text (t, 2, y, TAB_LEFT, val_lab_get_escaped_label (vl)); + y++; + } + free (labels); } - if (flags & ~DF_DICT_INDEX) - tab_vline (t, TAL_1, nc - 1, 0, r - 1); -#endif - table_item_submit (table_item_create (table, NULL /* XXX */)); + tab_submit (t); } static bool -is_at_name (const char *name) +is_at_name (const char *name) { return name[0] == '@' || (name[0] == '$' && name[1] == '@'); } static size_t -count_attributes (const struct attrset *set, int flags) +count_attributes (const struct attrset *set, int flags) { struct attrset_iterator i; struct attribute *attr; size_t n_attrs; - + n_attrs = 0; for (attr = attrset_first (set, &i); attr != NULL; - attr = attrset_next (set, &i)) + attr = attrset_next (set, &i)) if (flags & DF_AT_ATTRIBUTES || !is_at_name (attribute_get_name (attr))) n_attrs += attribute_get_n_values (attr); return n_attrs; } -static struct table * -describe_attributes (const struct attrset *set, int flags) +static int +display_attrset (const char *name, const struct attrset *set, int flags, + struct tab_table *t, int y) { - struct attribute **attrs; - struct tab_table *t; - size_t n_attrs; - size_t i; - int r = 1; + size_t n_total = count_attributes (set, flags); + if (!n_total) + return y; - 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")); + tab_joint_text (t, 0, y, 0, y + (n_total - 1), TAB_LEFT, name); - n_attrs = attrset_count (set); - attrs = attrset_sorted (set); - for (i = 0; i < n_attrs; i++) + size_t n_attrs = attrset_count (set); + struct attribute **attrs = attrset_sorted (set); + for (size_t i = 0; i < n_attrs; i++) { const struct attribute *attr = attrs[i]; const char *name = attribute_get_name (attr); - size_t n_values; - size_t j; if (!(flags & DF_AT_ATTRIBUTES) && is_at_name (name)) continue; - n_values = attribute_get_n_values (attr); - for (j = 0; j < n_values; j++) + size_t n_values = attribute_get_n_values (attr); + for (size_t j = 0; j < n_values; j++) { if (n_values > 1) - tab_text_format (t, 0, r, TAB_LEFT, "%s[%zu]", name, j + 1); + tab_text_format (t, 1, y, TAB_LEFT, "%s[%zu]", name, j + 1); else - tab_text (t, 0, r, TAB_LEFT, name); - tab_text (t, 1, r, TAB_LEFT, attribute_get_value (attr, j)); - r++; + tab_text (t, 1, y, TAB_LEFT, name); + tab_text (t, 2, y, TAB_LEFT, attribute_get_value (attr, j)); + y++; } } free (attrs); - return &t->table; + return y; } static void -display_data_file_attributes (struct attrset *set, int flags) -{ - if (count_attributes (set, flags)) - table_item_submit (table_item_create (describe_attributes (set, flags), - _("Custom data file attributes."))); -} - -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_labels + 1); - tab_box (t, TAL_1, TAL_1, -1, TAL_1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1); - - 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++) - { - 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); - - return &t->table; -} - -/* 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) +display_attributes (const struct attrset *dict_attrset, + const struct variable **vars, size_t n_vars, 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)) - ds_put_format (&s, _("Label: %s\n"), var_get_label (v)); - else - ds_put_format (&s, "%s\n", var_get_label (v)); - } - - /* Print/write format, or print and write formats. */ - if (flags & DF_FORMATS) - { - 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)) - ds_put_format (&s, _("Format: %s\n"), fmt_to_string (print, str)); - else - { - 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_MEASURE) - ds_put_format (&s, _("Measure: %s\n"), - measure_to_string (var_get_measure (v))); - - if (flags & DF_ROLE) - ds_put_format (&s, _("Role: %s\n"), var_role_to_string (var_get_role (v))); - - - 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)); - - /* Missing values if any. */ - if (flags & DF_MISSING_VALUES && var_has_missing_values (v)) - { - const struct missing_values *mv = var_get_missing_values (v); - int cnt = 0; - int i; - - ds_put_cstr (&s, _("Missing Values: ")); - - if (mv_has_range (mv)) - { - double x, y; - mv_get_range (mv, &x, &y); - if (x == LOWEST) - ds_put_format (&s, "LOWEST THRU %.*g", DBL_DIG + 1, y); - else if (y == HIGHEST) - ds_put_format (&s, "%.*g THRU HIGHEST", DBL_DIG + 1, x); - else - ds_put_format (&s, "%.*g THRU %.*g", - DBL_DIG + 1, x, - DBL_DIG + 1, y); - cnt++; - } - for (i = 0; i < mv_n_values (mv); i++) - { - const union value *value = mv_get_value (mv, i); - if (cnt++ > 0) - ds_put_cstr (&s, "; "); - if (var_is_numeric (v)) - 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); - - ds_put_byte (&s, '"'); - memcpy (ds_put_uninit (&s, mv_width), - value_str (value, width), mv_width); - ds_put_byte (&s, '"'); - } - } - 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)) - table = table_vpaste (table, table_create_nested (describe_value_labels (v))); - - if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES)) - { - struct attrset *attrs = var_get_attributes (v); - - if (count_attributes (attrs, flags)) - table = table_vpaste ( - table, table_create_nested (describe_attributes (attrs, flags))); - } - - if (table == NULL) - table = table_from_string (TAB_LEFT, ""); - - table = table_hpaste (table_from_string (0, var_get_name (v)), - table_stomp (table)); - if (flags & DF_DICT_INDEX) - { - char s[INT_BUFSIZE_BOUND (size_t)]; + size_t n_attributes = count_attributes (dict_attrset, flags); + for (size_t i = 0; i < n_vars; i++) + n_attributes += count_attributes (var_get_attributes (vars[i]), flags); + if (!n_attributes) + return; + + struct tab_table *t = tab_create (3, n_attributes + 1); + tab_title (t, "%s", _("Variable and Dataset Attributes")); + tab_headers (t, 0, 0, 1, 0); + tab_hline (t, TAL_2, 0, 2, 1); + tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable")); + tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Name")); + tab_text (t, 2, 0, TAB_LEFT | TAT_TITLE, _("Value")); - sprintf (s, "%zu", var_get_dict_index (v) + 1); - table = table_hpaste (table, table_from_string (0, s)); - } + int y = display_attrset (_("(dataset)"), dict_attrset, flags, t, 1); + for (size_t i = 0; i < n_vars; i++) + y = display_attrset (var_get_name (vars[i]), var_get_attributes (vars[i]), + flags, t, y); - return table; + tab_submit (t); } /* Display a list of vectors. If SORTED is nonzero then they are @@ -944,22 +896,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++) { @@ -994,20 +939,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); @@ -1034,20 +974,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); @@ -1090,36 +1023,4 @@ report_encodings (const struct file_handle *h, const struct sfm_reader *r) } } tab_submit (t); - - pool_destroy (pool); -} - -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; - } - - return mask; }