diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-07-12 09:03:38 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-07-12 09:03:38 (GMT) |
commit | a6ed76df7c2b1d8c8f3296a99023f88fc76c3f04 (patch) | |
tree | 955ddc69de09c5f08e526db3e20e07c84f86b103 | |
parent | 91982ba7527160c9c64c671e494999b3dbf54490 (diff) | |
parent | 505c18d593b11fa682694a7653b17b325c1aac0e (diff) | |
download | tcl-a6ed76df7c2b1d8c8f3296a99023f88fc76c3f04.zip tcl-a6ed76df7c2b1d8c8f3296a99023f88fc76c3f04.tar.gz tcl-a6ed76df7c2b1d8c8f3296a99023f88fc76c3f04.tar.bz2 |
Merge 8.7. Clean-up tclWinConsole.c the same way
-rw-r--r-- | generic/regexec.c | 66 | ||||
-rw-r--r-- | generic/tclClock.c | 4 | ||||
-rw-r--r-- | generic/tclUtf.c | 6 | ||||
-rw-r--r-- | win/nmakehlp.c | 9 | ||||
-rw-r--r-- | win/tclWinConsole.c | 81 | ||||
-rw-r--r-- | win/tclWinDde.c | 4 | ||||
-rw-r--r-- | win/tclWinLoad.c | 5 |
7 files changed, 86 insertions, 89 deletions
diff --git a/generic/regexec.c b/generic/regexec.c index 54cb905..7ef048e 100644 --- a/generic/regexec.c +++ b/generic/regexec.c @@ -236,13 +236,15 @@ exec( v->err = 0; assert(v->g->ntree >= 0); n = v->g->ntree; - if (n <= LOCALDFAS) + if (n <= LOCALDFAS) { v->subdfas = subdfas; - else + } else { v->subdfas = (struct dfa **) MALLOC(n * sizeof(struct dfa *)); + } if (v->subdfas == NULL) { - if (v->pmatch != pmatch && v->pmatch != mat) + if (v->pmatch != pmatch && v->pmatch != mat) { FREE(v->pmatch); + } FreeVars(v); return REG_ESPACE; } @@ -279,11 +281,13 @@ exec( } n = v->g->ntree; for (i = 0; i < n; i++) { - if (v->subdfas[i] != NULL) + if (v->subdfas[i] != NULL) { freeDFA(v->subdfas[i]); + } } - if (v->subdfas != subdfas) + if (v->subdfas != subdfas) { FREE(v->subdfas); + } FreeVars(v); return st; } @@ -299,8 +303,9 @@ getsubdfa(struct vars * v, { if (v->subdfas[t->id] == NULL) { v->subdfas[t->id] = newDFA(v, &t->cnfa, &v->g->cmap, NULL); - if (ISERR()) + if (ISERR()) { return NULL; + } } return v->subdfas[t->id]; } @@ -640,10 +645,11 @@ cdissect( break; case '.': /* concatenation */ assert(t->left != NULL && t->right != NULL); - if (t->left->flags & SHORTER) /* reverse scan */ + if (t->left->flags & SHORTER) {/* reverse scan */ er = crevcondissect(v, t, begin, end); - else + } else { er = ccondissect(v, t, begin, end); + } break; case '|': /* alternation */ assert(t->left != NULL); @@ -651,10 +657,11 @@ cdissect( break; case '*': /* iteration */ assert(t->left != NULL); - if (t->left->flags & SHORTER) /* reverse scan */ + if (t->left->flags & SHORTER) {/* reverse scan */ er = creviterdissect(v, t, begin, end); - else + } else { er = citerdissect(v, t, begin, end); + } break; case '(': /* capturing */ assert(t->left != NULL && t->right == NULL); @@ -920,17 +927,20 @@ cbrdissect( assert(end > begin); tlen = end - begin; - if (tlen % brlen != 0) + if (tlen % brlen != 0) { return REG_NOMATCH; + } numreps = tlen / brlen; - if (numreps < (size_t)min || (numreps > (size_t)max && max != DUPINF)) + if (numreps < (size_t)min || (numreps > (size_t)max && max != DUPINF)) { return REG_NOMATCH; + } /* okay, compare the actual string contents */ p = begin; while (numreps-- > 0) { - if ((*v->g->compare) (brstring, p, brlen) != 0) + if ((*v->g->compare) (brstring, p, brlen) != 0) { return REG_NOMATCH; + } p += brlen; } @@ -1007,8 +1017,9 @@ citerdissect(struct vars * v, */ min_matches = t->min; if (min_matches <= 0) { - if (begin == end) + if (begin == end) { return REG_OKAY; + } min_matches = 1; } @@ -1022,8 +1033,9 @@ citerdissect(struct vars * v, * sub-match endpoints in endpts[1..max_matches]. */ max_matches = end - begin; - if (max_matches > (size_t)t->max && t->max != DUPINF) + if (max_matches > (size_t)t->max && t->max != DUPINF) { max_matches = t->max; + } if (max_matches < (size_t)min_matches) max_matches = min_matches; endpts = (chr **) MALLOC((max_matches + 1) * sizeof(chr *)); @@ -1066,8 +1078,9 @@ citerdissect(struct vars * v, t->id, k, LOFF(endpts[k]))); /* k'th sub-match can no longer be considered verified */ - if (nverified >= k) + if (nverified >= k) { nverified = k - 1; + } if (endpts[k] != end) { /* haven't reached end yet, try another iteration if allowed */ @@ -1093,8 +1106,9 @@ citerdissect(struct vars * v, * number of matches, start the slow part: recurse to verify each * sub-match. We always have k <= max_matches, needn't check that. */ - if (k < min_matches) + if (k < min_matches) { goto backtrack; + } MDEBUG(("%d: verifying %d..%d\n", t->id, nverified + 1, k)); @@ -1105,8 +1119,9 @@ citerdissect(struct vars * v, nverified = i; continue; } - if (er == REG_NOMATCH) + if (er == REG_NOMATCH) { break; + } /* oops, something failed */ FREE(endpts); return er; @@ -1180,8 +1195,9 @@ creviterdissect(struct vars * v, */ min_matches = t->min; if (min_matches <= 0) { - if (begin == end) + if (begin == end) { return REG_OKAY; + } min_matches = 1; } @@ -1235,8 +1251,9 @@ creviterdissect(struct vars * v, limit++; /* if this is the last allowed sub-match, it must reach to the end */ - if ((size_t)k >= max_matches) + if ((size_t)k >= max_matches) { limit = end; + } /* try to find an endpoint for the k'th sub-match */ endpts[k] = shortest(v, d, endpts[k - 1], limit, end, @@ -1250,8 +1267,9 @@ creviterdissect(struct vars * v, t->id, k, LOFF(endpts[k]))); /* k'th sub-match can no longer be considered verified */ - if (nverified >= k) + if (nverified >= k) { nverified = k - 1; + } if (endpts[k] != end) { /* haven't reached end yet, try another iteration if allowed */ @@ -1272,8 +1290,9 @@ creviterdissect(struct vars * v, * number of matches, start the slow part: recurse to verify each * sub-match. We always have k <= max_matches, needn't check that. */ - if (k < min_matches) + if (k < min_matches) { goto backtrack; + } MDEBUG(("%d: verifying %d..%d\n", t->id, nverified + 1, k)); @@ -1284,8 +1303,9 @@ creviterdissect(struct vars * v, nverified = i; continue; } - if (er == REG_NOMATCH) + if (er == REG_NOMATCH) { break; + } /* oops, something failed */ FREE(endpts); return er; diff --git a/generic/tclClock.c b/generic/tclClock.c index 0669ffe..86eed73 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -1520,9 +1520,9 @@ GetJulianDayFromEraYearMonthDay( * Have to make sure quotient is truncated towards 0 when negative. * See above bug for details. The casts are necessary. */ - if (ym1 >= 0) + if (ym1 >= 0) { ym1o4 = ym1 / 4; - else { + } else { ym1o4 = - (int) (((unsigned int) -ym1) / 4); } #endif diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 82adf65..87216c2 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -495,8 +495,7 @@ Tcl_UtfToUniChar( * A three-byte-character lead-byte not followed by two trail-bytes * represents itself. */ - } - else if (byte < 0xF5) { + } else if (byte < 0xF5) { if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80) && ((src[3] & 0xC0) == 0x80)) { /* * Four-byte-character lead byte followed by three trail bytes. @@ -591,8 +590,7 @@ Tcl_UtfToChar16( * A three-byte-character lead-byte not followed by two trail-bytes * represents itself. */ - } - else if (byte < 0xF5) { + } else if (byte < 0xF5) { if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80)) { /* * Four-byte-character lead byte followed by at least two trail bytes. diff --git a/win/nmakehlp.c b/win/nmakehlp.c index 71d727f..fc40da4 100644 --- a/win/nmakehlp.c +++ b/win/nmakehlp.c @@ -718,11 +718,13 @@ static int LocateDependencyHelper(const char *dir, const char *keypath) int keylen, ret; WIN32_FIND_DATA finfo; - if (dir == NULL || keypath == NULL) + if (dir == NULL || keypath == NULL) { return 2; /* Have no real error reporting mechanism into nmake */ + } dirlen = strlen(dir); - if ((dirlen + 3) > sizeof(path)) + if ((dirlen + 3) > sizeof(path)) { return 2; + } strncpy(path, dir, dirlen); strncpy(path+dirlen, "\\*", 3); /* Including terminating \0 */ keylen = strlen(keypath); @@ -788,8 +790,9 @@ static int LocateDependency(const char *keypath) for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) { ret = LocateDependencyHelper(paths[i], keypath); - if (ret == 0) + if (ret == 0) { return ret; + } } return ret; } diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c index 4a9a2df..23652de 100644 --- a/win/tclWinConsole.c +++ b/win/tclWinConsole.c @@ -411,14 +411,12 @@ RingBufferIn( if (endSpace >= srcLen) { /* Everything fits at the back */ memmove(endSpaceStart + ringPtr->bufPtr, srcPtr, srcLen); - } - else { + } else { /* srcLen > endSpace */ memmove(endSpaceStart + ringPtr->bufPtr, srcPtr, endSpace); memmove(ringPtr->bufPtr, endSpace + srcPtr, srcLen - endSpace); } - } - else { + } else { /* No room at the back. Existing data wrap to front. */ RingSizeT wrapLen = ringPtr->start + ringPtr->length - ringPtr->capacity; @@ -468,8 +466,7 @@ RingBufferOut(RingBuffer *ringPtr, if (ringPtr->start <= (ringPtr->capacity - ringPtr->length)) { /* No content wrap around. So leadLen is entire content */ leadLen = ringPtr->length; - } - else { + } else { /* Content wraps around so lead segment stretches to end of buffer */ leadLen = ringPtr->capacity - ringPtr->start; } @@ -478,8 +475,7 @@ RingBufferOut(RingBuffer *ringPtr, memmove(dstPtr, ringPtr->start + ringPtr->bufPtr, dstCapacity); } ringPtr->start += dstCapacity; - } - else { + } else { RingSizeT wrapLen = dstCapacity - leadLen; if (dstPtr) { memmove(dstPtr, @@ -566,8 +562,7 @@ ReadConsoleChars( } *nCharsReadPtr = nRead; return 0; - } - else + } else return GetLastError(); } @@ -608,8 +603,7 @@ WriteConsoleChars( } *nCharsWrittenPtr = nCharsWritten; return 0; - } - else { + } else { return GetLastError(); } } @@ -793,8 +787,7 @@ ConsoleSetupProc( || handleInfoPtr->lastError != ERROR_SUCCESS) { block = 0; /* Input data available */ } - } - else if (chanInfoPtr->watchMask & TCL_WRITABLE) { + } else if (chanInfoPtr->watchMask & TCL_WRITABLE) { if (RingBufferHasFreeSpace(&handleInfoPtr->buffer)) { /* TCL_WRITABLE */ block = 0; /* Output space available */ @@ -876,8 +869,7 @@ ConsoleCheckProc( || handleInfoPtr->lastError != ERROR_SUCCESS) { needEvent = 1; /* Input data available or error/EOF */ } - } - else if (chanInfoPtr->watchMask & TCL_WRITABLE) { + } else if (chanInfoPtr->watchMask & TCL_WRITABLE) { if (RingBufferHasFreeSpace(&handleInfoPtr->buffer)) { needEvent = 1; /* Output space available */ } @@ -983,8 +975,7 @@ ConsoleCloseProc( && (GetStdHandle(STD_OUTPUT_HANDLE) != chanInfoPtr->handle) && (GetStdHandle(STD_ERROR_HANDLE) != chanInfoPtr->handle))) { closeHandle = 1; - } - else { + } else { closeHandle = 0; } @@ -1053,8 +1044,7 @@ ConsoleCloseProc( if (chanInfoPtr->numRefs > 1) { /* There may be references already on the event queue */ chanInfoPtr->numRefs -= 1; - } - else { + } else { ckfree(chanInfoPtr); } @@ -1131,8 +1121,7 @@ ConsoleInputProc( if (handleInfoPtr->lastError != 0) { if (handleInfoPtr->lastError == ERROR_INVALID_HANDLE) { numRead = 0; /* Treat as EOF */ - } - else { + } else { Tcl_WinConvertError(handleInfoPtr->lastError); handleInfoPtr->lastError = 0; *errorCode = Tcl_GetErrno(); @@ -1176,12 +1165,10 @@ ConsoleInputProc( Tcl_WinConvertError(lastError); *errorCode = Tcl_GetErrno(); return -1; - } - else if (numChars > 0) { + } else if (numChars > 0) { /* Successfully read something. */ return numChars * sizeof(WCHAR); - } - else { + } else { /* * Ctrl-C/Ctrl-Brk interrupt. Loop around to retry. * We have to reacquire the lock. No worried about handleInfoPtr @@ -1326,8 +1313,7 @@ ConsoleOutputProc( numWritten = -1; break; } - } - else { + } else { /* Direct output */ DWORD winStatus; HANDLE consoleHandle = handleInfoPtr->console; @@ -1340,8 +1326,7 @@ ConsoleOutputProc( &numWritten); if (winStatus == ERROR_SUCCESS) { return numWritten * sizeof(WCHAR); - } - else { + } else { Tcl_WinConvertError(winStatus); *errorCode = Tcl_GetErrno(); return -1; @@ -1420,15 +1405,13 @@ ConsoleEventProc( if (chanInfoPtr->watchMask & TCL_READABLE) { mask = TCL_READABLE; } - } - else { + } else { AcquireSRWLockShared(&handleInfoPtr->lock); /* Remember at most one of READABLE, WRITABLE set */ if ((chanInfoPtr->watchMask & TCL_READABLE) && RingBufferLength(&handleInfoPtr->buffer)) { mask = TCL_READABLE; - } - else if ((chanInfoPtr->watchMask & TCL_WRITABLE) + } else if ((chanInfoPtr->watchMask & TCL_WRITABLE) && RingBufferHasFreeSpace(&handleInfoPtr->buffer)) { /* Generate write event space available */ mask = TCL_WRITABLE; @@ -1454,14 +1437,14 @@ ConsoleEventProc( if (chanInfoPtr->numRefs > 1) { chanInfoPtr->numRefs -= 1; freeChannel = 0; - } - else { + } else { assert(chanInfoPtr->channel == NULL); freeChannel = 1; } - if (freeChannel) + if (freeChannel) { ckfree(chanInfoPtr); + } return 1; } @@ -1564,8 +1547,7 @@ ConsoleGetHandleProc( if (chanInfoPtr->handle == INVALID_HANDLE_VALUE) { return TCL_ERROR; - } - else { + } else { *handlePtr = chanInfoPtr->handle; return TCL_OK; } @@ -1684,8 +1666,7 @@ ConsoleReaderThread( inputOffset = 0; inputLen = 0; } - } - else { + } else { /* * On error, nothing but inform caller and wait * We do not want to exit until there are no client interps. @@ -1743,8 +1724,7 @@ ConsoleReaderThread( AcquireSRWLockExclusive(&handleInfoPtr->lock); if (error == 0) { inputLen *= sizeof(WCHAR); - } - else { + } else { /* * We only store the last error. It is up to channel * handlers whether to close or not in case of errors. @@ -1754,8 +1734,7 @@ ConsoleReaderThread( handleInfoPtr->console = INVALID_HANDLE_VALUE; } } - } - else { + } else { /* * Either no one was asking for data, or no data was available. * In the former case, wait until someone wakes us asking for @@ -2140,8 +2119,7 @@ TclWinOpenConsoleChannel( /* Why was priority being set on console input? Code smell */ SetThreadPriority(infoPtr->reader.thread, THREAD_PRIORITY_HIGHEST); #endif - } - else { + } else { /* Already checked permissions is WRITABLE if not READABLE */ /* TODO - enable ansi escape processing? */ } @@ -2157,8 +2135,7 @@ TclWinOpenConsoleChannel( if (handleInfoPtr == NULL) { /* Not found. Allocate one */ handleInfoPtr = AllocateConsoleHandleInfo(handle, permissions); - } - else { + } else { /* Found. Its direction (read/write) better be the same */ if (handleInfoPtr->permissions != permissions) { handleInfoPtr = NULL; @@ -2234,8 +2211,7 @@ ConsoleThreadActionProc( if (action == TCL_CHANNEL_THREAD_INSERT) { ConsoleInit(); /* Needed to set up event source handlers for this thread */ chanInfoPtr->threadId = Tcl_GetCurrentThread(); - } - else { + } else { chanInfoPtr->threadId = NULL; } } @@ -2398,8 +2374,7 @@ ConsoleGetOptionProc( Tcl_DStringAppendElement(dsPtr, "raw"); } } - } - else { + } else { /* * Output channel. Get option -winsize * Option is readonly and returned by [fconfigure chan -winsize] but not diff --git a/win/tclWinDde.c b/win/tclWinDde.c index 2570954..1c10c65 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -1789,9 +1789,9 @@ DdeObjCmd( } if (result == TCL_OK) { - if (objc == 1) + if (objc == 1) { objPtr = objv[0]; - else { + } else { objPtr = Tcl_ConcatObj(objc, objv); } if (riPtr->handlerPtr != NULL) { diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c index e262595..1134e12 100644 --- a/win/tclWinLoad.c +++ b/win/tclWinLoad.c @@ -114,10 +114,11 @@ TclpDlopen( * first error for reporting purposes. */ if (firstError == ERROR_MOD_NOT_FOUND || - firstError == ERROR_DLL_NOT_FOUND) + firstError == ERROR_DLL_NOT_FOUND) { lastError = GetLastError(); - else + } else { lastError = firstError; + } errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ", Tcl_GetString(pathPtr)); |