(display_variables): Fix DISPLAY LABELS. Thanks to Guido Gay
[pspp] / src / language / dictionary / sys-file-info.c
index 7f6cda3f2c4cc133620d64eff7ca540ca3dc5637..b98854db6ea290a053a43fa377b6d0e4d246b305 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 
 #include <language/data-io/file-handle.h>
 #include <language/lexer/lexer.h>
 #include <language/lexer/variable-parser.h>
-#include <libpspp/alloc.h>
 #include <libpspp/array.h>
 #include <libpspp/hash.h>
-#include <libpspp/magic.h>
 #include <libpspp/message.h>
 #include <libpspp/message.h>
 #include <libpspp/misc.h>
@@ -47,6 +43,7 @@
 #include <output/table.h>
 
 #include "minmax.h"
+#include "xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -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:"));
@@ -167,7 +167,7 @@ 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;
@@ -187,6 +187,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
 
   dict_destroy (d);
 
+  fh_unref (h);
   return lex_end_of_command (lexer);
 }
 \f
@@ -408,7 +409,7 @@ display_variables (const struct variable **vl, size_t n, int as)
        {
          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;
@@ -422,12 +423,12 @@ display_variables (const struct variable **vl, size_t n, int as)
             {
               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++;
@@ -456,10 +457,12 @@ 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))
     {
@@ -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))
     {
@@ -630,7 +650,7 @@ display_vectors (const struct dictionary *dict, int sorted)
           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++;