1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2010, 2011 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/>. */
23 #include "data/dataset.h"
24 #include "data/format.h"
25 #include "data/variable.h"
26 #include "language/command.h"
27 #include "language/lexer/format-parser.h"
28 #include "language/lexer/lexer.h"
29 #include "language/lexer/variable-parser.h"
30 #include "libpspp/message.h"
31 #include "libpspp/misc.h"
32 #include "libpspp/str.h"
35 #define _(msgid) gettext (msgid)
37 static int cmd_formats__ (struct lexer *, struct dataset *ds,
38 bool print_format, bool write_format);
41 cmd_print_formats (struct lexer *lexer, struct dataset *ds)
43 return cmd_formats__ (lexer, ds, true, false);
47 cmd_write_formats (struct lexer *lexer, struct dataset *ds)
49 return cmd_formats__ (lexer, ds, false, true);
53 cmd_formats (struct lexer *lexer, struct dataset *ds)
55 return cmd_formats__ (lexer, ds, true, true);
59 cmd_formats__ (struct lexer *lexer, struct dataset *ds,
60 bool print_format, bool write_format)
72 lex_match (lexer, T_SLASH);
74 if (lex_token (lexer) == T_ENDCMD)
77 if (!parse_variables (lexer, dataset_dict (ds), &v, &cv, PV_SAME_WIDTH))
79 width = var_get_width (v[0]);
81 if (!lex_match (lexer, T_LPAREN))
83 lex_error_expecting (lexer, "`('");
86 if (!parse_format_specifier (lexer, &f))
88 char *error = fmt_check_output__ (&f);
90 error = fmt_check_width_compat__ (&f, var_get_name (v[0]), width);
93 lex_next_error (lexer, -1, -1, "%s", error);
98 if (!lex_match (lexer, T_RPAREN))
100 lex_error_expecting (lexer, "`)'");
104 for (i = 0; i < cv; i++)
107 var_set_print_format (v[i], &f);
109 var_set_write_format (v[i], &f);