X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fsys-file-info.c;h=b98854db6ea290a053a43fa377b6d0e4d246b305;hb=b5b474193e450bba97610065df0518c08074a7fb;hp=180188abd285ebae3c12d457f4f46fe1eb31d102;hpb=92c09e564002d356d20fc1e2e131027ef89f6748;p=pspp-builds.git diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 180188ab..b98854db 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. +/* PSPP - a program for statistical analysis. 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 - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ #include @@ -35,10 +33,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -47,6 +43,7 @@ #include #include "minmax.h" +#include "xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -64,7 +61,7 @@ enum }; static int describe_variable (const struct variable *v, struct tab_table *t, int r, int as); - + /* Sets the widths of all the columns and heights of all the rows in table T for driver D. */ static void @@ -102,7 +99,10 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) reader = sfm_open_reader (h, &d, &info); if (!reader) - return CMD_FAILURE; + { + fh_unref (h); + return CMD_FAILURE; + } casereader_destroy (reader); t = tab_create (2, 10, 0); @@ -133,11 +133,11 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) : 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, 1, 5, TAB_LEFT | TAT_PRINTF, "%zu", 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); + info.case_cnt == -1 ? _("Unknown") : "%ld", + (long int) info.case_cnt); 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:")); @@ -145,7 +145,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) struct variable *weight_var = dict_get_weight (d); tab_text (t, 1, 8, TAB_LEFT, (weight_var != NULL - ? var_get_name (weight_var) : _("Not weighted."))); + ? var_get_name (weight_var) : _("Not weighted."))); } tab_text (t, 0, 9, TAB_LEFT, _("Mode:")); tab_text (t, 1, 9, TAB_LEFT | TAT_PRINTF, @@ -166,8 +166,8 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) { struct variable *v = dict_get_var (d, i); const int nvl = val_labs_count (var_get_value_labels (v)); - - if (r + 10 + nvl > nr) + + if (r + 13 + nvl > nr) { nr = MAX (nr * dict_get_var_cnt (d) / (i + 1), nr); nr += 10 + nvl; @@ -186,7 +186,8 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) tab_submit (t); dict_destroy (d); - + + fh_unref (h); return lex_end_of_command (lexer); } @@ -323,7 +324,7 @@ display_documents (const struct dictionary *dict) tab_output_text (TAB_LEFT | TAT_TITLE, _("Documents in the active file:")); som_blank_line (); - for (i = 0; i < dict_get_document_line_cnt (dict); i++) + for (i = 0; i < dict_get_document_line_cnt (dict); i++) { dict_get_document_line (dict, i, &line); tab_output_text (TAB_LEFT | TAB_FIX | TAT_NOWRAP, ds_cstr (&line)); @@ -341,7 +342,7 @@ variables_dim (struct tab_table *t, struct outp_driver *d) { int pc; int i; - + t->w[0] = tab_natural_width (t, d, 0); if (_as == AS_DICTIONARY || _as == AS_VARIABLES || _as == AS_LABELS) { @@ -356,7 +357,7 @@ variables_dim (struct tab_table *t, struct outp_driver *d) for (i = 0; i < t->nr; i++) t->h[i] = tab_natural_height (t, d, i); } - + static void display_variables (const struct variable **vl, size_t n, int as) { @@ -395,7 +396,7 @@ display_variables (const struct variable **vl, size_t n, int as) else if (as == AS_LABELS) tab_joint_text (t, 1, 0, 2, 0, TAB_LEFT | TAT_TITLE, _("Label")); tab_dim (t, variables_dim); - + for (i = r = 1; i <= n; i++) { const struct variable *v; @@ -407,8 +408,8 @@ display_variables (const struct variable **vl, size_t n, int as) if (as == AS_DICTIONARY || as == AS_VARIABLES) { int nvl = val_labs_count (var_get_value_labels (v)); - - if (r + 10 + nvl > nr) + + if (r + 13 + nvl > nr) { nr = MAX (nr * n / (i + 1), nr); nr += 10 + nvl; @@ -418,16 +419,16 @@ display_variables (const struct variable **vl, size_t n, int as) r = describe_variable (v, t, r, as); } else { tab_text (t, 0, r, TAB_LEFT, var_get_name (v)); - if (as == AS_LABELS) + 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); + label == NULL ? "(no label)" : label); } if (as != AS_NAMES) { - tab_text (t, pc, r, TAT_PRINTF, "%d", - (int) var_get_dict_index (v) + 1); + tab_text (t, pc, r, TAT_PRINTF, "%zu", + var_get_dict_index (v) + 1); tab_hline (t, TAL_1, 0, nc - 1, r); } r++; @@ -451,22 +452,24 @@ display_variables (const struct variable **vl, size_t n, int as) /* Puts a description of variable V into table T starting at row R. The variable will be described in the format AS. Returns the next row available for use in the table. */ -static int +static int describe_variable (const 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); + enum measure m = var_get_measure (v); + enum alignment a = var_get_alignment (v); /* Put the name, var label, and position into the first row. */ 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); + tab_text (t, 3, r, TAT_PRINTF, "%zu", var_get_dict_index (v) + 1); - if (as == AS_DICTIONARY && var_has_label (v)) + if (as == AS_DICTIONARY && var_has_label (v)) { tab_joint_text (t, 1, r, 2, r, TAB_LEFT, var_get_label (v)); r++; } - + /* Print/write format, or print and write formats. */ if (fmt_equal (print, write)) { @@ -486,6 +489,23 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, int as) r++; } + /* Measurement level, display width, alignment. */ + tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, + _("Measure: %s"), + m == MEASURE_NOMINAL ? _("Nominal") + : m == MEASURE_ORDINAL ? _("Ordinal") + : _("Scale")); + r++; + tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, + _("Display Alignment: %s"), + a == ALIGN_LEFT ? _("Left") + : a == ALIGN_CENTRE ? _("Center") + : _("Right")); + r++; + tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, + _("Display Width: %d"), var_get_display_width (v)); + r++; + /* Missing values if any. */ if (var_has_missing_values (v)) { @@ -493,11 +513,11 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, int as) char *cp; struct missing_values mv; int cnt = 0; - + cp = stpcpy (buf, _("Missing Values: ")); - + mv_copy (&mv, var_get_missing_values (v)); - if (mv_has_range (&mv)) + if (mv_has_range (&mv)) { double x, y; mv_pop_range (&mv, &x, &y); @@ -509,7 +529,7 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, int as) cp += sprintf (cp, "%g THRU %g", x, y); cnt++; } - while (mv_has_value (&mv)) + while (mv_has_value (&mv)) { union value value; mv_pop_value (&mv, &value); @@ -517,7 +537,7 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, int as) cp += sprintf (cp, "; "); if (var_is_numeric (v)) cp += sprintf (cp, "%g", value.f); - else + else { *cp++ = '"'; memcpy (cp, value.s, var_get_width (v)); @@ -584,7 +604,7 @@ display_vectors (const struct dictionary *dict, int sorted) size_t nvec; size_t nrow; size_t row; - + nvec = dict_get_vector_cnt (dict); if (nvec == 0) { @@ -594,10 +614,10 @@ display_vectors (const struct dictionary *dict, int sorted) vl = xnmalloc (nvec, sizeof *vl); nrow = 0; - for (i = 0; i < nvec; i++) + for (i = 0; i < nvec; i++) { vl[i] = dict_get_vector (dict, i); - nrow += vector_get_var_cnt (vl[i]); + nrow += vector_get_var_cnt (vl[i]); } if (sorted) qsort (vl, nvec, sizeof *vl, compare_vector_ptrs_by_name); @@ -616,11 +636,11 @@ display_vectors (const struct dictionary *dict, int sorted) tab_flags (t, SOMF_NO_TITLE); row = 1; - for (i = 0; i < nvec; i++) + 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])); @@ -629,8 +649,8 @@ display_vectors (const struct dictionary *dict, int sorted) 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, 1, row, TAB_RIGHT | TAT_PRINTF, "%zu", j + 1); tab_text (t, 2, row, TAB_LEFT, var_get_name (var)); tab_text (t, 3, row, TAB_LEFT, fmt_string); row++;