Change many %g format specifiers to %.*g with precision DBL_DIG + 1.
[pspp] / src / language / dictionary / sys-file-info.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <ctype.h>
20 #include <float.h>
21 #include <stdlib.h>
22
23 #include "data/attributes.h"
24 #include "data/casereader.h"
25 #include "data/dataset.h"
26 #include "data/dictionary.h"
27 #include "data/file-handle-def.h"
28 #include "data/format.h"
29 #include "data/missing-values.h"
30 #include "data/sys-file-reader.h"
31 #include "data/value-labels.h"
32 #include "data/variable.h"
33 #include "data/vector.h"
34 #include "language/command.h"
35 #include "language/data-io/file-handle.h"
36 #include "language/lexer/lexer.h"
37 #include "language/lexer/variable-parser.h"
38 #include "libpspp/array.h"
39 #include "libpspp/message.h"
40 #include "libpspp/misc.h"
41 #include "libpspp/string-array.h"
42 #include "output/tab.h"
43
44 #include "gl/minmax.h"
45 #include "gl/xalloc.h"
46
47 #include "gettext.h"
48 #define _(msgid) gettext (msgid)
49
50 /* Information to include in displaying a dictionary. */
51 enum 
52   {
53     DF_DICT_INDEX       = 1 << 0,
54     DF_FORMATS          = 1 << 1,
55     DF_VALUE_LABELS     = 1 << 2,
56     DF_VARIABLE_LABELS  = 1 << 3,
57     DF_MISSING_VALUES   = 1 << 4,
58     DF_AT_ATTRIBUTES    = 1 << 5, /* Attributes whose names begin with @. */
59     DF_ATTRIBUTES       = 1 << 6, /* All other attributes. */
60     DF_MISC             = 1 << 7,
61     DF_ALL              = (1 << 8) - 1
62   };
63
64 static int describe_variable (const struct variable *v, struct tab_table *t,
65                               int r, int pc, int flags);
66
67 /* SYSFILE INFO utility. */
68 int
69 cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
70 {
71   struct file_handle *h;
72   struct dictionary *d;
73   struct tab_table *t;
74   struct casereader *reader;
75   struct sfm_read_info info;
76   int r, i;
77
78   lex_match_id (lexer, "FILE");
79   lex_match (lexer, T_EQUALS);
80
81   h = fh_parse (lexer, FH_REF_FILE, NULL);
82   if (!h)
83     return CMD_FAILURE;
84
85   reader = sfm_open_reader (h, NULL, &d, &info);
86   if (!reader)
87     {
88       fh_unref (h);
89       return CMD_FAILURE;
90     }
91   casereader_destroy (reader);
92
93   t = tab_create (2, 11 + (info.product_ext != NULL));
94   r = 0;
95   tab_vline (t, TAL_GAP, 1, 0, 8);
96
97   tab_text (t, 0, r, TAB_LEFT, _("File:"));
98   tab_text (t, 1, r++, TAB_LEFT, fh_get_file_name (h));
99
100   tab_text (t, 0, r, TAB_LEFT, _("Label:"));
101   {
102     const char *label = dict_get_label (d);
103     if (label == NULL)
104       label = _("No label.");
105     tab_text (t, 1, r++, TAB_LEFT, label);
106   }
107
108   tab_text (t, 0, r, TAB_LEFT, _("Created:"));
109   tab_text_format (t, 1, r++, TAB_LEFT, "%s %s by %s",
110                    info.creation_date, info.creation_time, info.product);
111
112   if (info.product_ext)
113     {
114       tab_text (t, 0, r, TAB_LEFT, _("Product:"));
115       tab_text (t, 1, r++, TAB_LEFT, info.product_ext);
116     }
117
118   tab_text (t, 0, r, TAB_LEFT, _("Integer Format:"));
119   tab_text (t, 1, r++, TAB_LEFT,
120             info.integer_format == INTEGER_MSB_FIRST ? _("Big Endian")
121             : info.integer_format == INTEGER_LSB_FIRST ? _("Little Endian")
122             : _("Unknown"));
123
124   tab_text (t, 0, r, TAB_LEFT, _("Real Format:"));
125   tab_text (t, 1, r++, TAB_LEFT,
126             info.float_format == FLOAT_IEEE_DOUBLE_LE ? _("IEEE 754 LE.")
127             : info.float_format == FLOAT_IEEE_DOUBLE_BE ? _("IEEE 754 BE.")
128             : info.float_format == FLOAT_VAX_D ? _("VAX D.")
129             : info.float_format == FLOAT_VAX_G ? _("VAX G.")
130             : info.float_format == FLOAT_Z_LONG ? _("IBM 390 Hex Long.")
131             : _("Unknown"));
132
133   tab_text (t, 0, r, TAB_LEFT, _("Variables:"));
134   tab_text_format (t, 1, r++, TAB_LEFT, "%zu", dict_get_var_cnt (d));
135
136   tab_text (t, 0, r, TAB_LEFT, _("Cases:"));
137   if (info.case_cnt == -1)
138     tab_text (t, 1, r, TAB_LEFT, _("Unknown"));
139   else
140     tab_text_format (t, 1, r, TAB_LEFT, "%ld", (long int) info.case_cnt);
141   r++;
142
143   tab_text (t, 0, r, TAB_LEFT, _("Type:"));
144   tab_text (t, 1, r++, TAB_LEFT, _("System File"));
145
146   tab_text (t, 0, r, TAB_LEFT, _("Weight:"));
147   {
148     struct variable *weight_var = dict_get_weight (d);
149     tab_text (t, 1, r++, TAB_LEFT,
150               (weight_var != NULL
151                ? var_get_name (weight_var) : _("Not weighted.")));
152   }
153
154   tab_text (t, 0, r, TAB_LEFT, _("Compression:"));
155   tab_text_format (t, 1, r++, TAB_LEFT,
156                    info.compression == SFM_COMP_NONE ? _("None")
157                    : info.compression == SFM_COMP_SIMPLE ? "SAV"
158                    : "ZSAV");
159
160   tab_text (t, 0, r, TAB_LEFT, _("Charset:"));
161   tab_text (t, 1, r++, TAB_LEFT, dict_get_encoding (d));
162
163   tab_submit (t);
164
165   t = tab_create (4, 1 + 2 * dict_get_var_cnt (d));
166   tab_headers (t, 0, 0, 1, 0);
167   tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable"));
168   tab_joint_text (t, 1, 0, 2, 0, TAB_LEFT | TAT_TITLE, _("Description"));
169   tab_text (t, 3, 0, TAB_LEFT | TAT_TITLE, _("Position"));
170   tab_hline (t, TAL_2, 0, 3, 1);
171   for (r = 1, i = 0; i < dict_get_var_cnt (d); i++)
172     r = describe_variable (dict_get_var (d, i), t, r, 3,
173                            DF_ALL & ~DF_AT_ATTRIBUTES);
174
175   tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 3, r);
176   tab_vline (t, TAL_1, 1, 0, r);
177   tab_vline (t, TAL_1, 3, 0, r);
178
179   tab_resize (t, -1, r);
180   tab_submit (t);
181
182   dict_destroy (d);
183
184   fh_unref (h);
185   sfm_read_info_destroy (&info);
186   return CMD_SUCCESS;
187 }
188 \f
189 /* DISPLAY utility. */
190
191 static void display_macros (void);
192 static void display_documents (const struct dictionary *dict);
193 static void display_variables (const struct variable **, size_t, int);
194 static void display_vectors (const struct dictionary *dict, int sorted);
195 static void display_data_file_attributes (struct attrset *, int flags);
196
197 int
198 cmd_display (struct lexer *lexer, struct dataset *ds)
199 {
200   /* Whether to sort the list of variables alphabetically. */
201   int sorted;
202
203   /* Variables to display. */
204   size_t n;
205   const struct variable **vl;
206
207   if (lex_match_id (lexer, "MACROS"))
208     display_macros ();
209   else if (lex_match_id (lexer, "DOCUMENTS"))
210     display_documents (dataset_dict (ds));
211   else if (lex_match_id (lexer, "FILE"))
212     {
213       if (!lex_force_match_id (lexer, "LABEL"))
214         return CMD_FAILURE;
215       if (dict_get_label (dataset_dict (ds)) == NULL)
216         tab_output_text (TAB_LEFT,
217                          _("The active dataset does not have a file label."));
218       else
219         tab_output_text_format (TAB_LEFT, _("File label: %s"),
220                                 dict_get_label (dataset_dict (ds)));
221     }
222   else
223     {
224       int flags;
225
226       sorted = lex_match_id (lexer, "SORTED");
227
228       if (lex_match_id (lexer, "VECTORS"))
229         {
230           display_vectors (dataset_dict(ds), sorted);
231           return CMD_SUCCESS;
232         }
233       else if (lex_match_id (lexer, "SCRATCH")) 
234         {
235           dict_get_vars (dataset_dict (ds), &vl, &n, DC_ORDINARY);
236           flags = 0;
237         }
238       else 
239         {
240           struct subcommand 
241             {
242               const char *name;
243               int flags;
244             };
245           static const struct subcommand subcommands[] = 
246             {
247               {"@ATTRIBUTES", DF_ATTRIBUTES | DF_AT_ATTRIBUTES},
248               {"ATTRIBUTES", DF_ATTRIBUTES},
249               {"DICTIONARY", DF_ALL & ~DF_AT_ATTRIBUTES},
250               {"INDEX", DF_DICT_INDEX},
251               {"LABELS", DF_DICT_INDEX | DF_VARIABLE_LABELS},
252               {"NAMES", 0},
253               {"VARIABLES",
254                DF_DICT_INDEX | DF_FORMATS | DF_MISSING_VALUES | DF_MISC},
255               {NULL, 0},
256             };
257           const struct subcommand *sbc;
258
259           flags = 0;
260           for (sbc = subcommands; sbc->name != NULL; sbc++)
261             if (lex_match_id (lexer, sbc->name))
262               {
263                 flags = sbc->flags;
264                 break;
265               }
266
267           lex_match (lexer, T_SLASH);
268           lex_match_id (lexer, "VARIABLES");
269           lex_match (lexer, T_EQUALS);
270
271           if (lex_token (lexer) != T_ENDCMD)
272             {
273               if (!parse_variables_const (lexer, dataset_dict (ds), &vl, &n,
274                                           PV_NONE))
275                 {
276                   free (vl);
277                   return CMD_FAILURE;
278                 }
279             }
280           else
281             dict_get_vars (dataset_dict (ds), &vl, &n, 0);
282         }
283
284       if (n > 0) 
285         {
286           sort (vl, n, sizeof *vl,
287                 (sorted
288                  ? compare_var_ptrs_by_name
289                  : compare_var_ptrs_by_dict_index), NULL);
290           display_variables (vl, n, flags);
291         }
292       else
293         msg (SW, _("No variables to display."));
294       free (vl);
295
296       if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES))
297         display_data_file_attributes (dict_get_attributes (dataset_dict (ds)),
298                                       flags);
299     }
300
301   return CMD_SUCCESS;
302 }
303
304 static void
305 display_macros (void)
306 {
307   tab_output_text (TAB_LEFT, _("Macros not supported."));
308 }
309
310 static void
311 display_documents (const struct dictionary *dict)
312 {
313   const struct string_array *documents = dict_get_documents (dict);
314
315   if (string_array_is_empty (documents))
316     tab_output_text (TAB_LEFT, _("The active dataset dictionary does not "
317                                  "contain any documents."));
318   else
319     {
320       size_t i;
321
322       tab_output_text (TAB_LEFT | TAT_TITLE,
323                        _("Documents in the active dataset:"));
324       for (i = 0; i < dict_get_document_line_cnt (dict); i++)
325         tab_output_text (TAB_LEFT | TAB_FIX, dict_get_document_line (dict, i));
326     }
327 }
328
329 static void
330 display_variables (const struct variable **vl, size_t n, int flags)
331 {
332   struct tab_table *t;
333   int nc;                       /* Number of columns. */
334   int pc;                       /* `Position column' */
335   int r;                        /* Current row. */
336   size_t i;
337
338   /* One column for the name,
339      two columns for general description,
340      one column for dictionary index. */
341   nc = 1;
342   if (flags & ~DF_DICT_INDEX)
343     nc += 2;
344   pc = nc;
345   if (flags & DF_DICT_INDEX)
346     nc++;
347
348   t = tab_create (nc, n + 5);
349   tab_headers (t, 0, 0, 1, 0);
350   tab_hline (t, TAL_2, 0, nc - 1, 1);
351   tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable"));
352   if (flags & ~DF_DICT_INDEX) 
353     tab_joint_text (t, 1, 0, 2, 0, TAB_LEFT | TAT_TITLE,
354                     (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS)
355                      ? _("Description") : _("Label")));
356   if (flags & DF_DICT_INDEX)
357     tab_text (t, pc, 0, TAB_LEFT | TAT_TITLE, _("Position"));
358
359   r = 1;
360   for (i = 0; i < n; i++)
361     r = describe_variable (vl[i], t, r, pc, flags);
362   tab_hline (t, flags & ~DF_DICT_INDEX ? TAL_2 : TAL_1, 0, nc - 1, 1);
363   if (flags)
364     {
365       tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, nc - 1, r - 1);
366       tab_vline (t, TAL_1, 1, 0, r - 1);
367     }
368   if (flags & ~DF_DICT_INDEX)
369     tab_vline (t, TAL_1, nc - 1, 0, r - 1);
370   tab_resize (t, -1, r);
371   tab_submit (t);
372 }
373 \f
374 static bool
375 is_at_name (const char *name) 
376 {
377   return name[0] == '@' || (name[0] == '$' && name[1] == '@');
378 }
379
380 static size_t
381 count_attributes (const struct attrset *set, int flags) 
382 {
383   struct attrset_iterator i;
384   struct attribute *attr;
385   size_t n_attrs;
386   
387   n_attrs = 0;
388   for (attr = attrset_first (set, &i); attr != NULL;
389        attr = attrset_next (set, &i)) 
390     if (flags & DF_AT_ATTRIBUTES || !is_at_name (attribute_get_name (attr)))
391       n_attrs += attribute_get_n_values (attr);
392   return n_attrs;
393 }
394
395 static void
396 display_attributes (struct tab_table *t, const struct attrset *set, int flags,
397                     int c, int r)
398 {
399   struct attribute **attrs;
400   size_t n_attrs;
401   size_t i;
402
403   n_attrs = attrset_count (set);
404   attrs = attrset_sorted (set);
405   for (i = 0; i < n_attrs; i++)
406     {
407       const struct attribute *attr = attrs[i];
408       const char *name = attribute_get_name (attr);
409       size_t n_values;
410       size_t j;
411
412       if (!(flags & DF_AT_ATTRIBUTES) && is_at_name (name))
413         continue;
414
415       n_values = attribute_get_n_values (attr);
416       for (j = 0; j < n_values; j++)
417         {
418           if (n_values > 1)
419             tab_text_format (t, c, r, TAB_LEFT, "%s[%zu]", name, j + 1);
420           else
421             tab_text (t, c, r, TAB_LEFT, name);
422           tab_text (t, c + 1, r, TAB_LEFT, attribute_get_value (attr, j));
423           r++;
424         }
425     }
426   free (attrs);
427 }
428
429 static void
430 display_data_file_attributes (struct attrset *set, int flags) 
431 {
432   struct tab_table *t;
433   size_t n_attrs;
434
435   n_attrs = count_attributes (set, flags);
436   if (!n_attrs)
437     return;
438
439   t = tab_create (2, n_attrs + 1);
440   tab_headers (t, 0, 0, 1, 0);
441   tab_box (t, TAL_1, TAL_1, -1, TAL_1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1);
442   tab_hline (t, TAL_2, 0, 1, 1); 
443   tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Attribute"));
444   tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Value"));
445   display_attributes (t, set, flags, 0, 1);
446   tab_title (t, "Custom data file attributes.");
447   tab_submit (t);
448 }
449
450 /* Puts a description of variable V into table T starting at row
451    R.  The variable will be described in the format given by
452    FLAGS.  Returns the next row available for use in the
453    table. */
454 static int
455 describe_variable (const struct variable *v, struct tab_table *t, int r,
456                    int pc, int flags)
457 {
458   size_t n_attrs = 0;
459   int need_rows;
460
461   /* Make sure that enough rows are allocated. */
462   need_rows = 1;
463   if (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS))
464     need_rows += 16;
465   if (flags & DF_VALUE_LABELS)
466     need_rows += val_labs_count (var_get_value_labels (v));
467   if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES))
468     {
469       n_attrs = count_attributes (var_get_attributes (v), flags);
470       need_rows += n_attrs; 
471     }
472   if (r + need_rows > tab_nr (t))
473     {
474       int nr = MAX (r + need_rows, tab_nr (t) * 2);
475       tab_realloc (t, -1, nr);
476     }
477
478   /* Put the name, var label, and position into the first row. */
479   tab_text (t, 0, r, TAB_LEFT, var_get_name (v));
480   if (flags & DF_DICT_INDEX)
481     tab_text_format (t, pc, r, 0, "%zu", var_get_dict_index (v) + 1);
482
483   if (flags & DF_VARIABLE_LABELS && var_has_label (v))
484     {
485       if (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS))
486         tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
487                                _("Label: %s"), var_get_label (v));
488       else
489         tab_joint_text (t, 1, r, 2, r, TAB_LEFT, var_get_label (v));
490       r++;
491     }
492
493   /* Print/write format, or print and write formats. */
494   if (flags & DF_FORMATS) 
495     {
496       const struct fmt_spec *print = var_get_print_format (v);
497       const struct fmt_spec *write = var_get_write_format (v);
498
499       if (fmt_equal (print, write))
500         {
501           char str[FMT_STRING_LEN_MAX + 1];
502           tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
503                                  _("Format: %s"), fmt_to_string (print, str));
504           r++;
505         }
506       else
507         {
508           char str[FMT_STRING_LEN_MAX + 1];
509           tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
510                                  _("Print Format: %s"),
511                                  fmt_to_string (print, str));
512           r++;
513           tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
514                                  _("Write Format: %s"),
515                                  fmt_to_string (write, str));
516           r++;
517         }
518     }
519   
520   /* Measurement level, role, display width, alignment. */
521   if (flags & DF_MISC) 
522     {
523       enum var_role role = var_get_role (v);
524
525       tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
526                              _("Measure: %s"),
527                              measure_to_string (var_get_measure (v)));
528       r++;
529
530       if (role != ROLE_INPUT)
531         {
532           tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
533                                  _("Role: %s"), var_role_to_string (role));
534           r++;
535         }
536
537       tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
538                              _("Display Alignment: %s"),
539                              alignment_to_string (var_get_alignment (v)));
540       r++;
541
542       tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT,
543                              _("Display Width: %d"),
544                              var_get_display_width (v));
545       r++;
546     }
547   
548   /* Missing values if any. */
549   if (flags & DF_MISSING_VALUES && var_has_missing_values (v))
550     {
551       const struct missing_values *mv = var_get_missing_values (v);
552       char buf[128];
553       char *cp;
554       int cnt = 0;
555       int i;
556
557       cp = stpcpy (buf, _("Missing Values: "));
558
559       if (mv_has_range (mv))
560         {
561           double x, y;
562           mv_get_range (mv, &x, &y);
563           if (x == LOWEST)
564             cp += sprintf (cp, "LOWEST THRU %.*g", DBL_DIG + 1, y);
565           else if (y == HIGHEST)
566             cp += sprintf (cp, "%.*g THRU HIGHEST", DBL_DIG + 1, x);
567           else
568             cp += sprintf (cp, "%.*g THRU %.*g",
569                            DBL_DIG + 1, x,
570                            DBL_DIG + 1, y);
571           cnt++;
572         }
573       for (i = 0; i < mv_n_values (mv); i++)
574         {
575           const union value *value = mv_get_value (mv, i);
576           if (cnt++ > 0)
577             cp += sprintf (cp, "; ");
578           if (var_is_numeric (v))
579             cp += sprintf (cp, "%.*g", DBL_DIG + 1, value->f);
580           else
581             {
582               int width = var_get_width (v);
583               int mv_width = MIN (width, MV_MAX_STRING);
584
585               *cp++ = '"';
586               memcpy (cp, value_str (value, width), mv_width);
587               cp += mv_width;
588               *cp++ = '"';
589               *cp = '\0';
590             }
591         }
592
593       tab_joint_text (t, 1, r, 2, r, TAB_LEFT, buf);
594       r++;
595     }
596
597   /* Value labels. */
598   if (flags & DF_VALUE_LABELS && var_has_value_labels (v))
599     {
600       const struct val_labs *val_labs = var_get_value_labels (v);
601       size_t n_labels = val_labs_count (val_labs);
602       const struct val_lab **labels;
603       int orig_r = r;
604       size_t i;
605
606 #if 0
607       tab_text (t, 1, r, TAB_LEFT, _("Value"));
608       tab_text (t, 2, r, TAB_LEFT, _("Label"));
609       r++;
610 #endif
611
612       tab_hline (t, TAL_1, 1, 2, r);
613
614       labels = val_labs_sorted (val_labs);
615       for (i = 0; i < n_labels; i++)
616         {
617           const struct val_lab *vl = labels[i];
618
619           tab_value (t, 1, r, TAB_NONE, &vl->value, v, NULL);
620           tab_text (t, 2, r, TAB_LEFT, val_lab_get_escaped_label (vl));
621           r++;
622         }
623       free (labels);
624
625       tab_vline (t, TAL_1, 2, orig_r, r - 1);
626     }
627
628   if (flags & (DF_ATTRIBUTES | DF_AT_ATTRIBUTES) && n_attrs)
629     {
630       tab_joint_text (t, 1, r, 2, r, TAB_LEFT, "Custom attributes:");
631       r++;
632
633       display_attributes (t, var_get_attributes (v), flags, 1, r);
634       r += n_attrs;
635     }
636
637   /* Draw a line below the last row of information on this variable. */
638   tab_hline (t, TAL_1, 0, tab_nc (t) - 1, r);
639
640   return r;
641 }
642
643 /* Display a list of vectors.  If SORTED is nonzero then they are
644    sorted alphabetically. */
645 static void
646 display_vectors (const struct dictionary *dict, int sorted)
647 {
648   const struct vector **vl;
649   int i;
650   struct tab_table *t;
651   size_t nvec;
652   size_t nrow;
653   size_t row;
654
655   nvec = dict_get_vector_cnt (dict);
656   if (nvec == 0)
657     {
658       msg (SW, _("No vectors defined."));
659       return;
660     }
661
662   vl = xnmalloc (nvec, sizeof *vl);
663   nrow = 0;
664   for (i = 0; i < nvec; i++)
665     {
666       vl[i] = dict_get_vector (dict, i);
667       nrow += vector_get_var_cnt (vl[i]);
668     }
669   if (sorted)
670     qsort (vl, nvec, sizeof *vl, compare_vector_ptrs_by_name);
671
672   t = tab_create (4, nrow + 1);
673   tab_headers (t, 0, 0, 1, 0);
674   tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 3, nrow);
675   tab_box (t, -1, -1, -1, TAL_1, 0, 0, 3, nrow);
676   tab_hline (t, TAL_2, 0, 3, 1);
677   tab_text (t, 0, 0, TAT_TITLE | TAB_LEFT, _("Vector"));
678   tab_text (t, 1, 0, TAT_TITLE | TAB_LEFT, _("Position"));
679   tab_text (t, 2, 0, TAT_TITLE | TAB_LEFT, _("Variable"));
680   tab_text (t, 3, 0, TAT_TITLE | TAB_LEFT, _("Print Format"));
681
682   row = 1;
683   for (i = 0; i < nvec; i++)
684     {
685       const struct vector *vec = vl[i];
686       size_t j;
687
688       tab_joint_text (t, 0, row, 0, row + vector_get_var_cnt (vec) - 1,
689                       TAB_LEFT, vector_get_name (vl[i]));
690
691       for (j = 0; j < vector_get_var_cnt (vec); j++)
692         {
693           struct variable *var = vector_get_var (vec, j);
694           char fmt_string[FMT_STRING_LEN_MAX + 1];
695           fmt_to_string (var_get_print_format (var), fmt_string);
696
697           tab_text_format (t, 1, row, TAB_RIGHT, "%zu", j + 1);
698           tab_text (t, 2, row, TAB_LEFT, var_get_name (var));
699           tab_text (t, 3, row, TAB_LEFT, fmt_string);
700           row++;
701         }
702       tab_hline (t, TAL_1, 0, 3, row);
703     }
704
705   tab_submit (t);
706
707   free (vl);
708 }