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