Skip to content

Commit

Permalink
SAS catalog files: skip over long names
Browse files Browse the repository at this point in the history
A bit-field appears to determine whether a format has a 32-character
long name present. I'm not sure whether to return the short name or long
name to the client code; probably whichever sas7bdat uses to refer to
formats. I'm guessing sas7bdat uses the short name, but we'll need more
sample files to know for sure.
  • Loading branch information
evanmiller committed Sep 26, 2015
1 parent 9754b22 commit c732495
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/readstat_sas.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ static readstat_error_t sas_parse_catalog_page(const char *page, size_t page_siz
size_t pad = (lsp[12] & 0x08) ? 4 : 0; // might be 0x10, not sure
int label_count_capacity = read4(&lsp[48+pad], ctx->bswap);
int label_count_used = read4(&lsp[52+pad], ctx->bswap);
char name[4*8+1];
char name[4*32+1];

retval = readstat_convert(name, sizeof(name), &lsp[18], 8, ctx->converter);
if (retval != READSTAT_OK)
Expand All @@ -764,6 +764,15 @@ static readstat_error_t sas_parse_catalog_page(const char *page, size_t page_siz
pad += 16;
}

if ((lsp[12] & 0x80)) { // has long name
/* Uncomment to return long name to client code instead of short name
retval = readstat_convert(name, sizeof(name), &lsp[116+pad], 32, ctx->converter);
if (retval != READSTAT_OK)
goto cleanup;
*/
pad += 32;
}

const char *lbp1 = &lsp[116+pad];

/* Pass 1 -- find out the offset of the labels */
Expand Down Expand Up @@ -1240,8 +1249,8 @@ readstat_error_t readstat_parse_sas7bcat(readstat_parser_t *parser, const char *

ctx->u64 = hinfo->u64;
ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
if (!strcmp(hinfo->encoding, "UTF-8") == 0 &&
!strcmp(hinfo->encoding, "US-ASCII") == 0) {
if (strcmp(hinfo->encoding, "UTF-8") != 0 &&
strcmp(hinfo->encoding, "US-ASCII") != 0) {
iconv_t converter = iconv_open("UTF-8", hinfo->encoding);
if (converter == (iconv_t)-1) {
retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
Expand Down

0 comments on commit c732495

Please sign in to comment.