@@ -169,15 +169,15 @@ static readstat_error_t sav_skip_variable_record(sav_ctx_t *ctx) {
169
169
retval = READSTAT_ERROR_READ ;
170
170
goto cleanup ;
171
171
}
172
- label_len = ctx -> machine_needs_byte_swap ? byteswap4 (label_len ) : label_len ;
172
+ label_len = ctx -> bswap ? byteswap4 (label_len ) : label_len ;
173
173
int32_t label_capacity = (label_len + 3 ) / 4 * 4 ;
174
174
if (io -> seek (label_capacity , READSTAT_SEEK_CUR , io -> io_ctx ) == -1 ) {
175
175
retval = READSTAT_ERROR_SEEK ;
176
176
goto cleanup ;
177
177
}
178
178
}
179
179
if (variable .n_missing_values ) {
180
- int n_missing_values = ctx -> machine_needs_byte_swap ? byteswap4 (variable .n_missing_values ) : variable .n_missing_values ;
180
+ int n_missing_values = ctx -> bswap ? byteswap4 (variable .n_missing_values ) : variable .n_missing_values ;
181
181
if (io -> seek (abs (n_missing_values ) * sizeof (double ), READSTAT_SEEK_CUR , io -> io_ctx ) == -1 ) {
182
182
retval = READSTAT_ERROR_SEEK ;
183
183
goto cleanup ;
@@ -201,11 +201,11 @@ static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
201
201
retval = READSTAT_ERROR_READ ;
202
202
goto cleanup ;
203
203
}
204
- variable .print = ctx -> machine_needs_byte_swap ? byteswap4 (variable .print ) : variable .print ;
205
- variable .write = ctx -> machine_needs_byte_swap ? byteswap4 (variable .write ) : variable .write ;
204
+ variable .print = ctx -> bswap ? byteswap4 (variable .print ) : variable .print ;
205
+ variable .write = ctx -> bswap ? byteswap4 (variable .write ) : variable .write ;
206
206
207
207
readstat_type_t dta_type = READSTAT_TYPE_DOUBLE ;
208
- int32_t type = ctx -> machine_needs_byte_swap ? byteswap4 (variable .type ) : variable .type ;
208
+ int32_t type = ctx -> bswap ? byteswap4 (variable .type ) : variable .type ;
209
209
int i ;
210
210
if (type < 0 ) {
211
211
if (ctx -> var_index == 0 ) {
@@ -252,7 +252,7 @@ static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
252
252
retval = READSTAT_ERROR_READ ;
253
253
goto cleanup ;
254
254
}
255
- label_len = ctx -> machine_needs_byte_swap ? byteswap4 (label_len ) : label_len ;
255
+ label_len = ctx -> bswap ? byteswap4 (label_len ) : label_len ;
256
256
int32_t label_capacity = (label_len + 3 ) / 4 * 4 ;
257
257
char * label_buf = malloc (label_capacity );
258
258
size_t out_label_len = label_len * 4 + 1 ;
@@ -277,7 +277,7 @@ static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
277
277
ctx -> varinfo [ctx -> var_index ].labels_index = -1 ;
278
278
279
279
if (variable .n_missing_values ) {
280
- info -> n_missing_values = ctx -> machine_needs_byte_swap ? byteswap4 (variable .n_missing_values ) : variable .n_missing_values ;
280
+ info -> n_missing_values = ctx -> bswap ? byteswap4 (variable .n_missing_values ) : variable .n_missing_values ;
281
281
if (info -> n_missing_values < 0 ) {
282
282
info -> missing_range = 1 ;
283
283
info -> n_missing_values = abs (info -> n_missing_values );
@@ -293,7 +293,7 @@ static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
293
293
goto cleanup ;
294
294
}
295
295
for (i = 0 ; i < info -> n_missing_values ; i ++ ) {
296
- if (ctx -> machine_needs_byte_swap ) {
296
+ if (ctx -> bswap ) {
297
297
info -> missing_values [i ] = byteswap_double (info -> missing_values [i ]);
298
298
}
299
299
@@ -328,7 +328,7 @@ static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) {
328
328
retval = READSTAT_ERROR_READ ;
329
329
goto cleanup ;
330
330
}
331
- if (ctx -> machine_needs_byte_swap )
331
+ if (ctx -> bswap )
332
332
label_count = byteswap4 (label_count );
333
333
int i ;
334
334
for (i = 0 ; i < label_count ; i ++ ) {
@@ -348,7 +348,7 @@ static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) {
348
348
retval = READSTAT_ERROR_READ ;
349
349
goto cleanup ;
350
350
}
351
- if (ctx -> machine_needs_byte_swap )
351
+ if (ctx -> bswap )
352
352
rec_type = byteswap4 (rec_type );
353
353
354
354
if (rec_type != 4 ) {
@@ -359,7 +359,7 @@ static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) {
359
359
retval = READSTAT_ERROR_READ ;
360
360
goto cleanup ;
361
361
}
362
- if (ctx -> machine_needs_byte_swap )
362
+ if (ctx -> bswap )
363
363
var_count = byteswap4 (var_count );
364
364
365
365
if (io -> seek (var_count * sizeof (int32_t ), READSTAT_SEEK_CUR , io -> io_ctx ) == -1 ) {
@@ -385,7 +385,7 @@ static readstat_error_t sav_submit_value_labels(value_label_t *value_labels, int
385
385
if (value_type == READSTAT_TYPE_DOUBLE ) {
386
386
double val_d = 0.0 ;
387
387
memcpy (& val_d , vlabel -> value , 8 );
388
- if (ctx -> machine_needs_byte_swap )
388
+ if (ctx -> bswap )
389
389
val_d = byteswap_double (val_d );
390
390
391
391
value .v .double_value = val_d ;
@@ -419,7 +419,7 @@ static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
419
419
retval = READSTAT_ERROR_READ ;
420
420
goto cleanup ;
421
421
}
422
- if (ctx -> machine_needs_byte_swap )
422
+ if (ctx -> bswap )
423
423
label_count = byteswap4 (label_count );
424
424
425
425
if ((value_labels = malloc (label_count * sizeof (value_label_t ))) == NULL ) {
@@ -448,7 +448,7 @@ static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
448
448
retval = READSTAT_ERROR_READ ;
449
449
goto cleanup ;
450
450
}
451
- if (ctx -> machine_needs_byte_swap )
451
+ if (ctx -> bswap )
452
452
rec_type = byteswap4 (rec_type );
453
453
454
454
if (rec_type != 4 ) {
@@ -459,7 +459,7 @@ static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
459
459
retval = READSTAT_ERROR_READ ;
460
460
goto cleanup ;
461
461
}
462
- if (ctx -> machine_needs_byte_swap )
462
+ if (ctx -> bswap )
463
463
var_count = byteswap4 (var_count );
464
464
465
465
if ((vars = malloc (var_count * sizeof (int32_t ))) == NULL ) {
@@ -472,7 +472,7 @@ static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
472
472
}
473
473
for (i = 0 ; i < var_count ; i ++ ) {
474
474
int var_offset = vars [i ];
475
- if (ctx -> machine_needs_byte_swap )
475
+ if (ctx -> bswap )
476
476
var_offset = byteswap4 (var_offset );
477
477
478
478
var_offset -- ; // Why subtract 1????
@@ -506,7 +506,7 @@ static readstat_error_t sav_skip_document_record(sav_ctx_t *ctx) {
506
506
retval = READSTAT_ERROR_READ ;
507
507
goto cleanup ;
508
508
}
509
- if (ctx -> machine_needs_byte_swap )
509
+ if (ctx -> bswap )
510
510
n_lines = byteswap4 (n_lines );
511
511
if (io -> seek (n_lines * SPSS_DOC_LINE_SIZE , READSTAT_SEEK_CUR , io -> io_ctx ) == -1 ) {
512
512
retval = READSTAT_ERROR_SEEK ;
@@ -528,7 +528,7 @@ static readstat_error_t sav_read_document_record(sav_ctx_t *ctx) {
528
528
retval = READSTAT_ERROR_READ ;
529
529
goto cleanup ;
530
530
}
531
- if (ctx -> machine_needs_byte_swap )
531
+ if (ctx -> bswap )
532
532
n_lines = byteswap4 (n_lines );
533
533
534
534
char raw_buffer [SPSS_DOC_LINE_SIZE ];
@@ -644,7 +644,7 @@ static readstat_error_t sav_process_row(unsigned char *buffer, size_t buffer_len
644
644
}
645
645
} else if (var_info -> type == READSTAT_TYPE_DOUBLE ) {
646
646
memcpy (& fp_value , & buffer [data_offset ], 8 );
647
- if (ctx -> machine_needs_byte_swap ) {
647
+ if (ctx -> bswap ) {
648
648
fp_value = byteswap_double (fp_value );
649
649
}
650
650
value .v .double_value = fp_value ;
@@ -706,8 +706,8 @@ static readstat_error_t sav_read_compressed_data(sav_ctx_t *ctx) {
706
706
off_t uncompressed_offset = 0 ;
707
707
unsigned char * uncompressed_row = malloc (uncompressed_row_len );
708
708
709
- int machine_needs_byte_swap = ctx -> machine_needs_byte_swap ;
710
- ctx -> machine_needs_byte_swap = 0 ;
709
+ int bswap = ctx -> bswap ;
710
+ ctx -> bswap = 0 ;
711
711
712
712
while (1 ) {
713
713
if (data_offset >= buffer_used ) {
@@ -772,7 +772,7 @@ static readstat_error_t sav_read_compressed_data(sav_ctx_t *ctx) {
772
772
if (uncompressed_row )
773
773
free (uncompressed_row );
774
774
775
- ctx -> machine_needs_byte_swap = machine_needs_byte_swap ;
775
+ ctx -> bswap = bswap ;
776
776
777
777
return retval ;
778
778
}
@@ -785,7 +785,7 @@ static readstat_error_t sav_parse_machine_integer_info_record(const void *data,
785
785
const char * dst_charset = ctx -> output_encoding ;
786
786
sav_machine_integer_info_record_t record ;
787
787
memcpy (& record , data , data_len );
788
- if (ctx -> machine_needs_byte_swap ) {
788
+ if (ctx -> bswap ) {
789
789
record .character_code = byteswap4 (record .character_code );
790
790
}
791
791
if (ctx -> input_encoding ) {
@@ -823,9 +823,9 @@ static readstat_error_t sav_parse_machine_floating_point_record(const void *data
823
823
sav_machine_floating_point_info_record_t fp_info ;
824
824
memcpy (& fp_info , data , sizeof (sav_machine_floating_point_info_record_t ));
825
825
826
- ctx -> missing_double = ctx -> machine_needs_byte_swap ? byteswap8 (fp_info .sysmis ) : fp_info .sysmis ;
827
- ctx -> highest_double = ctx -> machine_needs_byte_swap ? byteswap8 (fp_info .highest ) : fp_info .highest ;
828
- ctx -> lowest_double = ctx -> machine_needs_byte_swap ? byteswap8 (fp_info .lowest ) : fp_info .lowest ;
826
+ ctx -> missing_double = ctx -> bswap ? byteswap8 (fp_info .sysmis ) : fp_info .sysmis ;
827
+ ctx -> highest_double = ctx -> bswap ? byteswap8 (fp_info .highest ) : fp_info .highest ;
828
+ ctx -> lowest_double = ctx -> bswap ? byteswap8 (fp_info .lowest ) : fp_info .lowest ;
829
829
830
830
return READSTAT_OK ;
831
831
}
@@ -842,7 +842,7 @@ static readstat_error_t sav_store_variable_display_parameter_record(const void *
842
842
843
843
ctx -> variable_display_values_count = count ;
844
844
for (i = 0 ; i < count ; i ++ ) {
845
- ctx -> variable_display_values [i ] = ctx -> machine_needs_byte_swap ? byteswap4 (data_ptr [i ]) : data_ptr [i ];
845
+ ctx -> variable_display_values [i ] = ctx -> bswap ? byteswap4 (data_ptr [i ]) : data_ptr [i ];
846
846
}
847
847
return READSTAT_OK ;
848
848
}
@@ -894,7 +894,7 @@ static readstat_error_t sav_parse_long_value_labels_record(const void *data, siz
894
894
}
895
895
896
896
memcpy (& label_name_len , data_ptr , sizeof (int32_t ));
897
- if (ctx -> machine_needs_byte_swap )
897
+ if (ctx -> bswap )
898
898
label_name_len = byteswap4 (label_name_len );
899
899
900
900
data_ptr += sizeof (int32_t );
@@ -934,7 +934,7 @@ static readstat_error_t sav_parse_long_value_labels_record(const void *data, siz
934
934
}
935
935
936
936
memcpy (& label_count , data_ptr , sizeof (int32_t ));
937
- if (ctx -> machine_needs_byte_swap )
937
+ if (ctx -> bswap )
938
938
label_count = byteswap4 (label_count );
939
939
940
940
data_ptr += sizeof (int32_t );
@@ -949,7 +949,7 @@ static readstat_error_t sav_parse_long_value_labels_record(const void *data, siz
949
949
}
950
950
951
951
memcpy (& value_len , data_ptr , sizeof (int32_t ));
952
- if (ctx -> machine_needs_byte_swap )
952
+ if (ctx -> bswap )
953
953
value_len = byteswap4 (value_len );
954
954
955
955
data_ptr += sizeof (int32_t );
@@ -978,7 +978,7 @@ static readstat_error_t sav_parse_long_value_labels_record(const void *data, siz
978
978
}
979
979
980
980
memcpy (& label_len , data_ptr , sizeof (int32_t ));
981
- if (ctx -> machine_needs_byte_swap )
981
+ if (ctx -> bswap )
982
982
label_len = byteswap4 (label_len );
983
983
984
984
data_ptr += sizeof (int32_t );
@@ -1030,7 +1030,7 @@ static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) {
1030
1030
goto cleanup ;
1031
1031
}
1032
1032
1033
- if (ctx -> machine_needs_byte_swap ) {
1033
+ if (ctx -> bswap ) {
1034
1034
rec_type = byteswap4 (rec_type );
1035
1035
}
1036
1036
@@ -1058,7 +1058,7 @@ static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) {
1058
1058
retval = READSTAT_ERROR_READ ;
1059
1059
goto cleanup ;
1060
1060
}
1061
- if (ctx -> machine_needs_byte_swap ) {
1061
+ if (ctx -> bswap ) {
1062
1062
for (i = 0 ; i < 3 ; i ++ )
1063
1063
extra_info [i ] = byteswap4 (extra_info [i ]);
1064
1064
}
@@ -1119,7 +1119,7 @@ static readstat_error_t sav_parse_records_pass2(sav_ctx_t *ctx) {
1119
1119
goto cleanup ;
1120
1120
}
1121
1121
1122
- if (ctx -> machine_needs_byte_swap ) {
1122
+ if (ctx -> bswap ) {
1123
1123
rec_type = byteswap4 (rec_type );
1124
1124
}
1125
1125
@@ -1150,7 +1150,7 @@ static readstat_error_t sav_parse_records_pass2(sav_ctx_t *ctx) {
1150
1150
retval = READSTAT_ERROR_READ ;
1151
1151
goto cleanup ;
1152
1152
}
1153
- if (ctx -> machine_needs_byte_swap ) {
1153
+ if (ctx -> bswap ) {
1154
1154
for (i = 0 ; i < 3 ; i ++ )
1155
1155
extra_info [i ] = byteswap4 (extra_info [i ]);
1156
1156
}
0 commit comments