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