1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 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
35 #include "identifier.h"
39 #include <libpspp/assertion.h>
40 #include <libpspp/compiler.h>
41 #include <libpspp/integer-format.h>
42 #include <libpspp/magic.h>
43 #include <libpspp/message.h>
44 #include <libpspp/misc.h>
45 #include <libpspp/str.h>
53 #define _(msgid) gettext (msgid)
55 /* Information about parsing one data field. */
58 struct substring input; /* Source. */
59 enum fmt_type format; /* Input format. */
60 int implied_decimals; /* Number of implied decimal places. */
62 union value *output; /* Destination. */
63 int width; /* Output width. */
65 int first_column; /* First column of field; 0 if inapplicable. */
66 int last_column; /* Last column. */
69 /* Integer format used for IB and PIB input. */
70 static enum integer_format input_integer_format = INTEGER_NATIVE;
72 /* Floating-point format used for RB and RBHEX input. */
73 static enum float_format input_float_format = FLOAT_NATIVE_DOUBLE;
75 typedef bool data_in_parser_func (struct data_in *);
76 #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) \
77 static data_in_parser_func parse_##METHOD;
80 static void vdata_warning (const struct data_in *, const char *, va_list)
82 static void data_warning (const struct data_in *, const char *, ...)
85 static void apply_implied_decimals (struct data_in *);
86 static void default_result (struct data_in *);
87 static bool trim_spaces_and_check_missing (struct data_in *);
89 static int hexit_value (int c);
91 /* Parses the characters in INPUT according to FORMAT. Stores
92 the parsed representation in OUTPUT, which has the given WIDTH
93 (0 for a numeric field, otherwise the string width).
95 If no decimal point is included in a numeric format, then
96 IMPLIED_DECIMALS decimal places are implied. Specify 0 if no
97 decimal places should be implied.
99 If FIRST_COLUMN is nonzero, then it should be the 1-based
100 column number of the first character in INPUT, used in error
103 data_in (struct substring input,
104 enum fmt_type format, int implied_decimals,
105 int first_column, union value *output, int width)
107 static data_in_parser_func *const handlers[FMT_NUMBER_OF_FORMATS] =
109 #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) parse_##METHOD,
110 #include "format.def"
116 assert ((width != 0) == fmt_is_string (format));
120 i.implied_decimals = implied_decimals;
125 i.first_column = first_column;
126 i.last_column = first_column + ss_length (input) - 1;
128 if (!ss_is_empty (i.input))
130 ok = handlers[i.format] (&i);
143 /* Returns the integer format used for IB and PIB input. */
145 data_in_get_integer_format (void)
147 return input_integer_format;
150 /* Sets the integer format used for IB and PIB input to
153 data_in_set_integer_format (enum integer_format format)
155 input_integer_format = format;
158 /* Returns the floating-point format used for RB and RBHEX
161 data_in_get_float_format (void)
163 return input_float_format;
166 /* Sets the floating-point format used for RB and RBHEX input to
169 data_in_set_float_format (enum float_format format)
171 input_float_format = format;
174 /* Format parsers. */
176 /* Parses F, COMMA, DOT, DOLLAR, PCT, and E input formats. */
178 parse_number (struct data_in *i)
180 const struct fmt_number_style *style = fmt_get_style (i->format);
184 bool explicit_decimals = false;
188 assert (fmt_get_category (i->format) != FMT_CAT_CUSTOM);
190 /* Trim spaces and check for missing value representation. */
191 if (trim_spaces_and_check_missing (i))
194 ds_init_empty (&tmp);
195 ds_extend (&tmp, 64);
197 /* Prefix character may precede sign. */
198 if (!ss_is_empty (style->prefix))
200 ss_match_char (&i->input, ss_first (style->prefix));
201 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
205 if (ss_match_char (&i->input, '-'))
207 ds_put_char (&tmp, '-');
208 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
212 ss_match_char (&i->input, '+');
213 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
216 /* Prefix character may follow sign. */
217 if (!ss_is_empty (style->prefix))
219 ss_match_char (&i->input, ss_first (style->prefix));
220 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
223 /* Digits before decimal point. */
224 while (c_isdigit (ss_first (i->input)))
226 ds_put_char (&tmp, ss_get_char (&i->input));
227 if (style->grouping != 0)
228 ss_match_char (&i->input, style->grouping);
231 /* Decimal point and following digits. */
232 if (ss_match_char (&i->input, style->decimal))
234 explicit_decimals = true;
235 ds_put_char (&tmp, '.');
236 while (c_isdigit (ss_first (i->input)))
237 ds_put_char (&tmp, ss_get_char (&i->input));
241 if (!ds_is_empty (&tmp)
242 && !ss_is_empty (i->input)
243 && strchr ("eEdD-+", ss_first (i->input)))
245 explicit_decimals = true;
246 ds_put_char (&tmp, 'e');
248 if (strchr ("eEdD", ss_first (i->input)))
250 ss_advance (&i->input, 1);
251 ss_match_char (&i->input, ' ');
254 if (ss_first (i->input) == '-' || ss_first (i->input) == '+')
256 if (ss_get_char (&i->input) == '-')
257 ds_put_char (&tmp, '-');
258 ss_match_char (&i->input, ' ');
261 while (c_isdigit (ss_first (i->input)))
262 ds_put_char (&tmp, ss_get_char (&i->input));
265 /* Suffix character. */
266 if (!ss_is_empty (style->suffix))
267 ss_match_char (&i->input, ss_first (style->suffix));
269 if (!ss_is_empty (i->input))
271 if (ds_is_empty (&tmp))
272 data_warning (i, _("Field contents are not numeric."));
274 data_warning (i, _("Number followed by garbage."));
279 /* Let strtod() do the conversion. */
282 i->output->f = strtod (ds_cstr (&tmp), &tail);
285 data_warning (i, _("Invalid numeric syntax."));
290 else if (errno == ERANGE)
292 if (fabs (i->output->f) > 1)
294 data_warning (i, _("Too-large number set to system-missing."));
295 i->output->f = SYSMIS;
299 data_warning (i, _("Too-small number set to zero."));
306 if (!explicit_decimals)
307 apply_implied_decimals (i);
314 /* Parses N format. */
316 parse_N (struct data_in *i)
321 while ((c = ss_get_char (&i->input)) != EOF)
325 data_warning (i, _("All characters in field must be digits."));
328 i->output->f = i->output->f * 10.0 + (c - '0');
331 apply_implied_decimals (i);
335 /* Parses PIBHEX format. */
337 parse_PIBHEX (struct data_in *i)
344 while ((c = ss_get_char (&i->input)) != EOF)
348 data_warning (i, _("Unrecognized character in field."));
351 n = n * 16.0 + hexit_value (c);
358 /* Parses RBHEX format. */
360 parse_RBHEX (struct data_in *i)
365 memset (&d, 0, sizeof d);
366 for (j = 0; !ss_is_empty (i->input) && j < sizeof d; j++)
368 int hi = ss_get_char (&i->input);
369 int lo = ss_get_char (&i->input);
372 data_warning (i, _("Field must have even length."));
375 else if (!c_isxdigit (hi) || !c_isxdigit (lo))
377 data_warning (i, _("Field must contain only hex digits."));
380 ((unsigned char *) &d)[j] = 16 * hexit_value (hi) + hexit_value (lo);
388 /* Digits for Z format. */
389 static const char z_digits[] = "0123456789{ABCDEFGHI}JKLMNOPQR";
391 /* Returns true if C is a Z format digit, false otherwise. */
395 return c > 0 && strchr (z_digits, c) != NULL;
398 /* Returns the (absolute value of the) value of C as a Z format
401 z_digit_value (int c)
403 assert (is_z_digit (c));
404 return (strchr (z_digits, c) - z_digits) % 10;
407 /* Returns true if Z format digit C represents a negative value,
410 is_negative_z_digit (int c)
412 assert (is_z_digit (c));
413 return (strchr (z_digits, c) - z_digits) >= 20;
416 /* Parses Z format. */
418 parse_Z (struct data_in *i)
424 bool got_dot = false;
425 bool got_final_digit = false;
427 /* Trim spaces and check for missing value representation. */
428 if (trim_spaces_and_check_missing (i))
431 ds_init_empty (&tmp);
432 ds_extend (&tmp, 64);
434 ds_put_char (&tmp, '+');
435 while (!ss_is_empty (i->input))
437 int c = ss_get_char (&i->input);
438 if (c_isdigit (c) && !got_final_digit)
439 ds_put_char (&tmp, c);
440 else if (is_z_digit (c) && !got_final_digit)
442 ds_put_char (&tmp, z_digit_value (c) + '0');
443 if (is_negative_z_digit (c))
444 ds_data (&tmp)[0] = '-';
445 got_final_digit = true;
447 else if (c == '.' && !got_dot)
449 ds_put_char (&tmp, '.');
459 if (!ss_is_empty (i->input))
461 if (ds_length (&tmp) == 1)
462 data_warning (i, _("Field contents are not numeric."));
464 data_warning (i, _("Number followed by garbage."));
469 /* Let strtod() do the conversion. */
472 i->output->f = strtod (ds_cstr (&tmp), NULL);
475 if (fabs (i->output->f) > 1)
477 data_warning (i, _("Too-large number set to system-missing."));
478 i->output->f = SYSMIS;
482 data_warning (i, _("Too-small number set to zero."));
490 apply_implied_decimals (i);
497 /* Parses IB format. */
499 parse_IB (struct data_in *i)
505 bytes = MIN (8, ss_length (i->input));
506 value = integer_get (input_integer_format, ss_data (i->input), bytes);
508 sign_bit = UINT64_C(1) << (8 * bytes - 1);
509 if (!(value & sign_bit))
510 i->output->f = value;
513 /* Sign-extend to full 64 bits. */
514 value -= sign_bit << 1;
515 i->output->f = -(double) -value;
518 apply_implied_decimals (i);
523 /* Parses PIB format. */
525 parse_PIB (struct data_in *i)
527 i->output->f = integer_get (input_integer_format, ss_data (i->input),
528 MIN (8, ss_length (i->input)));
530 apply_implied_decimals (i);
535 /* Consumes the first character of S. Stores its high 4 bits in
536 HIGH_NIBBLE and its low 4 bits in LOW_NIBBLE. */
538 get_nibbles (struct substring *s, int *high_nibble, int *low_nibble)
540 int c = ss_get_char (s);
542 *high_nibble = (c >> 4) & 15;
543 *low_nibble = c & 15;
546 /* Parses P format. */
548 parse_P (struct data_in *i)
550 int high_nibble, low_nibble;
554 while (ss_length (i->input) > 1)
556 get_nibbles (&i->input, &high_nibble, &low_nibble);
557 if (high_nibble > 9 || low_nibble > 9)
559 i->output->f = (100 * i->output->f) + (10 * high_nibble) + low_nibble;
562 get_nibbles (&i->input, &high_nibble, &low_nibble);
565 i->output->f = (10 * i->output->f) + high_nibble;
567 i->output->f = (10 * i->output->f) + low_nibble;
568 else if (low_nibble == 0xb || low_nibble == 0xd)
569 i->output->f = -i->output->f;
571 apply_implied_decimals (i);
576 /* Parses PK format. */
578 parse_PK (struct data_in *i)
581 while (!ss_is_empty (i->input))
583 int high_nibble, low_nibble;
585 get_nibbles (&i->input, &high_nibble, &low_nibble);
586 if (high_nibble > 9 || low_nibble > 9)
588 i->output->f = SYSMIS;
591 i->output->f = (100 * i->output->f) + (10 * high_nibble) + low_nibble;
594 apply_implied_decimals (i);
599 /* Parses RB format. */
601 parse_RB (struct data_in *i)
603 size_t size = float_get_size (input_float_format);
604 if (ss_length (i->input) >= size)
605 float_convert (input_float_format, ss_data (i->input),
606 FLOAT_NATIVE_DOUBLE, &i->output->f);
608 i->output->f = SYSMIS;
613 /* Parses A format. */
615 parse_A (struct data_in *i)
617 buf_copy_rpad (i->output->s, i->width,
618 ss_data (i->input), ss_length (i->input));
622 /* Parses AHEX format. */
624 parse_AHEX (struct data_in *i)
630 int hi = ss_get_char (&i->input);
631 int lo = ss_get_char (&i->input);
636 data_warning (i, _("Field must have even length."));
640 if (!c_isxdigit (hi) || !c_isxdigit (lo))
642 data_warning (i, _("Field must contain only hex digits."));
647 i->output->s[j] = hexit_value (hi) * 16 + hexit_value (lo);
650 memset (i->output->s + j, ' ', i->width - j);
655 /* Date & time format components. */
657 /* Sign of a time value. */
660 SIGN_NO_TIME, /* No time yet encountered. */
661 SIGN_POSITIVE, /* Positive time. */
662 SIGN_NEGATIVE /* Negative time. */
665 /* Parses a signed decimal integer from at most the first
666 MAX_DIGITS characters in I, storing the result into *RESULT.
667 Returns true if successful, false if no integer was
670 parse_int (struct data_in *i, long *result, size_t max_digits)
672 struct substring head = ss_head (i->input, max_digits);
673 size_t n = ss_get_long (&head, result);
676 ss_advance (&i->input, n);
681 data_warning (i, _("Syntax error in date field."));
686 /* Parses a date integer between 1 and 31 from I, storing it into
688 Returns true if successful, false if no date was present. */
690 parse_day (struct data_in *i, long *day)
692 if (!parse_int (i, day, SIZE_MAX))
694 if (*day >= 1 && *day <= 31)
697 data_warning (i, _("Day (%ld) must be between 1 and 31."), *day);
701 /* Parses an integer from the beginning of I.
702 Adds SECONDS_PER_UNIT times the absolute value of the integer
704 If *TIME_SIGN is SIGN_NO_TIME, allows a sign to precede the
705 time and sets *TIME_SIGN. Otherwise, does not allow a sign.
706 Returns true if successful, false if no integer was present. */
708 parse_time_units (struct data_in *i, double seconds_per_unit,
709 enum time_sign *time_sign, double *time)
714 if (*time_sign == SIGN_NO_TIME)
716 if (ss_match_char (&i->input, '-'))
717 *time_sign = SIGN_NEGATIVE;
720 ss_match_char (&i->input, '+');
721 *time_sign = SIGN_POSITIVE;
724 if (!parse_int (i, &units, SIZE_MAX))
728 data_warning (i, _("Syntax error in date field."));
731 *time += units * seconds_per_unit;
735 /* Parses a data delimiter from the beginning of I.
736 Returns true if successful, false if no delimiter was
739 parse_date_delimiter (struct data_in *i)
741 if (ss_ltrim (&i->input, ss_cstr ("-/.," CC_SPACES)))
744 data_warning (i, _("Delimiter expected between fields in date."));
748 /* Parses spaces at the beginning of I. */
750 parse_spaces (struct data_in *i)
752 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
755 static struct substring
756 parse_name_token (struct data_in *i)
758 struct substring token;
759 ss_get_chars (&i->input, ss_span (i->input, ss_cstr (CC_LETTERS)), &token);
763 /* Reads a name from I and sets *OUTPUT to the value associated
764 with that name. If ALLOW_SUFFIXES is true, then names that
765 begin with one of the names are accepted; otherwise, only
766 exact matches (except for case) are allowed.
767 Returns true if successful, false otherwise. */
769 match_name (struct substring token, const char **names, long *output)
773 for (i = 1; *names != NULL; i++)
774 if (ss_equals_case (ss_cstr (*names++), token))
783 /* Parses a month name or number from the beginning of I,
784 storing the month (in range 1...12) into *MONTH.
785 Returns true if successful, false if no month was present. */
787 parse_month (struct data_in *i, long *month)
789 if (c_isdigit (ss_first (i->input)))
791 if (!parse_int (i, month, SIZE_MAX))
793 if (*month >= 1 && *month <= 12)
798 static const char *english_names[] =
800 "jan", "feb", "mar", "apr", "may", "jun",
801 "jul", "aug", "sep", "oct", "nov", "dec",
805 static const char *roman_names[] =
807 "i", "ii", "iii", "iv", "v", "vi",
808 "vii", "viii", "ix", "x", "xi", "xii",
812 struct substring token = parse_name_token (i);
813 if (match_name (ss_head (token, 3), english_names, month)
814 || match_name (ss_head (token, 4), roman_names, month))
818 data_warning (i, _("Unrecognized month format. Months may be specified "
819 "as Arabic or Roman numerals or as at least 3 letters "
820 "of their English names."));
824 /* Parses a year of at most MAX_DIGITS from the beginning of I,
825 storing a "4-digit" year into *YEAR. */
827 parse_year (struct data_in *i, long *year, size_t max_digits)
829 if (!parse_int (i, year, max_digits))
832 if (*year >= 0 && *year <= 99)
834 int epoch = get_epoch ();
835 int epoch_century = ROUND_DOWN (epoch, 100);
836 int epoch_offset = epoch - epoch_century;
837 if (*year >= epoch_offset)
838 *year += epoch_century;
840 *year += epoch_century + 100;
842 if (*year >= 1582 || *year <= 19999)
845 data_warning (i, _("Year (%ld) must be between 1582 and 19999."), *year);
849 /* Returns true if input in I has been exhausted,
852 parse_trailer (struct data_in *i)
854 if (ss_is_empty (i->input))
857 data_warning (i, _("Trailing garbage \"%.*s\" following date."),
858 (int) ss_length (i->input), ss_data (i->input));
862 /* Parses a 3-digit Julian day-of-year value from I into *YDAY.
863 Returns true if successful, false on failure. */
865 parse_yday (struct data_in *i, long *yday)
867 struct substring num_s;
870 ss_get_chars (&i->input, 3, &num_s);
871 if (ss_span (num_s, ss_cstr (CC_DIGITS)) != 3)
873 data_warning (i, _("Julian day must have exactly three digits."));
876 else if (!ss_get_long (&num_s, &num) || num < 1 || num > 366)
878 data_warning (i, _("Julian day (%ld) must be between 1 and 366."), num);
886 /* Parses a quarter-of-year integer between 1 and 4 from I.
887 Stores the corresponding month into *MONTH.
888 Returns true if successful, false if no quarter was present. */
890 parse_quarter (struct data_in *i, long int *month)
894 if (!parse_int (i, &quarter, SIZE_MAX))
896 if (quarter >= 1 && quarter <= 4)
898 *month = (quarter - 1) * 3 + 1;
902 data_warning (i, _("Quarter (%ld) must be between 1 and 4."), quarter);
906 /* Parses a week-of-year integer between 1 and 53 from I,
907 Stores the corresponding year-of-day into *YDAY.
908 Returns true if successful, false if no week was present. */
910 parse_week (struct data_in *i, long int *yday)
914 if (!parse_int (i, &week, SIZE_MAX))
916 if (week >= 1 && week <= 53)
918 *yday = (week - 1) * 7 + 1;
922 data_warning (i, _("Week (%ld) must be between 1 and 53."), week);
926 /* Parses a time delimiter from the beginning of I.
927 Returns true if successful, false if no delimiter was
930 parse_time_delimiter (struct data_in *i)
932 if (ss_ltrim (&i->input, ss_cstr (":" CC_SPACES)) > 0)
935 data_warning (i, _("Delimiter expected between fields in time."));
939 /* Parses minutes and optional seconds from the beginning of I.
940 The time is converted into seconds, which are added to
942 Returns true if successful, false if an error was found. */
944 parse_minute_second (struct data_in *i, double *time)
951 if (!parse_int (i, &minute, SIZE_MAX))
953 if (minute < 0 || minute > 59)
955 data_warning (i, _("Minute (%ld) must be between 0 and 59."), minute);
958 *time += 60. * minute;
960 /* Check for seconds. */
961 if (ss_ltrim (&i->input, ss_cstr (":" CC_SPACES)) == 0
962 || !c_isdigit (ss_first (i->input)))
967 while (c_isdigit (ss_first (i->input)))
968 *cp++ = ss_get_char (&i->input);
969 if (ss_match_char (&i->input, fmt_decimal_char (FMT_F)))
971 while (c_isdigit (ss_first (i->input)))
972 *cp++ = ss_get_char (&i->input);
975 *time += strtod (buf, NULL);
980 /* Parses a weekday name from the beginning of I,
981 storing a value of 1=Sunday...7=Saturday into *WEEKDAY.
982 Returns true if successful, false if an error was found. */
984 parse_weekday (struct data_in *i, long *weekday)
986 static const char *weekday_names[] =
988 "su", "mo", "tu", "we", "th", "fr", "sa",
992 struct substring token = parse_name_token (i);
993 bool ok = match_name (ss_head (token, 2), weekday_names, weekday);
995 data_warning (i, _("Unrecognized weekday name. At least the first two "
996 "letters of an English weekday name must be "
1001 /* Date & time formats. */
1003 /* Helper function for passing to
1004 calendar_gregorian_to_offset. */
1006 calendar_error (void *i_, const char *format, ...)
1008 struct data_in *i = i_;
1011 va_start (args, format);
1012 vdata_warning (i, format, args);
1016 /* Parses WKDAY format. */
1018 parse_WKDAY (struct data_in *i)
1022 if (trim_spaces_and_check_missing (i))
1025 if (!parse_weekday (i, &weekday)
1026 || !parse_trailer (i))
1029 i->output->f = weekday;
1033 /* Parses MONTH format. */
1035 parse_MONTH (struct data_in *i)
1039 if (trim_spaces_and_check_missing (i))
1042 if (!parse_month (i, &month)
1043 || !parse_trailer (i))
1046 i->output->f = month;
1050 /* Parses DATE, ADATE, EDATE, JDATE, SDATE, QYR, MOYR, KWYR,
1051 DATETIME, TIME and DTIME formats. */
1053 parse_date (struct data_in *i)
1055 long int year = INT_MIN;
1059 double time = 0, date = 0;
1060 enum time_sign time_sign = SIGN_NO_TIME;
1062 const char *template = fmt_date_template (i->format);
1063 size_t template_width = strlen (template);
1065 if (trim_spaces_and_check_missing (i))
1068 while (*template != '\0')
1070 unsigned char ch = *template;
1074 while (template[count] == ch)
1082 ok = count < 3 ? parse_day (i, &day) : parse_yday (i, &yday);
1085 ok = parse_month (i, &month);
1090 if (!c_isalpha (*template))
1091 max_digits = SIZE_MAX;
1094 if (ss_length (i->input) >= template_width + 2)
1099 ok = parse_year (i, &year, max_digits);
1103 ok = parse_quarter (i, &month);
1106 ok = parse_week (i, &yday);
1109 ok = parse_time_units (i, 60. * 60. * 24., &time_sign, &time);
1112 ok = parse_time_units (i, 60. * 60., &time_sign, &time);
1115 ok = parse_minute_second (i, &time);
1121 ok = parse_date_delimiter (i);
1124 ok = parse_time_delimiter (i);
1129 assert (count == 1);
1130 if (!ss_match_char (&i->input, c_toupper (ch))
1131 && !ss_match_char (&i->input, c_tolower (ch)))
1133 data_warning (i, _("`%c' expected in date field."), ch);
1141 if (!parse_trailer (i))
1144 if (year != INT_MIN)
1146 double ofs = calendar_gregorian_to_offset (year, month, day,
1150 date = (yday - 1 + ofs) * 60. * 60. * 24.;
1154 i->output->f = date + (time_sign == SIGN_NEGATIVE ? -time : time);
1159 /* Utility functions. */
1161 /* Outputs FORMAT with the given ARGS as a warning for input
1164 vdata_warning (const struct data_in *i, const char *format, va_list args)
1169 ds_init_empty (&text);
1170 ds_put_char (&text, '(');
1171 if (i->first_column != 0)
1173 if (i->first_column == i->last_column)
1174 ds_put_format (&text, _("column %d"), i->first_column);
1176 ds_put_format (&text, _("columns %d-%d"),
1177 i->first_column, i->last_column);
1178 ds_put_cstr (&text, ", ");
1180 ds_put_format (&text, _("%s field) "), fmt_name (i->format));
1181 ds_put_vformat (&text, format, args);
1183 m.category = MSG_DATA;
1184 m.severity = MSG_WARNING;
1185 m.text = ds_cstr (&text);
1190 /* Outputs FORMAT with the given ARGS as a warning for input
1193 data_warning (const struct data_in *i, const char *format, ...)
1197 va_start (args, format);
1198 vdata_warning (i, format, args);
1202 /* Apply implied decimal places to output. */
1204 apply_implied_decimals (struct data_in *i)
1206 if (i->implied_decimals > 0)
1207 i->output->f /= pow (10., i->implied_decimals);
1210 /* Sets the default result for I.
1211 For a numeric format, this is the value set on SET BLANKS
1212 (typically system-missing); for a string format, it is all
1215 default_result (struct data_in *i)
1217 if (fmt_is_string (i->format))
1218 memset (i->output->s, ' ', i->width);
1220 i->output->f = get_blanks ();
1223 /* Trims leading and trailing spaces from I.
1224 If the result is empty, or a single period character, then
1225 sets the default result and returns true; otherwise, returns
1228 trim_spaces_and_check_missing (struct data_in *i)
1230 ss_trim (&i->input, ss_cstr (" "));
1231 if (ss_is_empty (i->input) || ss_equals (i->input, ss_cstr (".")))
1239 /* Returns the integer value of hex digit C. */
1243 const char s[] = "0123456789abcdef";
1244 const char *cp = strchr (s, c_tolower ((unsigned char) c));
1246 assert (cp != NULL);