1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2014 Free Software Foundation, Inc.
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.
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.
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/>. */
22 #include "data/dataset.h"
23 #include "data/settings.h"
24 #include "data/format.h"
25 #include "language/command.h"
26 #include "language/lexer/lexer.h"
27 #include "language/lexer/format-parser.h"
28 #include "libpspp/message.h"
29 #include "libpspp/version.h"
30 #include "output/tab.h"
32 #include "gl/xalloc.h"
35 #define _(msgid) gettext (msgid)
39 const char *identifier;
43 extern struct fmt_spec ugly [n_RC];
45 static const struct thing things[] =
47 {"SIGNIFICANCE", RC_PVALUE},
51 #define N_THINGS (sizeof (things) / sizeof (struct thing))
55 /* An array of classes */
56 enum result_class *rc;
60 /* The format to be applied to these classes */
65 cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
68 struct output_spec *output_specs = NULL;
71 if (!lex_force_match_id (lexer, "MODIFY"))
73 lex_error (lexer, NULL);
77 while (lex_token (lexer) != T_ENDCMD)
79 lex_match (lexer, T_SLASH);
81 if (lex_match_id (lexer, "SELECT"))
83 if (!lex_match_id (lexer, "TABLES"))
85 lex_error (lexer, NULL);
89 else if (lex_match_id (lexer, "TABLECELLS"))
91 struct output_spec *os;
92 output_specs = xrealloc (output_specs, sizeof (*output_specs) * ++n_os);
93 os = &output_specs[n_os - 1];
98 while (lex_token (lexer) != T_SLASH &&
99 lex_token (lexer) != T_ENDCMD)
101 if (lex_match_id (lexer, "SELECT"))
103 lex_force_match (lexer, T_EQUALS);
104 lex_force_match (lexer, T_LBRACK);
106 while (lex_token (lexer) != T_RBRACK &&
107 lex_token (lexer) != T_ENDCMD)
110 for (i = 0 ; i < N_THINGS; ++i)
112 if (lex_match_id (lexer, things[i].identifier))
114 os->rc = xrealloc (os->rc, sizeof (*os->rc) * ++os->n_rc);
115 os->rc[os->n_rc - 1] = things[i].rc;
121 lex_error (lexer, _("Unknown TABLECELLS class"));
125 lex_force_match (lexer, T_RBRACK);
127 else if (lex_match_id (lexer, "FORMAT"))
130 char type[FMT_TYPE_LEN_MAX + 1];
134 lex_force_match (lexer, T_EQUALS);
135 if (! parse_abstract_format_specifier (lexer, type, &width, &decimals))
137 lex_error (lexer, NULL);
143 const struct fmt_spec *dflt = settings_get_format ();
147 if (!fmt_from_name (type, &fmt.type))
149 lex_error (lexer, _("Unknown format type `%s'."), type);
161 lex_error (lexer, NULL);
170 lex_error (lexer, NULL);
175 /* Populate the global table, with the values we parsed */
176 for (i = 0; i < n_os; ++i)
178 for (j = 0; j < output_specs[i].n_rc; ++j)
180 ugly [output_specs[i].rc[j]] = output_specs[i].fmt;
184 for (j = 0; j < n_os; ++j)
185 free (output_specs[j].rc);
190 for (j = 0; j < n_os; ++j)
191 free (output_specs[j].rc);