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/>. */
32 #include "identifier.h"
36 #include <libpspp/assertion.h>
37 #include <libpspp/compiler.h>
38 #include <libpspp/integer-format.h>
39 #include <libpspp/magic.h>
40 #include <libpspp/message.h>
41 #include <libpspp/misc.h>
42 #include <libpspp/str.h>
50 #define _(msgid) gettext (msgid)
52 /* Information about parsing one data field. */
55 struct substring input; /* Source. */
56 enum fmt_type format; /* Input format. */
57 int implied_decimals; /* Number of implied decimal places. */
59 union value *output; /* Destination. */
60 int width; /* Output width. */
62 int first_column; /* First column of field; 0 if inapplicable. */
63 int last_column; /* Last column. */
66 /* Integer format used for IB and PIB input. */
67 static enum integer_format input_integer_format = INTEGER_NATIVE;
69 /* Floating-point format used for RB and RBHEX input. */
70 static enum float_format input_float_format = FLOAT_NATIVE_DOUBLE;
72 typedef bool data_in_parser_func (struct data_in *);
73 #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) \
74 static data_in_parser_func parse_##METHOD;
77 static void vdata_warning (const struct data_in *, const char *, va_list)
79 static void data_warning (const struct data_in *, const char *, ...)
82 static void apply_implied_decimals (struct data_in *);
83 static void default_result (struct data_in *);
84 static bool trim_spaces_and_check_missing (struct data_in *);
86 static int hexit_value (int c);
88 /* Parses the characters in INPUT according to FORMAT. Stores
89 the parsed representation in OUTPUT, which has the given WIDTH
90 (0 for a numeric field, otherwise the string width).
92 If no decimal point is included in a numeric format, then
93 IMPLIED_DECIMALS decimal places are implied. Specify 0 if no
94 decimal places should be implied.
96 If FIRST_COLUMN is nonzero, then it should be the 1-based
97 column number of the first character in INPUT, used in error
100 data_in (struct substring input,
101 enum fmt_type format, int implied_decimals,
102 int first_column, union value *output, int width)
104 static data_in_parser_func *const handlers[FMT_NUMBER_OF_FORMATS] =
106 #define FMT(NAME, METHOD, IMIN, OMIN, IO, CATEGORY) parse_##METHOD,
107 #include "format.def"
113 assert ((width != 0) == fmt_is_string (format));
117 i.implied_decimals = implied_decimals;
122 i.first_column = first_column;
123 i.last_column = first_column + ss_length (input) - 1;
125 if (!ss_is_empty (i.input))
127 ok = handlers[i.format] (&i);
140 /* Returns the integer format used for IB and PIB input. */
142 data_in_get_integer_format (void)
144 return input_integer_format;
147 /* Sets the integer format used for IB and PIB input to
150 data_in_set_integer_format (enum integer_format format)
152 input_integer_format = format;
155 /* Returns the floating-point format used for RB and RBHEX
158 data_in_get_float_format (void)
160 return input_float_format;
163 /* Sets the floating-point format used for RB and RBHEX input to
166 data_in_set_float_format (enum float_format format)
168 input_float_format = format;
171 /* Format parsers. */
173 /* Parses F, COMMA, DOT, DOLLAR, PCT, and E input formats. */
175 parse_number (struct data_in *i)
177 const struct fmt_number_style *style = fmt_get_style (i->format);
181 bool explicit_decimals = false;
185 assert (fmt_get_category (i->format) != FMT_CAT_CUSTOM);
187 /* Trim spaces and check for missing value representation. */
188 if (trim_spaces_and_check_missing (i))
191 ds_init_empty (&tmp);
192 ds_extend (&tmp, 64);
194 /* Prefix character may precede sign. */
195 if (!ss_is_empty (style->prefix))
197 ss_match_char (&i->input, ss_first (style->prefix));
198 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
202 if (ss_match_char (&i->input, '-'))
204 ds_put_char (&tmp, '-');
205 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
209 ss_match_char (&i->input, '+');
210 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
213 /* Prefix character may follow sign. */
214 if (!ss_is_empty (style->prefix))
216 ss_match_char (&i->input, ss_first (style->prefix));
217 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
220 /* Digits before decimal point. */
221 while (c_isdigit (ss_first (i->input)))
223 ds_put_char (&tmp, ss_get_char (&i->input));
224 if (style->grouping != 0)
225 ss_match_char (&i->input, style->grouping);
228 /* Decimal point and following digits. */
229 if (ss_match_char (&i->input, style->decimal))
231 explicit_decimals = true;
232 ds_put_char (&tmp, '.');
233 while (c_isdigit (ss_first (i->input)))
234 ds_put_char (&tmp, ss_get_char (&i->input));
238 if (!ds_is_empty (&tmp)
239 && !ss_is_empty (i->input)
240 && strchr ("eEdD-+", ss_first (i->input)))
242 explicit_decimals = true;
243 ds_put_char (&tmp, 'e');
245 if (strchr ("eEdD", ss_first (i->input)))
247 ss_advance (&i->input, 1);
248 ss_match_char (&i->input, ' ');
251 if (ss_first (i->input) == '-' || ss_first (i->input) == '+')
253 if (ss_get_char (&i->input) == '-')
254 ds_put_char (&tmp, '-');
255 ss_match_char (&i->input, ' ');
258 while (c_isdigit (ss_first (i->input)))
259 ds_put_char (&tmp, ss_get_char (&i->input));
262 /* Suffix character. */
263 if (!ss_is_empty (style->suffix))
264 ss_match_char (&i->input, ss_first (style->suffix));
266 if (!ss_is_empty (i->input))
268 if (ds_is_empty (&tmp))
269 data_warning (i, _("Field contents are not numeric."));
271 data_warning (i, _("Number followed by garbage."));
276 /* Let strtod() do the conversion. */
279 i->output->f = strtod (ds_cstr (&tmp), &tail);
282 data_warning (i, _("Invalid numeric syntax."));
287 else if (errno == ERANGE)
289 if (fabs (i->output->f) > 1)
291 data_warning (i, _("Too-large number set to system-missing."));
292 i->output->f = SYSMIS;
296 data_warning (i, _("Too-small number set to zero."));
303 if (!explicit_decimals)
304 apply_implied_decimals (i);
311 /* Parses N format. */
313 parse_N (struct data_in *i)
318 while ((c = ss_get_char (&i->input)) != EOF)
322 data_warning (i, _("All characters in field must be digits."));
325 i->output->f = i->output->f * 10.0 + (c - '0');
328 apply_implied_decimals (i);
332 /* Parses PIBHEX format. */
334 parse_PIBHEX (struct data_in *i)
341 while ((c = ss_get_char (&i->input)) != EOF)
345 data_warning (i, _("Unrecognized character in field."));
348 n = n * 16.0 + hexit_value (c);
355 /* Parses RBHEX format. */
357 parse_RBHEX (struct data_in *i)
362 memset (&d, 0, sizeof d);
363 for (j = 0; !ss_is_empty (i->input) && j < sizeof d; j++)
365 int hi = ss_get_char (&i->input);
366 int lo = ss_get_char (&i->input);
369 data_warning (i, _("Field must have even length."));
372 else if (!c_isxdigit (hi) || !c_isxdigit (lo))
374 data_warning (i, _("Field must contain only hex digits."));
377 ((unsigned char *) &d)[j] = 16 * hexit_value (hi) + hexit_value (lo);
385 /* Digits for Z format. */
386 static const char z_digits[] = "0123456789{ABCDEFGHI}JKLMNOPQR";
388 /* Returns true if C is a Z format digit, false otherwise. */
392 return c > 0 && strchr (z_digits, c) != NULL;
395 /* Returns the (absolute value of the) value of C as a Z format
398 z_digit_value (int c)
400 assert (is_z_digit (c));
401 return (strchr (z_digits, c) - z_digits) % 10;
404 /* Returns true if Z format digit C represents a negative value,
407 is_negative_z_digit (int c)
409 assert (is_z_digit (c));
410 return (strchr (z_digits, c) - z_digits) >= 20;
413 /* Parses Z format. */
415 parse_Z (struct data_in *i)
421 bool got_dot = false;
422 bool got_final_digit = false;
424 /* Trim spaces and check for missing value representation. */
425 if (trim_spaces_and_check_missing (i))
428 ds_init_empty (&tmp);
429 ds_extend (&tmp, 64);
431 ds_put_char (&tmp, '+');
432 while (!ss_is_empty (i->input))
434 int c = ss_get_char (&i->input);
435 if (c_isdigit (c) && !got_final_digit)
436 ds_put_char (&tmp, c);
437 else if (is_z_digit (c) && !got_final_digit)
439 ds_put_char (&tmp, z_digit_value (c) + '0');
440 if (is_negative_z_digit (c))
441 ds_data (&tmp)[0] = '-';
442 got_final_digit = true;
444 else if (c == '.' && !got_dot)
446 ds_put_char (&tmp, '.');
456 if (!ss_is_empty (i->input))
458 if (ds_length (&tmp) == 1)
459 data_warning (i, _("Field contents are not numeric."));
461 data_warning (i, _("Number followed by garbage."));
466 /* Let strtod() do the conversion. */
469 i->output->f = strtod (ds_cstr (&tmp), NULL);
472 if (fabs (i->output->f) > 1)
474 data_warning (i, _("Too-large number set to system-missing."));
475 i->output->f = SYSMIS;
479 data_warning (i, _("Too-small number set to zero."));
487 apply_implied_decimals (i);
494 /* Parses IB format. */
496 parse_IB (struct data_in *i)
502 bytes = MIN (8, ss_length (i->input));
503 value = integer_get (input_integer_format, ss_data (i->input), bytes);
505 sign_bit = UINT64_C(1) << (8 * bytes - 1);
506 if (!(value & sign_bit))
507 i->output->f = value;
510 /* Sign-extend to full 64 bits. */
511 value -= sign_bit << 1;
512 i->output->f = -(double) -value;
515 apply_implied_decimals (i);
520 /* Parses PIB format. */
522 parse_PIB (struct data_in *i)
524 i->output->f = integer_get (input_integer_format, ss_data (i->input),
525 MIN (8, ss_length (i->input)));
527 apply_implied_decimals (i);
532 /* Consumes the first character of S. Stores its high 4 bits in
533 HIGH_NIBBLE and its low 4 bits in LOW_NIBBLE. */
535 get_nibbles (struct substring *s, int *high_nibble, int *low_nibble)
537 int c = ss_get_char (s);
539 *high_nibble = (c >> 4) & 15;
540 *low_nibble = c & 15;
543 /* Parses P format. */
545 parse_P (struct data_in *i)
547 int high_nibble, low_nibble;
551 while (ss_length (i->input) > 1)
553 get_nibbles (&i->input, &high_nibble, &low_nibble);
554 if (high_nibble > 9 || low_nibble > 9)
556 i->output->f = (100 * i->output->f) + (10 * high_nibble) + low_nibble;
559 get_nibbles (&i->input, &high_nibble, &low_nibble);
562 i->output->f = (10 * i->output->f) + high_nibble;
564 i->output->f = (10 * i->output->f) + low_nibble;
565 else if (low_nibble == 0xb || low_nibble == 0xd)
566 i->output->f = -i->output->f;
568 apply_implied_decimals (i);
573 /* Parses PK format. */
575 parse_PK (struct data_in *i)
578 while (!ss_is_empty (i->input))
580 int high_nibble, low_nibble;
582 get_nibbles (&i->input, &high_nibble, &low_nibble);
583 if (high_nibble > 9 || low_nibble > 9)
585 i->output->f = SYSMIS;
588 i->output->f = (100 * i->output->f) + (10 * high_nibble) + low_nibble;
591 apply_implied_decimals (i);
596 /* Parses RB format. */
598 parse_RB (struct data_in *i)
600 size_t size = float_get_size (input_float_format);
601 if (ss_length (i->input) >= size)
602 float_convert (input_float_format, ss_data (i->input),
603 FLOAT_NATIVE_DOUBLE, &i->output->f);
605 i->output->f = SYSMIS;
610 /* Parses A format. */
612 parse_A (struct data_in *i)
614 buf_copy_rpad (i->output->s, i->width,
615 ss_data (i->input), ss_length (i->input));
619 /* Parses AHEX format. */
621 parse_AHEX (struct data_in *i)
627 int hi = ss_get_char (&i->input);
628 int lo = ss_get_char (&i->input);
633 data_warning (i, _("Field must have even length."));
637 if (!c_isxdigit (hi) || !c_isxdigit (lo))
639 data_warning (i, _("Field must contain only hex digits."));
644 i->output->s[j] = hexit_value (hi) * 16 + hexit_value (lo);
647 memset (i->output->s + j, ' ', i->width - j);
652 /* Date & time format components. */
654 /* Sign of a time value. */
657 SIGN_NO_TIME, /* No time yet encountered. */
658 SIGN_POSITIVE, /* Positive time. */
659 SIGN_NEGATIVE /* Negative time. */
662 /* Parses a signed decimal integer from at most the first
663 MAX_DIGITS characters in I, storing the result into *RESULT.
664 Returns true if successful, false if no integer was
667 parse_int (struct data_in *i, long *result, size_t max_digits)
669 struct substring head = ss_head (i->input, max_digits);
670 size_t n = ss_get_long (&head, result);
673 ss_advance (&i->input, n);
678 data_warning (i, _("Syntax error in date field."));
683 /* Parses a date integer between 1 and 31 from I, storing it into
685 Returns true if successful, false if no date was present. */
687 parse_day (struct data_in *i, long *day)
689 if (!parse_int (i, day, SIZE_MAX))
691 if (*day >= 1 && *day <= 31)
694 data_warning (i, _("Day (%ld) must be between 1 and 31."), *day);
698 /* Parses an integer from the beginning of I.
699 Adds SECONDS_PER_UNIT times the absolute value of the integer
701 If *TIME_SIGN is SIGN_NO_TIME, allows a sign to precede the
702 time and sets *TIME_SIGN. Otherwise, does not allow a sign.
703 Returns true if successful, false if no integer was present. */
705 parse_time_units (struct data_in *i, double seconds_per_unit,
706 enum time_sign *time_sign, double *time)
711 if (*time_sign == SIGN_NO_TIME)
713 if (ss_match_char (&i->input, '-'))
714 *time_sign = SIGN_NEGATIVE;
717 ss_match_char (&i->input, '+');
718 *time_sign = SIGN_POSITIVE;
721 if (!parse_int (i, &units, SIZE_MAX))
725 data_warning (i, _("Syntax error in date field."));
728 *time += units * seconds_per_unit;
732 /* Parses a data delimiter from the beginning of I.
733 Returns true if successful, false if no delimiter was
736 parse_date_delimiter (struct data_in *i)
738 if (ss_ltrim (&i->input, ss_cstr ("-/.," CC_SPACES)))
741 data_warning (i, _("Delimiter expected between fields in date."));
745 /* Parses spaces at the beginning of I. */
747 parse_spaces (struct data_in *i)
749 ss_ltrim (&i->input, ss_cstr (CC_SPACES));
752 static struct substring
753 parse_name_token (struct data_in *i)
755 struct substring token;
756 ss_get_chars (&i->input, ss_span (i->input, ss_cstr (CC_LETTERS)), &token);
760 /* Reads a name from I and sets *OUTPUT to the value associated
761 with that name. If ALLOW_SUFFIXES is true, then names that
762 begin with one of the names are accepted; otherwise, only
763 exact matches (except for case) are allowed.
764 Returns true if successful, false otherwise. */
766 match_name (struct substring token, const char **names, long *output)
770 for (i = 1; *names != NULL; i++)
771 if (ss_equals_case (ss_cstr (*names++), token))
780 /* Parses a month name or number from the beginning of I,
781 storing the month (in range 1...12) into *MONTH.
782 Returns true if successful, false if no month was present. */
784 parse_month (struct data_in *i, long *month)
786 if (c_isdigit (ss_first (i->input)))
788 if (!parse_int (i, month, SIZE_MAX))
790 if (*month >= 1 && *month <= 12)
795 static const char *english_names[] =
797 "jan", "feb", "mar", "apr", "may", "jun",
798 "jul", "aug", "sep", "oct", "nov", "dec",
802 static const char *roman_names[] =
804 "i", "ii", "iii", "iv", "v", "vi",
805 "vii", "viii", "ix", "x", "xi", "xii",
809 struct substring token = parse_name_token (i);
810 if (match_name (ss_head (token, 3), english_names, month)
811 || match_name (ss_head (token, 4), roman_names, month))
815 data_warning (i, _("Unrecognized month format. Months may be specified "
816 "as Arabic or Roman numerals or as at least 3 letters "
817 "of their English names."));
821 /* Parses a year of at most MAX_DIGITS from the beginning of I,
822 storing a "4-digit" year into *YEAR. */
824 parse_year (struct data_in *i, long *year, size_t max_digits)
826 if (!parse_int (i, year, max_digits))
829 if (*year >= 0 && *year <= 99)
831 int epoch = get_epoch ();
832 int epoch_century = ROUND_DOWN (epoch, 100);
833 int epoch_offset = epoch - epoch_century;
834 if (*year >= epoch_offset)
835 *year += epoch_century;
837 *year += epoch_century + 100;
839 if (*year >= 1582 || *year <= 19999)
842 data_warning (i, _("Year (%ld) must be between 1582 and 19999."), *year);
846 /* Returns true if input in I has been exhausted,
849 parse_trailer (struct data_in *i)
851 if (ss_is_empty (i->input))
854 data_warning (i, _("Trailing garbage \"%.*s\" following date."),
855 (int) ss_length (i->input), ss_data (i->input));
859 /* Parses a 3-digit Julian day-of-year value from I into *YDAY.
860 Returns true if successful, false on failure. */
862 parse_yday (struct data_in *i, long *yday)
864 struct substring num_s;
867 ss_get_chars (&i->input, 3, &num_s);
868 if (ss_span (num_s, ss_cstr (CC_DIGITS)) != 3)
870 data_warning (i, _("Julian day must have exactly three digits."));
873 else if (!ss_get_long (&num_s, &num) || num < 1 || num > 366)
875 data_warning (i, _("Julian day (%ld) must be between 1 and 366."), num);
883 /* Parses a quarter-of-year integer between 1 and 4 from I.
884 Stores the corresponding month into *MONTH.
885 Returns true if successful, false if no quarter was present. */
887 parse_quarter (struct data_in *i, long int *month)
891 if (!parse_int (i, &quarter, SIZE_MAX))
893 if (quarter >= 1 && quarter <= 4)
895 *month = (quarter - 1) * 3 + 1;
899 data_warning (i, _("Quarter (%ld) must be between 1 and 4."), quarter);
903 /* Parses a week-of-year integer between 1 and 53 from I,
904 Stores the corresponding year-of-day into *YDAY.
905 Returns true if successful, false if no week was present. */
907 parse_week (struct data_in *i, long int *yday)
911 if (!parse_int (i, &week, SIZE_MAX))
913 if (week >= 1 && week <= 53)
915 *yday = (week - 1) * 7 + 1;
919 data_warning (i, _("Week (%ld) must be between 1 and 53."), week);
923 /* Parses a time delimiter from the beginning of I.
924 Returns true if successful, false if no delimiter was
927 parse_time_delimiter (struct data_in *i)
929 if (ss_ltrim (&i->input, ss_cstr (":" CC_SPACES)) > 0)
932 data_warning (i, _("Delimiter expected between fields in time."));
936 /* Parses minutes and optional seconds from the beginning of I.
937 The time is converted into seconds, which are added to
939 Returns true if successful, false if an error was found. */
941 parse_minute_second (struct data_in *i, double *time)
948 if (!parse_int (i, &minute, SIZE_MAX))
950 if (minute < 0 || minute > 59)
952 data_warning (i, _("Minute (%ld) must be between 0 and 59."), minute);
955 *time += 60. * minute;
957 /* Check for seconds. */
958 if (ss_ltrim (&i->input, ss_cstr (":" CC_SPACES)) == 0
959 || !c_isdigit (ss_first (i->input)))
964 while (c_isdigit (ss_first (i->input)))
965 *cp++ = ss_get_char (&i->input);
966 if (ss_match_char (&i->input, fmt_decimal_char (FMT_F)))
968 while (c_isdigit (ss_first (i->input)))
969 *cp++ = ss_get_char (&i->input);
972 *time += strtod (buf, NULL);
977 /* Parses a weekday name from the beginning of I,
978 storing a value of 1=Sunday...7=Saturday into *WEEKDAY.
979 Returns true if successful, false if an error was found. */
981 parse_weekday (struct data_in *i, long *weekday)
983 static const char *weekday_names[] =
985 "su", "mo", "tu", "we", "th", "fr", "sa",
989 struct substring token = parse_name_token (i);
990 bool ok = match_name (ss_head (token, 2), weekday_names, weekday);
992 data_warning (i, _("Unrecognized weekday name. At least the first two "
993 "letters of an English weekday name must be "
998 /* Date & time formats. */
1000 /* Helper function for passing to
1001 calendar_gregorian_to_offset. */
1003 calendar_error (void *i_, const char *format, ...)
1005 struct data_in *i = i_;
1008 va_start (args, format);
1009 vdata_warning (i, format, args);
1013 /* Parses WKDAY format. */
1015 parse_WKDAY (struct data_in *i)
1019 if (trim_spaces_and_check_missing (i))
1022 if (!parse_weekday (i, &weekday)
1023 || !parse_trailer (i))
1026 i->output->f = weekday;
1030 /* Parses MONTH format. */
1032 parse_MONTH (struct data_in *i)
1036 if (trim_spaces_and_check_missing (i))
1039 if (!parse_month (i, &month)
1040 || !parse_trailer (i))
1043 i->output->f = month;
1047 /* Parses DATE, ADATE, EDATE, JDATE, SDATE, QYR, MOYR, KWYR,
1048 DATETIME, TIME and DTIME formats. */
1050 parse_date (struct data_in *i)
1052 long int year = INT_MIN;
1056 double time = 0, date = 0;
1057 enum time_sign time_sign = SIGN_NO_TIME;
1059 const char *template = fmt_date_template (i->format);
1060 size_t template_width = strlen (template);
1062 if (trim_spaces_and_check_missing (i))
1065 while (*template != '\0')
1067 unsigned char ch = *template;
1071 while (template[count] == ch)
1079 ok = count < 3 ? parse_day (i, &day) : parse_yday (i, &yday);
1082 ok = parse_month (i, &month);
1087 if (!c_isalpha (*template))
1088 max_digits = SIZE_MAX;
1091 if (ss_length (i->input) >= template_width + 2)
1096 ok = parse_year (i, &year, max_digits);
1100 ok = parse_quarter (i, &month);
1103 ok = parse_week (i, &yday);
1106 ok = parse_time_units (i, 60. * 60. * 24., &time_sign, &time);
1109 ok = parse_time_units (i, 60. * 60., &time_sign, &time);
1112 ok = parse_minute_second (i, &time);
1118 ok = parse_date_delimiter (i);
1121 ok = parse_time_delimiter (i);
1126 assert (count == 1);
1127 if (!ss_match_char (&i->input, c_toupper (ch))
1128 && !ss_match_char (&i->input, c_tolower (ch)))
1130 data_warning (i, _("`%c' expected in date field."), ch);
1138 if (!parse_trailer (i))
1141 if (year != INT_MIN)
1143 double ofs = calendar_gregorian_to_offset (year, month, day,
1147 date = (yday - 1 + ofs) * 60. * 60. * 24.;
1151 i->output->f = date + (time_sign == SIGN_NEGATIVE ? -time : time);
1156 /* Utility functions. */
1158 /* Outputs FORMAT with the given ARGS as a warning for input
1161 vdata_warning (const struct data_in *i, const char *format, va_list args)
1166 ds_init_empty (&text);
1167 ds_put_char (&text, '(');
1168 if (i->first_column != 0)
1170 if (i->first_column == i->last_column)
1171 ds_put_format (&text, _("column %d"), i->first_column);
1173 ds_put_format (&text, _("columns %d-%d"),
1174 i->first_column, i->last_column);
1175 ds_put_cstr (&text, ", ");
1177 ds_put_format (&text, _("%s field) "), fmt_name (i->format));
1178 ds_put_vformat (&text, format, args);
1180 m.category = MSG_DATA;
1181 m.severity = MSG_WARNING;
1182 m.text = ds_cstr (&text);
1187 /* Outputs FORMAT with the given ARGS as a warning for input
1190 data_warning (const struct data_in *i, const char *format, ...)
1194 va_start (args, format);
1195 vdata_warning (i, format, args);
1199 /* Apply implied decimal places to output. */
1201 apply_implied_decimals (struct data_in *i)
1203 if (i->implied_decimals > 0)
1204 i->output->f /= pow (10., i->implied_decimals);
1207 /* Sets the default result for I.
1208 For a numeric format, this is the value set on SET BLANKS
1209 (typically system-missing); for a string format, it is all
1212 default_result (struct data_in *i)
1214 if (fmt_is_string (i->format))
1215 memset (i->output->s, ' ', i->width);
1217 i->output->f = get_blanks ();
1220 /* Trims leading and trailing spaces from I.
1221 If the result is empty, or a single period character, then
1222 sets the default result and returns true; otherwise, returns
1225 trim_spaces_and_check_missing (struct data_in *i)
1227 ss_trim (&i->input, ss_cstr (" "));
1228 if (ss_is_empty (i->input) || ss_equals (i->input, ss_cstr (".")))
1236 /* Returns the integer value of hex digit C. */
1240 const char s[] = "0123456789abcdef";
1241 const char *cp = strchr (s, c_tolower ((unsigned char) c));
1243 assert (cp != NULL);