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