1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <data/format.h>
23 #include <libpspp/message.h>
25 #include <libpspp/message.h>
27 #include <libpspp/misc.h>
28 #include <libpspp/str.h>
29 #include <data/variable.h>
32 #define _(msgid) gettext (msgid)
35 /* Parses the alphabetic prefix of the current token as a format
36 specifier name. Returns the corresponding format specifier
37 type if successful, or -1 on failure. If ALLOW_XT is zero,
38 then X and T format specifiers are not allowed. If CP is
39 nonzero, then *CP is set to the first non-alphabetic character
40 in the current token on success or to a null pointer on
43 parse_format_specifier_name (const char **cp, enum fmt_parse_flags flags)
48 sp = ep = ds_c_str (&tokstr);
49 while (isalpha ((unsigned char) *ep))
55 for (idx = 0; idx < FMT_NUMBER_OF_FORMATS; idx++)
56 if (strlen (formats[idx].name) == ep - sp
57 && !buf_compare_case (formats[idx].name, sp, ep - sp))
61 if (idx < FMT_NUMBER_OF_FORMATS)
63 if (!(flags & FMTP_ALLOW_XT) && (idx == FMT_T || idx == FMT_X))
65 if (!(flags & FMTP_SUPPRESS_ERRORS))
66 msg (SE, _("X and T format specifiers not allowed here."));
73 if (!(flags & FMTP_SUPPRESS_ERRORS))
74 msg (SE, _("%.*s is not a valid data format."),
75 (int) (ep - sp), ds_c_str (&tokstr));
81 lex_error ("expecting data format");
97 /* Parses a format specifier from the token stream and returns
98 nonzero only if successful. Emits an error message on
99 failure. Allows X and T format specifiers only if ALLOW_XT is
100 nonzero. The caller should call check_input_specifier() or
101 check_output_specifier() on the parsed format as
104 parse_format_specifier (struct fmt_spec *input, enum fmt_parse_flags flags)
106 struct fmt_spec spec;
114 if (!(flags & FMTP_SUPPRESS_ERRORS))
115 msg (SE, _("Format specifier expected."));
118 type = parse_format_specifier_name (&cp, flags);
123 w = strtol (cp, &cp2, 10);
124 if (cp2 == cp && type != FMT_X)
126 if (!(flags & FMTP_SUPPRESS_ERRORS))
127 msg (SE, _("Data format %s does not specify a width."),
133 if (f->n_args > 1 && *cp == '.')
136 d = strtol (cp, &cp2, 10);
144 if (!(flags & FMTP_SUPPRESS_ERRORS))
145 msg (SE, _("Data format %s is not valid."), ds_c_str (&tokstr));