superscript
[pspp] / tests / output / pivot-table-test.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 <errno.h>
20 #include <getopt.h>
21 #include <limits.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "data/file-handle-def.h"
27 #include "language/lexer/lexer.h"
28 #include "language/lexer/format-parser.h"
29 #include "libpspp/assertion.h"
30 #include "libpspp/compiler.h"
31 #include "libpspp/i18n.h"
32 #include "libpspp/string-map.h"
33 #include "output/driver.h"
34 #include "output/message-item.h"
35 #include "output/options.h"
36 #include "output/pivot-table.h"
37 #include "output/table-item.h"
38
39 #include "gl/error.h"
40 #include "gl/progname.h"
41 #include "gl/xalloc.h"
42 #include "gl/xvasprintf.h"
43
44 /* --emphasis: Enable emphasis in ASCII driver? */
45 static bool emphasis;
46
47 /* --box: ASCII driver box option. */
48 static char *box;
49
50 /* -o, --output: Base name for output files. */
51 static const char *output_base = "render";
52
53 static const char *parse_options (int argc, char **argv);
54 static void usage (void) NO_RETURN;
55 static struct pivot_table *read_table (struct lexer *);
56 static void output_msg (const struct msg *, void *);
57
58 int
59 main (int argc, char **argv)
60 {
61   const char *input_file_name;
62
63   set_program_name (argv[0]);
64   i18n_init ();
65   output_engine_push ();
66   input_file_name = parse_options (argc, argv);
67
68   settings_init ();
69
70   struct lex_reader *reader = lex_reader_for_file (input_file_name, NULL,
71                                                    LEX_SYNTAX_AUTO,
72                                                    LEX_ERROR_CONTINUE);
73   if (!reader)
74     exit (1);
75
76   struct lexer *lexer = lex_create ();
77   msg_set_handler (output_msg, lexer);
78   lex_include (lexer, reader);
79   lex_get (lexer);
80
81   for (;;)
82     {
83       while (lex_match (lexer, T_ENDCMD))
84         continue;
85       if (lex_match (lexer, T_STOP))
86         break;
87
88       struct pivot_table *pt = read_table (lexer);
89       pivot_table_dump (pt, 0);
90       pivot_table_submit (pt);
91     }
92
93   lex_destroy (lexer);
94   output_engine_pop ();
95   fh_done ();
96
97   return 0;
98 }
99
100 static void PRINTF_FORMAT (2, 3)
101 register_driver (struct string_map *options,
102                  const char *output_file, ...)
103 {
104   va_list args;
105   va_start (args, output_file);
106   string_map_insert_nocopy (options, xstrdup ("output-file"),
107                             xvasprintf (output_file, args));
108   va_end (args);
109
110   struct output_driver *driver = output_driver_create (options);
111   if (driver == NULL)
112     exit (EXIT_FAILURE);
113   output_driver_register (driver);
114 }
115
116 static void
117 configure_drivers (int width, int length, int min_break)
118 {
119   /* Render to stdout. */
120   struct string_map options = STRING_MAP_INITIALIZER (options);
121   string_map_insert (&options, "format", "txt");
122   string_map_insert_nocopy (&options, xstrdup ("width"),
123                             xasprintf ("%d", width));
124   if (min_break >= 0)
125     string_map_insert_nocopy (&options, xstrdup ("min-hbreak"),
126                               xasprintf ("%d", min_break));
127   string_map_insert (&options, "emphasis", emphasis ? "true" : "false");
128   if (box != NULL)
129     string_map_insert (&options, "box", box);
130   register_driver (&options, "-");
131
132
133 #ifdef HAVE_CAIRO
134   /* Render to <base>.pdf. */
135   string_map_insert (&options, "top-margin", "0");
136   string_map_insert (&options, "bottom-margin", "0");
137   string_map_insert (&options, "left-margin", "0");
138   string_map_insert (&options, "right-margin", "0");
139   string_map_insert_nocopy (&options, xstrdup ("paper-size"),
140                             xasprintf ("%dx%dpt", width * 5, length * 8));
141   if (min_break >= 0)
142     {
143       string_map_insert_nocopy (&options, xstrdup ("min-hbreak"),
144                                 xasprintf ("%d", min_break * 5));
145       string_map_insert_nocopy (&options, xstrdup ("min-vbreak"),
146                                 xasprintf ("%d", min_break * 8));
147     }
148   register_driver (&options, "%s.pdf", output_base);
149 #endif
150
151   register_driver (&options, "%s.txt", output_base);
152   register_driver (&options, "%s.csv", output_base);
153   register_driver (&options, "%s.odt", output_base);
154   register_driver (&options, "%s.spv", output_base);
155
156   string_map_destroy (&options);
157 }
158
159 static const char *
160 parse_options (int argc, char **argv)
161 {
162   int width = 79;
163   int length = 66;
164   int min_break = -1;
165
166   for (;;)
167     {
168       enum {
169         OPT_WIDTH = UCHAR_MAX + 1,
170         OPT_LENGTH,
171         OPT_MIN_BREAK,
172         OPT_EMPHASIS,
173         OPT_BOX,
174         OPT_TABLE_LOOK,
175         OPT_HELP
176       };
177       static const struct option options[] =
178         {
179           {"width", required_argument, NULL, OPT_WIDTH},
180           {"length", required_argument, NULL, OPT_LENGTH},
181           {"min-break", required_argument, NULL, OPT_MIN_BREAK},
182           {"emphasis", no_argument, NULL, OPT_EMPHASIS},
183           {"box", required_argument, NULL, OPT_BOX},
184           {"output", required_argument, NULL, 'o'},
185           {"table-look", required_argument, NULL, OPT_TABLE_LOOK},
186           {"help", no_argument, NULL, OPT_HELP},
187           {NULL, 0, NULL, 0},
188         };
189
190       int c = getopt_long (argc, argv, "o:", options, NULL);
191       if (c == -1)
192         break;
193
194       switch (c)
195         {
196         case OPT_WIDTH:
197           width = atoi (optarg);
198           break;
199
200         case OPT_LENGTH:
201           length = atoi (optarg);
202           break;
203
204         case OPT_MIN_BREAK:
205           min_break = atoi (optarg);
206           break;
207
208         case OPT_EMPHASIS:
209           emphasis = true;
210           break;
211
212         case OPT_BOX:
213           box = optarg;
214           break;
215
216         case 'o':
217           output_base = optarg;
218           break;
219
220         case OPT_TABLE_LOOK:
221           {
222             struct pivot_table_look *look;
223             char *err = pivot_table_look_read (optarg, &look);
224             if (err)
225               error (1, 0, "%s", err);
226             pivot_table_look_set_default (look);
227             pivot_table_look_unref (look);
228           }
229           break;
230
231         case OPT_HELP:
232           usage ();
233
234         case 0:
235           break;
236
237         case '?':
238           exit(EXIT_FAILURE);
239           break;
240
241         default:
242           NOT_REACHED ();
243         }
244
245     }
246
247   configure_drivers (width, length, min_break);
248
249   if (optind + 1 != argc)
250     error (1, 0, "exactly one non-option argument required; "
251            "use --help for help");
252   return argv[optind];
253 }
254
255 static void
256 usage (void)
257 {
258   printf ("%s, to test rendering of PSPP tables\n"
259           "usage: %s [OPTIONS] INPUT\n"
260           "\nOptions:\n"
261           "  --width=WIDTH   set page width in characters\n"
262           "  --length=LINE   set page length in lines\n",
263           program_name, program_name);
264   exit (EXIT_SUCCESS);
265 }
266
267 static bool
268 parse_settings_value_show (struct lexer *lexer, const char *name,
269                            enum settings_value_show *show)
270 {
271   if (lex_match_id (lexer, name))
272     {
273       if (!lex_force_match (lexer, T_EQUALS))
274         exit (1);
275
276       if (lex_match_id (lexer, "DEFAULT"))
277         *show = SETTINGS_VALUE_SHOW_DEFAULT;
278       else if (lex_match_id (lexer, "VALUE"))
279         *show = SETTINGS_VALUE_SHOW_VALUE;
280       else if (lex_match_id (lexer, "LABEL"))
281         *show = SETTINGS_VALUE_SHOW_LABEL;
282       else if (lex_match_id (lexer, "BOTH"))
283         *show = SETTINGS_VALUE_SHOW_BOTH;
284       else
285         {
286           lex_error_expecting (lexer, "DEFAULT", "VALUE", "LABEL", "BOTH");
287           exit (1);
288         }
289
290       return true;
291     }
292   else
293     return false;
294 }
295
296 static bool
297 parse_string_setting (struct lexer *lexer, const char *name, char **stringp)
298 {
299   if (lex_match_id (lexer, name))
300     {
301       lex_match (lexer, T_EQUALS);
302       if (!lex_force_string (lexer))
303         exit (1);
304
305       free (*stringp);
306       *stringp = xstrdup (lex_tokcstr (lexer));
307
308       lex_get (lexer);
309       return true;
310     }
311   else
312     return false;
313 }
314
315 static void
316 read_value_option (struct lexer *lexer, struct pivot_value *value)
317 {
318   enum settings_value_show *show
319     = (value->type == PIVOT_VALUE_NUMERIC ? &value->numeric.show
320        : value->type == PIVOT_VALUE_STRING ? &value->string.show
321        : value->type == PIVOT_VALUE_VARIABLE ? &value->variable.show
322        : NULL);
323   if (show && parse_settings_value_show (lexer, "SHOW", show))
324     return;
325
326   char **var_name
327     = (value->type == PIVOT_VALUE_NUMERIC ? &value->numeric.var_name
328        : value->type == PIVOT_VALUE_STRING ? &value->string.var_name
329        : NULL);
330   if (var_name && parse_string_setting (lexer, "VAR", var_name))
331     return;
332
333   char **label
334     = (value->type == PIVOT_VALUE_NUMERIC ? &value->numeric.value_label
335        : value->type == PIVOT_VALUE_STRING ? &value->string.value_label
336        : value->type == PIVOT_VALUE_VARIABLE ? &value->variable.var_label
337        : NULL);
338   if (label && parse_string_setting (lexer, "LABEL", label))
339     return;
340
341   if (value->type == PIVOT_VALUE_STRING && lex_match_id (lexer, "HEX"))
342     {
343       value->string.hex = true;
344       return;
345     }
346
347   if (value->type == PIVOT_VALUE_NUMERIC)
348     {
349       msg_disable ();
350       struct fmt_spec fmt;
351       bool ok = parse_format_specifier (lexer, &fmt);
352       msg_enable ();
353
354       if (ok)
355         {
356           if (!fmt_check_output (&fmt)
357               || !fmt_check_type_compat (&fmt, VAL_NUMERIC))
358             exit (1);
359
360           value->numeric.format = fmt;
361           return;
362         }
363     }
364
365   if (lex_match_id (lexer, "SUBSCRIPTS"))
366     {
367       lex_match (lexer, T_EQUALS);
368       size_t allocated_subscripts = value->n_subscripts;
369       while (lex_token (lexer) == T_STRING)
370         {
371           if (value->n_subscripts >= allocated_subscripts)
372             value->subscripts = x2nrealloc (value->subscripts,
373                                             &allocated_subscripts,
374                                             sizeof *value->subscripts);
375
376           value->subscripts[value->n_subscripts++] = xstrdup (
377             lex_tokcstr (lexer));
378           lex_get (lexer);
379         }
380       return;
381     }
382
383   lex_error (lexer, "Expecting valid value option");
384   exit (1);
385 }
386
387 static struct pivot_value *
388 read_value (struct lexer *lexer)
389 {
390   struct pivot_value *value;
391   if (lex_is_number (lexer))
392     {
393       value = pivot_value_new_number (lex_number (lexer));
394       lex_get (lexer);
395     }
396   else if (lex_is_string (lexer))
397     {
398       value = xmalloc (sizeof *value);
399       *value = (struct pivot_value) {
400         .type = PIVOT_VALUE_STRING,
401         .string = { .s = xstrdup (lex_tokcstr (lexer)) },
402       };
403       lex_get (lexer);
404     }
405   else if (lex_token (lexer) == T_ID)
406     {
407       value = xmalloc (sizeof *value);
408       *value = (struct pivot_value) {
409         .type = PIVOT_VALUE_VARIABLE,
410         .variable = { .var_name = xstrdup (lex_tokcstr (lexer)) },
411       };
412       lex_get (lexer);
413     }
414   else
415     {
416       msg (SE, "Expecting pivot_value");
417       exit (1);
418     }
419
420   while (lex_match (lexer, T_LBRACK))
421     {
422       read_value_option (lexer, value);
423
424       if (!lex_force_match (lexer, T_RBRACK))
425         exit (1);
426     }
427
428   return value;
429 }
430
431 static void
432 read_group (struct lexer *lexer, struct pivot_table *pt,
433             struct pivot_category *group)
434 {
435   if (lex_match (lexer, T_ASTERISK))
436     group->show_label = true;
437
438   if (!lex_force_match (lexer, T_LPAREN))
439     exit (1);
440
441   if (lex_match (lexer, T_RPAREN))
442     return;
443
444   do
445     {
446       struct pivot_value *name = read_value (lexer);
447       if (lex_token (lexer) == T_ASTERISK
448           || lex_token (lexer) == T_LPAREN)
449         read_group (lexer, pt, pivot_category_create_group__ (group, name));
450       else
451         {
452           char *rc;
453           if (lex_token (lexer) == T_ID
454               && is_pivot_result_class (lex_tokcstr (lexer)))
455             {
456               rc = xstrdup (lex_tokcstr (lexer));
457               lex_get (lexer);
458             }
459           else
460             rc = NULL;
461
462           pivot_category_create_leaf_rc (group, name, rc);
463
464           free (rc);
465         }
466     }
467   while (lex_match (lexer, T_COMMA));
468   if (!lex_force_match (lexer, T_RPAREN))
469     exit (1);
470 }
471
472 static void
473 read_dimension (struct lexer *lexer, struct pivot_table *pt,
474                 enum pivot_axis_type a)
475 {
476   lex_match (lexer, T_EQUALS);
477
478   struct pivot_value *name = read_value (lexer);
479   struct pivot_dimension *dim = pivot_dimension_create__ (pt, a, name);
480   read_group (lexer, pt, dim->root);
481 }
482
483 static bool
484 parse_bool_setting (struct lexer *lexer, const char *name,
485                     const char *true_kw, const char *false_kw,
486                     bool *out)
487 {
488   if (lex_match_id (lexer, name))
489     {
490       if (!lex_force_match (lexer, T_EQUALS))
491         exit (1);
492
493       if (lex_match_id (lexer, true_kw))
494         *out = true;
495       else if (lex_match_id (lexer, false_kw))
496         *out = false;
497       else
498         {
499           lex_error_expecting (lexer, true_kw, false_kw);
500           exit (1);
501         }
502
503       return true;
504     }
505   else
506     return false;
507 }
508
509 static void
510 read_look (struct lexer *lexer, struct pivot_table *pt)
511 {
512   lex_match (lexer, T_EQUALS);
513
514   if (lex_is_string (lexer))
515     {
516       struct pivot_table_look *look;
517       char *error = pivot_table_look_read (lex_tokcstr (lexer), &look);
518       if (error)
519         {
520           msg (SE, "%s", error);
521           exit (1);
522         }
523       lex_get (lexer);
524
525       pivot_table_set_look (pt, look);
526       pivot_table_look_unref (look);
527     }
528
529   struct pivot_table_look *look = pivot_table_look_unshare (
530     pivot_table_look_ref (pt->look));
531   for (;;)
532     {
533       if (!parse_bool_setting (lexer, "EMPTY", "HIDE", "SHOW",
534                                &look->omit_empty)
535           && !parse_bool_setting (lexer, "ROWLABELS", "CORNER", "NESTED",
536                                   &look->row_labels_in_corner)
537           && !parse_bool_setting (lexer, "MARKERS", "NUMERIC", "ALPHA",
538                                   &look->show_numeric_markers)
539           && !parse_bool_setting (lexer, "LEVEL", "SUPER", "SUB",
540                                   &look->footnote_marker_superscripts)
541           && !parse_bool_setting (lexer, "LAYERS", "CURRENT", "ALL",
542                                   &look->print_all_layers)
543           && !parse_bool_setting (lexer, "PAGINATELAYERS", "YES", "NO",
544                                   &look->paginate_layers)
545           && !parse_bool_setting (lexer, "HSHRINK", "YES", "NO",
546                                   &look->shrink_to_fit[TABLE_HORZ])
547           && !parse_bool_setting (lexer, "VSHRINK", "YES", "NO",
548                                   &look->shrink_to_fit[TABLE_VERT])
549           && !parse_bool_setting (lexer, "TOPCONTINUATION", "YES", "NO",
550                                   &look->top_continuation)
551           && !parse_bool_setting (lexer, "BOTTOMCONTINUATION", "YES", "NO",
552                                   &look->bottom_continuation)
553           && !parse_string_setting (lexer, "CONTINUATION",
554                                     &look->continuation))
555         break;
556     }
557   pivot_table_set_look (pt, look);
558   pivot_table_look_unref (look);
559 }
560
561 static enum table_stroke
562 read_stroke (struct lexer *lexer)
563 {
564   for (int stroke = 0; stroke < TABLE_N_STROKES; stroke++)
565     if (lex_match_id (lexer, table_stroke_to_string (stroke)))
566       return stroke;
567
568   lex_error (lexer, "expecting stroke");
569   exit (1);
570 }
571
572 static struct cell_color
573 read_color (struct lexer *lexer)
574 {
575   struct cell_color color;
576   if (!parse_color__ (lex_tokcstr (lexer), &color))
577     {
578       msg (SE, "%s: unknown color", lex_tokcstr (lexer));
579       exit (1);
580     }
581   lex_get (lexer);
582   return color;
583 }
584
585 static bool
586 parse_value_setting (struct lexer *lexer, const char *name,
587                      struct pivot_value **valuep)
588 {
589   if (lex_match_id (lexer, name))
590     {
591       lex_match (lexer, T_EQUALS);
592
593       pivot_value_destroy (*valuep);
594       *valuep = read_value (lexer);
595
596       return true;
597     }
598   else
599     return false;
600 }
601
602 static void
603 read_border (struct lexer *lexer, struct pivot_table *pt)
604 {
605   static const char *const pivot_border_ids[PIVOT_N_BORDERS] = {
606     [PIVOT_BORDER_TITLE] = "title",
607     [PIVOT_BORDER_OUTER_LEFT] = "outer-left",
608     [PIVOT_BORDER_OUTER_TOP] = "outer-top",
609     [PIVOT_BORDER_OUTER_RIGHT] = "outer-right",
610     [PIVOT_BORDER_OUTER_BOTTOM] = "outer-bottom",
611     [PIVOT_BORDER_INNER_LEFT] = "inner-left",
612     [PIVOT_BORDER_INNER_TOP] = "inner-top",
613     [PIVOT_BORDER_INNER_RIGHT] = "inner-right",
614     [PIVOT_BORDER_INNER_BOTTOM] = "inner-bottom",
615     [PIVOT_BORDER_DATA_LEFT] = "data-left",
616     [PIVOT_BORDER_DATA_TOP] = "data-top",
617     [PIVOT_BORDER_DIM_ROW_HORZ] = "dim-row-horz",
618     [PIVOT_BORDER_DIM_ROW_VERT] = "dim-row-vert",
619     [PIVOT_BORDER_DIM_COL_HORZ] = "dim-col-horz",
620     [PIVOT_BORDER_DIM_COL_VERT] = "dim-col-vert",
621     [PIVOT_BORDER_CAT_ROW_HORZ] = "cat-row-horz",
622     [PIVOT_BORDER_CAT_ROW_VERT] = "cat-row-vert",
623     [PIVOT_BORDER_CAT_COL_HORZ] = "cat-col-horz",
624     [PIVOT_BORDER_CAT_COL_VERT] = "cat-col-vert",
625   };
626
627   lex_match (lexer, T_EQUALS);
628
629   struct pivot_table_look *look = pivot_table_look_unshare (
630     pivot_table_look_ref (pt->look));
631   while (lex_token (lexer) == T_STRING)
632     {
633       char *s = xstrdup (lex_tokcstr (lexer));
634       lex_get (lexer);
635       if (!lex_force_match (lexer, T_LPAREN))
636         exit (1);
637
638       struct table_border_style style = TABLE_BORDER_STYLE_INITIALIZER;
639       style.stroke = read_stroke (lexer);
640       if (lex_is_string (lexer))
641         style.color = read_color (lexer);
642       if (!lex_force_match (lexer, T_RPAREN))
643         exit (1);
644
645       int n = 0;
646       for (int b = 0; b < PIVOT_N_BORDERS; b++)
647         {
648           if (!strncmp (s, pivot_border_ids[b], strlen (s)))
649             {
650               look->borders[b] = style;
651               n++;
652             }
653         }
654       if (!n)
655         {
656           msg (SE, "%s: no matching borders", s);
657           exit (1);
658         }
659       free (s);
660     }
661   pivot_table_set_look (pt, look);
662   pivot_table_look_unref (look);
663 }
664
665 static struct pivot_table *
666 read_table (struct lexer *lexer)
667 {
668   struct pivot_table *pt = pivot_table_create__ (NULL, NULL);
669   while (lex_match (lexer, T_SLASH))
670     {
671       assert (!pivot_table_is_shared (pt));
672
673       if (lex_match_id (lexer, "ROW"))
674         read_dimension (lexer, pt, PIVOT_AXIS_ROW);
675       else if (lex_match_id (lexer, "COLUMN"))
676         read_dimension (lexer, pt, PIVOT_AXIS_COLUMN);
677       else if (lex_match_id (lexer, "LAYER"))
678         read_dimension (lexer, pt, PIVOT_AXIS_LAYER);
679       else if (lex_match_id (lexer, "LOOK"))
680         read_look (lexer, pt);
681       else if (lex_match_id (lexer, "ROTATE"))
682         {
683           lex_match (lexer, T_EQUALS);
684           while (lex_token (lexer) == T_ID)
685             if (!parse_bool_setting (lexer, "INNERCOLUMNS", "YES", "NO",
686                                      &pt->rotate_inner_column_labels)
687                 && !parse_bool_setting (lexer, "OUTERROWS", "YES", "NO",
688                                         &pt->rotate_outer_row_labels))
689               break;
690         }
691       else if (lex_match_id (lexer, "DISPLAY"))
692         {
693           lex_match (lexer, T_EQUALS);
694           while (lex_token (lexer) == T_ID)
695             {
696               if (parse_bool_setting (lexer, "GRID", "YES", "NO",
697                                       &pt->show_grid_lines)
698                   || parse_bool_setting (lexer, "CAPTION", "YES", "NO",
699                                          &pt->show_caption)
700                   || parse_bool_setting (lexer, "TITLE", "YES", "NO",
701                                          &pt->show_title))
702                 continue;
703
704               if (parse_settings_value_show (lexer, "VALUES", &pt->show_values)
705                   || parse_settings_value_show (lexer, "VARIABLES",
706                                                 &pt->show_variables))
707                 continue;
708
709               break;
710             }
711         }
712       else if (parse_value_setting (lexer, "TITLE", &pt->title)
713                || parse_value_setting (lexer, "SUBTYPE", &pt->subtype)
714                || parse_value_setting (lexer, "CORNER", &pt->corner_text)
715                || parse_value_setting (lexer, "CAPTION", &pt->caption)
716                || parse_string_setting (lexer, "NOTES", &pt->notes))
717         {
718           /* Nothing. */
719         }
720       else if (lex_match_id (lexer, "BORDER"))
721         read_border (lexer, pt);
722       else
723         {
724           msg (SE, "Expecting keyword");
725           exit (1);
726         }
727     }
728
729   size_t *dindexes = xcalloc (pt->n_dimensions, sizeof *dindexes);
730   for (size_t i = 0; ; i++)
731     {
732       pivot_table_put (pt, dindexes, pt->n_dimensions,
733                        pivot_value_new_integer (i));
734
735       for (size_t j = 0; j < pt->n_dimensions; j++)
736         {
737           if (++dindexes[j] < pt->dimensions[j]->n_leaves)
738             goto next;
739           dindexes[j] = 0;
740         }
741         break;
742     next:;
743     }
744   free (dindexes);
745
746   if (!lex_force_match (lexer, T_ENDCMD))
747     exit (1);
748   return pt;
749 }
750
751 static void
752 output_msg (const struct msg *m_, void *lexer_)
753 {
754   struct lexer *lexer = lexer_;
755   struct msg m = *m_;
756
757   if (m.file_name == NULL)
758     {
759       m.file_name = CONST_CAST (char *, lex_get_file_name (lexer));
760       m.first_line = lex_get_first_line_number (lexer, 0);
761       m.last_line = lex_get_last_line_number (lexer, 0);
762     }
763
764   m.command_name = output_get_command_name ();
765
766   message_item_submit (message_item_create (&m));
767
768   free (m.command_name);
769 }