59 |
|
|
60 |
/* Variables. */ |
/* Variables. */ |
61 |
struct sfm_var *vars; /* Variables. */ |
struct sfm_var *vars; /* Variables. */ |
|
size_t var_cnt; /* Number of variables. */ |
|
62 |
|
|
63 |
/* File's special constants. */ |
/* File's special constants. */ |
64 |
flt64 sysmis; |
flt64 sysmis; |
220 |
r->weight_idx = -1; |
r->weight_idx = -1; |
221 |
|
|
222 |
r->vars = NULL; |
r->vars = NULL; |
|
r->var_cnt = 0; |
|
223 |
|
|
224 |
r->sysmis = -FLT64_MAX; |
r->sysmis = -FLT64_MAX; |
225 |
r->highest = FLT64_MAX; |
r->highest = FLT64_MAX; |
242 |
if (!read_header (r, *dict, info) || !read_variables (r, *dict, &var_by_idx)) |
if (!read_header (r, *dict, info) || !read_variables (r, *dict, &var_by_idx)) |
243 |
goto error; |
goto error; |
244 |
|
|
245 |
|
|
246 |
/* Handle weighting. */ |
/* Handle weighting. */ |
247 |
if (r->weight_idx != -1) |
if (r->weight_idx != -1) |
248 |
{ |
{ |
739 |
int long_string_count = 0; /* # of long string continuation |
int long_string_count = 0; /* # of long string continuation |
740 |
records still expected. */ |
records still expected. */ |
741 |
int next_value = 0; /* Index to next `value' structure. */ |
int next_value = 0; /* Index to next `value' structure. */ |
|
size_t var_cap = 0; |
|
742 |
|
|
743 |
assert(r); |
assert(r); |
744 |
|
|
746 |
|
|
747 |
/* Pre-allocate variables. */ |
/* Pre-allocate variables. */ |
748 |
if ( r->value_cnt != -1 ) |
if ( r->value_cnt != -1 ) |
749 |
*var_by_idx = xmalloc(r->value_cnt * sizeof (**var_by_idx)); |
{ |
750 |
|
*var_by_idx = xmalloc(r->value_cnt * sizeof (**var_by_idx)); |
751 |
|
r->vars = xmalloc( r->value_cnt * sizeof (*r->vars) ); |
752 |
|
} |
753 |
|
|
754 |
|
|
755 |
/* Read in the entry for each variable and use the info to |
/* Read in the entry for each variable and use the info to |
757 |
for (i = 0; ; ++i) |
for (i = 0; ; ++i) |
758 |
{ |
{ |
759 |
struct variable *vv; |
struct variable *vv; |
760 |
char name[9]; |
char name[SHORT_NAME_LEN + 1]; |
761 |
int nv; |
int nv; |
762 |
int j; |
int j; |
763 |
|
|
780 |
if (sv.rec_type != 2) |
if (sv.rec_type != 2) |
781 |
{ |
{ |
782 |
buf_unread(r, sizeof sv); |
buf_unread(r, sizeof sv); |
783 |
|
r->value_cnt = i; |
784 |
break; |
break; |
785 |
} |
} |
786 |
|
|
787 |
if ( -1 == r->value_cnt ) |
if ( -1 == r->value_cnt ) |
788 |
*var_by_idx = xrealloc (*var_by_idx, sizeof **var_by_idx * (i+1) ); |
{ |
789 |
|
*var_by_idx = xrealloc (*var_by_idx, sizeof **var_by_idx * (i + 1)); |
790 |
|
r->vars = xrealloc(r->vars, (i + 1) * sizeof (*r->vars) ); |
791 |
|
} |
792 |
|
|
793 |
/* If there was a long string previously, make sure that the |
/* If there was a long string previously, make sure that the |
794 |
continuations are present; otherwise make sure there aren't |
continuations are present; otherwise make sure there aren't |
800 |
"proper number of continuation records."), |
"proper number of continuation records."), |
801 |
handle_get_filename (r->fh), i)); |
handle_get_filename (r->fh), i)); |
802 |
|
|
803 |
|
|
804 |
|
r->vars[i].width = -1; |
805 |
(*var_by_idx)[i] = NULL; |
(*var_by_idx)[i] = NULL; |
806 |
long_string_count--; |
long_string_count--; |
807 |
continue; |
continue; |
969 |
|| !parse_format_spec (r, sv.write, &vv->write, vv)) |
|| !parse_format_spec (r, sv.write, &vv->write, vv)) |
970 |
goto error; |
goto error; |
971 |
|
|
972 |
/* Add variable to list. */ |
r->vars[i].width = vv->width; |
973 |
if (var_cap >= r->var_cnt) |
r->vars[i].fv = vv->fv; |
974 |
{ |
|
|
var_cap = 2 + r->var_cnt * 2; |
|
|
r->vars = xrealloc (r->vars, var_cap * sizeof *r->vars); |
|
|
} |
|
|
r->vars[r->var_cnt].width = vv->width; |
|
|
r->vars[r->var_cnt].fv = vv->fv; |
|
|
r->var_cnt++; |
|
975 |
} |
} |
976 |
|
|
977 |
/* Some consistency checks. */ |
/* Some consistency checks. */ |
985 |
"%d were read from file."), |
"%d were read from file."), |
986 |
handle_get_filename (r->fh), r->value_cnt, next_value); |
handle_get_filename (r->fh), r->value_cnt, next_value); |
987 |
|
|
988 |
|
|
989 |
return 1; |
return 1; |
990 |
|
|
991 |
error: |
error: |
1330 |
|
|
1331 |
for (;;) |
for (;;) |
1332 |
{ |
{ |
1333 |
for (; p < p_end; p++) |
for (; p < p_end; p++){ |
1334 |
switch (*p) |
switch (*p) |
1335 |
{ |
{ |
1336 |
case 0: |
case 0: |
1384 |
goto success; |
goto success; |
1385 |
break; |
break; |
1386 |
} |
} |
1387 |
|
} |
1388 |
/* We have reached the end of this instruction octet. Read |
/* We have reached the end of this instruction octet. Read |
1389 |
another. */ |
another. */ |
1390 |
if (r->ptr == NULL || r->ptr >= r->end) |
if (r->ptr == NULL || r->ptr >= r->end) |
1435 |
{ |
{ |
1436 |
int i; |
int i; |
1437 |
|
|
1438 |
for (i = 0; i < r->var_cnt; i++) |
for (i = 0; i < r->value_cnt; i++) |
1439 |
if (r->vars[i].width == 0) |
if (r->vars[i].width == 0) |
1440 |
bswap_flt64 (&case_data_rw (c, r->vars[i].fv)->f); |
bswap_flt64 (&case_data_rw (c, r->vars[i].fv)->f); |
1441 |
} |
} |
1447 |
{ |
{ |
1448 |
int i; |
int i; |
1449 |
|
|
1450 |
for (i = 0; i < r->var_cnt; i++) |
for (i = 0; i < r->value_cnt; i++) |
1451 |
if (r->vars[i].width == 0 && case_num (c, i) == r->sysmis) |
if (r->vars[i].width == 0 && case_num (c, i) == r->sysmis) |
1452 |
case_data_rw (c, r->vars[i].fv)->f = SYSMIS; |
case_data_rw (c, r->vars[i].fv)->f = SYSMIS; |
1453 |
} |
} |
1475 |
return 0; |
return 0; |
1476 |
} |
} |
1477 |
|
|
1478 |
for (i = 0; i < r->var_cnt; i++) |
for (i = 0; i < r->value_cnt; i++) |
1479 |
{ |
{ |
1480 |
struct sfm_var *v = &r->vars[i]; |
struct sfm_var *v = &r->vars[i]; |
1481 |
|
|
1484 |
flt64 f = *bounce_cur++; |
flt64 f = *bounce_cur++; |
1485 |
if (r->reverse_endian) |
if (r->reverse_endian) |
1486 |
bswap_flt64 (&f); |
bswap_flt64 (&f); |
1487 |
case_data_rw (c, i)->f = f == r->sysmis ? SYSMIS : f; |
case_data_rw (c, v->fv)->f = f == r->sysmis ? SYSMIS : f; |
1488 |
} |
} |
1489 |
else |
else if (v->width != -1) |
1490 |
{ |
{ |
1491 |
memcpy (case_data_rw (c, v->fv)->s, bounce_cur, v->width); |
memcpy (case_data_rw (c, v->fv)->s, bounce_cur, v->width); |
1492 |
bounce_cur += DIV_RND_UP (v->width, sizeof (flt64)); |
bounce_cur += DIV_RND_UP (v->width, sizeof (flt64)); |