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/string-set.h"
30 #include "libpspp/version.h"
31 #include "output/pivot-table.h"
33 #include "gl/xalloc.h"
36 #define _(msgid) gettext (msgid)
39 cmd_output (struct lexer *lexer, struct dataset *ds UNUSED)
41 struct string_set rc_names = STRING_SET_INITIALIZER (rc_names);
43 if (!lex_force_match_id (lexer, "MODIFY"))
45 lex_error (lexer, NULL);
49 while (lex_token (lexer) != T_ENDCMD)
51 lex_match (lexer, T_SLASH);
53 if (lex_match_id (lexer, "SELECT"))
55 if (!lex_match_id (lexer, "TABLES"))
57 lex_error (lexer, NULL);
61 else if (lex_match_id (lexer, "TABLECELLS"))
63 string_set_clear (&rc_names);
64 struct fmt_spec fmt = { .type = 0 };
66 while (lex_token (lexer) != T_SLASH &&
67 lex_token (lexer) != T_ENDCMD)
69 if (lex_match_id (lexer, "SELECT"))
71 if (! lex_force_match (lexer, T_EQUALS))
74 if (! lex_force_match (lexer, T_LBRACK))
77 while (lex_token (lexer) == T_ID)
79 string_set_insert (&rc_names, lex_tokcstr (lexer));
83 if (! lex_force_match (lexer, T_RBRACK))
86 else if (lex_match_id (lexer, "FORMAT"))
88 char type[FMT_TYPE_LEN_MAX + 1];
92 if (! lex_force_match (lexer, T_EQUALS))
94 if (! parse_abstract_format_specifier (lexer, type, &width, &decimals))
96 lex_error (lexer, NULL);
102 const struct fmt_spec *dflt = settings_get_format ();
106 if (!fmt_from_name (type, &fmt.type))
108 lex_error (lexer, _("Unknown format type `%s'."), type);
117 lex_error (lexer, NULL);
124 const struct string_set_node *node;
126 STRING_SET_FOR_EACH (s, node, &rc_names)
127 if (!pivot_result_class_change (s, &fmt))
128 lex_error (lexer, _("Unknown cell class %s."), s);
133 lex_error (lexer, NULL);
138 string_set_destroy (&rc_names);
142 string_set_destroy (&rc_names);