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