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];
97 while (lex_token (lexer) != T_SLASH &&
98 lex_token (lexer) != T_ENDCMD)
100 if (lex_match_id (lexer, "SELECT"))
102 lex_force_match (lexer, T_EQUALS);
103 lex_force_match (lexer, T_LBRACK);
105 while (lex_token (lexer) != T_RBRACK &&
106 lex_token (lexer) != T_ENDCMD)
109 for (i = 0 ; i < N_THINGS; ++i)
111 if (lex_match_id (lexer, things[i].identifier))
113 os->rc = xrealloc (os->rc, sizeof (*os->rc) * ++os->n_rc);
114 os->rc[os->n_rc - 1] = things[i].rc;
120 lex_error (lexer, _("Unknown TABLECELLS class"));
124 lex_force_match (lexer, T_RBRACK);
126 else if (lex_match_id (lexer, "FORMAT"))
129 char type[FMT_TYPE_LEN_MAX + 1];
133 lex_force_match (lexer, T_EQUALS);
134 if (! parse_abstract_format_specifier (lexer, type, &width, &decimals))
136 lex_error (lexer, NULL);
142 const struct fmt_spec *dflt = settings_get_format ();
146 if (!fmt_from_name (type, &fmt.type))
148 lex_error (lexer, _("Unknown format type `%s'."), type);
159 lex_error (lexer, NULL);
167 lex_error (lexer, NULL);
173 /* Populate the global table, with the values we parsed */
174 for (i = 0; i < n_os; ++i)
176 for (j = 0; j < output_specs[i].n_rc; ++j)
178 ugly [output_specs[i].rc[j]] = output_specs[i].fmt;
182 for (j = 0; j < n_os; ++j)
183 free (output_specs[j].rc);
188 for (j = 0; j < n_os; ++j)
189 free (output_specs[j].rc);