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