Skip to content

Commit

Permalink
cleanup and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Dec 1, 2023
1 parent d703fbc commit 0272760
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/readsas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@ Rcpp::List readsas(const char * filePath,

// not sure yet, whats the right thing to do here
bool page0not = 0;
if ((pg == 0) & (sc != 3))
page0not = (PAGE_TYPE == 0) & (potabs[sc].SH_LEN == rowlength);
if ((pg == 0) && (sc != 3))
page0not = (PAGE_TYPE == 0) && (potabs[sc].SH_LEN == rowlength);

int64_t sas_offset = alignval;
if (! ((potabs[sc].COMPRESSION == 4) |
Expand Down Expand Up @@ -1195,7 +1195,7 @@ Rcpp::List readsas(const char * filePath,
scv[i].FIRST = readbin(scv[i].FIRST, sas, swapit);
scv[i].F_POS = readbin(scv[i].F_POS, sas, swapit);

if ((i == 0) & (scv[i].SIG != -4))
if ((i == 0) && (scv[i].SIG != -4))
warning("first SIG is not -4");

unk16 = readbin(unk16, sas, swapit);
Expand Down Expand Up @@ -1381,14 +1381,14 @@ Rcpp::List readsas(const char * filePath,
unk16 = readbin(unk16, sas, swapit); // 0
// Rcout << unk16 << std::endl;

if ((PAGE_TYPE != 1024) & (c5first == 0)) {
if ((PAGE_TYPE != 1024) && (c5first == 0)) {
unk16 = readbin(unk16, sas, swapit); // 0 | 0 | 27977
// Rcout << unk16 << std::endl;
unk16 = readbin(unk16, sas, swapit); // 0 | 15872 | 30064
// Rcout << unk16 << std::endl;
}

if ((c5typ == 0) & (pg == 0)) {
if ((c5typ == 0) && (pg == 0)) {

uint64_t pos_beg = sas.tellg();
int8_t tmp = 16; // always 16?
Expand Down Expand Up @@ -1561,8 +1561,8 @@ Rcpp::List readsas(const char * filePath,
capois[i].UNK8 = readbin(capois[i].UNK8, sas, swapit);


if ((capois[i].CN_TYP >= 1) & (capois[i].CN_TYP <= 2) &
(capois[i].CN_WID >= 0) & // just > ?
if ((capois[i].CN_TYP >= 1) && (capois[i].CN_TYP <= 2) &&
(capois[i].CN_WID >= 0) && // just > ?
((uint32_t)capois[i].CN_WID <= pagesize)) {
if (debug)
Rprintf("OFF %d; WID: %d; FLAG %d; TYP %d; UNK8 %d\n",
Expand Down Expand Up @@ -1677,7 +1677,7 @@ Rcpp::List readsas(const char * filePath,
if (debug)
Rcout << "-------- case 10 "<< sas.tellg() << std::endl;

if ((potabs[sc].SH_LEN > alignval) &
if ((potabs[sc].SH_LEN > alignval) &&
(potabs[sc].SH_LEN < pagesize))
{
// uncompressed row containing data
Expand Down Expand Up @@ -1708,8 +1708,8 @@ Rcpp::List readsas(const char * filePath,
// some subheaders are pointers to positions inside the file.
// their use for SAS is unknown and they are not required for R.
// if SC_LEN == alignval it is just padding?
if ((potabs[sc].SH_LEN > alignval) &
(potabs[sc].SH_LEN < pagesize) &
if ((potabs[sc].SH_LEN > alignval) &&
(potabs[sc].SH_LEN < pagesize) &&
(potabs[sc].COMPRESSION != 4) )
{
auto unklen = potabs[sc].SH_LEN;
Expand Down Expand Up @@ -2086,7 +2086,7 @@ Rcpp::List readsas(const char * filePath,
uint64_t pos = pp + (double)rowlength * ii;

/* unknown */
if (!(dataoffset == 1 || dataoffset == 256) & (firstpage == 0)) {
if (!(dataoffset == 1 || dataoffset == 256) && (firstpage == 0)) {
pos += alignval;
}

Expand Down Expand Up @@ -2119,7 +2119,7 @@ Rcpp::List readsas(const char * filePath,
if (debug && i == 0)
Rcout << ord << std::endl;

if ((wid < 8) & (typ == 1)) {
if ((wid < 8) && (typ == 1)) {

if (keepr && keepc) {
if (skipahead > 0) {
Expand All @@ -2146,7 +2146,7 @@ Rcpp::List readsas(const char * filePath,

}

if ((wid == 8) & (typ == 1)) {
if ((wid == 8) && (typ == 1)) {

if (keepr && keepc) {
if (skipahead > 0) {
Expand All @@ -2173,7 +2173,7 @@ Rcpp::List readsas(const char * filePath,

}

if ((wid > 0) & (typ == 2)) {
if ((wid > 0) && (typ == 2)) {

if (keepr && keepc) {
if (skipahead > 0) {
Expand Down Expand Up @@ -2276,7 +2276,7 @@ Rcpp::List readsas(const char * filePath,
Rcout << "row i / iii / keepr: " << i << " " << iii <<" " << keepr << std::endl;
}

if ((wid > 0) & (wid < 8) & (typ == 1)) {
if ((wid > 0) && (wid < 8) && (typ == 1)) {


if (keepc) {
Expand All @@ -2297,7 +2297,7 @@ Rcpp::List readsas(const char * filePath,

}

if ((wid == 8) & (typ == 1)) {
if ((wid == 8) && (typ == 1)) {

if (keepc) {

Expand All @@ -2322,7 +2322,7 @@ Rcpp::List readsas(const char * filePath,

}

if ((wid > 0) & (typ == 2)) {
if ((wid > 0) && (typ == 2)) {

if (keepc) {

Expand Down
2 changes: 2 additions & 0 deletions src/writesas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
offsetpos += lblz.size();
lbls.OFF = offsetpos;

// somehow this does not work with datetime. Maybe the offset
// needs to be recalculated afterwards?
std::string fmtz = varformats[z];
offsetpos += fmtz.size();
fmts.OFF = offsetpos;
Expand Down

0 comments on commit 0272760

Please sign in to comment.