diff --git a/configure.ac b/configure.ac index 6cc35c6..7855bd9 100644 --- a/configure.ac +++ b/configure.ac @@ -60,15 +60,7 @@ AS_CASE([$host], AC_SUBST([EXTRA_LDFLAGS]) AS_CASE([$host], - [*mingw*], - [ - #There is no real way to determine whether UCRT is used vs normal MINGW but one way is by checking a define in - #If we are in UCRT we do not want to set the spawnv define because it breaks the build - IS_UCRT=`echo '#include '| gcc -E -dM - | grep -i _UCRT | xargs` - AS_IF([test "$IS_UCRT" == ""], [ - CFLAGS="$CFLAGS -D_spawnv=spawnv" - ]) - ], + [*mingw*], [CFLAGS="$CFLAGS -D_spawnv=spawnv"], [CFLAGS="$CFLAGS"]) AC_ARG_VAR([LIB_FUZZING_ENGINE], [Location of prebuilt fuzzing engine library]) diff --git a/src/bin/read_csv/json_metadata.c b/src/bin/read_csv/json_metadata.c index 7d79049..d739e7a 100644 --- a/src/bin/read_csv/json_metadata.c +++ b/src/bin/read_csv/json_metadata.c @@ -7,11 +7,11 @@ #include "../../readstat.h" #include "../util/file_format.h" -/* Function realloc_it() is a wrapper function for standard realloc() +/* Function realloc_it() is a wrapper function for standart realloc() * with one difference - it frees old memory pointer in case of realloc * failure. Thus, DO NOT use old data pointer in anyway after call to * realloc_it(). If your code has some kind of fallback algorithm if - * memory can't be re-allocated - use standard realloc() instead. + * memory can't be re-allocated - use standart realloc() instead. */ static inline void *realloc_it(void *ptrmem, size_t size) { void *p = realloc(ptrmem, size); diff --git a/src/bin/readstat.c b/src/bin/readstat.c index e3fbbd1..aab6c9a 100644 --- a/src/bin/readstat.c +++ b/src/bin/readstat.c @@ -154,7 +154,7 @@ readstat_error_t parse_file(readstat_parser_t *parser, const char *input_filenam return error; } -static void print_version(void) { +static void print_version() { fprintf(stdout, "ReadStat version " READSTAT_VERSION "\n"); } @@ -397,6 +397,8 @@ static int convert_file(const char *input_filename, const char *catalog_filename module->finish(rs_ctx->module_ctx); } + free(rs_ctx); + if (error != READSTAT_OK) { if (file_exists) { fprintf(stderr, "Error opening %s: File exists (Use -f to overwrite)\n", output_filename); @@ -404,14 +406,9 @@ static int convert_file(const char *input_filename, const char *catalog_filename fprintf(stderr, "Error processing %s: %s\n", rs_ctx->error_filename, readstat_error_message(error)); unlink(output_filename); } - - free(rs_ctx); - return 1; } - free(rs_ctx); - return 0; } diff --git a/src/readstat.h b/src/readstat.h index faccdbe..bf2c375 100644 --- a/src/readstat.h +++ b/src/readstat.h @@ -104,22 +104,11 @@ typedef enum readstat_error_e { READSTAT_ERROR_TOO_FEW_COLUMNS, READSTAT_ERROR_TOO_MANY_COLUMNS, READSTAT_ERROR_NAME_IS_ZERO_LENGTH, - READSTAT_ERROR_BAD_TIMESTAMP_VALUE, - READSTAT_ERROR_BAD_MR_STRING + READSTAT_ERROR_BAD_TIMESTAMP_VALUE } readstat_error_t; const char *readstat_error_message(readstat_error_t error_code); -typedef struct mr_set_s { - char type; - char *name; - char *label; - int is_dichotomy; - int counted_value; - char **subvariables; - int num_subvars; -} mr_set_t; - typedef struct readstat_metadata_s { int64_t row_count; int64_t var_count; @@ -132,8 +121,6 @@ typedef struct readstat_metadata_s { const char *file_label; const char *file_encoding; unsigned int is64bit:1; - size_t multiple_response_sets_length; - mr_set_t *mr_sets; } readstat_metadata_t; /* If the row count is unknown (e.g. it's an XPORT or POR file, or an SAV @@ -151,8 +138,6 @@ readstat_endian_t readstat_get_endianness(readstat_metadata_t *metadata); const char *readstat_get_table_name(readstat_metadata_t *metadata); const char *readstat_get_file_label(readstat_metadata_t *metadata); const char *readstat_get_file_encoding(readstat_metadata_t *metadata); -const mr_set_t *readstat_get_mr_sets(readstat_metadata_t *metadata); -size_t readstat_get_multiple_response_sets_length(readstat_metadata_t *metadata); typedef struct readstat_value_s { union { diff --git a/src/readstat_bits.c b/src/readstat_bits.c index be192e5..af11269 100644 --- a/src/readstat_bits.c +++ b/src/readstat_bits.c @@ -8,7 +8,7 @@ #include "readstat_bits.h" -int machine_is_little_endian(void) { +int machine_is_little_endian() { int test_byte_order = 1; return ((char *)&test_byte_order)[0]; } diff --git a/src/readstat_metadata.c b/src/readstat_metadata.c index e098b26..2534539 100644 --- a/src/readstat_metadata.c +++ b/src/readstat_metadata.c @@ -43,11 +43,3 @@ const char *readstat_get_file_encoding(readstat_metadata_t *metadata) { const char *readstat_get_table_name(readstat_metadata_t *metadata) { return metadata->table_name; } - -size_t readstat_get_multiple_response_sets_length(readstat_metadata_t *metadata) { - return metadata->multiple_response_sets_length; -} - -const mr_set_t *readstat_get_mr_sets(readstat_metadata_t *metadata) { - return metadata->mr_sets; -} diff --git a/src/readstat_parser.c b/src/readstat_parser.c index e5c4625..d081400 100644 --- a/src/readstat_parser.c +++ b/src/readstat_parser.c @@ -3,7 +3,7 @@ #include "readstat.h" #include "readstat_io_unistd.h" -readstat_parser_t *readstat_parser_init(void) { +readstat_parser_t *readstat_parser_init() { readstat_parser_t *parser = calloc(1, sizeof(readstat_parser_t)); parser->io = calloc(1, sizeof(readstat_io_t)); if (unistd_io_init(parser) != READSTAT_OK) { diff --git a/src/readstat_variable.c b/src/readstat_variable.c index ecd71ab..6172abd 100644 --- a/src/readstat_variable.c +++ b/src/readstat_variable.c @@ -5,7 +5,7 @@ static readstat_value_t make_blank_value(void); static readstat_value_t make_double_value(double dval); -static readstat_value_t make_blank_value(void) { +static readstat_value_t make_blank_value() { readstat_value_t value = { .is_system_missing = 1, .v = { .double_value = NAN }, .type = READSTAT_TYPE_DOUBLE }; return value; } diff --git a/src/readstat_writer.c b/src/readstat_writer.c index c1e9890..82219f2 100644 --- a/src/readstat_writer.c +++ b/src/readstat_writer.c @@ -35,7 +35,7 @@ readstat_string_ref_t *readstat_string_ref_init(const char *string) { return ref; } -readstat_writer_t *readstat_writer_init(void) { +readstat_writer_t *readstat_writer_init() { readstat_writer_t *writer = calloc(1, sizeof(readstat_writer_t)); writer->variables = calloc(VARIABLES_INITIAL_CAPACITY, sizeof(readstat_variable_t *)); diff --git a/src/sas/ieee.c b/src/sas/ieee.c index b74fc68..f6b7d87 100644 --- a/src/sas/ieee.c +++ b/src/sas/ieee.c @@ -96,7 +96,7 @@ int cnxptiee(const void *from_bytes, int fromtype, void *to_bytes, int totype) return(0); } -int get_native(void) { +int get_native() { static unsigned char float_reps[][8] = { {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00}, {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00}, @@ -366,7 +366,7 @@ void ieee2xpt(unsigned char *ieee, unsigned char *xport) { shift = (int) (ieee_exp = (int)(((ieee1 >> 16) & 0x7ff0) >> 4) - 1023) & 3; - /* the ieee format has an implied "1" immediately to the left */ + /* the ieee format has an implied "1" immdeiately to the left */ /* of the binary point. Show it in here. */ xport1 |= 0x00100000; if (shift) @@ -377,7 +377,7 @@ void ieee2xpt(unsigned char *ieee, unsigned char *xport) { /* from the lower half that would have been shifted in (if */ /* we could shift a double). The shift count can never */ /* exceed 3, so all we care about are the high order 3 */ - /* bits. We don't want sign extension so make sure it's an */ + /* bits. We don't want sign extention so make sure it's an */ /* unsigned char. We'll shift either5, 6, or 7 places to */ /* keep 3, 2, or 1 bits. After that, shift the second half */ /* of the number the right number of places. We always get */ @@ -391,9 +391,9 @@ void ieee2xpt(unsigned char *ieee, unsigned char *xport) { /* Now set the ibm exponent and the sign of the fraction. The */ /* power of 2 ieee exponent must be divided by 4 and made */ - /* excess 64 (we add 65 here because of the position of the */ + /* excess 64 (we add 65 here because of the poisition of the */ /* fraction bits, essentially 4 positions lower than they */ - /* should be so we increment the ibm exponent). */ + /* should be so we incrment the ibm exponent). */ xport1 |= diff --git a/src/sas/readstat_sas.c b/src/sas/readstat_sas.c index 542d466..2b3e7cf 100644 --- a/src/sas/readstat_sas.c +++ b/src/sas/readstat_sas.c @@ -120,12 +120,11 @@ static readstat_charset_entry_t _charset_table[] = { { .code = 248, .name = "SHIFT_JISX0213" }, }; -static time_t sas_epoch(void) { +static time_t sas_epoch() { return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970 } -static time_t sas_convert_time(double time, double time_diff, time_t epoch) { - time -= time_diff; +static time_t sas_convert_time(double time, time_t epoch) { time += epoch; if (isnan(time)) return 0; @@ -213,7 +212,7 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, goto cleanup; } - double creation_time, modification_time, creation_time_diff, modification_time_diff; + double creation_time, modification_time; if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) { retval = READSTAT_ERROR_READ; @@ -229,22 +228,13 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, if (bswap) modification_time = byteswap_double(modification_time); - if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) { - retval = READSTAT_ERROR_READ; - goto cleanup; - } - if (bswap) - creation_time_diff = byteswap_double(creation_time_diff); - - if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) { - retval = READSTAT_ERROR_READ; + hinfo->creation_time = sas_convert_time(creation_time, epoch); + hinfo->modification_time = sas_convert_time(modification_time, epoch); + + if (io->seek(16, READSTAT_SEEK_CUR, io->io_ctx) == -1) { + retval = READSTAT_ERROR_SEEK; goto cleanup; } - if (bswap) - modification_time_diff = byteswap_double(modification_time_diff); - - hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch); - hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch); uint32_t header_size, page_size; diff --git a/src/sas/readstat_xport_read.c b/src/sas/readstat_xport_read.c index 6bd9ddb..0bbb433 100644 --- a/src/sas/readstat_xport_read.c +++ b/src/sas/readstat_xport_read.c @@ -45,7 +45,7 @@ static readstat_error_t xport_update_progress(xport_ctx_t *ctx) { return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx); } -static xport_ctx_t *xport_ctx_init(void) { +static xport_ctx_t *xport_ctx_init() { xport_ctx_t *ctx = calloc(1, sizeof(xport_ctx_t)); return ctx; } diff --git a/src/sas/readstat_xport_write.c b/src/sas/readstat_xport_write.c index 761f38a..3d312da 100644 --- a/src/sas/readstat_xport_write.c +++ b/src/sas/readstat_xport_write.c @@ -10,7 +10,7 @@ #include "readstat_xport_parse_format.h" #include "ieee.h" -#define XPORT_DEFAULT_VERSION 8 +#define XPORT_DEFAULT_VERISON 8 #define RECORD_LEN 80 #if defined _MSC_VER @@ -531,7 +531,7 @@ static readstat_error_t xport_metadata_ok(void *writer_ctx) { readstat_error_t readstat_begin_writing_xport(readstat_writer_t *writer, void *user_ctx, long row_count) { if (writer->version == 0) - writer->version = XPORT_DEFAULT_VERSION; + writer->version = XPORT_DEFAULT_VERISON; writer->callbacks.metadata_ok = &xport_metadata_ok; writer->callbacks.write_int8 = &xport_write_int8; diff --git a/src/spss/readstat_por.c b/src/spss/readstat_por.c index 0fff250..05cf350 100644 --- a/src/spss/readstat_por.c +++ b/src/spss/readstat_por.c @@ -64,7 +64,7 @@ uint16_t por_unicode_lookup[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -por_ctx_t *por_ctx_init(void) { +por_ctx_t *por_ctx_init() { por_ctx_t *ctx = calloc(1, sizeof(por_ctx_t)); ctx->space = ' '; diff --git a/src/spss/readstat_por_write.c b/src/spss/readstat_por_write.c index cae2af0..3f39816 100644 --- a/src/spss/readstat_por_write.c +++ b/src/spss/readstat_por_write.c @@ -167,7 +167,7 @@ static readstat_error_t por_write_string_field(readstat_writer_t *writer, por_wr return por_write_string_field_n(writer, ctx, string, strlen(string)); } -static por_write_ctx_t *por_write_ctx_init(void) { +static por_write_ctx_t *por_write_ctx_init() { por_write_ctx_t *ctx = calloc(1, sizeof(por_write_ctx_t)); uint16_t max_unicode = 0; int i; diff --git a/src/spss/readstat_sav.c b/src/spss/readstat_sav.c index 62188bb..18a5916 100644 --- a/src/spss/readstat_sav.c +++ b/src/spss/readstat_sav.c @@ -59,8 +59,6 @@ sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) { return NULL; } - ctx->mr_sets = NULL; - ctx->io = io; return ctx; @@ -91,25 +89,6 @@ void sav_ctx_free(sav_ctx_t *ctx) { if (ctx->variable_display_values) { free(ctx->variable_display_values); } - if (ctx->mr_sets) { - for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) { - if (ctx->mr_sets[i].name) { - free(ctx->mr_sets[i].name); - } - if (ctx->mr_sets[i].label) { - free(ctx->mr_sets[i].label); - } - if (ctx->mr_sets[i].subvariables) { - for (size_t j = 0; j < ctx->mr_sets[i].num_subvars; j++) { - if (ctx->mr_sets[i].subvariables[j]) { - free(ctx->mr_sets[i].subvariables[j]); - } - } - free(ctx->mr_sets[i].subvariables); - } - } - free(ctx->mr_sets); - } free(ctx); } diff --git a/src/spss/readstat_sav.h b/src/spss/readstat_sav.h index e417ac4..c4b68de 100644 --- a/src/spss/readstat_sav.h +++ b/src/spss/readstat_sav.h @@ -3,7 +3,6 @@ // #include "readstat_spss.h" -#include "../readstat.h" #pragma pack(push, 1) @@ -101,9 +100,6 @@ typedef struct sav_ctx_s { uint64_t lowest_double; uint64_t highest_double; - size_t multiple_response_sets_length; - mr_set_t *mr_sets; - double bias; int format_version; @@ -121,7 +117,6 @@ typedef struct sav_ctx_s { #define SAV_RECORD_SUBTYPE_INTEGER_INFO 3 #define SAV_RECORD_SUBTYPE_FP_INFO 4 -#define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS 7 #define SAV_RECORD_SUBTYPE_PRODUCT_INFO 10 #define SAV_RECORD_SUBTYPE_VAR_DISPLAY 11 #define SAV_RECORD_SUBTYPE_LONG_VAR_NAME 13 diff --git a/src/spss/readstat_sav_read.c b/src/spss/readstat_sav_read.c index f318764..7f49490 100644 --- a/src/spss/readstat_sav_read.c +++ b/src/spss/readstat_sav_read.c @@ -8,14 +8,12 @@ #include #include #include -#include #include "../readstat.h" #include "../readstat_bits.h" #include "../readstat_iconv.h" #include "../readstat_convert.h" #include "../readstat_malloc.h" -#include "../CKHashTable.h" #include "readstat_sav.h" #include "readstat_sav_compress.h" @@ -147,212 +145,6 @@ static readstat_error_t sav_parse_variable_display_parameter_record(sav_ctx_t *c static readstat_error_t sav_parse_machine_integer_info_record(const void *data, size_t data_len, sav_ctx_t *ctx); static readstat_error_t sav_parse_long_string_value_labels_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx); static readstat_error_t sav_parse_long_string_missing_values_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx); -static readstat_error_t sav_read_multiple_response_sets(size_t data_len, sav_ctx_t *ctx); - -static readstat_error_t parse_mr_counted_value(const char **next_part, mr_set_t *result) { - readstat_error_t retval = READSTAT_OK; - if (result->type == 'D') { - result->is_dichotomy = 1; - const char *digit_start = (*next_part); - while (*(*next_part) != ' ' && *(*next_part) != '\0') { - (*next_part)++; - } - int internal_count = (int)strtol(digit_start, NULL, 10); - if (*(*next_part) != ' ') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - (*next_part)++; - digit_start = (*next_part); - for (int i = 0; i < internal_count && isdigit((unsigned char)*(*next_part)); i++) { - (*next_part)++; - } - result->counted_value = (int)strtol(digit_start, NULL, 10); - if (*(*next_part) != ' ' && *(*next_part) != '\0') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - } - else if (result->type == 'C') { - result->is_dichotomy = 0; - result->counted_value = -1; - } - else { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } -cleanup: - return retval; -} - - -static readstat_error_t parse_mr_line(const char *line, mr_set_t *result) { - readstat_error_t retval = READSTAT_OK; - *result = (mr_set_t){0}; - - const char *equals_pos = strchr(line, '='); - if (equals_pos == NULL || equals_pos[1] == '\0') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - - result->type = equals_pos[1]; - int name_length = equals_pos - line; - if (name_length < 1) { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - if ((result->name = readstat_malloc(name_length + 1)) == NULL) { - retval = READSTAT_ERROR_MALLOC; - goto cleanup; - } - strncpy(result->name, line, name_length); - result->name[name_length] = '\0'; - - if (equals_pos[2] == '\0') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - const char *next_part = equals_pos + 2; // Start after the '=' and type character - if ((retval = parse_mr_counted_value(&next_part, result)) != READSTAT_OK) goto cleanup; - if (*next_part != ' ') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - next_part++; - const char *digit_start = next_part; - while (isdigit((unsigned char)*next_part)) { - next_part++; - } - if (*next_part != ' ') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - if (digit_start == next_part) { // ensure digit start not empty - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - char *endptr = NULL; - size_t count = strtoul(digit_start, &endptr, 10); - if (endptr == digit_start) { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - - next_part = endptr; - if (*next_part != ' ') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - next_part++; // Move past the space after the digits - if (strlen(next_part) < count) { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - - result->label = readstat_malloc(count + 1); // +1 for the null-terminator - if (result->label == NULL) { - retval = READSTAT_ERROR_MALLOC; - goto cleanup; - } - strncpy(result->label, next_part, count); - result->label[count] = '\0'; - - next_part += count; - if (*next_part != ' ') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - next_part++; - - char **subvariables = NULL; - int subvar_count = 0; - while (*next_part) { - if (*next_part == ' ') { // Skip any extra spaces - next_part++; - continue; - } - - const char *start = next_part; - while (*next_part && *next_part != ' ') { - next_part++; // Move to the end of the current subvariable - } - - size_t length = next_part - start; - char *subvariable = readstat_malloc(length + 1); // Allocate memory for the subvariable - if (subvariable == NULL) { - retval = READSTAT_ERROR_MALLOC; - for (int i = 0; i < subvar_count; i++) { - free(subvariables[i]); - subvariables[i] = NULL; - } - free(subvariables); - goto cleanup; - } - strncpy(subvariable, start, length); - subvariable[length] = '\0'; // Null-terminate the string - - char **temp = realloc(subvariables, (subvar_count + 1) * sizeof(char *)); - if (temp == NULL) { - retval = READSTAT_ERROR_MALLOC; - free(subvariable); - for (int i = 0; i < subvar_count; i++) { - free(subvariables[i]); - subvariables[i] = NULL; - } - free(subvariables); - goto cleanup; - } - subvariables = temp; - subvariables[subvar_count++] = subvariable; // Add the new subvariable to the array - - if (*next_part == ' ') next_part++; // Move past the space - } - - result->subvariables = subvariables; - result->num_subvars = subvar_count; - -cleanup: - return retval; -} - -static readstat_error_t sav_read_multiple_response_sets(size_t data_len, sav_ctx_t *ctx) { - readstat_error_t retval = READSTAT_OK; - - char *mr_string = readstat_malloc(data_len + 1); - if (mr_string == NULL) { - retval = READSTAT_ERROR_MALLOC; - goto cleanup; - } - mr_string[data_len] = '\0'; - if (ctx->io->read(mr_string, data_len, ctx->io->io_ctx) < data_len) { - retval = READSTAT_ERROR_PARSE; - goto cleanup; - } - if (mr_string[0] != '$') { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - - fprintf(stderr, "\n\n\nDebug: MR string: '%s'\n", mr_string); - char *token = strtok(mr_string, "$\n"); - int num_lines = 0; - while (token != NULL) { - if ((ctx->mr_sets = realloc(ctx->mr_sets, (num_lines + 1) * sizeof(mr_set_t))) == NULL) { - retval = READSTAT_ERROR_MALLOC; - goto cleanup; - } - retval = parse_mr_line(token, &ctx->mr_sets[num_lines]); - if (retval != READSTAT_OK) goto cleanup; - num_lines++; - token = strtok(NULL, "$\n"); - } - ctx->multiple_response_sets_length = num_lines; - -cleanup: - free(mr_string); - return retval; -} static void sav_tag_missing_double(readstat_value_t *value, sav_ctx_t *ctx) { double fp_value = value->v.double_value; @@ -925,10 +717,6 @@ static readstat_error_t sav_process_row(unsigned char *buffer, size_t buffer_len } if (++offset == col_info->width) { if (++segment_offset < var_info->n_segments) { - if (raw_str_used == 0) { - retval = READSTAT_ERROR_PARSE; - goto done; - } raw_str_used--; } offset = 0; @@ -1547,14 +1335,6 @@ static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) { retval = sav_parse_machine_integer_info_record(data_buf, data_len, ctx); if (retval != READSTAT_OK) goto cleanup; - } else if (subtype == SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS) { - if (ctx->mr_sets != NULL) { - retval = READSTAT_ERROR_BAD_MR_STRING; - goto cleanup; - } - retval = sav_read_multiple_response_sets(data_len, ctx); - if (retval != READSTAT_OK) - goto cleanup; } else { if (io->seek(data_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) { retval = READSTAT_ERROR_SEEK; @@ -1882,48 +1662,6 @@ readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, metadata.file_label = ctx->file_label; - // Replace short MR names with long names - ck_hash_table_t *var_dict = ck_hash_table_init(1024, 8); - for (size_t i = 0; i < ctx->var_count; i++) { - spss_varinfo_t *current_varinfo = ctx->varinfo[i]; - if (current_varinfo != NULL && current_varinfo->name[0] != '\0') { - ck_str_hash_insert(current_varinfo->name, current_varinfo, var_dict); - } - } - for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) { - mr_set_t mr = ctx->mr_sets[i]; - for (size_t j = 0; j < mr.num_subvars; j++) { - char* sv_name_upper = malloc(strlen(mr.subvariables[j]) + 1); - if (sv_name_upper == NULL) { - retval = READSTAT_ERROR_MALLOC; - goto cleanup; - } - sv_name_upper[strlen(mr.subvariables[j])] = '\0'; - for (int c = 0; mr.subvariables[j][c] != '\0'; c++) { - sv_name_upper[c] = toupper((unsigned char) mr.subvariables[j][c]); - } - spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(sv_name_upper, var_dict); - if (info) { - free(mr.subvariables[j]); - // mr.subvariables[j] = NULL; - if ((mr.subvariables[j] = readstat_malloc(strlen(info->longname) + 1)) == NULL) { - retval = READSTAT_ERROR_MALLOC; - goto cleanup; - } - // mr.subvariables[j][strlen(info->longname)] = '\0'; - strcpy(mr.subvariables[j], info->longname); - // mr.subvariables[j] = info->longname; - } - free(sv_name_upper); - // sv_name_upper = NULL; - } - } - if (var_dict) - ck_hash_table_free(var_dict); - - metadata.multiple_response_sets_length = ctx->multiple_response_sets_length; - metadata.mr_sets = ctx->mr_sets; - if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) { retval = READSTAT_ERROR_USER_ABORT; goto cleanup; @@ -1936,7 +1674,6 @@ readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, if ((retval = sav_handle_variables(ctx)) != READSTAT_OK) goto cleanup; - if ((retval = sav_handle_fweight(ctx)) != READSTAT_OK) goto cleanup;