2 #include "range-parser.h"
4 #include <data/data-in.h>
5 #include <libpspp/message.h>
7 #include <libpspp/magic.h>
8 #include <libpspp/str.h>
9 #include <data/value.h>
12 #define _(msgid) gettext (msgid)
13 #define N_(msgid) msgid
15 static bool parse_number (double *, const struct fmt_spec *);
17 /* Parses and stores a numeric value, or a range of the form "x
18 THRU y". Open-ended ranges may be specified as "LO(WEST) THRU
19 y" or "x THRU HI(GHEST)". Sets *X and *Y to the range or the
20 value and returns success.
22 Numeric values are always accepted. If F is nonnull, then
23 string values are also accepted, and converted to numeric
24 values using the specified format. */
26 parse_num_range (double *x, double *y, const struct fmt_spec *f)
28 if (lex_match_id ("LO") || lex_match_id ("LOWEST"))
30 else if (!parse_number (x, f))
33 if (lex_match_id ("THRU"))
35 if (lex_match_id ("HI") || lex_match_id ("HIGHEST"))
37 else if (!parse_number (y, f))
43 msg (SW, _("Low end of range (%g) is below high end (%g). "
44 "The range will be treated as reversed."),
51 msg (SW, _("Ends of range are equal (%g)."), *x);
59 msg (SE, _("LO or LOWEST must be part of a range."));
68 /* Parses a number and stores it in *X. Returns success.
70 Numeric values are always accepted. If F is nonnull, then
71 string values are also accepted, and converted to numeric
72 values using the specified format. */
74 parse_number (double *x, const struct fmt_spec *f)
82 else if (token == T_STRING && f != NULL)
86 di.s = ds_data (&tokstr);
87 di.e = ds_end (&tokstr);
91 di.f2 = ds_length (&tokstr);
98 lex_error (_("System-missing value is not valid here."));
106 lex_error (_("expecting number or data string"));