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;
291 for (cp = i->s; cp < i->e; cp++)
295 dls_error (i, _("All characters in field must be digits."));
299 i->v->f = i->v->f * 10.0 + *cp - '0';
303 i->v->f /= pow (10.0, i->format.d);
308 parse_PIBHEX (struct data_in *i)
311 const unsigned char *cp;
316 for (cp = i->s; cp < i->e; cp++)
320 dls_error (i, _("Unrecognized character in field."));
324 n = n * 16.0 + hexit_value (*cp);
332 parse_RBHEX (struct data_in *i)
334 /* Validate input. */
336 if ((i->e - i->s) % 2)
338 dls_error (i, _("Field must have even length."));
343 const unsigned char *cp;
345 for (cp = i->s; cp < i->e; cp++)
348 dls_error (i, _("Field must contain only hex digits."));
358 unsigned char c[sizeof (double)];
364 memset (u.c, 0, sizeof u.c);
365 for (j = 0; j < min ((i->e - i->s) / 2, sizeof u.d); j++)
366 u.c[j] = 16 * hexit_value (i->s[j * 2]) + hexit_value (i->s[j * 2 + 1]);
375 parse_Z (struct data_in *i)
379 /* Warn user that we suck. */
385 msg (MW, _("Quality of zoned decimal (Z) input format code is "
386 "suspect. Check your results three times, report bugs "
392 /* Validate input. */
397 dls_error (i, _("Zoned decimal field contains fewer than 2 "
402 /* Copy sign into buf[0]. */
403 if ((i->e[-1] & 0xc0) != 0xc0)
405 dls_error (i, _("Bad sign byte in zoned decimal number."));
408 buf[0] = (i->e[-1] ^ (i->e[-1] >> 1)) & 0x10 ? '-' : '+';
410 /* Copy digits into buf[1 ... len - 1] and terminate string. */
412 const unsigned char *sp;
415 for (sp = i->s, dp = buf + 1; sp < i->e - 1; sp++, dp++)
418 else if ((*sp & 0xf0) == 0xf0 && (*sp & 0xf) < 10)
419 *dp = (*sp & 0xf) + '0';
422 dls_error (i, _("Format error in zoned decimal number."));
429 /* Parse as number. */
433 i->v->f = strtod ((char *) buf, (char **) &tail);
434 if ((unsigned char *) tail != i->e)
436 dls_error (i, _("Error in syntax of zoned decimal number."));
445 parse_IB (struct data_in *i)
452 /* We want the data to be in big-endian format. If this is a
453 little-endian machine, reverse the byte order. */
454 #ifdef WORDS_BIGENDIAN
457 memcpy (buf, i->s, i->e - i->s);
458 mm_reverse (buf, i->e - i->s);
462 /* If the value is negative, we need to logical-NOT each value
473 for (j = 0; j < i->e - i->s; j++)
474 i->v->f = i->v->f * 256.0 + (p[j] ^ xor);
477 /* If the value is negative, add 1 and set the sign, to complete a
478 two's-complement negation. */
480 i->v->f = -(i->v->f + 1.0);
483 i->v->f /= pow (10.0, i->format.d);
489 parse_PIB (struct data_in *i)
495 for (j = 0; j < i->e - i->s; j++)
496 i->v->f = i->v->f * 256.0 + i->s[j];
498 for (j = i->e - i->s - 1; j >= 0; j--)
499 i->v->f = i->v->f * 256.0 + i->s[j];
503 i->v->f /= pow (10.0, i->format.d);
509 parse_P (struct data_in *i)
511 const unsigned char *cp;
514 for (cp = i->s; cp < i->e - 1; cp++)
516 i->v->f = i->v->f * 10 + (*cp >> 4);
517 i->v->f = i->v->f * 10 + (*cp & 15);
519 i->v->f = i->v->f * 10 + (*cp >> 4);
520 if ((*cp ^ (*cp >> 1)) & 0x10)
524 i->v->f /= pow (10.0, i->format.d);
530 parse_PK (struct data_in *i)
532 const unsigned char *cp;
535 for (cp = i->s; cp < i->e; cp++)
537 i->v->f = i->v->f * 10 + (*cp >> 4);
538 i->v->f = i->v->f * 10 + (*cp & 15);
542 i->v->f /= pow (10.0, i->format.d);
548 parse_RB (struct data_in *i)
553 unsigned char c[sizeof (double)];
557 memset (u.c, 0, sizeof u.c);
558 memcpy (u.c, i->s, min ((int) sizeof (u.c), i->e - i->s));
565 parse_A (struct data_in *i)
567 ptrdiff_t len = i->e - i->s;
569 if (len >= i->format.w)
570 memcpy (i->v->s, i->s, i->format.w);
573 memcpy (i->v->s, i->s, len);
574 memset (i->v->s + len, ' ', i->format.w - len);
581 parse_AHEX (struct data_in *i)
583 /* Validate input. */
585 if ((i->e - i->s) % 2)
587 dls_error (i, _("Field must have even length."));
592 const unsigned char *cp;
594 for (cp = i->s; cp < i->e; cp++)
597 dls_error (i, _("Field must contain only hex digits."));
606 for (j = 0; j < min (i->e - i->s, i->format.w); j += 2)
607 i->v->s[j / 2] = hexit_value (i->s[j]) * 16 + hexit_value (i->s[j + 1]);
608 memset (i->v->s + (i->e - i->s) / 2, ' ', (i->format.w - (i->e - i->s)) / 2);
614 /* Date & time format components. */
616 /* Advances *CP past any whitespace characters. */
618 skip_whitespace (struct data_in *i)
620 while (isspace ((unsigned char) *i->s))
625 parse_leader (struct data_in *i)
632 force_have_char (struct data_in *i)
637 dls_error (i, _("Unexpected end of field."));
642 parse_int (struct data_in *i, long *result)
646 if (!force_have_char (i))
654 else if (*i->s == '-')
661 if (!isdigit (*i->s))
663 dls_error (i, _("Digit expected in field."));
670 *result = *result * 10 + *i->s++ - '0';
671 if (!have_char (i) || !isdigit (*i->s))
681 parse_day (struct data_in *i, long *day)
683 if (!parse_int (i, day))
685 if (*day >= 1 && *day <= 31)
688 dls_error (i, _("Day (%ld) must be between 1 and 31."), *day);
693 parse_day_count (struct data_in *i, long *day_count)
695 return parse_int (i, day_count);
699 parse_date_delimiter (struct data_in *i)
704 && (*i->s == '-' || *i->s == '/' || isspace (*i->s)
705 || *i->s == '.' || *i->s == ','))
713 dls_error (i, _("Delimiter expected between fields in date."));
717 /* Formats NUMBER as Roman numerals in ROMAN, or as Arabic numerals if
718 the Roman expansion would be too long. */
720 to_roman (int number, char roman[32])
722 int save_number = number;
726 int value; /* Value corresponding to this digit. */
727 char name; /* Digit name. */
730 static const struct roman_digit roman_tab[7] =
745 assert (32 >= INT_DIGITS + 1);
755 for (i = 0; i < 7; i++)
757 int digit = roman_tab[i].value;
758 while (number >= digit)
763 *cp++ = roman_tab[i].name;
766 for (j = i + 1; j < 7; j++)
768 if (i == 4 && j == 5) /* VX is not a shortened form of V. */
771 digit = roman_tab[i].value - roman_tab[j].value;
772 while (number >= digit)
777 *cp++ = roman_tab[j].name;
778 *cp++ = roman_tab[i].name;
786 sprintf (roman, "%d", save_number);
789 /* Returns true if C is a (lowercase) roman numeral. */
790 #define CHAR_IS_ROMAN(C) \
791 ((C) == 'x' || (C) == 'v' || (C) == 'i')
793 /* Returns the value of a single (lowercase) roman numeral. */
794 #define ROMAN_VALUE(C) \
795 ((C) == 'x' ? 10 : ((C) == 'v' ? 5 : 1))
798 parse_month (struct data_in *i, long *month)
800 if (!force_have_char (i))
805 if (!parse_int (i, month))
807 if (*month >= 1 && *month <= 12)
810 dls_error (i, _("Month (%ld) must be between 1 and 12."), *month);
814 if (CHAR_IS_ROMAN (tolower (*i->s)))
816 int last = ROMAN_VALUE (tolower (*i->s));
824 if (!have_char || !CHAR_IS_ROMAN (tolower (*i->s)))
831 value = ROMAN_VALUE (tolower (*i->s));
834 else if (value > last)
836 *month += value - last;
846 if (*month < 1 || *month > 12)
850 to_roman (*month, buf);
851 dls_error (i, _("Month (%s) must be between I and XII."), buf);
859 static const char *months[12] =
861 "january", "february", "march", "april", "may", "june",
862 "july", "august", "september", "october", "november", "december",
871 have_char (i) && isalpha (*i->s) && mp < &month_buf[31];
873 *mp++ = tolower (*i->s);
876 if (have_char (i) && isalpha (*i->s))
878 dls_error (i, _("Month name (%s...) is too long."), month_buf);
882 for (j = 0; j < 12; j++)
883 if (lex_id_match (months[j], month_buf))
889 dls_error (i, _("Bad month name (%s)."), month_buf);
895 parse_year (struct data_in *i, long *year)
897 if (!parse_int (i, year))
900 if (*year >= 0 && *year <= 199)
902 if (*year >= 1582 || *year <= 19999)
905 dls_error (i, _("Year (%ld) must be between 1582 and 19999."), *year);
910 parse_trailer (struct data_in *i)
916 dls_error (i, _("Trailing garbage \"%s\" following date."), i->s);
921 parse_julian (struct data_in *i, long *julian)
923 if (!parse_int (i, julian))
927 int day = *julian % 1000;
929 if (day < 1 || day > 366)
931 dls_error (i, _("Julian day (%d) must be between 1 and 366."), day);
937 int year = *julian / 1000;
939 if (year >= 0 && year <= 199)
941 else if (year < 1582 || year > 19999)
943 dls_error (i, _("Year (%d) must be between 1582 and 19999."), year);
952 parse_quarter (struct data_in *i, long *quarter)
954 if (!parse_int (i, quarter))
956 if (*quarter >= 1 && *quarter <= 4)
959 dls_error (i, _("Quarter (%ld) must be between 1 and 4."), *quarter);
964 parse_q_delimiter (struct data_in *i)
967 if (!have_char (i) || tolower (*i->s) != 'q')
969 dls_error (i, _("`Q' expected between quarter and year."));
978 parse_week (struct data_in *i, long *week)
980 if (!parse_int (i, week))
982 if (*week >= 1 && *week <= 53)
985 dls_error (i, _("Week (%ld) must be between 1 and 53."), *week);
990 parse_wk_delimiter (struct data_in *i)
994 || tolower (i->s[0]) != 'w' || tolower (i->s[1]) != 'k')
996 dls_error (i, _("`WK' expected between week and year."));
1000 skip_whitespace (i);
1005 parse_time_delimiter (struct data_in *i)
1009 while (have_char (i)
1010 && (*i->s == ':' || *i->s == '.' || isspace (*i->s)))
1019 dls_error (i, _("Delimiter expected between fields in time."));
1024 parse_hour (struct data_in *i, long *hour)
1026 if (!parse_int (i, hour))
1031 dls_error (i, _("Hour (%ld) must be positive."), *hour);
1036 parse_minute (struct data_in *i, long *minute)
1038 if (!parse_int (i, minute))
1040 if (*minute >= 0 && *minute <= 59)
1043 dls_error (i, _("Minute (%ld) must be between 0 and 59."), *minute);
1048 parse_opt_second (struct data_in *i, double *second)
1055 while (have_char (i)
1056 && (*i->s == ':' || *i->s == '.' || isspace (*i->s)))
1062 if (!delim || !isdigit (*i->s))
1069 while (have_char (i) && isdigit (*i->s))
1071 if (have_char (i) && *i->s == '.')
1073 while (have_char (i) && isdigit (*i->s))
1077 *second = strtod (buf, NULL);
1083 parse_hour24 (struct data_in *i, long *hour24)
1085 if (!parse_int (i, hour24))
1087 if (*hour24 >= 0 && *hour24 <= 23)
1090 dls_error (i, _("Hour (%ld) must be between 0 and 23."), *hour24);
1096 parse_weekday (struct data_in *i, int *weekday)
1099 #define TUPLE(A,B) \
1102 if (i->s + 1 >= i->e)
1104 dls_error (i, _("Day of the week expected in date value."));
1108 switch (TUPLE (tolower (i->s[0]), tolower (i->s[1])))
1110 case TUPLE ('s', 'u'):
1114 case TUPLE ('m', 'o'):
1118 case TUPLE ('t', 'u'):
1122 case TUPLE ('w', 'e'):
1126 case TUPLE ('t', 'h'):
1130 case TUPLE ('f', 'r'):
1134 case TUPLE ('s', 'a'):
1139 dls_error (i, _("Day of the week expected in date value."));
1143 while (have_char (i) && isalpha (*i->s))
1152 parse_spaces (struct data_in *i)
1154 skip_whitespace (i);
1159 parse_sign (struct data_in *i, int *sign)
1161 if (!force_have_char (i))
1183 /* Date & time formats. */
1186 valid_date (struct data_in *i)
1188 if (i->v->f == SYSMIS)
1190 dls_error (i, _("Date is not in valid range between "
1191 "15 Oct 1582 and 31 Dec 19999."));
1199 parse_DATE (struct data_in *i)
1201 long day, month, year;
1203 if (!parse_leader (i)
1204 || !parse_day (i, &day)
1205 || !parse_date_delimiter (i)
1206 || !parse_month (i, &month)
1207 || !parse_date_delimiter (i)
1208 || !parse_year (i, &year)
1209 || !parse_trailer (i))
1212 i->v->f = calendar_to_julian (year, month, day);
1213 if (!valid_date (i))
1215 i->v->f *= 60. * 60. * 24.;
1221 parse_ADATE (struct data_in *i)
1223 long month, day, year;
1225 if (!parse_leader (i)
1226 || !parse_month (i, &month)
1227 || !parse_date_delimiter (i)
1228 || !parse_day (i, &day)
1229 || !parse_date_delimiter (i)
1230 || !parse_year (i, &year)
1231 || !parse_trailer (i))
1234 i->v->f = calendar_to_julian (year, month, day);
1235 if (!valid_date (i))
1237 i->v->f *= 60. * 60. * 24.;
1243 parse_EDATE (struct data_in *i)
1245 long month, day, year;
1247 if (!parse_leader (i)
1248 || !parse_day (i, &day)
1249 || !parse_date_delimiter (i)
1250 || !parse_month (i, &month)
1251 || !parse_date_delimiter (i)
1252 || !parse_year (i, &year)
1253 || !parse_trailer (i))
1256 i->v->f = calendar_to_julian (year, month, day);
1257 if (!valid_date (i))
1259 i->v->f *= 60. * 60. * 24.;
1265 parse_SDATE (struct data_in *i)
1267 long month, day, year;
1269 if (!parse_leader (i)
1270 || !parse_year (i, &year)
1271 || !parse_date_delimiter (i)
1272 || !parse_month (i, &month)
1273 || !parse_date_delimiter (i)
1274 || !parse_day (i, &day)
1275 || !parse_trailer (i))
1278 i->v->f = calendar_to_julian (year, month, day);
1279 if (!valid_date (i))
1281 i->v->f *= 60. * 60. * 24.;
1287 parse_JDATE (struct data_in *i)
1291 if (!parse_leader (i)
1292 || !parse_julian (i, &julian)
1293 || !parse_trailer (i))
1296 if (julian / 1000 == 1582)
1297 i->v->f = calendar_to_julian (1583, 1, 1) - 365;
1299 i->v->f = calendar_to_julian (julian / 1000, 1, 1);
1303 i->v->f = (i->v->f + julian % 1000 - 1) * 60. * 60. * 24.;
1308 return valid_date (i);
1312 parse_QYR (struct data_in *i)
1316 if (!parse_leader (i)
1317 || !parse_quarter (i, &quarter)
1318 || !parse_q_delimiter (i)
1319 || !parse_year (i, &year)
1320 || !parse_trailer (i))
1323 i->v->f = calendar_to_julian (year, (quarter - 1) * 3 + 1, 1);
1324 if (!valid_date (i))
1326 i->v->f *= 60. * 60. * 24.;
1332 parse_MOYR (struct data_in *i)
1336 if (!parse_leader (i)
1337 || !parse_month (i, &month)
1338 || !parse_date_delimiter (i)
1339 || !parse_year (i, &year)
1340 || !parse_trailer (i))
1343 i->v->f = calendar_to_julian (year, month, 1);
1344 if (!valid_date (i))
1346 i->v->f *= 60. * 60. * 24.;
1352 parse_WKYR (struct data_in *i)
1356 if (!parse_leader (i)
1357 || !parse_week (i, &week)
1358 || !parse_wk_delimiter (i)
1359 || !parse_year (i, &year)
1360 || !parse_trailer (i))
1363 i->v->f = calendar_to_julian (year, 1, 1);
1364 if (!valid_date (i))
1366 i->v->f = (i->v->f + (week - 1) * 7) * 60. * 60. * 24.;
1372 parse_TIME (struct data_in *i)
1378 if (!parse_leader (i)
1379 || !parse_sign (i, &sign)
1380 || !parse_spaces (i)
1381 || !parse_hour (i, &hour)
1382 || !parse_time_delimiter (i)
1383 || !parse_minute (i, &minute)
1384 || !parse_opt_second (i, &second))
1387 i->v->f = hour * 60. * 60. + minute * 60. + second;
1394 parse_DTIME (struct data_in *i)
1397 long day_count, hour;
1401 if (!parse_leader (i)
1402 || !parse_sign (i, &sign)
1403 || !parse_spaces (i)
1404 || !parse_day_count (i, &day_count)
1405 || !parse_time_delimiter (i)
1406 || !parse_hour (i, &hour)
1407 || !parse_time_delimiter (i)
1408 || !parse_minute (i, &minute)
1409 || !parse_opt_second (i, &second))
1412 i->v->f = (day_count * 60. * 60. * 24.
1422 parse_DATETIME (struct data_in *i)
1424 long day, month, year;
1429 if (!parse_leader (i)
1430 || !parse_day (i, &day)
1431 || !parse_date_delimiter (i)
1432 || !parse_month (i, &month)
1433 || !parse_date_delimiter (i)
1434 || !parse_year (i, &year)
1435 || !parse_time_delimiter (i)
1436 || !parse_hour24 (i, &hour24)
1437 || !parse_time_delimiter (i)
1438 || !parse_minute (i, &minute)
1439 || !parse_opt_second (i, &second))
1442 i->v->f = calendar_to_julian (year, month, day);
1443 if (!valid_date (i))
1445 i->v->f = (i->v->f * 60. * 60. * 24.
1446 + hour24 * 60. * 60.
1454 parse_WKDAY (struct data_in *i)
1458 if (!parse_leader (i)
1459 || !parse_weekday (i, &weekday)
1460 || !parse_trailer (i))
1468 parse_MONTH (struct data_in *i)
1472 if (!parse_leader (i)
1473 || !parse_month (i, &month)
1474 || !parse_trailer (i))
1481 /* Main dispatcher. */
1484 default_result (struct data_in *i)
1486 const struct fmt_desc *const fmt = &formats[i->format.type];
1488 /* Default to SYSMIS or blanks. */
1489 if (fmt->cat & FCAT_STRING)
1490 memset (i->v->s, ' ', i->format.w);
1492 i->v->f = set_blanks;
1496 data_in (struct data_in *i)
1498 const struct fmt_desc *const fmt = &formats[i->format.type];
1500 /* Check that we've got a string to work with. */
1501 if (i->e == i->s || i->format.w <= 0)
1507 i->f2 = i->f1 + (i->e - i->s) - 1;
1509 /* Make sure that the string isn't too long. */
1510 if (i->format.w > fmt->Imax_w)
1512 dls_error (i, _("Field too long (%d characters). Truncated after "
1514 i->format.w, fmt->Imax_w);
1515 i->format.w = fmt->Imax_w;
1518 if (fmt->cat & FCAT_BLANKS_SYSMIS)
1520 const unsigned char *cp;
1530 i->v->f = set_blanks;
1537 static int (*const handlers[FMT_NUMBER_OF_FORMATS])(struct data_in *) =
1539 parse_numeric, parse_N, parse_numeric, parse_numeric,
1540 parse_numeric, parse_numeric, parse_numeric,
1541 parse_Z, parse_A, parse_AHEX, parse_IB, parse_P, parse_PIB,
1542 parse_PIBHEX, parse_PK, parse_RB, parse_RBHEX,
1543 NULL, NULL, NULL, NULL, NULL,
1544 parse_DATE, parse_EDATE, parse_SDATE, parse_ADATE, parse_JDATE,
1545 parse_QYR, parse_MOYR, parse_WKYR,
1546 parse_DATETIME, parse_TIME, parse_DTIME,
1547 parse_WKDAY, parse_MONTH,
1550 int (*handler)(struct data_in *);
1553 handler = handlers[i->format.type];
1554 assert (handler != NULL);
1556 success = handler (i);
1564 /* Utility function. */
1566 /* Sets DI->{s,e} appropriately given that LINE has length LEN and the
1567 field starts at one-based column FC and ends at one-based column
1570 data_in_finite_line (struct data_in *di, const char *line, size_t len,
1573 di->s = line + ((size_t) fc <= len ? fc - 1 : len);
1574 di->e = line + ((size_t) lc <= len ? lc : len);