1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006 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/procedure.h>
24 #include <data/variable.h>
25 #include <data/format.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)
43 static int internal_cmd_formats (struct lexer *, struct dataset *ds, int);
46 cmd_print_formats (struct lexer *lexer, struct dataset *ds)
48 return internal_cmd_formats (lexer, ds, FORMATS_PRINT);
52 cmd_write_formats (struct lexer *lexer, struct dataset *ds)
54 return internal_cmd_formats (lexer, ds, FORMATS_WRITE);
58 cmd_formats (struct lexer *lexer, struct dataset *ds)
60 return internal_cmd_formats (lexer, ds, FORMATS_PRINT | FORMATS_WRITE);
64 internal_cmd_formats (struct lexer *lexer, struct dataset *ds, int which)
70 /* Format to set the variables to. */
73 /* Numeric or string. */
81 if (lex_token (lexer) == '.')
84 if (!parse_variables (lexer, dataset_dict (ds), &v, &cv, PV_NUMERIC))
86 type = var_get_type (v[0]);
88 if (!lex_match (lexer, '('))
90 msg (SE, _("`(' expected after variable list."));
93 if (!parse_format_specifier (lexer, &f)
94 || !fmt_check_output (&f)
95 || !fmt_check_type_compat (&f, VAL_NUMERIC))
98 if (!lex_match (lexer, ')'))
100 msg (SE, _("`)' expected after output format."));
104 for (i = 0; i < cv; i++)
106 if (which & FORMATS_PRINT)
107 var_set_print_format (v[i], &f);
108 if (which & FORMATS_WRITE)
109 var_set_write_format (v[i], &f);