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., 59 Temple Place - Suite 330, Boston, MA
31 #include "julcal/julcal.h"
40 /*#define DEBUGGING 1 */
41 #include "debug-print.h"
44 /* Specialized error routine. */
46 static void dls_error (const struct data_in *, const char *format, ...)
47 __attribute__ ((format (printf, 2, 3)));
50 dls_error (const struct data_in *i, const char *format, ...)
54 if (i->flags & DI_IGNORE_ERROR)
60 va_start (args, format);
61 snprintf (buf, 1024, format, args);
69 ds_init (NULL, &title, 64);
70 if (!getl_reading_script)
71 ds_concat (&title, _("data-file error: "));
73 ds_printf (&title, _("(column %d"), i->f1);
75 ds_printf (&title, _("(columns %d-%d"), i->f1, i->f2);
76 ds_printf (&title, _(", field type %s) "), fmt_to_string (&i->format));
79 err_location (&e.where);
80 e.title = ds_value (&title);
89 /* Excludes leading and trailing whitespace from I by adjusting
92 trim_whitespace (struct data_in *i)
94 while (i->s < i->e && isspace (i->s[0]))
97 while (i->s < i->e && isspace (i->e[-1]))
101 /* Returns nonzero if we're not at the end of the string being
104 have_char (struct data_in *i)
109 /* Format parsers. */
111 static int parse_int (struct data_in *i, long *result);
113 /* This function is based on strtod() from the GNU C library. */
115 parse_numeric (struct data_in *i)
117 short int sign; /* +1 or -1. */
118 double num; /* The number so far. */
120 int got_dot; /* Found a decimal point. */
121 int got_digit; /* Count of digits. */
123 int decimal; /* Decimal point character. */
124 int grouping; /* Grouping character. */
126 long int exponent; /* Number's exponent. */
127 int type; /* Usually same as i->format.type. */
131 type = i->format.type;
132 if (type == FMT_DOLLAR && have_char (i) && *i->s == '$')
141 sign = *i->s == '-' ? -1 : 1;
142 if (*i->s == '-' || *i->s == '+')
148 decimal = set_decimal;
149 grouping = set_grouping;
153 decimal = set_grouping;
154 grouping = set_decimal;
162 for (; have_char (i); i->s++)
168 /* Make sure that multiplication by 10 will not overflow. */
169 if (num > DBL_MAX * 0.1)
170 /* The value of the digit doesn't matter, since we have already
171 gotten as many digits as can be represented in a `double'.
172 This doesn't necessarily mean the result will overflow.
173 The exponent may reduce it to within range.
175 We just need to record that there was another
176 digit so that we can multiply by 10 later. */
179 num = (num * 10.0) + (*i->s - '0');
181 /* Keep track of the number of digits after the decimal point.
182 If we just divided by 10 here, we would lose precision. */
186 else if (!got_dot && *i->s == decimal)
187 /* Record that we have found the decimal point. */
189 else if ((type != FMT_COMMA && type != FMT_DOT) || *i->s != grouping)
190 /* Any other character terminates the number. */
205 && (tolower (*i->s) == 'e' || tolower (*i->s) == 'd'
206 || (type == FMT_E && (*i->s == '+' || *i->s == '-'))))
208 /* Get the exponent specified after the `e' or `E'. */
213 if (!parse_int (i, &exp))
219 exponent -= i->format.d;
221 if (type == FMT_PCT && have_char (i) && *i->s == '%')
225 dls_error (i, _("Field contents followed by garbage."));
236 /* Multiply NUM by 10 to the EXPONENT power, checking for overflow
241 if (-exponent + got_digit > -(DBL_MIN_10_EXP) + 5
242 || num < DBL_MIN * pow (10.0, (double) -exponent))
244 num *= pow (10.0, (double) exponent);
246 else if (exponent > 0)
248 if (num > DBL_MAX * pow (10.0, (double) -exponent))
250 num *= pow (10.0, (double) exponent);
253 i->v->f = sign * num;
257 /* Return an overflow error. */
258 dls_error (i, _("Overflow in floating-point constant."));
263 /* Return an underflow error. */
264 dls_error (i, _("Underflow in floating-point constant."));
269 /* There was no number. */
270 dls_error (i, _("Field does not form a valid floating-point constant."));
275 /* Returns the integer value of hex digit C. */
279 const char s[] = "0123456789abcdef";
280 const char *cp = strchr (s, tolower ((unsigned char) c));
287 parse_N (struct data_in *i)
289 const unsigned char *cp;
292 for (cp = i->s; cp < i->e; cp++)
296 dls_error (i, _("All characters in field must be digits."));
300 i->v->f = i->v->f * 10.0 + *cp - '0';
304 i->v->f /= pow (10.0, i->format.d);
309 parse_PIBHEX (struct data_in *i)
312 const unsigned char *cp;
317 for (cp = i->s; cp < i->e; cp++)
321 dls_error (i, _("Unrecognized character in field."));
325 n = n * 16.0 + hexit_value (*cp);
333 parse_RBHEX (struct data_in *i)
335 /* Validate input. */
337 if ((i->e - i->s) % 2)
339 dls_error (i, _("Field must have even length."));
344 const unsigned char *cp;
346 for (cp = i->s; cp < i->e; cp++)
349 dls_error (i, _("Field must contain only hex digits."));
359 unsigned char c[sizeof (double)];
365 memset (u.c, 0, sizeof u.c);
366 for (j = 0; j < min ((i->e - i->s) / 2, sizeof u.d); j++)
367 u.c[j] = 16 * hexit_value (i->s[j * 2]) + hexit_value (i->s[j * 2 + 1]);
376 parse_Z (struct data_in *i)
380 /* Warn user that we suck. */
386 msg (MW, _("Quality of zoned decimal (Z) input format code is "
387 "suspect. Check your results three times, report bugs "
393 /* Validate input. */
398 dls_error (i, _("Zoned decimal field contains fewer than 2 "
403 /* Copy sign into buf[0]. */
404 if ((i->e[-1] & 0xc0) != 0xc0)
406 dls_error (i, _("Bad sign byte in zoned decimal number."));
409 buf[0] = (i->e[-1] ^ (i->e[-1] >> 1)) & 0x10 ? '-' : '+';
411 /* Copy digits into buf[1 ... len - 1] and terminate string. */
413 const unsigned char *sp;
416 for (sp = i->s, dp = buf + 1; sp < i->e - 1; sp++, dp++)
419 else if ((*sp & 0xf0) == 0xf0 && (*sp & 0xf) < 10)
420 *dp = (*sp & 0xf) + '0';
423 dls_error (i, _("Format error in zoned decimal number."));
430 /* Parse as number. */
434 i->v->f = strtod ((char *) buf, (char **) &tail);
435 if ((unsigned char *) tail != i->e)
437 dls_error (i, _("Error in syntax of zoned decimal number."));
446 parse_IB (struct data_in *i)
453 /* We want the data to be in big-endian format. If this is a
454 little-endian machine, reverse the byte order. */
455 #ifdef WORDS_BIGENDIAN
458 memcpy (buf, i->s, i->e - i->s);
459 mm_reverse (buf, i->e - i->s);
463 /* If the value is negative, we need to logical-NOT each value
474 for (j = 0; j < i->e - i->s; j++)
475 i->v->f = i->v->f * 256.0 + (p[j] ^ xor);
478 /* If the value is negative, add 1 and set the sign, to complete a
479 two's-complement negation. */
481 i->v->f = -(i->v->f + 1.0);
484 i->v->f /= pow (10.0, i->format.d);
490 parse_PIB (struct data_in *i)
496 for (j = 0; j < i->e - i->s; j++)
497 i->v->f = i->v->f * 256.0 + i->s[j];
499 for (j = i->e - i->s - 1; j >= 0; j--)
500 i->v->f = i->v->f * 256.0 + i->s[j];
504 i->v->f /= pow (10.0, i->format.d);
510 parse_P (struct data_in *i)
512 const unsigned char *cp;
515 for (cp = i->s; cp < i->e - 1; cp++)
517 i->v->f = i->v->f * 10 + (*cp >> 4);
518 i->v->f = i->v->f * 10 + (*cp & 15);
520 i->v->f = i->v->f * 10 + (*cp >> 4);
521 if ((*cp ^ (*cp >> 1)) & 0x10)
525 i->v->f /= pow (10.0, i->format.d);
531 parse_PK (struct data_in *i)
533 const unsigned char *cp;
536 for (cp = i->s; cp < i->e; cp++)
538 i->v->f = i->v->f * 10 + (*cp >> 4);
539 i->v->f = i->v->f * 10 + (*cp & 15);
543 i->v->f /= pow (10.0, i->format.d);
549 parse_RB (struct data_in *i)
554 unsigned char c[sizeof (double)];
558 memset (u.c, 0, sizeof u.c);
559 memcpy (u.c, i->s, min ((int) sizeof (u.c), i->e - i->s));
566 parse_A (struct data_in *i)
568 ptrdiff_t len = i->e - i->s;
570 if (len >= i->format.w)
571 memcpy (i->v->s, i->s, i->format.w);
574 memcpy (i->v->s, i->s, len);
575 memset (i->v->s + len, ' ', i->format.w - len);
582 parse_AHEX (struct data_in *i)
584 /* Validate input. */
586 if ((i->e - i->s) % 2)
588 dls_error (i, _("Field must have even length."));
593 const unsigned char *cp;
595 for (cp = i->s; cp < i->e; cp++)
598 dls_error (i, _("Field must contain only hex digits."));
607 for (j = 0; j < min (i->e - i->s, i->format.w); j += 2)
608 i->v->s[j / 2] = hexit_value (i->s[j]) * 16 + hexit_value (i->s[j + 1]);
609 memset (i->v->s + (i->e - i->s) / 2, ' ', (i->format.w - (i->e - i->s)) / 2);
615 /* Date & time format components. */
617 /* Advances *CP past any whitespace characters. */
619 skip_whitespace (struct data_in *i)
621 while (isspace ((unsigned char) *i->s))
626 parse_leader (struct data_in *i)
633 force_have_char (struct data_in *i)
638 dls_error (i, _("Unexpected end of field."));
643 parse_int (struct data_in *i, long *result)
647 if (!force_have_char (i))
655 else if (*i->s == '-')
662 if (!isdigit (*i->s))
664 dls_error (i, _("Digit expected in field."));
671 *result = *result * 10 + *i->s++ - '0';
672 if (!have_char (i) || !isdigit (*i->s))
682 parse_day (struct data_in *i, long *day)
684 if (!parse_int (i, day))
686 if (*day >= 1 && *day <= 31)
689 dls_error (i, _("Day (%ld) must be between 1 and 31."), *day);
694 parse_day_count (struct data_in *i, long *day_count)
696 return parse_int (i, day_count);
700 parse_date_delimiter (struct data_in *i)
705 && (*i->s == '-' || *i->s == '/' || isspace (*i->s)
706 || *i->s == '.' || *i->s == ','))
714 dls_error (i, _("Delimiter expected between fields in date."));
718 /* Formats NUMBER as Roman numerals in ROMAN, or as Arabic numerals if
719 the Roman expansion would be too long. */
721 to_roman (int number, char roman[32])
723 int save_number = number;
727 int value; /* Value corresponding to this digit. */
728 char name; /* Digit name. */
731 static const struct roman_digit roman_tab[7] =
746 assert (32 >= INT_DIGITS + 1);
756 for (i = 0; i < 7; i++)
758 int digit = roman_tab[i].value;
759 while (number >= digit)
764 *cp++ = roman_tab[i].name;
767 for (j = i + 1; j < 7; j++)
769 if (i == 4 && j == 5) /* VX is not a shortened form of V. */
772 digit = roman_tab[i].value - roman_tab[j].value;
773 while (number >= digit)
778 *cp++ = roman_tab[j].name;
779 *cp++ = roman_tab[i].name;
787 sprintf (roman, "%d", save_number);
790 /* Returns true if C is a (lowercase) roman numeral. */
791 #define CHAR_IS_ROMAN(C) \
792 ((C) == 'x' || (C) == 'v' || (C) == 'i')
794 /* Returns the value of a single (lowercase) roman numeral. */
795 #define ROMAN_VALUE(C) \
796 ((C) == 'x' ? 10 : ((C) == 'v' ? 5 : 1))
799 parse_month (struct data_in *i, long *month)
801 if (!force_have_char (i))
806 if (!parse_int (i, month))
808 if (*month >= 1 && *month <= 12)
811 dls_error (i, _("Month (%ld) must be between 1 and 12."), *month);
815 if (CHAR_IS_ROMAN (tolower (*i->s)))
817 int last = ROMAN_VALUE (tolower (*i->s));
825 if (!have_char || !CHAR_IS_ROMAN (tolower (*i->s)))
832 value = ROMAN_VALUE (tolower (*i->s));
835 else if (value > last)
837 *month += value - last;
847 if (*month < 1 || *month > 12)
851 to_roman (*month, buf);
852 dls_error (i, _("Month (%s) must be between I and XII."), buf);
860 static const char *months[12] =
862 "january", "february", "march", "april", "may", "june",
863 "july", "august", "september", "october", "november", "december",
872 have_char (i) && isalpha (*i->s) && mp < &month_buf[31];
874 *mp++ = tolower (*i->s);
877 if (have_char (i) && isalpha (*i->s))
879 dls_error (i, _("Month name (%s...) is too long."), month_buf);
883 for (j = 0; j < 12; j++)
884 if (lex_id_match (months[j], month_buf))
890 dls_error (i, _("Bad month name (%s)."), month_buf);
896 parse_year (struct data_in *i, long *year)
898 if (!parse_int (i, year))
901 if (*year >= 0 && *year <= 199)
903 if (*year >= 1582 || *year <= 19999)
906 dls_error (i, _("Year (%ld) must be between 1582 and 19999."), *year);
911 parse_trailer (struct data_in *i)
917 dls_error (i, _("Trailing garbage \"%s\" following date."), i->s);
922 parse_julian (struct data_in *i, long *julian)
924 if (!parse_int (i, julian))
928 int day = *julian % 1000;
930 if (day < 1 || day > 366)
932 dls_error (i, _("Julian day (%d) must be between 1 and 366."), day);
938 int year = *julian / 1000;
940 if (year >= 0 && year <= 199)
942 else if (year < 1582 || year > 19999)
944 dls_error (i, _("Year (%d) must be between 1582 and 19999."), year);
953 parse_quarter (struct data_in *i, long *quarter)
955 if (!parse_int (i, quarter))
957 if (*quarter >= 1 && *quarter <= 4)
960 dls_error (i, _("Quarter (%ld) must be between 1 and 4."), *quarter);
965 parse_q_delimiter (struct data_in *i)
968 if (!have_char (i) || tolower (*i->s) != 'q')
970 dls_error (i, _("`Q' expected between quarter and year."));
979 parse_week (struct data_in *i, long *week)
981 if (!parse_int (i, week))
983 if (*week >= 1 && *week <= 53)
986 dls_error (i, _("Week (%ld) must be between 1 and 53."), *week);
991 parse_wk_delimiter (struct data_in *i)
995 || tolower (i->s[0]) != 'w' || tolower (i->s[1]) != 'k')
997 dls_error (i, _("`WK' expected between week and year."));
1001 skip_whitespace (i);
1006 parse_time_delimiter (struct data_in *i)
1010 while (have_char (i)
1011 && (*i->s == ':' || *i->s == '.' || isspace (*i->s)))
1020 dls_error (i, _("Delimiter expected between fields in time."));
1025 parse_hour (struct data_in *i, long *hour)
1027 if (!parse_int (i, hour))
1032 dls_error (i, _("Hour (%ld) must be positive."), *hour);
1037 parse_minute (struct data_in *i, long *minute)
1039 if (!parse_int (i, minute))
1041 if (*minute >= 0 && *minute <= 59)
1044 dls_error (i, _("Minute (%ld) must be between 0 and 59."), *minute);
1049 parse_opt_second (struct data_in *i, double *second)
1056 while (have_char (i)
1057 && (*i->s == ':' || *i->s == '.' || isspace (*i->s)))
1063 if (!delim || !isdigit (*i->s))
1070 while (have_char (i) && isdigit (*i->s))
1072 if (have_char (i) && *i->s == '.')
1074 while (have_char (i) && isdigit (*i->s))
1078 *second = strtod (buf, NULL);
1084 parse_hour24 (struct data_in *i, long *hour24)
1086 if (!parse_int (i, hour24))
1088 if (*hour24 >= 0 && *hour24 <= 23)
1091 dls_error (i, _("Hour (%ld) must be between 0 and 23."), *hour24);
1097 parse_weekday (struct data_in *i, int *weekday)
1100 #define TUPLE(A,B) \
1103 if (i->s + 1 >= i->e)
1105 dls_error (i, _("Day of the week expected in date value."));
1109 switch (TUPLE (tolower (i->s[0]), tolower (i->s[1])))
1111 case TUPLE ('s', 'u'):
1115 case TUPLE ('m', 'o'):
1119 case TUPLE ('t', 'u'):
1123 case TUPLE ('w', 'e'):
1127 case TUPLE ('t', 'h'):
1131 case TUPLE ('f', 'r'):
1135 case TUPLE ('s', 'a'):
1140 dls_error (i, _("Day of the week expected in date value."));
1144 while (have_char (i) && isalpha (*i->s))
1153 parse_spaces (struct data_in *i)
1155 skip_whitespace (i);
1160 parse_sign (struct data_in *i, int *sign)
1162 if (!force_have_char (i))
1184 /* Date & time formats. */
1187 valid_date (struct data_in *i)
1189 if (i->v->f == SYSMIS)
1191 dls_error (i, _("Date is not in valid range between "
1192 "15 Oct 1582 and 31 Dec 19999."));
1200 parse_DATE (struct data_in *i)
1202 long day, month, year;
1204 if (!parse_leader (i)
1205 || !parse_day (i, &day)
1206 || !parse_date_delimiter (i)
1207 || !parse_month (i, &month)
1208 || !parse_date_delimiter (i)
1209 || !parse_year (i, &year)
1210 || !parse_trailer (i))
1213 i->v->f = calendar_to_julian (year, month, day);
1214 if (!valid_date (i))
1216 i->v->f *= 60. * 60. * 24.;
1222 parse_ADATE (struct data_in *i)
1224 long month, day, year;
1226 if (!parse_leader (i)
1227 || !parse_month (i, &month)
1228 || !parse_date_delimiter (i)
1229 || !parse_day (i, &day)
1230 || !parse_date_delimiter (i)
1231 || !parse_year (i, &year)
1232 || !parse_trailer (i))
1235 i->v->f = calendar_to_julian (year, month, day);
1236 if (!valid_date (i))
1238 i->v->f *= 60. * 60. * 24.;
1244 parse_EDATE (struct data_in *i)
1246 long month, day, year;
1248 if (!parse_leader (i)
1249 || !parse_day (i, &day)
1250 || !parse_date_delimiter (i)
1251 || !parse_month (i, &month)
1252 || !parse_date_delimiter (i)
1253 || !parse_year (i, &year)
1254 || !parse_trailer (i))
1257 i->v->f = calendar_to_julian (year, month, day);
1258 if (!valid_date (i))
1260 i->v->f *= 60. * 60. * 24.;
1266 parse_SDATE (struct data_in *i)
1268 long month, day, year;
1270 if (!parse_leader (i)
1271 || !parse_year (i, &year)
1272 || !parse_date_delimiter (i)
1273 || !parse_month (i, &month)
1274 || !parse_date_delimiter (i)
1275 || !parse_day (i, &day)
1276 || !parse_trailer (i))
1279 i->v->f = calendar_to_julian (year, month, day);
1280 if (!valid_date (i))
1282 i->v->f *= 60. * 60. * 24.;
1288 parse_JDATE (struct data_in *i)
1292 if (!parse_leader (i)
1293 || !parse_julian (i, &julian)
1294 || !parse_trailer (i))
1297 if (julian / 1000 == 1582)
1298 i->v->f = calendar_to_julian (1583, 1, 1) - 365;
1300 i->v->f = calendar_to_julian (julian / 1000, 1, 1);
1304 i->v->f = (i->v->f + julian % 1000 - 1) * 60. * 60. * 24.;
1309 return valid_date (i);
1313 parse_QYR (struct data_in *i)
1317 if (!parse_leader (i)
1318 || !parse_quarter (i, &quarter)
1319 || !parse_q_delimiter (i)
1320 || !parse_year (i, &year)
1321 || !parse_trailer (i))
1324 i->v->f = calendar_to_julian (year, (quarter - 1) * 3 + 1, 1);
1325 if (!valid_date (i))
1327 i->v->f *= 60. * 60. * 24.;
1333 parse_MOYR (struct data_in *i)
1337 if (!parse_leader (i)
1338 || !parse_month (i, &month)
1339 || !parse_date_delimiter (i)
1340 || !parse_year (i, &year)
1341 || !parse_trailer (i))
1344 i->v->f = calendar_to_julian (year, month, 1);
1345 if (!valid_date (i))
1347 i->v->f *= 60. * 60. * 24.;
1353 parse_WKYR (struct data_in *i)
1357 if (!parse_leader (i)
1358 || !parse_week (i, &week)
1359 || !parse_wk_delimiter (i)
1360 || !parse_year (i, &year)
1361 || !parse_trailer (i))
1364 i->v->f = calendar_to_julian (year, 1, 1);
1365 if (!valid_date (i))
1367 i->v->f = (i->v->f + (week - 1) * 7) * 60. * 60. * 24.;
1373 parse_TIME (struct data_in *i)
1379 if (!parse_leader (i)
1380 || !parse_sign (i, &sign)
1381 || !parse_spaces (i)
1382 || !parse_hour (i, &hour)
1383 || !parse_time_delimiter (i)
1384 || !parse_minute (i, &minute)
1385 || !parse_opt_second (i, &second))
1388 i->v->f = hour * 60. * 60. + minute * 60. + second;
1395 parse_DTIME (struct data_in *i)
1398 long day_count, hour;
1402 if (!parse_leader (i)
1403 || !parse_sign (i, &sign)
1404 || !parse_spaces (i)
1405 || !parse_day_count (i, &day_count)
1406 || !parse_time_delimiter (i)
1407 || !parse_hour (i, &hour)
1408 || !parse_time_delimiter (i)
1409 || !parse_minute (i, &minute)
1410 || !parse_opt_second (i, &second))
1413 i->v->f = (day_count * 60. * 60. * 24.
1423 parse_DATETIME (struct data_in *i)
1425 long day, month, year;
1430 if (!parse_leader (i)
1431 || !parse_day (i, &day)
1432 || !parse_date_delimiter (i)
1433 || !parse_month (i, &month)
1434 || !parse_date_delimiter (i)
1435 || !parse_year (i, &year)
1436 || !parse_time_delimiter (i)
1437 || !parse_hour24 (i, &hour24)
1438 || !parse_time_delimiter (i)
1439 || !parse_minute (i, &minute)
1440 || !parse_opt_second (i, &second))
1443 i->v->f = calendar_to_julian (year, month, day);
1444 if (!valid_date (i))
1446 i->v->f = (i->v->f * 60. * 60. * 24.
1447 + hour24 * 60. * 60.
1455 parse_WKDAY (struct data_in *i)
1459 if (!parse_leader (i)
1460 || !parse_weekday (i, &weekday)
1461 || !parse_trailer (i))
1469 parse_MONTH (struct data_in *i)
1473 if (!parse_leader (i)
1474 || !parse_month (i, &month)
1475 || !parse_trailer (i))
1482 /* Main dispatcher. */
1485 default_result (struct data_in *i)
1487 const struct fmt_desc *const fmt = &formats[i->format.type];
1489 /* Default to SYSMIS or blanks. */
1490 if (fmt->cat & FCAT_STRING)
1491 memset (i->v->s, ' ', i->format.w);
1493 i->v->f = set_blanks;
1497 data_in (struct data_in *i)
1499 const struct fmt_desc *const fmt = &formats[i->format.type];
1501 /* Check that we've got a string to work with. */
1502 if (i->e == i->s || i->format.w <= 0)
1508 i->f2 = i->f1 + (i->e - i->s) - 1;
1510 /* Make sure that the string isn't too long. */
1511 if (i->format.w > fmt->Imax_w)
1513 dls_error (i, _("Field too long (%d characters). Truncated after "
1515 i->format.w, fmt->Imax_w);
1516 i->format.w = fmt->Imax_w;
1519 if (fmt->cat & FCAT_BLANKS_SYSMIS)
1521 const unsigned char *cp;
1531 i->v->f = set_blanks;
1538 static int (*const handlers[FMT_NUMBER_OF_FORMATS])(struct data_in *) =
1540 parse_numeric, parse_N, parse_numeric, parse_numeric,
1541 parse_numeric, parse_numeric, parse_numeric,
1542 parse_Z, parse_A, parse_AHEX, parse_IB, parse_P, parse_PIB,
1543 parse_PIBHEX, parse_PK, parse_RB, parse_RBHEX,
1544 NULL, NULL, NULL, NULL, NULL,
1545 parse_DATE, parse_EDATE, parse_SDATE, parse_ADATE, parse_JDATE,
1546 parse_QYR, parse_MOYR, parse_WKYR,
1547 parse_DATETIME, parse_TIME, parse_DTIME,
1548 parse_WKDAY, parse_MONTH,
1551 int (*handler)(struct data_in *);
1554 handler = handlers[i->format.type];
1555 assert (handler != NULL);
1557 success = handler (i);
1565 /* Utility function. */
1567 /* Sets DI->{s,e} appropriately given that LINE has length LEN and the
1568 field starts at one-based column FC and ends at one-based column
1571 data_in_finite_line (struct data_in *di, const char *line, size_t len,
1574 di->s = line + ((size_t) fc <= len ? fc - 1 : len);
1575 di->e = line + ((size_t) lc <= len ? lc : len);