1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <data/procedure.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/lexer/format-parser.h>
29 #include <language/lexer/lexer.h>
30 #include <language/lexer/variable-parser.h>
31 #include <libpspp/message.h>
32 #include <libpspp/misc.h>
33 #include <libpspp/str.h>
36 #define _(msgid) gettext (msgid)
44 static int internal_cmd_formats (struct lexer *, struct dataset *ds, int);
47 cmd_print_formats (struct lexer *lexer, struct dataset *ds)
49 return internal_cmd_formats (lexer, ds, FORMATS_PRINT);
53 cmd_write_formats (struct lexer *lexer, struct dataset *ds)
55 return internal_cmd_formats (lexer, ds, FORMATS_WRITE);
59 cmd_formats (struct lexer *lexer, struct dataset *ds)
61 return internal_cmd_formats (lexer, ds, FORMATS_PRINT | FORMATS_WRITE);
65 internal_cmd_formats (struct lexer *lexer, struct dataset *ds, int which)
71 /* Format to set the variables to. */
74 /* Numeric or string. */
82 if (lex_token (lexer) == '.')
85 if (!parse_variables (lexer, dataset_dict (ds), &v, &cv, PV_NUMERIC))
87 type = var_get_type (v[0]);
89 if (!lex_match (lexer, '('))
91 msg (SE, _("`(' expected after variable list."));
94 if (!parse_format_specifier (lexer, &f)
95 || !fmt_check_output (&f)
96 || !fmt_check_type_compat (&f, VAR_NUMERIC))
99 if (!lex_match (lexer, ')'))
101 msg (SE, _("`)' expected after output format."));
105 for (i = 0; i < cv; i++)
107 if (which & FORMATS_PRINT)
108 var_set_print_format (v[i], &f);
109 if (which & FORMATS_WRITE)
110 var_set_write_format (v[i], &f);