X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fsys-file-info.c;h=a13dda37d746f5fae28c8c3d44e46fa353461a64;hb=077a1c38bd58911cb74a08f95be3691e49b87779;hp=13c3275e035093a5c2c7be31bd1fc479f3d2c3a6;hpb=81fff61a96bece351e381ad3fef8ab1248a952ba;p=pspp-builds.git diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 13c3275e..a13dda37 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . + Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -24,13 +23,17 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include +#include #include #include #include @@ -42,6 +45,8 @@ #include #include +#include "minmax.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -69,7 +74,7 @@ sysfile_info_dim (struct tab_table *t, struct outp_driver *d) int i; for (p = max; *p; p++) - t->w[p - max] = min (tab_natural_width (t, d, p - max), + t->w[p - max] = MIN (tab_natural_width (t, d, p - max), *p * d->prop_em_width); for (i = 0; i < t->nr; i++) t->h[i] = tab_natural_height (t, d, i); @@ -77,7 +82,7 @@ sysfile_info_dim (struct tab_table *t, struct outp_driver *d) /* SYSFILE INFO utility. */ int -cmd_sysfile_info (void) +cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) { struct file_handle *h; struct dictionary *d; @@ -87,10 +92,10 @@ cmd_sysfile_info (void) int r, nr; int i; - lex_match_id ("FILE"); - lex_match ('='); + lex_match_id (lexer, "FILE"); + lex_match (lexer, '='); - h = fh_parse (FH_REF_FILE); + h = fh_parse (lexer, FH_REF_FILE); if (!h) return CMD_FAILURE; @@ -99,7 +104,7 @@ cmd_sysfile_info (void) return CMD_FAILURE; sfm_close_reader (reader); - t = tab_create (2, 9, 0); + t = tab_create (2, 10, 0); tab_vline (t, TAL_GAP, 1, 0, 8); tab_text (t, 0, 0, TAB_LEFT, _("File:")); tab_text (t, 1, 0, TAB_LEFT, fh_get_file_name (h)); @@ -113,24 +118,36 @@ cmd_sysfile_info (void) tab_text (t, 0, 2, TAB_LEFT, _("Created:")); tab_text (t, 1, 2, TAB_LEFT | TAT_PRINTF, "%s %s by %s", info.creation_date, info.creation_time, info.product); - tab_text (t, 0, 3, TAB_LEFT, _("Endian:")); - tab_text (t, 1, 3, TAB_LEFT, info.big_endian ? _("Big.") : _("Little.")); - tab_text (t, 0, 4, TAB_LEFT, _("Variables:")); - tab_text (t, 1, 4, TAB_LEFT | TAT_PRINTF, "%d", - dict_get_var_cnt (d)); - tab_text (t, 0, 5, TAB_LEFT, _("Cases:")); - tab_text (t, 1, 5, TAB_LEFT | TAT_PRINTF, + tab_text (t, 0, 3, TAB_LEFT, _("Integer Format:")); + tab_text (t, 1, 3, TAB_LEFT, + info.integer_format == INTEGER_MSB_FIRST ? _("Big Endian.") + : info.integer_format == INTEGER_LSB_FIRST ? _("Little Endian.") + : _("Unknown.")); + tab_text (t, 0, 4, TAB_LEFT, _("Real Format:")); + tab_text (t, 1, 4, TAB_LEFT, + info.float_format == FLOAT_IEEE_DOUBLE_LE ? _("IEEE 754 LE.") + : info.float_format == FLOAT_IEEE_DOUBLE_BE ? _("IEEE 754 BE.") + : info.float_format == FLOAT_VAX_D ? _("VAX D.") + : info.float_format == FLOAT_VAX_G ? _("VAX G.") + : info.float_format == FLOAT_Z_LONG ? _("IBM 390 Hex Long.") + : _("Unknown.")); + tab_text (t, 0, 5, TAB_LEFT, _("Variables:")); + tab_text (t, 1, 5, TAB_LEFT | TAT_PRINTF, "%u", + (unsigned int) dict_get_var_cnt (d)); + tab_text (t, 0, 6, TAB_LEFT, _("Cases:")); + tab_text (t, 1, 6, TAB_LEFT | TAT_PRINTF, info.case_cnt == -1 ? _("Unknown") : "%d", info.case_cnt); - tab_text (t, 0, 6, TAB_LEFT, _("Type:")); - tab_text (t, 1, 6, TAB_LEFT, _("System File.")); - tab_text (t, 0, 7, TAB_LEFT, _("Weight:")); + tab_text (t, 0, 7, TAB_LEFT, _("Type:")); + tab_text (t, 1, 7, TAB_LEFT, _("System File.")); + tab_text (t, 0, 8, TAB_LEFT, _("Weight:")); { struct variable *weight_var = dict_get_weight (d); - tab_text (t, 1, 7, TAB_LEFT, - weight_var != NULL ? weight_var->name : _("Not weighted.")); + tab_text (t, 1, 8, TAB_LEFT, + (weight_var != NULL + ? var_get_name (weight_var) : _("Not weighted."))); } - tab_text (t, 0, 8, TAB_LEFT, _("Mode:")); - tab_text (t, 1, 8, TAB_LEFT | TAT_PRINTF, + tab_text (t, 0, 9, TAB_LEFT, _("Mode:")); + tab_text (t, 1, 9, TAB_LEFT | TAT_PRINTF, _("Compression %s."), info.compressed ? _("on") : _("off")); tab_dim (t, tab_natural_dimensions); tab_submit (t); @@ -147,11 +164,11 @@ cmd_sysfile_info (void) for (r = 1, i = 0; i < dict_get_var_cnt (d); i++) { struct variable *v = dict_get_var (d, i); - const int nvl = val_labs_count (v->val_labs); + const int nvl = val_labs_count (var_get_value_labels (v)); if (r + 10 + nvl > nr) { - nr = max (nr * dict_get_var_cnt (d) / (i + 1), nr); + nr = MAX (nr * dict_get_var_cnt (d) / (i + 1), nr); nr += 10 + nvl; tab_realloc (t, 4, nr); } @@ -169,18 +186,18 @@ cmd_sysfile_info (void) dict_destroy (d); - return lex_end_of_command (); + return lex_end_of_command (lexer); } /* DISPLAY utility. */ static void display_macros (void); -static void display_documents (void); +static void display_documents (const struct dictionary *dict); static void display_variables (struct variable **, size_t, int); -static void display_vectors (int sorted); +static void display_vectors (const struct dictionary *dict, int sorted); int -cmd_display (void) +cmd_display (struct lexer *lexer, struct dataset *ds) { /* Whether to sort the list of variables alphabetically. */ int sorted; @@ -189,22 +206,22 @@ cmd_display (void) size_t n; struct variable **vl; - if (lex_match_id ("MACROS")) + if (lex_match_id (lexer, "MACROS")) display_macros (); - else if (lex_match_id ("DOCUMENTS")) - display_documents (); - else if (lex_match_id ("FILE")) + else if (lex_match_id (lexer, "DOCUMENTS")) + display_documents (dataset_dict (ds)); + else if (lex_match_id (lexer, "FILE")) { som_blank_line (); - if (!lex_force_match_id ("LABEL")) + if (!lex_force_match_id (lexer, "LABEL")) return CMD_FAILURE; - if (dict_get_label (default_dict) == NULL) + if (dict_get_label (dataset_dict (ds)) == NULL) tab_output_text (TAB_LEFT, _("The active file does not have a file label.")); else { tab_output_text (TAB_LEFT | TAT_TITLE, _("File label:")); - tab_output_text (TAB_LEFT | TAB_FIX, dict_get_label (default_dict)); + tab_output_text (TAB_LEFT | TAB_FIX, dict_get_label (dataset_dict (ds))); } } else @@ -215,12 +232,13 @@ cmd_display (void) const char **cp; int as; - sorted = lex_match_id ("SORTED"); + sorted = lex_match_id (lexer, "SORTED"); for (cp = sbc; *cp; cp++) - if (token == T_ID && lex_id_match (*cp, tokid)) + if (lex_token (lexer) == T_ID + && lex_id_match (ss_cstr (*cp), ss_cstr (lex_tokid (lexer)))) { - lex_get (); + lex_get (lexer); break; } as = cp - sbc; @@ -230,17 +248,17 @@ cmd_display (void) if (as == AS_VECTOR) { - display_vectors (sorted); + display_vectors (dataset_dict(ds), sorted); return CMD_SUCCESS; } - lex_match ('/'); - lex_match_id ("VARIABLES"); - lex_match ('='); + lex_match (lexer, '/'); + lex_match_id (lexer, "VARIABLES"); + lex_match (lexer, '='); - if (token != '.') + if (lex_token (lexer) != '.') { - if (!parse_variables (default_dict, &vl, &n, PV_NONE)) + if (!parse_variables (lexer, dataset_dict (ds), &vl, &n, PV_NONE)) { free (vl); return CMD_FAILURE; @@ -248,13 +266,13 @@ cmd_display (void) as = AS_DICTIONARY; } else - dict_get_vars (default_dict, &vl, &n, 0); + dict_get_vars (dataset_dict (ds), &vl, &n, 0); if (as == AS_SCRATCH) { size_t i, m; for (i = 0, m = n; i < n; i++) - if (dict_class_from_id (vl[i]->name) != DC_SCRATCH) + if (dict_class_from_id (var_get_name (vl[i])) != DC_SCRATCH) { vl[i] = NULL; m--; @@ -270,14 +288,14 @@ cmd_display (void) } if (sorted) - sort (vl, n, sizeof *vl, compare_var_names, NULL); + sort (vl, n, sizeof *vl, compare_var_ptrs_by_name, NULL); display_variables (vl, n, as); free (vl); } - return lex_end_of_command (); + return lex_end_of_command (lexer); } static void @@ -288,9 +306,9 @@ display_macros (void) } static void -display_documents (void) +display_documents (const struct dictionary *dict) { - const char *documents = dict_get_documents (default_dict); + const char *documents = dict_get_documents (dict); som_blank_line (); if (documents == NULL) @@ -333,8 +351,8 @@ variables_dim (struct tab_table *t, struct outp_driver *d) t->w[0] = tab_natural_width (t, d, 0); if (_as == AS_DICTIONARY || _as == AS_VARIABLES || _as == AS_LABELS) { - t->w[1] = max (tab_natural_width (t, d, 1), d->prop_em_width * 5); - t->w[2] = max (tab_natural_width (t, d, 2), d->prop_em_width * 35); + t->w[1] = MAX (tab_natural_width (t, d, 1), d->prop_em_width * 5); + t->w[2] = MAX (tab_natural_width (t, d, 2), d->prop_em_width * 35); pc = 3; } else pc = 1; @@ -394,24 +412,28 @@ display_variables (struct variable **vl, size_t n, int as) if (as == AS_DICTIONARY || as == AS_VARIABLES) { - int nvl = val_labs_count (v->val_labs); + int nvl = val_labs_count (var_get_value_labels (v)); if (r + 10 + nvl > nr) { - nr = max (nr * n / (i + 1), nr); + nr = MAX (nr * n / (i + 1), nr); nr += 10 + nvl; tab_realloc (t, nc, nr); } r = describe_variable (v, t, r, as); } else { - tab_text (t, 0, r, TAB_LEFT, v->name); - if (as == AS_LABELS) - tab_joint_text (t, 1, r, 2, r, TAB_LEFT, - v->label == NULL ? "(no label)" : v->label); + tab_text (t, 0, r, TAB_LEFT, var_get_name (v)); + if (as == AS_LABELS) + { + const char *label = var_get_label (v); + tab_joint_text (t, 1, r, 2, r, TAB_LEFT, + label != NULL ? "(no label)" : label); + } if (as != AS_NAMES) { - tab_text (t, pc, r, TAT_PRINTF, "%d", v->index + 1); + tab_text (t, pc, r, TAT_PRINTF, "%d", + (int) var_get_dict_index (v) + 1); tab_hline (t, TAL_1, 0, nc - 1, r); } r++; @@ -438,37 +460,40 @@ display_variables (struct variable **vl, size_t n, int as) static int describe_variable (struct variable *v, struct tab_table *t, int r, int as) { + const struct fmt_spec *print = var_get_print_format (v); + const struct fmt_spec *write = var_get_write_format (v); + /* Put the name, var label, and position into the first row. */ - tab_text (t, 0, r, TAB_LEFT, v->name); - tab_text (t, 3, r, TAT_PRINTF, "%d", v->index + 1); + tab_text (t, 0, r, TAB_LEFT, var_get_name (v)); + tab_text (t, 3, r, TAT_PRINTF, "%d", (int) var_get_dict_index (v) + 1); - if (as == AS_DICTIONARY && v->label) + if (as == AS_DICTIONARY && var_has_label (v)) { - tab_joint_text (t, 1, r, 2, r, TAB_LEFT, v->label); + tab_joint_text (t, 1, r, 2, r, TAB_LEFT, var_get_label (v)); r++; } /* Print/write format, or print and write formats. */ - if (v->print.type == v->write.type - && v->print.w == v->write.w - && v->print.d == v->write.d) + if (fmt_equal (print, write)) { + char str[FMT_STRING_LEN_MAX + 1]; tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, _("Format: %s"), - fmt_to_string (&v->print)); + fmt_to_string (print, str)); r++; } else { + char str[FMT_STRING_LEN_MAX + 1]; tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Print Format: %s"), fmt_to_string (&v->print)); + _("Print Format: %s"), fmt_to_string (print, str)); r++; tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Write Format: %s"), fmt_to_string (&v->write)); + _("Write Format: %s"), fmt_to_string (write, str)); r++; } /* Missing values if any. */ - if (!mv_is_empty (&v->miss)) + if (var_has_missing_values (v)) { char buf[128]; char *cp; @@ -476,17 +501,18 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) int cnt = 0; cp = stpcpy (buf, _("Missing Values: ")); - mv_copy (&mv, &v->miss); + + mv_copy (&mv, var_get_missing_values (v)); if (mv_has_range (&mv)) { double x, y; mv_pop_range (&mv, &x, &y); if (x == LOWEST) - cp += nsprintf (cp, "LOWEST THRU %g", y); + cp += sprintf (cp, "LOWEST THRU %g", y); else if (y == HIGHEST) - cp += nsprintf (cp, "%g THRU HIGHEST", x); + cp += sprintf (cp, "%g THRU HIGHEST", x); else - cp += nsprintf (cp, "%g THRU %g", x, y); + cp += sprintf (cp, "%g THRU %g", x, y); cnt++; } while (mv_has_value (&mv)) @@ -494,14 +520,14 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) union value value; mv_pop_value (&mv, &value); if (cnt++ > 0) - cp += nsprintf (cp, "; "); - if (v->type == NUMERIC) - cp += nsprintf (cp, "%g", value.f); + cp += sprintf (cp, "; "); + if (var_is_numeric (v)) + cp += sprintf (cp, "%g", value.f); else { *cp++ = '"'; - memcpy (cp, value.s, v->width); - cp += v->width; + memcpy (cp, value.s, var_get_width (v)); + cp += var_get_width (v); *cp++ = '"'; *cp = '\0'; } @@ -512,8 +538,9 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) } /* Value labels. */ - if (as == AS_DICTIONARY && val_labs_count (v->val_labs)) + if (as == AS_DICTIONARY && var_has_value_labels (v)) { + const struct val_labs *val_labs = var_get_value_labels (v); struct val_labs_iterator *i; struct val_lab *vl; int orig_r = r; @@ -525,15 +552,15 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) #endif tab_hline (t, TAL_1, 1, 2, r); - for (vl = val_labs_first_sorted (v->val_labs, &i); vl != NULL; - vl = val_labs_next (v->val_labs, &i)) + for (vl = val_labs_first_sorted (val_labs, &i); vl != NULL; + vl = val_labs_next (val_labs, &i)) { char buf[128]; - if (v->type == ALPHA) + if (var_is_alpha (v)) { - memcpy (buf, vl->value.s, v->width); - buf[v->width] = 0; + memcpy (buf, vl->value.s, var_get_width (v)); + buf[var_get_width (v)] = 0; } else sprintf (buf, "%g", vl->value.f); @@ -552,28 +579,19 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) return r; } -static int -compare_vectors_by_name (const void *a_, const void *b_) -{ - struct vector *const *pa = a_; - struct vector *const *pb = b_; - struct vector *a = *pa; - struct vector *b = *pb; - - return strcasecmp (a->name, b->name); -} - /* Display a list of vectors. If SORTED is nonzero then they are sorted alphabetically. */ static void -display_vectors (int sorted) +display_vectors (const struct dictionary *dict, int sorted) { const struct vector **vl; int i; struct tab_table *t; size_t nvec; + size_t nrow; + size_t row; - nvec = dict_get_vector_cnt (default_dict); + nvec = dict_get_vector_cnt (dict); if (nvec == 0) { msg (SW, _("No vectors defined.")); @@ -581,32 +599,52 @@ display_vectors (int sorted) } vl = xnmalloc (nvec, sizeof *vl); - for (i = 0; i < nvec; i++) - vl[i] = dict_get_vector (default_dict, i); + nrow = 0; + for (i = 0; i < nvec; i++) + { + vl[i] = dict_get_vector (dict, i); + nrow += vector_get_var_cnt (vl[i]); + } if (sorted) - qsort (vl, nvec, sizeof *vl, compare_vectors_by_name); + qsort (vl, nvec, sizeof *vl, compare_vector_ptrs_by_name); - t = tab_create (1, nvec + 1, 0); + t = tab_create (4, nrow + 1, 0); tab_headers (t, 0, 0, 1, 0); tab_columns (t, TAB_COL_DOWN, 1); tab_dim (t, tab_natural_dimensions); - tab_hline (t, TAL_1, 0, 0, 1); + tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 3, nrow); + tab_box (t, -1, -1, -1, TAL_1, 0, 0, 3, nrow); + tab_hline (t, TAL_2, 0, 3, 1); tab_text (t, 0, 0, TAT_TITLE | TAB_LEFT, _("Vector")); + tab_text (t, 1, 0, TAT_TITLE | TAB_LEFT, _("Position")); + tab_text (t, 2, 0, TAT_TITLE | TAB_LEFT, _("Variable")); + tab_text (t, 3, 0, TAT_TITLE | TAB_LEFT, _("Print Format")); tab_flags (t, SOMF_NO_TITLE); - for (i = 0; i < nvec; i++) - tab_text (t, 0, i + 1, TAB_LEFT, vl[i]->name); - tab_submit (t); - - free (vl); -} - - - - - - - + row = 1; + for (i = 0; i < nvec; i++) + { + const struct vector *vec = vl[i]; + size_t j; + + tab_joint_text (t, 0, row, 0, row + vector_get_var_cnt (vec) - 1, + TAB_LEFT, vector_get_name (vl[i])); + for (j = 0; j < vector_get_var_cnt (vec); j++) + { + struct variable *var = vector_get_var (vec, j); + char fmt_string[FMT_STRING_LEN_MAX + 1]; + fmt_to_string (var_get_print_format (var), fmt_string); + + tab_text (t, 1, row, TAB_RIGHT | TAT_PRINTF, "%d", (int) j + 1); + tab_text (t, 2, row, TAB_LEFT, var_get_name (var)); + tab_text (t, 3, row, TAB_LEFT, fmt_string); + row++; + } + tab_hline (t, TAL_1, 0, 3, row); + } + tab_submit (t); + free (vl); +}