From 3e62c48353d5014981dc77e3dc91d66d3704cfc7 Mon Sep 17 00:00:00 2001 From: Reinhold <8436725+reikoch@users.noreply.github.com> Date: Thu, 6 Aug 2020 09:54:31 +0200 Subject: [PATCH 1/2] make xpt v8 SAS-readable --- src/sas/readstat_xport_write.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sas/readstat_xport_write.c b/src/sas/readstat_xport_write.c index 5265fceb..6310185f 100644 --- a/src/sas/readstat_xport_write.c +++ b/src/sas/readstat_xport_write.c @@ -87,9 +87,11 @@ static readstat_error_t xport_write_variables(readstat_writer_t *writer) { readstat_variable_t *variable = readstat_get_variable(writer, i); size_t width = xport_variable_width(variable->type, variable->user_width); xport_namestr_t namestr = { - .nvar0 = i, + .nvar0 = i+1, .nlng = width, - .npos = offset + .npos = offset, + .niform = " ", + .nform = " " }; if (readstat_variable_get_type_class(variable) == READSTAT_TYPE_CLASS_STRING) { namestr.ntype = SAS_COLUMN_TYPE_CHR; From 842bf2877840c6a3f9e4599b0a1cbe5b0eacba82 Mon Sep 17 00:00:00 2001 From: Reinhold <8436725+reikoch@users.noreply.github.com> Date: Fri, 21 Aug 2020 13:09:55 +0200 Subject: [PATCH 2/2] fix reading long variable names from xpt --- .gitignore | 1 + src/sas/readstat_xport_read.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c2846b6b..592aecf3 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ test_double_decimals *.py *.tar.gz *.zip +.DS_Store diff --git a/src/sas/readstat_xport_read.c b/src/sas/readstat_xport_read.c index cf6bde18..7e3e55b2 100644 --- a/src/sas/readstat_xport_read.c +++ b/src/sas/readstat_xport_read.c @@ -449,8 +449,13 @@ static readstat_error_t xport_read_variables(xport_ctx_t *ctx) { variable->decimals = namestr.nfd; variable->alignment = namestr.nfj ? READSTAT_ALIGNMENT_RIGHT : READSTAT_ALIGNMENT_LEFT; - readstat_convert(variable->name, sizeof(variable->name), - namestr.nname, sizeof(namestr.nname), ctx->converter); + if (ctx->version == 5) { + readstat_convert(variable->name, sizeof(variable->name), + namestr.nname, sizeof(namestr.nname), ctx->converter); + } else { + readstat_convert(variable->name, sizeof(variable->name), + namestr.longname, sizeof(namestr.longname), ctx->converter); + } if (retval != READSTAT_OK) goto cleanup;