Skip to content

Commit ce9c19f

Browse files
Merge branch 'master' into macroRemoval
2 parents 81aeb70 + d2b3ea7 commit ce9c19f

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/fread.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static inline bool end_of_field(const char *ch) {
287287
// default, and therefore characters in the range 0x80-0xFF are negative.
288288
// We use eol() because that looks at eol_one_r inside it w.r.t. \r
289289
// \0 (maybe more than one) before eof are part of field and do not end it; eol() returns false for \0 but the ch==eof will return true for the \0 at eof.
290-
return *ch==sep || ((uint8_t)*ch <= 13 && (ch == eof || eol(&ch)));
290+
return *ch == sep || ((uint8_t)*ch <= 13 && (ch == eof || eol(&ch)));
291291
}
292292

293293
static inline const char *end_NA_string(const char *start) {
@@ -298,7 +298,7 @@ static inline const char *end_NA_string(const char *start) {
298298
const char *ch1 = start;
299299
const char *ch2 = *nastr;
300300
while (*ch1 == *ch2 && *ch2 != '\0') { ch1++; ch2++; }
301-
if (*ch2=='\0' && ch1 > mostConsumed) mostConsumed = ch1;
301+
if (*ch2 == '\0' && ch1 > mostConsumed) mostConsumed = ch1;
302302
nastr++;
303303
}
304304
return mostConsumed;
@@ -321,7 +321,7 @@ static inline int countfields(const char **pch)
321321
if (sep == ' ') while (*ch == ' ') ch++; // multiple sep==' ' at the start does not mean sep
322322
skip_white(&ch);
323323
if (eol(&ch) || ch == eof) {
324-
*pch = ch+1;
324+
*pch = ch + 1;
325325
return 0;
326326
}
327327
int ncol = 1;
@@ -340,7 +340,7 @@ static inline int countfields(const char **pch)
340340
ch++; // Move onto end of line character
341341
}
342342
}
343-
if (*ch==sep) {
343+
if (*ch == sep) {
344344
ch++;
345345
ncol++;
346346
continue;
@@ -564,7 +564,7 @@ static void Field(FieldParseContext *ctx)
564564
}
565565
target->len = (int32_t)(ch - fieldStart);
566566
target->off = (int32_t)(fieldStart - ctx->anchor);
567-
if (*ch==quote) { // quote=='\0' (user set quote="") would have returned earlier above in the same branch as quoteRule 3
567+
if (*ch == quote) { // quote=='\0' (user set quote="") would have returned earlier above in the same branch as quoteRule 3
568568
ch++;
569569
skip_white(&ch);
570570
*ctx->ch = ch;
@@ -918,7 +918,7 @@ static void parse_double_hexadecimal(FieldParseContext *ctx)
918918
E = 10 * E + digit;
919919
ch++;
920920
}
921-
E = 1023 + (Eneg? -E : E) - subnormal;
921+
E = 1023 + (Eneg ? -E : E) - subnormal;
922922
if (subnormal ? E : (E < 1 || E > 2046)) return;
923923

924924
*((uint64_t*)target) = (neg << 63) | (E << 52) | (acc);
@@ -977,7 +977,7 @@ static void parse_iso8601_date_core(const char **pch, int32_t *target)
977977
return;
978978

979979
*target =
980-
(year / 400 - 4)*cumDaysCycleYears[400] + // days to beginning of 400-year cycle
980+
(year / 400 - 4) * cumDaysCycleYears[400] + // days to beginning of 400-year cycle
981981
cumDaysCycleYears[year % 400] + // days to beginning of year within 400-year cycle
982982
(isLeapYear ? cumDaysCycleMonthsLeap[month - 1] : cumDaysCycleMonthsNorm[month - 1]) + // days to beginning of month within year
983983
day - 1; // day within month (subtract 1: 1970-01-01 -> 0)
@@ -1061,7 +1061,7 @@ static void parse_iso8601_timestamp(FieldParseContext *ctx)
10611061
}
10621062

10631063
// cast upfront needed to prevent silent overflow
1064-
*target = 86400*(double)date + 3600 * (hour - tz_hour) + 60 * (minute - tz_minute) + second;
1064+
*target = 86400 * (double)date + 3600 * (hour - tz_hour) + 60 * (minute - tz_minute) + second;
10651065

10661066
*ctx->ch = ch;
10671067
}
@@ -1318,7 +1318,7 @@ int freadMain(freadMainArgs _args) {
13181318
} else {
13191319
const char *ch = *nastr;
13201320
size_t nchar = strlen(ch);
1321-
if (isspace(ch[0]) || isspace(ch[nchar-1]))
1321+
if (isspace(ch[0]) || isspace(ch[nchar - 1]))
13221322
STOP(_("freadMain: NAstring <<%s>> has whitespace at the beginning or end"), ch);
13231323
if (strcmp(ch,"T") == 0 || strcmp(ch,"F") == 0 ||
13241324
strcmp(ch,"TRUE") == 0 || strcmp(ch,"FALSE") == 0 ||
@@ -1430,18 +1430,18 @@ int freadMain(freadMainArgs _args) {
14301430
HANDLE hFile = INVALID_HANDLE_VALUE;
14311431
int attempts = 0;
14321432
while(hFile == INVALID_HANDLE_VALUE && attempts < 5) {
1433-
hFile = CreateFile(fnam, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
1433+
hFile = CreateFile(fnam, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
14341434
// FILE_SHARE_WRITE is required otherwise if the file is open in Excel, CreateFile fails. Should be ok now.
14351435
if (hFile == INVALID_HANDLE_VALUE) {
1436-
if (GetLastError() == ERROR_FILE_NOT_FOUND) STOP(_("File not found: %s"),fnam);
1436+
if (GetLastError() == ERROR_FILE_NOT_FOUND) STOP(_("File not found: %s"), fnam);
14371437
if (attempts < 4) Sleep(250); // 250ms
14381438
}
14391439
attempts++;
14401440
// Looped retry to avoid ephemeral locks by system utilities as recommended here : http://support.microsoft.com/kb/316609
14411441
}
14421442
if (hFile == INVALID_HANDLE_VALUE) STOP(_("Unable to open file after %d attempts (error %lu): %s"), attempts, GetLastError(), fnam);
14431443
LARGE_INTEGER liFileSize;
1444-
if (GetFileSizeEx(hFile, &liFileSize)==0) { CloseHandle(hFile); STOP(_("GetFileSizeEx failed (returned 0) on file: %s"), fnam); }
1444+
if (GetFileSizeEx(hFile, &liFileSize) == 0) { CloseHandle(hFile); STOP(_("GetFileSizeEx failed (returned 0) on file: %s"), fnam); }
14451445
if (liFileSize.QuadPart > SIZE_MAX) {
14461446
CloseHandle(hFile); // # nocov
14471447
STOP(_("File size [%s] exceeds the address space: %s"), filesize_to_str(liFileSize.QuadPart), fnam); // # nocov
@@ -1720,7 +1720,7 @@ int freadMain(freadMainArgs _args) {
17201720
topQuoteRule = quoteRule;
17211721
firstJumpEnd = ch; // to know how many bytes jump 0 is, for nrow estimate later (a less-good estimate when fill=true since line lengths vary more)
17221722
if (verbose) {
1723-
DTPRINT((unsigned)sep<32
1723+
DTPRINT((unsigned)sep < 32
17241724
? _(" sep=%#02x with %d fields using quote rule %d\n")
17251725
: _(" sep='%c' with %d fields using quote rule %d\n"),
17261726
sep, topNumFields, quoteRule);
@@ -1750,7 +1750,7 @@ int freadMain(freadMainArgs _args) {
17501750
prevLineStart = NULL; lineStart = ch; thisRow++;
17511751
thisncol = countfields(&ch);
17521752
}
1753-
if (thisncol>0) {
1753+
if (thisncol > 0) {
17541754
lastncol = thisncol;
17551755
thisBlockLines = 1;
17561756
thisBlockPrevStart = prevLineStart; // remember previous line start in case it has column names to be filled
@@ -1769,7 +1769,7 @@ int freadMain(freadMainArgs _args) {
17691769
firstJumpEnd = ch;
17701770
topStart = thisBlockStart;
17711771
prevStart = thisBlockPrevStart; // only used when line prior to contiguous block has a wrong number of column names to be filled
1772-
topSkip = thisRow-thisBlockLines;
1772+
topSkip = thisRow - thisBlockLines;
17731773
if (topSkip < 0) topSkip = 0; // inelegant but will do for now to pass single row input such as test 890
17741774
if (verbose) {
17751775
DTPRINT((unsigned)sep < 32
@@ -1955,7 +1955,7 @@ int freadMain(freadMainArgs _args) {
19551955
if (verbose)
19561956
DTPRINT(thisNcol < ncol ? _(" A line with too-few fields (%d/%d) was found on line %d of sample jump %d. %s\n")
19571957
: _(" A line with too-many fields (%d/%d) was found on line %d of sample jump %d. %s\n"),
1958-
thisNcol, ncol, jumpLine, jump, jump>0 ? _("Most likely this jump landed awkwardly so type bumps here will be skipped.") : "");
1958+
thisNcol, ncol, jumpLine, jump, jump > 0 ? _("Most likely this jump landed awkwardly so type bumps here will be skipped.") : "");
19591959
bumped = false;
19601960
if (jump == 0) lastRowEnd = eof; // to prevent the end from being tested; e.g. a short file with blank line within first 100 like test 976
19611961
break;
@@ -2225,7 +2225,7 @@ int freadMain(freadMainArgs _args) {
22252225
if (verbose) {
22262226
DTPRINT(_("[10] Allocate memory for the datatable\n"));
22272227
DTPRINT(_(" Allocating %d column slots (%d - %d dropped) with %"PRId64" rows\n"),
2228-
ncol-ndrop, ncol, ndrop, allocnrow);
2228+
ncol - ndrop, ncol, ndrop, allocnrow);
22292229
}
22302230
size_t DTbytes = allocateDT(type, size, ncol, ndrop, allocnrow);
22312231
double tAlloc = wallclock();
@@ -2507,7 +2507,7 @@ int freadMain(freadMainArgs _args) {
25072507
// check this line has the correct number of fields. If not, don't apply the bump from this invalid line. Instead fall through to myStopEarly below.
25082508
const char *tt = fieldStart;
25092509
int fieldsRemaining = countfields(&tt);
2510-
if (j+fieldsRemaining != ncol) break;
2510+
if (j + fieldsRemaining != ncol) break;
25112511
checkedNumberOfFields = true;
25122512
}
25132513
if (thisType <= TOGGLE_BUMP(NUMTYPE)) {
@@ -2524,7 +2524,7 @@ int freadMain(freadMainArgs _args) {
25242524
_("Column %d%s%.*s%s bumped from '%s' to '%s' due to <<%.*s>> on row %"PRId64"\n"),
25252525
j + 1, colNames ? " <<" : "", colNames ? (colNames[j].len) : 0, colNames ? (colNamesAnchor + colNames[j].off) : "", colNames ? ">>" : "",
25262526
typeName[IGNORE_BUMP(joldType)], typeName[IGNORE_BUMP(thisType)],
2527-
(int)(tch-fieldStart), fieldStart, (int64_t)(ctx.DTi+myNrow));
2527+
(int)(tch-fieldStart), fieldStart, (int64_t)(ctx.DTi + myNrow));
25282528

25292529
len = iminInt(len, sizeof(buffer));
25302530

@@ -2556,7 +2556,7 @@ int freadMain(freadMainArgs _args) {
25562556
if (tch != eof) tch++;
25572557
myNrow++;
25582558
}
2559-
if (verbose) { double now = wallclock(); thRead += now-tLast; tLast = now; }
2559+
if (verbose) { double now = wallclock(); thRead += now - tLast; tLast = now; }
25602560
ctx.anchor = thisJumpStart;
25612561
ctx.nRows = myNrow;
25622562
postprocessBuffer(&ctx);
@@ -2598,7 +2598,7 @@ int freadMain(freadMainArgs _args) {
25982598
if (quoteRuleBumpedCh == NULL) {
25992599
// for warning message if the quote rule bump does in fact manage to heal it, e.g. test 1881
26002600
quoteRuleBumpedCh = tLineStart;
2601-
quoteRuleBumpedLine = row1line+DTi;
2601+
quoteRuleBumpedLine = row1line + DTi;
26022602
}
26032603
restartTeam = true;
26042604
jump0 = jump; // this jump will restart from headPos, not from its beginning, e.g. test 1453
@@ -2646,13 +2646,12 @@ int freadMain(freadMainArgs _args) {
26462646
dropFill = malloc(sizeof(*dropFill) * ndropFill);
26472647
if (!dropFill)
26482648
STOP(_("Failed to allocate %zu bytes for '%s'."), sizeof(*dropFill) * ndropFill, "dropFill"); // # nocov
2649-
int i=0;
2650-
for (int j = max_col; j < ncol; j++) {
2649+
for (int i = 0, j = max_col; j < ncol; j++, i++) {
26512650
type[j] = CT_DROP;
26522651
size[j] = 0;
26532652
ndrop++;
26542653
nNonStringCols--;
2655-
dropFill[i++] = j;
2654+
dropFill[i] = j;
26562655
}
26572656
dropFilledCols(dropFill, ndropFill);
26582657
}
@@ -2763,10 +2762,10 @@ int freadMain(freadMainArgs _args) {
27632762
int tt = countfields(&ch);
27642763
if (fill > 0) {
27652764
DTWARN(_("Stopped early on line %"PRId64". Expected %d fields but found %d. Consider fill=%d or even more based on your knowledge of the input file. Use fill=Inf for reading the whole file for detecting the number of fields. First discarded non-empty line: <<%s>>"),
2766-
DTi+row1line, ncol, tt, tt, strlim(skippedFooter, (char[500]) {}, 500));
2765+
DTi + row1line, ncol, tt, tt, strlim(skippedFooter, (char[500]) {}, 500));
27672766
} else {
27682767
DTWARN(_("Stopped early on line %"PRId64". Expected %d fields but found %d. Consider fill=TRUE. First discarded non-empty line: <<%s>>"),
2769-
DTi+row1line, ncol, tt, strlim(skippedFooter, (char[500]) {}, 500));
2768+
DTi + row1line, ncol, tt, strlim(skippedFooter, (char[500]) {}, 500));
27702769
}
27712770
}
27722771
}
@@ -2779,7 +2778,7 @@ int freadMain(freadMainArgs _args) {
27792778
DTPRINT("=============================\n"); // # notranslate
27802779
if (tTot < 0.000001) tTot = 0.000001; // to avoid nan% output in some trivially small tests where tot==0.000s
27812780
DTPRINT(_("%8.3fs (%3.0f%%) Memory map %.3fGB file\n"), tMap - t0, 100.0 * (tMap - t0) / tTot, 1.0 * fileSize / (1024 * 1024 * 1024));
2782-
DTPRINT(_("%8.3fs (%3.0f%%) sep="), tLayout-tMap, 100.0 * (tLayout - tMap) / tTot);
2781+
DTPRINT(_("%8.3fs (%3.0f%%) sep="), tLayout - tMap, 100.0 * (tLayout - tMap) / tTot);
27832782
DTPRINT(sep == '\t' ? "'\\t'" : (sep == '\n' ? "'\\n'" : "'%c'"), sep); // # notranslate
27842783
DTPRINT(_(" ncol=%d and header detection\n"), ncol);
27852784
DTPRINT(_("%8.3fs (%3.0f%%) Column type detection using %"PRId64" sample rows\n"),

0 commit comments

Comments
 (0)