320 |
break; |
break; |
321 |
|
|
322 |
case 5: |
case 5: |
323 |
case 6: |
case 6: /* ?? Used by SPSS 8.0. */ |
|
case 11: /* ?? Used by SPSS 8.0. */ |
|
324 |
skip = 1; |
skip = 1; |
325 |
break; |
break; |
326 |
|
|
327 |
|
case 11: /* Variable display parameters */ |
328 |
|
{ |
329 |
|
const int n_vars = data.count / 3 ; |
330 |
|
int i; |
331 |
|
if ( data.count % 3 ) |
332 |
|
{ |
333 |
|
msg (MW, _("%s: Invalid subrecord length. " |
334 |
|
"Record: 7; Subrecord: 11"), |
335 |
|
handle_get_filename (r->fh)); |
336 |
|
skip = 1; |
337 |
|
} |
338 |
|
|
339 |
|
for ( i = 0 ; i < n_vars ; ++i ) |
340 |
|
{ |
341 |
|
struct |
342 |
|
{ |
343 |
|
int32 measure P; |
344 |
|
int32 width P; |
345 |
|
int32 align P; |
346 |
|
} |
347 |
|
params; |
348 |
|
|
349 |
|
struct variable *v; |
350 |
|
|
351 |
|
assertive_buf_read (r, ¶ms, sizeof(params), 0); |
352 |
|
|
353 |
|
v = dict_get_var(*dict, i); |
354 |
|
|
355 |
|
v->measure = params.measure; |
356 |
|
v->display_width = params.width; |
357 |
|
v->alignment = params.align; |
358 |
|
} |
359 |
|
} |
360 |
|
break; |
361 |
|
|
362 |
|
case 13: /* SPSS 12.0 Long variable name map */ |
363 |
|
{ |
364 |
|
|
365 |
|
char *s; |
366 |
|
char *buf = xmalloc(data.size * data.count + 1); |
367 |
|
char *tbuf ; |
368 |
|
assertive_buf_read (r, buf, data.size * data.count, 0); |
369 |
|
buf[data.size * data.count]='\0'; |
370 |
|
|
371 |
|
s = strtok_r(buf, "\t", &tbuf); |
372 |
|
while ( s ) |
373 |
|
{ |
374 |
|
char *shortname, *longname; |
375 |
|
shortname = strsep(&s,"="); |
376 |
|
longname = strsep(&s,"="); |
377 |
|
|
378 |
|
dict_add_longvar_entry(*dict, shortname, longname); |
379 |
|
|
380 |
|
s = strtok_r(0,"\t", &tbuf); |
381 |
|
} |
382 |
|
|
383 |
|
free (buf); |
384 |
|
} |
385 |
|
break; |
386 |
|
|
387 |
default: |
default: |
388 |
msg (MW, _("%s: Unrecognized record type 7, subtype %d " |
msg (MW, _("%s: Unrecognized record type 7, subtype %d " |
687 |
int next_value = 0; /* Index to next `value' structure. */ |
int next_value = 0; /* Index to next `value' structure. */ |
688 |
size_t var_cap = 0; |
size_t var_cap = 0; |
689 |
|
|
690 |
|
assert(r); |
691 |
|
|
692 |
/* Allocate variables. */ |
/* Allocate variables. */ |
693 |
*var_by_idx = xmalloc (sizeof **var_by_idx * r->value_cnt); |
*var_by_idx = xmalloc (sizeof **var_by_idx * r->value_cnt); |
694 |
|
|
767 |
name[0] = toupper ((unsigned char) (sv.name[0])); |
name[0] = toupper ((unsigned char) (sv.name[0])); |
768 |
|
|
769 |
/* Copy remaining characters of variable name. */ |
/* Copy remaining characters of variable name. */ |
770 |
for (j = 1; j < 8; j++) |
for (j = 1; j < SHORT_NAME_LEN; j++) |
771 |
{ |
{ |
772 |
int c = (unsigned char) sv.name[j]; |
int c = (unsigned char) sv.name[j]; |
773 |
|
|
791 |
name[j] = 0; |
name[j] = 0; |
792 |
|
|
793 |
/* Create variable. */ |
/* Create variable. */ |
794 |
vv = (*var_by_idx)[i] = dict_create_var (dict, name, sv.type); |
vv = (*var_by_idx)[i] = dict_create_var_from_short (dict, name, sv.type); |
795 |
if (vv == NULL) |
if (vv == NULL) |
796 |
lose ((ME, _("%s: Duplicate variable name `%s' within system file."), |
lose ((ME, _("%s: Duplicate variable name `%s' within system file."), |
797 |
handle_get_filename (r->fh), name)); |
handle_get_filename (r->fh), name)); |
818 |
"length %d."), |
"length %d."), |
819 |
handle_get_filename (r->fh), vv->name, len)); |
handle_get_filename (r->fh), vv->name, len)); |
820 |
|
|
821 |
/* Read label into variable structure. */ |
if ( len != 0 ) |
822 |
vv->label = buf_read (r, NULL, ROUND_UP (len, sizeof (int32)), len + 1); |
{ |
823 |
if (vv->label == NULL) |
/* Read label into variable structure. */ |
824 |
goto error; |
vv->label = buf_read (r, NULL, ROUND_UP (len, sizeof (int32)), len + 1); |
825 |
vv->label[len] = '\0'; |
if (vv->label == NULL) |
826 |
|
goto error; |
827 |
|
vv->label[len] = '\0'; |
828 |
|
} |
829 |
} |
} |
830 |
|
|
831 |
/* Set missing values. */ |
/* Set missing values. */ |
1143 |
static void * |
static void * |
1144 |
buf_read (struct sfm_reader *r, void *buf, size_t byte_cnt, size_t min_alloc) |
buf_read (struct sfm_reader *r, void *buf, size_t byte_cnt, size_t min_alloc) |
1145 |
{ |
{ |
1146 |
if (buf == NULL) |
assert (r); |
1147 |
|
|
1148 |
|
if (buf == NULL && byte_cnt > 0 ) |
1149 |
buf = xmalloc (max (byte_cnt, min_alloc)); |
buf = xmalloc (max (byte_cnt, min_alloc)); |
1150 |
|
|
1151 |
|
if ( byte_cnt == 0 ) |
1152 |
|
return buf; |
1153 |
|
|
1154 |
|
|
1155 |
if (1 != fread (buf, byte_cnt, 1, r->file)) |
if (1 != fread (buf, byte_cnt, 1, r->file)) |
1156 |
{ |
{ |
1157 |
if (ferror (r->file)) |
if (ferror (r->file)) |