1426 |
if (!parse_num_or_var (&rpd->starts_end, "STARTS ending column")) |
if (!parse_num_or_var (&rpd->starts_end, "STARTS ending column")) |
1427 |
goto error; |
goto error; |
1428 |
} else { |
} else { |
1429 |
/* Otherwise, rpd->starts_end is left uninitialized. |
/* Otherwise, rpd->starts_end is uninitialized. We |
1430 |
This is okay. We will initialize it later from the |
will initialize it later from the record length |
1431 |
record length of the file. We can't do this now |
of the file. We can't do so now because the |
1432 |
because we can't be sure that the user has specified |
file handle may not be specified yet. */ |
|
the file handle yet. */ |
|
1433 |
} |
} |
1434 |
|
|
1435 |
if (rpd->starts_beg.num != 0 && rpd->starts_end.num != 0 |
if (rpd->starts_beg.num != 0 && rpd->starts_end.num != 0 |
1479 |
|
|
1480 |
if (!lex_match ('/')) |
if (!lex_match ('/')) |
1481 |
{ |
{ |
1482 |
if (!parse_num_or_var (&rpd->cont_beg, "CONTINUED beginning column")) |
if (!parse_num_or_var (&rpd->cont_beg, |
1483 |
|
"CONTINUED beginning column")) |
1484 |
goto error; |
goto error; |
1485 |
|
|
1486 |
lex_negative_to_dash (); |
lex_negative_to_dash (); |
1589 |
goto error; |
goto error; |
1590 |
} |
} |
1591 |
|
|
1592 |
/* Calculate starts_end, cont_end if necessary and possible. */ |
/* Calculate and check starts_end, cont_end if necessary. */ |
1593 |
if (fh != NULL) |
if (rpd->starts_end.num == 0 && rpd->starts_end.var == NULL) |
1594 |
{ |
{ |
1595 |
if (rpd->starts_end.num == 0 && rpd->starts_end.var == NULL) |
rpd->starts_end.num = fh != NULL ? handle_get_record_width (fh) : 80; |
1596 |
rpd->starts_end.num = handle_get_record_width (fh); |
if (rpd->starts_beg.num != 0 |
1597 |
if (rpd->cont_end.num == 0 && rpd->cont_end.var == NULL) |
&& rpd->starts_beg.num > rpd->starts_end.num) |
1598 |
rpd->cont_end.num = handle_get_record_width (fh); |
{ |
1599 |
|
msg (SE, _("STARTS beginning column (%d) exceeds " |
1600 |
|
"default STARTS ending column taken from file's " |
1601 |
|
"record width (%d)."), |
1602 |
|
rpd->starts_beg.num, rpd->starts_end.num); |
1603 |
|
goto error; |
1604 |
|
} |
1605 |
|
} |
1606 |
|
if (rpd->cont_end.num == 0 && rpd->cont_end.var == NULL) |
1607 |
|
{ |
1608 |
|
rpd->cont_end.num = fh != NULL ? handle_get_record_width (fh) : 80; |
1609 |
|
if (rpd->cont_beg.num != 0 |
1610 |
|
&& rpd->cont_beg.num > rpd->cont_end.num) |
1611 |
|
{ |
1612 |
|
msg (SE, _("CONTINUED beginning column (%d) exceeds " |
1613 |
|
"default CONTINUED ending column taken from file's " |
1614 |
|
"record width (%d)."), |
1615 |
|
rpd->cont_beg.num, rpd->cont_end.num); |
1616 |
|
goto error; |
1617 |
|
} |
1618 |
} |
} |
1619 |
|
|
1620 |
lex_match ('='); |
lex_match ('='); |
1763 |
/* Obtains the real value for rpd_num_or_var N in case C and returns |
/* Obtains the real value for rpd_num_or_var N in case C and returns |
1764 |
it. The valid range is nonnegative numbers, but numbers outside |
it. The valid range is nonnegative numbers, but numbers outside |
1765 |
this range can be returned and should be handled by the caller as |
this range can be returned and should be handled by the caller as |
1766 |
invalid. If N does not have a value, returns DEFAULT_VALUE, |
invalid. */ |
|
which must be nonzero if this is possible. */ |
|
1767 |
static int |
static int |
1768 |
realize_value (struct rpd_num_or_var *n, struct ccase *c, int default_value) |
realize_value (struct rpd_num_or_var *n, struct ccase *c) |
1769 |
{ |
{ |
1770 |
if (n->num != 0) |
if (n->var != NULL) |
|
return n->num; |
|
|
else if (n->var != NULL) |
|
1771 |
{ |
{ |
1772 |
double v = case_num (c, n->var->fv); |
double v = case_num (c, n->var->fv); |
1773 |
return v != SYSMIS && v >= INT_MIN && v <= INT_MAX ? v : -1; |
return v != SYSMIS && v >= INT_MIN && v <= INT_MAX ? v : -1; |
1774 |
} |
} |
1775 |
else |
else |
1776 |
{ |
return n->num; |
|
assert (default_value != 0); |
|
|
return default_value; |
|
|
} |
|
1777 |
} |
} |
1778 |
|
|
1779 |
/* Parameter record passed to rpd_parse_record(). */ |
/* Parameter record passed to rpd_parse_record(). */ |
1928 |
dfm_forward_record (t->reader); |
dfm_forward_record (t->reader); |
1929 |
|
|
1930 |
/* Calculate occurs, length. */ |
/* Calculate occurs, length. */ |
1931 |
occurs_left = occurs = realize_value (&t->occurs, c, 0); |
occurs_left = occurs = realize_value (&t->occurs, c); |
1932 |
if (occurs <= 0) |
if (occurs <= 0) |
1933 |
{ |
{ |
1934 |
tmsg (SE, RPD_ERR, _("Invalid value %d for OCCURS."), occurs); |
tmsg (SE, RPD_ERR, _("Invalid value %d for OCCURS."), occurs); |
1935 |
return -3; |
return -3; |
1936 |
} |
} |
1937 |
starts_beg = realize_value (&t->starts_beg, c, 0); |
starts_beg = realize_value (&t->starts_beg, c); |
1938 |
if (starts_beg <= 0) |
if (starts_beg <= 0) |
1939 |
{ |
{ |
1940 |
tmsg (SE, RPD_ERR, _("Beginning column for STARTS (%d) must be " |
tmsg (SE, RPD_ERR, _("Beginning column for STARTS (%d) must be " |
1942 |
starts_beg); |
starts_beg); |
1943 |
return -3; |
return -3; |
1944 |
} |
} |
1945 |
starts_end = realize_value (&t->starts_end, c, line.length + 1); |
starts_end = realize_value (&t->starts_end, c); |
1946 |
if (starts_end < starts_beg) |
if (starts_end < starts_beg) |
1947 |
{ |
{ |
1948 |
tmsg (SE, RPD_ERR, _("Ending column for STARTS (%d) is less than " |
tmsg (SE, RPD_ERR, _("Ending column for STARTS (%d) is less than " |
1950 |
starts_end, starts_beg); |
starts_end, starts_beg); |
1951 |
skip_first_record = 1; |
skip_first_record = 1; |
1952 |
} |
} |
1953 |
length = realize_value (&t->length, c, 0); |
length = realize_value (&t->length, c); |
1954 |
if (length < 0) |
if (length < 0) |
1955 |
{ |
{ |
1956 |
tmsg (SE, RPD_ERR, _("Invalid value %d for LENGTH."), length); |
tmsg (SE, RPD_ERR, _("Invalid value %d for LENGTH."), length); |
1957 |
length = 1; |
length = 1; |
1958 |
occurs = occurs_left = 1; |
occurs = occurs_left = 1; |
1959 |
} |
} |
1960 |
cont_beg = realize_value (&t->cont_beg, c, 0); |
cont_beg = realize_value (&t->cont_beg, c); |
1961 |
if (cont_beg < 0) |
if (cont_beg < 0) |
1962 |
{ |
{ |
1963 |
tmsg (SE, RPD_ERR, _("Beginning column for CONTINUED (%d) must be " |
tmsg (SE, RPD_ERR, _("Beginning column for CONTINUED (%d) must be " |
1965 |
cont_beg); |
cont_beg); |
1966 |
return -2; |
return -2; |
1967 |
} |
} |
1968 |
cont_end = realize_value (&t->cont_end, c, line.length + 1); |
cont_end = realize_value (&t->cont_end, c); |
1969 |
if (cont_end < cont_beg) |
if (cont_end < cont_beg) |
1970 |
{ |
{ |
1971 |
tmsg (SE, RPD_ERR, _("Ending column for CONTINUED (%d) is less than " |
tmsg (SE, RPD_ERR, _("Ending column for CONTINUED (%d) is less than " |