static readstat_error_t read_variable_record(readstat_por_ctx_t *ctx) { double value; int i; ctx->var_offset++; spss_varinfo_t *varinfo = &ctx->varinfo[ctx->var_offset]; spss_format_t *formats[2] = { &varinfo->print_format, &varinfo->write_format }; if (read_double(ctx, &value) == -1) { return READSTAT_ERROR_PARSE; } varinfo->labels_index = -1; varinfo->width = (int)value; if (varinfo->width == 0) { varinfo->type = READSTAT_TYPE_DOUBLE; } else { varinfo->type = READSTAT_TYPE_STRING; } if (read_string(ctx, varinfo->name, sizeof(varinfo->name)) == -1) { return READSTAT_ERROR_PARSE; } ck_str_hash_insert(varinfo->name, varinfo, ctx->var_dict); for (i=0; i<sizeof(formats)/sizeof(spss_format_t *); i++) { spss_format_t *format = formats[i]; if (read_double(ctx, &value) == -1) { return READSTAT_ERROR_PARSE; } format->type = (int)value; if (read_double(ctx, &value) == -1) { return READSTAT_ERROR_PARSE; } format->width = (int)value; if (read_double(ctx, &value) == -1) { return READSTAT_ERROR_PARSE; } format->decimal_places = (int)value; } return READSTAT_OK; }
static int handle_value_label(const char *val_labels, readstat_value_t value, const char *label, void *ctx) { rs_ctx_t *rs_ctx = (rs_ctx_t *)ctx; readstat_writer_t *writer = rs_ctx->writer; readstat_label_set_t *label_set = NULL; readstat_types_t type = readstat_value_type(value); label_set = (readstat_label_set_t *)ck_str_hash_lookup(val_labels, rs_ctx->label_set_dict); if (label_set == NULL) { label_set = readstat_add_label_set(writer, type, val_labels); ck_str_hash_insert(val_labels, label_set, rs_ctx->label_set_dict); } if (type == READSTAT_TYPE_INT32) { readstat_label_int32_value(label_set, readstat_int32_value(value), label); } else if (type == READSTAT_TYPE_DOUBLE) { readstat_label_double_value(label_set, readstat_double_value(value), label); } else if (type == READSTAT_TYPE_STRING) { readstat_label_string_value(label_set, readstat_string_value(value), label); } return 0; }