From 16b3adf662893e6db67e82fb1df01063e1315548 Mon Sep 17 00:00:00 2001 From: dkf Date: Tue, 19 Mar 2024 14:56:45 +0000 Subject: Fix indentation/brace usage style issues --- generic/tclArithSeries.c | 32 +++--- generic/tclAssembly.c | 1 - generic/tclBasic.c | 31 ++++-- generic/tclBinary.c | 3 +- generic/tclClock.c | 4 +- generic/tclCmdAH.c | 60 +++++------ generic/tclCmdIL.c | 28 ++--- generic/tclCmdMZ.c | 9 +- generic/tclCompCmds.c | 8 +- generic/tclCompCmdsSZ.c | 6 +- generic/tclCompile.c | 12 +-- generic/tclDictObj.c | 12 +-- generic/tclDisassemble.c | 4 +- generic/tclEncoding.c | 34 +++--- generic/tclEnsemble.c | 9 +- generic/tclEvent.c | 6 +- generic/tclExecute.c | 87 ++++++--------- generic/tclFCmd.c | 20 ++-- generic/tclFileName.c | 16 +-- generic/tclHash.c | 7 +- generic/tclIO.c | 120 +++++++++++---------- generic/tclIOCmd.c | 16 +-- generic/tclIORChan.c | 6 +- generic/tclIORTrans.c | 8 +- generic/tclIOUtil.c | 18 ++-- generic/tclIndexObj.c | 26 ++--- generic/tclListObj.c | 246 +++++++++++++++++++++--------------------- generic/tclLoad.c | 10 +- generic/tclOO.c | 5 +- generic/tclOOMethod.c | 5 +- generic/tclObj.c | 6 +- generic/tclParse.c | 2 +- generic/tclPathObj.c | 19 ++-- generic/tclProc.c | 9 +- generic/tclProcess.c | 121 ++++++++++++++------- generic/tclRegexp.c | 4 +- generic/tclScan.c | 2 +- generic/tclStrToD.c | 22 ++-- generic/tclStringObj.c | 40 ++++--- generic/tclStubInit.c | 10 +- generic/tclTestObj.c | 20 ++-- generic/tclTrace.c | 9 +- generic/tclUtf.c | 15 ++- generic/tclUtil.c | 39 +++---- generic/tclVar.c | 4 +- generic/tclZipfs.c | 158 ++++++++++++++------------- unix/tclLoadDyld.c | 16 ++- unix/tclUnixSock.c | 1 - unix/tclUnixTest.c | 2 +- unix/tclXtNotify.c | 2 +- unix/tclXtTest.c | 2 +- win/tclWinChan.c | 2 +- win/tclWinConsole.c | 274 ++++++++++++++++++++++------------------------- win/tclWinFCmd.c | 19 ++-- win/tclWinFile.c | 4 +- win/tclWinInit.c | 4 +- win/tclWinLoad.c | 2 +- win/tclWinNotify.c | 4 +- win/tclWinPipe.c | 2 +- win/tclWinReg.c | 3 +- win/tclWinSock.c | 6 +- win/tclWinTest.c | 9 +- 62 files changed, 852 insertions(+), 829 deletions(-) diff --git a/generic/tclArithSeries.c b/generic/tclArithSeries.c index 43a9995..50c8b13 100755 --- a/generic/tclArithSeries.c +++ b/generic/tclArithSeries.c @@ -339,7 +339,9 @@ NewArithSeriesInt(Tcl_WideInt start, Tcl_WideInt end, Tcl_WideInt step, Tcl_Wide ArithSeries *arithSeriesRepPtr; length = len>=0 ? len : -1; - if (length < 0) length = -1; + if (length < 0) { + length = -1; + } TclNewObj(arithSeriesObj); @@ -357,8 +359,9 @@ NewArithSeriesInt(Tcl_WideInt start, Tcl_WideInt end, Tcl_WideInt step, Tcl_Wide arithSeriesObj->internalRep.twoPtrValue.ptr1 = arithSeriesRepPtr; arithSeriesObj->internalRep.twoPtrValue.ptr2 = NULL; arithSeriesObj->typePtr = &arithSeriesType; - if (length > 0) + if (length > 0) { Tcl_InvalidateStringRep(arithSeriesObj); + } return arithSeriesObj; } @@ -644,7 +647,9 @@ TclArithSeriesObjIndex( * *---------------------------------------------------------------------- */ -Tcl_Size ArithSeriesObjLength(Tcl_Obj *arithSeriesObj) +Tcl_Size +ArithSeriesObjLength( + Tcl_Obj *arithSeriesObj) { ArithSeries *arithSeriesRepPtr = (ArithSeries*) arithSeriesObj->internalRep.twoPtrValue.ptr1; @@ -757,8 +762,7 @@ TclArithSeriesObjRange( toIdx = arithSeriesRepPtr->len-1; } - if (fromIdx > toIdx || - fromIdx >= arithSeriesRepPtr->len) { + if (fromIdx > toIdx || fromIdx >= arithSeriesRepPtr->len) { TclNewObj(*newObjPtr); return TCL_OK; } @@ -780,8 +784,7 @@ TclArithSeriesObjRange( TclArithSeriesObjStep(arithSeriesObj, &stepObj); Tcl_IncrRefCount(stepObj); - if (Tcl_IsShared(arithSeriesObj) || - ((arithSeriesObj->refCount > 1))) { + if (Tcl_IsShared(arithSeriesObj) || (arithSeriesObj->refCount > 1)) { int status = TclNewArithSeriesObj(NULL, newObjPtr, arithSeriesRepPtr->isDouble, startObj, endObj, stepObj, NULL); @@ -916,9 +919,7 @@ TclArithSeriesGetElements( *objcPtr = objc; } else { if (interp != NULL) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf("value is not an arithseries")); + Tcl_SetObjResult(interp, Tcl_ObjPrintf("value is not an arithseries")); Tcl_SetErrorCode(interp, "TCL", "VALUE", "UNKNOWN", (void *)NULL); } return TCL_ERROR; @@ -988,8 +989,7 @@ TclArithSeriesObjReverse( TclSetIntObj(stepObj, step); } - if (Tcl_IsShared(arithSeriesObj) || - ((arithSeriesObj->refCount > 1))) { + if (Tcl_IsShared(arithSeriesObj) || (arithSeriesObj->refCount > 1)) { Tcl_Obj *lenObj; TclNewIntObj(lenObj, len); if (TclNewArithSeriesObj(NULL, &resultObj, isDouble, @@ -1107,12 +1107,14 @@ UpdateStringOfArithSeries(Tcl_Obj *arithSeriesObjPtr) char *str = Tcl_GetStringFromObj(eleObj, &slen); strcpy(p, str); p[slen] = ' '; - p += slen+1; + p += slen + 1; Tcl_DecrRefCount(eleObj); } // else TODO: report error here? } - if (bytlen > 0) arithSeriesObjPtr->bytes[bytlen-1] = '\0'; - arithSeriesObjPtr->length = bytlen-1; + if (bytlen > 0) { + arithSeriesObjPtr->bytes[bytlen - 1] = '\0'; + } + arithSeriesObjPtr->length = bytlen - 1; } /* diff --git a/generic/tclAssembly.c b/generic/tclAssembly.c index ba2e5a7..b041670 100644 --- a/generic/tclAssembly.c +++ b/generic/tclAssembly.c @@ -986,7 +986,6 @@ TclCompileAssembleCmd( if (TCL_ERROR == TclAssembleCode(envPtr, tokenPtr[1].start, tokenPtr[1].size, TCL_EVAL_DIRECT)) { - Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (\"%.*s\" body, line %d)", (int)parsePtr->tokenPtr->size, parsePtr->tokenPtr->start, diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 5ec29f3..a2f4edc 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -300,12 +300,16 @@ typedef struct { * The built-in commands, and the functions that implement them: */ -int procObjCmd(void *clientData, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]) { +static int +procObjCmd( + void *clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ return Tcl_ProcObjCmd(clientData, interp, objc, objv); } - static const CmdInfo builtInCmds[] = { /* * Commands in the generic core. @@ -2689,7 +2693,9 @@ typedef struct { } CmdWrapperInfo; -static int cmdWrapperProc(void *clientData, +static int +cmdWrapperProc( + void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj * const *objv) @@ -2701,7 +2707,10 @@ static int cmdWrapperProc(void *clientData, return info->proc(info->clientData, interp, objc, objv); } -static void cmdWrapperDeleteProc(void *clientData) { +static void +cmdWrapperDeleteProc( + void *clientData) +{ CmdWrapperInfo *info = (CmdWrapperInfo *)clientData; clientData = info->deleteData; @@ -3277,7 +3286,9 @@ invokeObj2Command( return result; } -static int cmdWrapper2Proc(void *clientData, +static int +cmdWrapper2Proc( + void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]) @@ -5364,7 +5375,7 @@ TclEvalEx( /* Currently max command words in INT_MAX */ if (additionalObjsCount > INT_MAX || - objectsNeeded > (INT_MAX - additionalObjsCount)) { + objectsNeeded > (INT_MAX - additionalObjsCount)) { code = TclCommandWordLimitError(interp, -1); Tcl_DecrRefCount(objv[objectsUsed]); break; @@ -8469,7 +8480,8 @@ Tcl_NRCallObjProc( return TclNRRunCallbacks(interp, TCL_OK, rootPtr); } -int wrapperNRObjProc( +static int +wrapperNRObjProc( void *clientData, Tcl_Interp *interp, int objc, @@ -8536,7 +8548,8 @@ Tcl_NRCallObjProc2( *---------------------------------------------------------------------- */ -static int cmdWrapperNreProc( +static int +cmdWrapperNreProc( void *clientData, Tcl_Interp *interp, int objc, diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 152b21e..916ba4c 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -961,8 +961,7 @@ BinaryFormatCmd( * The macro evals its args more than once: avoid arg++ */ - if (TclListObjLength(interp, objv[arg], &listc - ) != TCL_OK) { + if (TclListObjLength(interp, objv[arg], &listc) != TCL_OK) { return TCL_ERROR; } diff --git a/generic/tclClock.c b/generic/tclClock.c index 83da0ef..b870f79 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -2083,7 +2083,9 @@ TzsetIfNecessary(void) wcscpy(tzWas, tzIsNow); } else if (tzIsNow == NULL && tzWas != NULL) { tzset(); - if (tzWas != (WCHAR *)INT2PTR(-1)) Tcl_Free(tzWas); + if (tzWas != (WCHAR *)INT2PTR(-1)) { + Tcl_Free(tzWas); + } tzWas = NULL; } Tcl_MutexUnlock(&clockMutex); diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 1268751..85d8a1c 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -62,7 +62,7 @@ static int GetStatBuf(Tcl_Interp *interp, Tcl_Obj *pathPtr, static const char * GetTypeFromMode(int mode); static int StoreStatData(Tcl_Interp *interp, Tcl_Obj *varName, Tcl_StatBuf *statPtr); -static int EachloopCmd(Tcl_Interp *interp, int collect, +static int EachloopCmd(Tcl_Interp *interp, int collect, int objc, Tcl_Obj *const objv[]); static Tcl_NRPostProc CatchObjCmdCallback; static Tcl_NRPostProc ExprCallback; @@ -424,7 +424,7 @@ TclInitEncodingCmd( *------------------------------------------------------------------------ */ static int -EncodingConvertParseOptions ( +EncodingConvertParseOptions( Tcl_Interp *interp, /* For error messages. May be NULL */ int objc, /* Number of arguments */ Tcl_Obj *const objv[], /* Argument objects as passed to command. */ @@ -452,11 +452,9 @@ EncodingConvertParseOptions ( */ if (objc == 1) { -numArgsError: /* ONLY jump here if nothing needs to be freed!!! */ - Tcl_WrongNumArgs(interp, - 1, - objv, - "?-profile profile? ?-failindex var? encoding data"); + numArgsError: /* ONLY jump here if nothing needs to be freed!!! */ + Tcl_WrongNumArgs(interp, 1, objv, + "?-profile profile? ?-failindex var? encoding data"); ((Interp *)interp)->flags |= INTERP_ALTERNATE_WRONG_ARGS; Tcl_WrongNumArgs(interp, 1, objv, "data"); return TCL_ERROR; @@ -469,9 +467,8 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */ } else { int argIndex; for (argIndex = 1; argIndex < (objc-2); ++argIndex) { - if (Tcl_GetIndexFromObj( - interp, objv[argIndex], options, "option", 0, &optIndex) - != TCL_OK) { + if (Tcl_GetIndexFromObj(interp, objv[argIndex], options, "option", + 0, &optIndex) != TCL_OK) { return TCL_ERROR; } if (++argIndex == (objc - 2)) { @@ -480,8 +477,7 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */ switch (optIndex) { case PROFILE: if (TclEncodingProfileNameToId(interp, - Tcl_GetString(objv[argIndex]), - &profile) != TCL_OK) { + Tcl_GetString(objv[argIndex]), &profile) != TCL_OK) { return TCL_ERROR; } break; @@ -491,8 +487,7 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */ } } /* Get encoding after opts so no need to free it on option error */ - if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) - != TCL_OK) { + if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) { return TCL_ERROR; } dataObj = objv[objc - 1]; @@ -537,9 +532,8 @@ EncodingConvertfromObjCmd( Tcl_Obj *failVarObj; Tcl_Size errorLocation; - if (EncodingConvertParseOptions( - interp, objc, objv, &encoding, &data, &flags, &failVarObj) - != TCL_OK) { + if (EncodingConvertParseOptions(interp, objc, objv, &encoding, &data, + &flags, &failVarObj) != TCL_OK) { return TCL_ERROR; } @@ -552,7 +546,7 @@ EncodingConvertfromObjCmd( return TCL_ERROR; } result = Tcl_ExternalToUtfDStringEx(interp, encoding, bytesPtr, length, flags, - &ds, failVarObj ? &errorLocation : NULL); + &ds, failVarObj ? &errorLocation : NULL); /* NOTE: ds must be freed beyond this point even on error */ switch (result) { case TCL_OK: @@ -583,11 +577,8 @@ EncodingConvertfromObjCmd( if (failVarObj) { Tcl_Obj *failIndex; TclNewIndexObj(failIndex, errorLocation); - if (Tcl_ObjSetVar2(interp, - failVarObj, - NULL, - failIndex, - TCL_LEAVE_ERR_MSG) == NULL) { + if (Tcl_ObjSetVar2(interp, failVarObj, NULL, failIndex, + TCL_LEAVE_ERR_MSG) == NULL) { Tcl_DStringFree(&ds); return TCL_ERROR; } @@ -630,16 +621,15 @@ EncodingConverttoObjCmd( Tcl_Obj *data; /* String to convert */ Tcl_DString ds; /* Buffer to hold the byte array */ Tcl_Encoding encoding; /* Encoding to use */ - Tcl_Size length; /* Length of the string being converted */ + Tcl_Size length; /* Length of the string being converted */ const char *stringPtr; /* Pointer to the first byte of the string */ int result; int flags; Tcl_Obj *failVarObj; Tcl_Size errorLocation; - if (EncodingConvertParseOptions( - interp, objc, objv, &encoding, &data, &flags, &failVarObj) - != TCL_OK) { + if (EncodingConvertParseOptions(interp, objc, objv, &encoding, &data, + &flags, &failVarObj) != TCL_OK) { return TCL_ERROR; } @@ -649,7 +639,7 @@ EncodingConverttoObjCmd( stringPtr = Tcl_GetStringFromObj(data, &length); result = Tcl_UtfToExternalDStringEx(interp, encoding, stringPtr, length, flags, - &ds, failVarObj ? &errorLocation : NULL); + &ds, failVarObj ? &errorLocation : NULL); /* NOTE: ds must be freed beyond this point even on error */ switch (result) { @@ -679,20 +669,18 @@ EncodingConverttoObjCmd( */ if (failVarObj) { Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); - if (Tcl_ObjSetVar2(interp, - failVarObj, - NULL, - failIndex, - TCL_LEAVE_ERR_MSG) == NULL) { + if (Tcl_ObjSetVar2(interp, failVarObj, NULL, failIndex, + TCL_LEAVE_ERR_MSG) == NULL) { Tcl_DStringFree(&ds); return TCL_ERROR; } } - Tcl_SetObjResult(interp, - Tcl_NewByteArrayObj((unsigned char*) Tcl_DStringValue(&ds), - Tcl_DStringLength(&ds))); + Tcl_SetObjResult(interp, Tcl_NewByteArrayObj( + (unsigned char*) Tcl_DStringValue(&ds), + Tcl_DStringLength(&ds))); Tcl_DStringFree(&ds); /* We're done with the encoding */ diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index fec8fcf..4474513 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -2174,9 +2174,8 @@ Tcl_JoinObjCmd( if (TclObjTypeHasProc(objv[1], getElementsProc)) { listLen = TclObjTypeLength(objv[1]); isAbstractList = (listLen ? 1 : 0); - if (listLen > 1 && - TclObjTypeGetElements(interp, objv[1], &listLen, &elemPtrs) - != TCL_OK) { + if (listLen > 1 && TclObjTypeGetElements(interp, objv[1], + &listLen, &elemPtrs) != TCL_OK) { return TCL_ERROR; } } else if (TclListObjGetElements(interp, objv[1], &listLen, @@ -2194,8 +2193,8 @@ Tcl_JoinObjCmd( Tcl_SetObjResult(interp, elemPtrs[0]); } else { Tcl_Obj *elemObj; - if (TclObjTypeIndex(interp, objv[1], 0, &elemObj) - != TCL_OK) { + + if (TclObjTypeIndex(interp, objv[1], 0, &elemObj) != TCL_OK) { return TCL_ERROR; } Tcl_SetObjResult(interp, elemObj); @@ -2289,6 +2288,7 @@ Tcl_LassignObjCmd( objv += 2; for (i = 0; i < objc && i < listObjc; ++i) { Tcl_Obj *elemObj; + if (Tcl_ListObjIndex(interp, listPtr, i, &elemObj) != TCL_OK) { return TCL_ERROR; } @@ -2299,8 +2299,8 @@ Tcl_LassignObjCmd( * the elemObj is stored in the var. See tests 6.{25,26} */ Tcl_IncrRefCount(elemObj); - if (Tcl_ObjSetVar2(interp, *objv++, NULL, elemObj, TCL_LEAVE_ERR_MSG) == - NULL) { + if (Tcl_ObjSetVar2(interp, *objv++, NULL, elemObj, + TCL_LEAVE_ERR_MSG) == NULL) { Tcl_DecrRefCount(elemObj); return TCL_ERROR; } @@ -2334,8 +2334,7 @@ Tcl_LassignObjCmd( interp, listPtr, fromIdx, toIdx, &resultObjPtr) != TCL_OK) { return TCL_ERROR; } - } - else { + } else { resultObjPtr = TclListObjRange( interp, listPtr, origListObjc - listObjc, origListObjc - 1); if (resultObjPtr == NULL) { @@ -3196,7 +3195,7 @@ Tcl_LreverseObjCmd( } if (Tcl_IsShared(objv[1]) - || ListObjRepIsShared(objv[1])) { /* Bug 1675044 */ + || ListObjRepIsShared(objv[1])) { /* Bug 1675044 */ Tcl_Obj *resultObj, **dataArray; ListRep listRep; @@ -4395,7 +4394,9 @@ Tcl_LseqObjCmd( done: // Free number arguments. while (--value_i>=0) { - if (numValues[value_i]) Tcl_DecrRefCount(numValues[value_i]); + if (numValues[value_i]) { + Tcl_DecrRefCount(numValues[value_i]); + } } // Free constants @@ -4904,8 +4905,7 @@ Tcl_LsortObjCmd( } else if (sortMode == SORTMODE_REAL) { double a; - if (Tcl_GetDoubleFromObj(sortInfo.interp, indexPtr, - &a) != TCL_OK) { + if (Tcl_GetDoubleFromObj(sortInfo.interp, indexPtr, &a) != TCL_OK) { sortInfo.resultCode = TCL_ERROR; goto done; } @@ -5368,7 +5368,7 @@ DictionaryCompare( int secondaryDiff = 0; while (1) { - if (isdigit(UCHAR(*right)) /* INTL: digit */ + if (isdigit(UCHAR(*right)) /* INTL: digit */ && isdigit(UCHAR(*left))) { /* INTL: digit */ /* * There are decimal numbers embedded in the two strings. Compare diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index a887aaf..56d4cca 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -30,9 +30,9 @@ static Tcl_NRPostProc TryPostFinal; static Tcl_NRPostProc TryPostHandler; static int UniCharIsAscii(int character); static int UniCharIsHexDigit(int character); -static int StringCmpOpts(Tcl_Interp *interp, int objc, - Tcl_Obj *const objv[], int *nocase, - Tcl_Size *reqlength); +static int StringCmpOpts(Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[], int *nocase, + Tcl_Size *reqlength); /* * Default set of characters to trim in [string trim] and friends. This is a @@ -2241,8 +2241,7 @@ StringMatchCmd( Tcl_Size length; const char *string = Tcl_GetStringFromObj(objv[1], &length); - if ((length > 1) && - strncmp(string, "-nocase", length) == 0) { + if ((length > 1) && strncmp(string, "-nocase", length) == 0) { nocase = TCL_MATCH_NOCASE; } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf( diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index 818b96b..98b1ec6 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -772,8 +772,8 @@ TclCompileClockClicksCmd( */ tokenPtr = TokenAfter(parsePtr->tokenPtr); if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD - || tokenPtr[1].size < 4 - || tokenPtr[1].size > 13) { + || tokenPtr[1].size < 4 + || tokenPtr[1].size > 13) { return TCL_ERROR; } else if (!strncmp(tokenPtr[1].start, "-microseconds", tokenPtr[1].size)) { @@ -3570,8 +3570,8 @@ TclPushVarName( */ simpleVarName = 0; - for (p = varTokenPtr[1].start, - last = p + varTokenPtr[1].size; p < last; p++) { + for (p = varTokenPtr[1].start, last = p + varTokenPtr[1].size; + p < last; p++) { if (*p == '(') { simpleVarName = 1; break; diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c index b25862f..5f221bd 100644 --- a/generic/tclCompCmdsSZ.c +++ b/generic/tclCompCmdsSZ.c @@ -42,11 +42,11 @@ static int CompileUnaryOpCmd(Tcl_Interp *interp, static void IssueSwitchChainedTests(Tcl_Interp *interp, CompileEnv *envPtr, int mode, int noCase, Tcl_Size numWords, Tcl_Token **bodyToken, - Tcl_Size *bodyLines, Tcl_Size **bodyNext); + Tcl_Size *bodyLines, Tcl_Size **bodyNext); static void IssueSwitchJumpTable(Tcl_Interp *interp, CompileEnv *envPtr, int numWords, - Tcl_Token **bodyToken, Tcl_Size *bodyLines, - Tcl_Size **bodyContLines); + Tcl_Token **bodyToken, Tcl_Size *bodyLines, + Tcl_Size **bodyContLines); static int IssueTryClausesInstructions(Tcl_Interp *interp, CompileEnv *envPtr, Tcl_Token *bodyToken, int numHandlers, int *matchCodes, diff --git a/generic/tclCompile.c b/generic/tclCompile.c index e321fc7..9866ce2 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -2182,7 +2182,7 @@ TclCompileScript( */ if (iPtr->numLevels / 5 > iPtr->maxNestingDepth / 4) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "too many nested compilations (infinite loop?)", -1)); + "too many nested compilations (infinite loop?)", -1)); Tcl_SetErrorCode(interp, "TCL", "LIMIT", "STACK", (void *)NULL); TclCompileSyntaxError(interp, envPtr); return; @@ -2200,10 +2200,10 @@ TclCompileScript( * Note this gets -errorline as 1. Not worth figuring out which line * crosses the limit to get -errorline for this error case. */ - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("Script length %" TCL_SIZE_MODIFIER - "d exceeds max permitted length %d.", - numBytes, INT_MAX-1)); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Script length %" TCL_SIZE_MODIFIER + "d exceeds max permitted length %d.", + numBytes, INT_MAX-1)); Tcl_SetErrorCode(interp, "TCL", "LIMIT", "SCRIPTLENGTH", (void *)NULL); TclCompileSyntaxError(interp, envPtr); return; @@ -2507,7 +2507,7 @@ TclCompileTokens( */ if ((length == 1) && (buffer[0] == ' ') && - (tokenPtr->start[1] == '\n')) { + (tokenPtr->start[1] == '\n')) { if (isLiteral) { int clPos = Tcl_DStringLength(&textBuffer); diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index 43f003b..8b7bc3d 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -3844,7 +3844,7 @@ DictAsListLength( int literal; if (TCL_OK != TclFindElement(NULL, nextElem, limit - nextElem, - &elemStart, &nextElem, &elemSize, &literal)) { + &elemStart, &nextElem, &elemSize, &literal)) { Tcl_DecrRefCount(elemPtr); return 0; } @@ -3854,14 +3854,14 @@ DictAsListLength( TclInvalidateStringRep(elemPtr); check = Tcl_InitStringRep(elemPtr, literal ? elemStart : NULL, - elemSize); + elemSize); if (elemSize && check == NULL) { Tcl_DecrRefCount(elemPtr); return 0; } if (!literal) { Tcl_InitStringRep(elemPtr, NULL, - TclCopyAndCollapse(elemSize, elemStart, check)); + TclCopyAndCollapse(elemSize, elemStart, check)); } llen++; } @@ -3916,7 +3916,7 @@ DictAsListIndex( int literal; if (TCL_OK != TclFindElement(NULL, nextElem, limit - nextElem, - &elemStart, &nextElem, &elemSize, &literal)) { + &elemStart, &nextElem, &elemSize, &literal)) { Tcl_DecrRefCount(elemPtr); return 0; } @@ -3926,7 +3926,7 @@ DictAsListIndex( TclInvalidateStringRep(elemPtr); check = Tcl_InitStringRep(elemPtr, literal ? elemStart : NULL, - elemSize); + elemSize); if (elemSize && check == NULL) { Tcl_DecrRefCount(elemPtr); if (interp) { @@ -3936,7 +3936,7 @@ DictAsListIndex( } if (!literal) { Tcl_InitStringRep(elemPtr, NULL, - TclCopyAndCollapse(elemSize, elemStart, check)); + TclCopyAndCollapse(elemSize, elemStart, check)); } if (llen == index) { *elemObjPtr = elemPtr; diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index 527f78f..1a41562 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -778,9 +778,9 @@ TclGetInnerContext( if (!objPtr) { Tcl_Panic("InnerContext: bad tos -- appending null object"); } - if ((objPtr->refCount<=0) + if ((objPtr->refCount <= 0) #ifdef TCL_MEM_DEBUG - || (objPtr->refCount==0x61616161) + || (objPtr->refCount == 0x61616161) #endif ) { Tcl_Panic("InnerContext: bad tos -- appending freed object %p", diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index f60f949..1b71026 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -1236,7 +1236,7 @@ Tcl_ExternalToUtfDStringEx( * and loop. Otherwise, return the result we got. */ if ((result != TCL_CONVERT_NOSPACE) && - !(result == TCL_CONVERT_MULTIBYTE && (flags & TCL_ENCODING_END))) { + !(result == TCL_CONVERT_MULTIBYTE && (flags & TCL_ENCODING_END))) { Tcl_Size nBytesProcessed = (src - srcStart); Tcl_DStringSetLength(dstPtr, soFar); @@ -1251,14 +1251,12 @@ Tcl_ExternalToUtfDStringEx( if (result != TCL_OK && interp != NULL) { char buf[TCL_INTEGER_SPACE]; snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "d", nBytesProcessed); - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf("unexpected byte sequence starting at index %" - TCL_SIZE_MODIFIER "d: '\\x%02X'", - nBytesProcessed, - UCHAR(srcStart[nBytesProcessed]))); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "unexpected byte sequence starting at index %" + TCL_SIZE_MODIFIER "d: '\\x%02X'", + nBytesProcessed, UCHAR(srcStart[nBytesProcessed]))); Tcl_SetErrorCode( - interp, "TCL", "ENCODING", "ILLEGALSEQUENCE", buf, (void *)NULL); + interp, "TCL", "ENCODING", "ILLEGALSEQUENCE", buf, (void *)NULL); } } if (result != TCL_OK) { @@ -1563,7 +1561,7 @@ Tcl_UtfToExternalDStringEx( * and loop. Otherwise, return the result we got. */ if ((result != TCL_CONVERT_NOSPACE) && - !(result == TCL_CONVERT_MULTIBYTE && (flags & TCL_ENCODING_END))) { + !(result == TCL_CONVERT_MULTIBYTE && (flags & TCL_ENCODING_END))) { Tcl_Size nBytesProcessed = (src - srcStart); Tcl_Size i = soFar + encodingPtr->nullSize - 1; /* Loop as DStringSetLength only stores one nul byte at a time */ @@ -1582,17 +1580,15 @@ Tcl_UtfToExternalDStringEx( Tcl_Size pos = Tcl_NumUtfChars(srcStart, nBytesProcessed); int ucs4; char buf[TCL_INTEGER_SPACE]; + Tcl_UtfToUniChar(&srcStart[nBytesProcessed], &ucs4); snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "d", nBytesProcessed); - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf( + Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unexpected character at index %" TCL_SIZE_MODIFIER "u: 'U+%06X'", - pos, - ucs4)); + pos, ucs4)); Tcl_SetErrorCode(interp, "TCL", "ENCODING", "ILLEGALSEQUENCE", - buf, (void *)NULL); + buf, (void *)NULL); } } if (result != TCL_OK) { @@ -4337,10 +4333,8 @@ TclEncodingProfileNameToId( } } if (interp) { - Tcl_Obj *errorObj; /* This code assumes at least two profiles :-) */ - errorObj = - Tcl_ObjPrintf("bad profile name \"%s\": must be", + Tcl_Obj *errorObj = Tcl_ObjPrintf("bad profile name \"%s\": must be", profileName); for (i = 0; i < (numProfiles - 1); ++i) { Tcl_AppendStringsToObj( @@ -4384,9 +4378,7 @@ TclEncodingProfileIdToName( } } if (interp) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf( + Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Internal error. Bad profile id \"%d\".", profileValue)); Tcl_SetErrorCode( diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 051eb7f..f4d4504 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -567,8 +567,7 @@ TclNamespaceEnsembleCmd( continue; } do { - if (TclListObjLength(interp, listObj, &len - ) != TCL_OK) { + if (TclListObjLength(interp, listObj, &len) != TCL_OK) { Tcl_DictObjDone(&search); if (patchedDict) { Tcl_DecrRefCount(patchedDict); @@ -2212,9 +2211,9 @@ TclSpellFix( TclNRAddCallback(interp, TclNRReleaseValues, fix, NULL, NULL, NULL); } -Tcl_Obj *const *TclEnsembleGetRewriteValues( - Tcl_Interp *interp /* Current interpreter. */ -) +Tcl_Obj *const * +TclEnsembleGetRewriteValues( + Tcl_Interp *interp) /* Current interpreter. */ { Interp *iPtr = (Interp *) interp; Tcl_Obj *const *origObjv = iPtr->ensembleRewrite.sourceObjs; diff --git a/generic/tclEvent.c b/generic/tclEvent.c index 54fe8dc..23925f2 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -1609,7 +1609,7 @@ Tcl_VwaitObjCmd( goto needArg; } if (TclGetChannelFromObj(interp, objv[i], &chan, &mode, 0) - != TCL_OK) { + != TCL_OK) { result = TCL_ERROR; goto done; } @@ -1633,7 +1633,7 @@ Tcl_VwaitObjCmd( goto needArg; } if (TclGetChannelFromObj(interp, objv[i], &chan, &mode, 0) - != TCL_OK) { + != TCL_OK) { result = TCL_ERROR; goto done; } @@ -1657,7 +1657,7 @@ Tcl_VwaitObjCmd( endOfOptionLoop: if ((mask & (TCL_FILE_EVENTS | TCL_IDLE_EVENTS | - TCL_TIMER_EVENTS | TCL_WINDOW_EVENTS)) == 0) { + TCL_TIMER_EVENTS | TCL_WINDOW_EVENTS)) == 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "can't wait: would block forever", -1)); Tcl_SetErrorCode(interp, "TCL", "EVENT", "NO_SOURCES", (void *)NULL); diff --git a/generic/tclExecute.c b/generic/tclExecute.c index fddceb5..ac27a87 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -2281,7 +2281,7 @@ TEBCresume( goto instLoadScalar1; } else if (inst == INST_PUSH1) { PUSH_OBJECT(codePtr->objArrayPtr[TclGetUInt1AtPtr(pc+1)]); - TRACE_WITH_OBJ(("%u => ", TclGetUInt1AtPtr(pc+1)), OBJ_AT_TOS); + TRACE_WITH_OBJ(("%u => ", TclGetUInt1AtPtr(pc + 1)), OBJ_AT_TOS); inst = *(pc += 2); goto peepholeStart; } else if (inst == INST_START_CMD) { @@ -2289,11 +2289,11 @@ TEBCresume( * Peephole: do not run INST_START_CMD, just skip it */ - iPtr->cmdCount += TclGetUInt4AtPtr(pc+5); + iPtr->cmdCount += TclGetUInt4AtPtr(pc + 5); if (checkInterp) { if (((codePtr->compileEpoch != iPtr->compileEpoch) || - (codePtr->nsEpoch != iPtr->varFramePtr->nsPtr->resolverEpoch)) && - !(codePtr->flags & TCL_BYTECODE_PRECOMPILED)) { + (codePtr->nsEpoch != iPtr->varFramePtr->nsPtr->resolverEpoch)) && + !(codePtr->flags & TCL_BYTECODE_PRECOMPILED)) { goto instStartCmdFailed; } checkInterp = 0; @@ -4763,17 +4763,13 @@ TEBCresume( { Tcl_Size value2Length; Tcl_Obj *indexListPtr = value2Ptr; + if ((TclListObjGetElements(interp, valuePtr, &objc, &objv) == TCL_OK) - && ( - !TclHasInternalRep(value2Ptr, &tclListType) - || - ((Tcl_ListObjLength(interp,value2Ptr,&value2Length), + && (!TclHasInternalRep(value2Ptr, &tclListType) + || (Tcl_ListObjLength(interp, value2Ptr, &value2Length), value2Length == 1 ? (indexListPtr = TclListObjGetElement(value2Ptr, 0), 1) - : 0 - )) - ) - ) { + : 0))) { int code; /* increment the refCount of value2Ptr because TclListObjGetElement may @@ -5197,9 +5193,8 @@ TEBCresume( DECACHE_STACK_INFO(); - if (TclGetIntForIndexM( - interp, fromIdxObj, length - end_indicator, &fromIdx) - != TCL_OK) { + if (TclGetIntForIndexM(interp, fromIdxObj, length - end_indicator, + &fromIdx) != TCL_OK) { CACHE_STACK_INFO(); TRACE_ERROR(interp); goto gotError; @@ -5211,9 +5206,8 @@ TEBCresume( } numToDelete = 0; if (toIdxObj) { - if (TclGetIntForIndexM( - interp, toIdxObj, length - end_indicator, &toIdx) - != TCL_OK) { + if (TclGetIntForIndexM(interp, toIdxObj, length - end_indicator, + &toIdx) != TCL_OK) { CACHE_STACK_INFO(); TRACE_ERROR(interp); goto gotError; @@ -5232,13 +5226,8 @@ TEBCresume( if (Tcl_IsShared(valuePtr)) { objResultPtr = Tcl_DuplicateObj(valuePtr); - if (Tcl_ListObjReplace(interp, - objResultPtr, - fromIdx, - numToDelete, - numNewElems, - &OBJ_AT_DEPTH(numNewElems - 1)) - != TCL_OK) { + if (Tcl_ListObjReplace(interp, objResultPtr, fromIdx, numToDelete, + numNewElems, &OBJ_AT_DEPTH(numNewElems - 1)) != TCL_OK) { TRACE_ERROR(interp); Tcl_DecrRefCount(objResultPtr); goto gotError; @@ -5246,13 +5235,8 @@ TEBCresume( TRACE_APPEND(("\"%.30s\"\n", O2S(objResultPtr))); NEXT_INST_V(6, opnd, 1); } else { - if (Tcl_ListObjReplace(interp, - valuePtr, - fromIdx, - numToDelete, - numNewElems, - &OBJ_AT_DEPTH(numNewElems - 1)) - != TCL_OK) { + if (Tcl_ListObjReplace(interp, valuePtr, fromIdx, numToDelete, + numNewElems, &OBJ_AT_DEPTH(numNewElems - 1)) != TCL_OK) { TRACE_ERROR(interp); goto gotError; } @@ -5437,14 +5421,12 @@ TEBCresume( slength = Tcl_GetCharLength(OBJ_AT_DEPTH(2)) - 1; DECACHE_STACK_INFO(); - if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, - &fromIdx) != TCL_OK) { + if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, &fromIdx) != TCL_OK) { CACHE_STACK_INFO(); TRACE_ERROR(interp); goto gotError; } - if (TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, - &toIdx) != TCL_OK) { + if (TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, &toIdx) != TCL_OK) { CACHE_STACK_INFO(); TRACE_ERROR(interp); goto gotError; @@ -5496,10 +5478,8 @@ TEBCresume( TRACE(("\"%.20s\" %s %s \"%.20s\" => ", O2S(valuePtr), O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), O2S(value3Ptr))); DECACHE_STACK_INFO(); - if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, - &fromIdx) != TCL_OK - || TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, - &toIdx) != TCL_OK) { + if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, &fromIdx) != TCL_OK + || TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, &toIdx) != TCL_OK) { CACHE_STACK_INFO(); TclDecrRefCount(value3Ptr); TRACE_ERROR(interp); @@ -5511,9 +5491,7 @@ TEBCresume( TclDecrRefCount(OBJ_AT_TOS); (void) POP_OBJECT(); - if ((toIdx < 0) || - (fromIdx > slength) || - (toIdx < fromIdx)) { + if ((toIdx < 0) || (fromIdx > slength) || (toIdx < fromIdx)) { TRACE_APPEND(("\"%.30s\"\n", O2S(valuePtr))); TclDecrRefCount(value3Ptr); NEXT_INST_F(1, 0, 0); @@ -5583,10 +5561,10 @@ TEBCresume( end = ustring1 + slength; for (; ustring1 < end; ustring1++) { if ((*ustring1 == *ustring2) && - /* Fix bug [69218ab7b]: restrict max compare length. */ - ((end-ustring1) >= length2) && (length2==1 || - memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * length2) - == 0)) { + /* Fix bug [69218ab7b]: restrict max compare length. */ + ((end - ustring1) >= length2) && (length2 == 1 || + memcmp(ustring1, ustring2, + sizeof(Tcl_UniChar) * length2) == 0)) { if (p != ustring1) { Tcl_AppendUnicodeToObj(objResultPtr, p, ustring1-p); p = ustring1 + length2; @@ -7168,7 +7146,6 @@ TEBCresume( searchPtr = (Tcl_DictSearch *)Tcl_Alloc(sizeof(Tcl_DictSearch)); if (Tcl_DictObjFirst(interp, dictPtr, searchPtr, &keyPtr, &valuePtr, &done) != TCL_OK) { - /* * dictPtr is no longer on the stack, and we're not * moving it into the internalrep of an iterator. We need @@ -8206,9 +8183,8 @@ ExecuteExtendedBinaryMathOp( if ((type1 == TCL_NUMBER_INT) && ((size_t)shift < CHAR_BIT*sizeof(Tcl_WideInt))) { w1 = *((const Tcl_WideInt *)ptr1); - if (!((w1>0 ? w1 : ~w1) - & -(((Tcl_WideUInt)1) - << (CHAR_BIT*sizeof(Tcl_WideInt) - 1 - shift)))) { + if (!((w1 > 0 ? w1 : ~w1) & -( + ((Tcl_WideUInt)1) << (CHAR_BIT*sizeof(Tcl_WideInt) - 1 - shift)))) { WIDE_RESULT((Tcl_WideUInt)w1 << shift); } } @@ -8599,8 +8575,7 @@ ExecuteExtendedBinaryMathOp( switch (opcode) { case INST_ADD: wResult = (Tcl_WideInt)((Tcl_WideUInt)w1 + (Tcl_WideUInt)w2); - if ((type1 == TCL_NUMBER_INT) || (type2 == TCL_NUMBER_INT)) - { + if ((type1 == TCL_NUMBER_INT) || (type2 == TCL_NUMBER_INT)) { /* * Check for overflow. */ @@ -8613,8 +8588,7 @@ ExecuteExtendedBinaryMathOp( case INST_SUB: wResult = (Tcl_WideInt)((Tcl_WideUInt)w1 - (Tcl_WideUInt)w2); - if ((type1 == TCL_NUMBER_INT) || (type2 == TCL_NUMBER_INT)) - { + if ((type1 == TCL_NUMBER_INT) || (type2 == TCL_NUMBER_INT)) { /* * Must check for overflow. The macro tests for overflows * in sums by looking at the sign bits. As we have a @@ -9077,8 +9051,7 @@ ValidatePcAndStackTop( opCode, relativePc); Tcl_Panic("TclNRExecuteByteCode execution failure: bad opcode"); } - if (checkStack && - (stackTop > stackUpperBound)) { + if (checkStack && (stackTop > stackUpperBound)) { Tcl_Size numChars; const char *cmd = GetSrcInfoForPc(pc, codePtr, &numChars, NULL, NULL); diff --git a/generic/tclFCmd.c b/generic/tclFCmd.c index c97997d..0285323 100644 --- a/generic/tclFCmd.c +++ b/generic/tclFCmd.c @@ -1247,12 +1247,12 @@ TclFileLinkCmd( if (Tcl_FSConvertToPathType(interp, objv[index]) != TCL_OK) { return TCL_ERROR; } - if (Tcl_UtfToExternalDStringEx(interp, TCLFSENCODING, TclGetString(objv[index]), - TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) { + if (Tcl_UtfToExternalDStringEx(interp, TCLFSENCODING, TclGetString(objv[index]), + TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) { + Tcl_DStringFree(&ds); + return TCL_ERROR; + } Tcl_DStringFree(&ds); - return TCL_ERROR; - } - Tcl_DStringFree(&ds); /* * Create link from source to target. @@ -1310,12 +1310,12 @@ TclFileLinkCmd( if (Tcl_FSConvertToPathType(interp, objv[index]) != TCL_OK) { return TCL_ERROR; } - if (Tcl_UtfToExternalDStringEx(interp, TCLFSENCODING, TclGetString(objv[index]), - TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) { + if (Tcl_UtfToExternalDStringEx(interp, TCLFSENCODING, TclGetString(objv[index]), + TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) { + Tcl_DStringFree(&ds); + return TCL_ERROR; + } Tcl_DStringFree(&ds); - return TCL_ERROR; - } - Tcl_DStringFree(&ds); /* * Read link diff --git a/generic/tclFileName.c b/generic/tclFileName.c index 5e167c7..baa915d 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.c @@ -113,14 +113,14 @@ ExtractWinRoot( { int extended = 0; - if ( (path[0] == '/' || path[0] == '\\') - && (path[1] == '/' || path[1] == '\\') - && (path[2] == '?') - && (path[3] == '/' || path[3] == '\\')) { + if ( (path[0] == '/' || path[0] == '\\') + && (path[1] == '/' || path[1] == '\\') + && (path[2] == '?') + && (path[3] == '/' || path[3] == '\\')) { extended = 1; path = path + 4; if (path[0] == 'U' && path[1] == 'N' && path[2] == 'C' - && (path[3] == '/' || path[3] == '\\')) { + && (path[3] == '/' || path[3] == '\\')) { extended = 2; path = path + 4; } @@ -583,7 +583,7 @@ Tcl_SplitPath( for (i = 0; i < *argcPtr; i++) { (*argvPtr)[i] = p; - for (; *(p++)!='\0'; ); + while (*(p++) != '\0'); } (*argvPtr)[i] = NULL; @@ -823,8 +823,8 @@ TclpNativeJoinPath( if (length != 0) { if ((p[0] == '.') && (p[1] == '/') && - (tclPlatform==TCL_PLATFORM_WINDOWS) && isalpha(UCHAR(p[2])) - && (p[3] == ':')) { + (tclPlatform==TCL_PLATFORM_WINDOWS) && isalpha(UCHAR(p[2])) + && (p[3] == ':')) { p += 2; } } diff --git a/generic/tclHash.c b/generic/tclHash.c index c45b6c3..d024ecc 100644 --- a/generic/tclHash.c +++ b/generic/tclHash.c @@ -36,7 +36,7 @@ static Tcl_HashEntry * AllocArrayEntry(Tcl_HashTable *tablePtr, void *keyPtr); static int CompareArrayKeys(void *keyPtr, Tcl_HashEntry *hPtr); -static size_t HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr); +static size_t HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr); /* * Prototypes for the string hash key methods. @@ -45,7 +45,7 @@ static size_t HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr); static Tcl_HashEntry * AllocStringEntry(Tcl_HashTable *tablePtr, void *keyPtr); static int CompareStringKeys(void *keyPtr, Tcl_HashEntry *hPtr); -static size_t HashStringKey(Tcl_HashTable *tablePtr, void *keyPtr); +static size_t HashStringKey(Tcl_HashTable *tablePtr, void *keyPtr); /* * Function prototypes for static functions in this file: @@ -286,8 +286,7 @@ CreateHashEntry( } /* if keys pointers or values are equal */ if ((key == hPtr->key.oneWordValue) - || compareKeysProc((void *) key, hPtr) - ) { + || compareKeysProc((void *) key, hPtr)) { if (newPtr) { *newPtr = 0; } diff --git a/generic/tclIO.c b/generic/tclIO.c index 75427de..df9f665 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -28,7 +28,7 @@ typedef struct ChannelHandler { int mask; /* Mask of desired events. */ Tcl_ChannelProc *proc; /* Procedure to call in the type of * Tcl_CreateChannelHandler. */ - void *clientData; /* Argument to pass to procedure. */ + void *clientData; /* Argument to pass to procedure. */ struct ChannelHandler *nextPtr; /* Next one in list of registered handlers. */ } ChannelHandler; @@ -50,11 +50,12 @@ typedef struct ChannelHandler { */ typedef struct NextChannelHandler { - ChannelHandler *nextHandlerPtr; /* The next handler to be invoked in - * this invocation. */ + ChannelHandler *nextHandlerPtr; + /* The next handler to be invoked in + * this invocation. */ struct NextChannelHandler *nestedHandlerPtr; - /* Next nested invocation of - * Tcl_NotifyChannel. */ + /* Next nested invocation of + * Tcl_NotifyChannel. */ } NextChannelHandler; /* @@ -103,7 +104,7 @@ typedef struct CopyState { Tcl_Interp *interp; /* Interp that started the copy. */ Tcl_Obj *cmdPtr; /* Command to be invoked at completion. */ Tcl_Size bufSize; /* Size of appended buffer. */ - char buffer[TCLFLEXARRAY]; /* Copy buffer, this must be the last + char buffer[TCLFLEXARRAY]; /* Copy buffer, this must be the last * field. */ } CopyState; @@ -141,10 +142,11 @@ static Tcl_ThreadDataKey dataKey; */ typedef struct CloseCallback { - Tcl_CloseProc *proc; /* The procedure to call. */ + Tcl_CloseProc *proc; /* The procedure to call. */ void *clientData; /* Arbitrary one-word data to pass - * to the callback. */ - struct CloseCallback *nextPtr; /* For chaining close callbacks. */ + * to the callback. */ + struct CloseCallback *nextPtr; + /* For chaining close callbacks. */ } CloseCallback; /* @@ -174,7 +176,7 @@ static int CloseWrite(Tcl_Interp *interp, Channel *chanPtr); static void CommonGetsCleanup(Channel *chanPtr); static int CopyData(CopyState *csPtr, int mask); static void DeleteTimerHandler(ChannelState *statePtr); -int Lossless(ChannelState *inStatePtr, +static int Lossless(ChannelState *inStatePtr, ChannelState *outStatePtr, long long toRead); static int MoveBytes(CopyState *csPtr); @@ -617,7 +619,7 @@ TclFinalizeIOSubsystem(void) continue; } if (!GotFlag(statePtr, CHANNEL_INCLOSE | CHANNEL_CLOSED ) - || GotFlag(statePtr, BG_FLUSH_SCHEDULED)) { + || GotFlag(statePtr, BG_FLUSH_SCHEDULED)) { ResetFlag(statePtr, BG_FLUSH_SCHEDULED); active = 1; break; @@ -4264,8 +4266,8 @@ WillWrite( { int inputBuffered; - if (((Tcl_ChannelWideSeekProc(chanPtr->typePtr) != NULL) - ) && ((inputBuffered = Tcl_InputBuffered((Tcl_Channel) chanPtr)) > 0)){ + if ((Tcl_ChannelWideSeekProc(chanPtr->typePtr) != NULL) + && ((inputBuffered = Tcl_InputBuffered((Tcl_Channel) chanPtr)) > 0)){ int ignore; DiscardInputQueued(chanPtr->state, 0); @@ -4286,8 +4288,8 @@ WillRead( Tcl_SetErrno(EINVAL); return -1; } - if (((Tcl_ChannelWideSeekProc(chanPtr->typePtr) != NULL) - ) && (Tcl_OutputBuffered((Tcl_Channel) chanPtr) > 0)) { + if ((Tcl_ChannelWideSeekProc(chanPtr->typePtr) != NULL) + && (Tcl_OutputBuffered((Tcl_Channel) chanPtr) > 0)) { /* * CAVEAT - The assumption here is that FlushChannel() will push out * the bytes of any writes that are in progress. Since this is a @@ -4299,7 +4301,7 @@ WillRead( */ if (FlushChannel(NULL, chanPtr, 0) != 0) { - return -1; + return -1; } } return 0; @@ -4403,14 +4405,11 @@ Write( * current output encoding and strict encoding is active. */ - if ( - (result == TCL_CONVERT_UNKNOWN || result == TCL_CONVERT_SYNTAX) - || - /* - * We're reading from invalid/incomplete UTF-8. - */ - ((result != TCL_OK) && (srcRead + dstWrote == 0)) - ) { + if ((result == TCL_CONVERT_UNKNOWN || result == TCL_CONVERT_SYNTAX) || + /* + * We're reading from invalid/incomplete UTF-8. + */ + ((result != TCL_OK) && (srcRead + dstWrote == 0))) { encodingError = 1; result = TCL_OK; } @@ -6249,7 +6248,9 @@ ReadChars( int factor = *factorPtr; int dstLimit = TCL_UTF_MAX - 1 + toRead * factor / UTF_EXPANSION_FACTOR; - if (dstLimit <= 0) dstLimit = INT_MAX; /* avoid overflow */ + if (dstLimit <= 0) { + dstLimit = INT_MAX; /* avoid overflow */ + } (void) Tcl_GetStringFromObj(objPtr, &numBytes); TclAppendUtfToUtf(objPtr, NULL, dstLimit); if (toRead == srcLen) { @@ -6306,12 +6307,8 @@ ReadChars( flags, &statePtr->inputEncodingState, dst, dstLimit, &srcRead, &dstDecoded, &numChars); - if (code == TCL_CONVERT_UNKNOWN || code == TCL_CONVERT_SYNTAX - || ( - code == TCL_CONVERT_MULTIBYTE - && GotFlag(statePtr, CHANNEL_EOF - )) - ) { + if (code == TCL_CONVERT_UNKNOWN || code == TCL_CONVERT_SYNTAX || + (code == TCL_CONVERT_MULTIBYTE && GotFlag(statePtr, CHANNEL_EOF))) { SetFlag(statePtr, CHANNEL_ENCODING_ERROR); code = TCL_OK; } @@ -6686,23 +6683,28 @@ TranslateInputEOL( int numBytes = crFound - src; memmove(dst, src, numBytes); - dst += numBytes; dstLen -= numBytes; - src += numBytes; srcLen -= numBytes; + dst += numBytes; + dstLen -= numBytes; + src += numBytes; + srcLen -= numBytes; if (srcLen == 1) { /* valid src bytes end in \r */ if (eof) { *dst++ = '\r'; - src++; srcLen--; + src++; + srcLen--; } else { lesser = 0; break; } } else if (src[1] == '\n') { *dst++ = '\n'; - src += 2; srcLen -= 2; + src += 2; + srcLen -= 2; } else { *dst++ = '\r'; - src++; srcLen--; + src++; + srcLen--; } dstLen--; lesser = (dstLen < srcLen) ? dstLen : srcLen; @@ -6718,21 +6720,27 @@ TranslateInputEOL( int lesser; if (GotFlag(statePtr, INPUT_SAW_CR) && srcLen) { - if (*src == '\n') { src++; srcLen--; } + if (*src == '\n') { + src++; + srcLen--; + } ResetFlag(statePtr, INPUT_SAW_CR); } lesser = (dstLen < srcLen) ? dstLen : srcLen; - while ((crFound = (const char *)memchr(src, '\r', lesser))) { + while ((crFound = (const char *) memchr(src, '\r', lesser))) { int numBytes = crFound - src; memmove(dst, src, numBytes); dst[numBytes] = '\n'; - dst += numBytes + 1; dstLen -= numBytes + 1; - src += numBytes + 1; srcLen -= numBytes + 1; + dst += numBytes + 1; + dstLen -= numBytes + 1; + src += numBytes + 1; + srcLen -= numBytes + 1; if (srcLen == 0) { SetFlag(statePtr, INPUT_SAW_CR); } else if (*src == '\n') { - src++; srcLen--; + src++; + srcLen--; } lesser = (dstLen < srcLen) ? dstLen : srcLen; } @@ -7152,8 +7160,7 @@ Tcl_Seek( * defined. This means that the channel does not support seeking. */ - if ((Tcl_ChannelWideSeekProc(chanPtr->typePtr) == NULL) - ) { + if (Tcl_ChannelWideSeekProc(chanPtr->typePtr) == NULL) { Tcl_SetErrno(EINVAL); return -1; } @@ -7317,8 +7324,7 @@ Tcl_Tell( * defined. This means that the channel does not support seeking. */ - if ((Tcl_ChannelWideSeekProc(chanPtr->typePtr) == NULL) - ) { + if (Tcl_ChannelWideSeekProc(chanPtr->typePtr) == NULL) { Tcl_SetErrno(EINVAL); return -1; } @@ -8698,19 +8704,18 @@ UpdateInterest( TclChannelPreserve((Tcl_Channel)chanPtr); statePtr->timerChanPtr = chanPtr; statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc, chanPtr); + ChannelTimerProc, chanPtr); } } } if (!statePtr->timer - && mask & TCL_WRITABLE - && GotFlag(statePtr, CHANNEL_NONBLOCKING)) { - + && mask & TCL_WRITABLE + && GotFlag(statePtr, CHANNEL_NONBLOCKING)) { TclChannelPreserve((Tcl_Channel)chanPtr); statePtr->timerChanPtr = chanPtr; statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME, - ChannelTimerProc,chanPtr); + ChannelTimerProc,chanPtr); } @@ -8754,9 +8759,8 @@ ChannelTimerProc( Tcl_Preserve(statePtr); statePtr->timer = NULL; if (statePtr->interestMask & TCL_WRITABLE - && GotFlag(statePtr, CHANNEL_NONBLOCKING) - && !GotFlag(statePtr, BG_FLUSH_SCHEDULED) - ) { + && GotFlag(statePtr, CHANNEL_NONBLOCKING) + && !GotFlag(statePtr, BG_FLUSH_SCHEDULED)) { /* * Restart the timer in case a channel handler reenters the event loop * before UpdateInterest gets called by Tcl_NotifyChannel. @@ -8768,9 +8772,9 @@ ChannelTimerProc( /* The channel may have just been closed from within Tcl_NotifyChannel */ if (!GotFlag(statePtr, CHANNEL_INCLOSE)) { if (!GotFlag(statePtr, CHANNEL_NEED_MORE_DATA) - && (statePtr->interestMask & TCL_READABLE) - && (statePtr->inQueueHead != NULL) - && IsBufferReady(statePtr->inQueueHead)) { + && (statePtr->interestMask & TCL_READABLE) + && (statePtr->inQueueHead != NULL) + && IsBufferReady(statePtr->inQueueHead)) { /* * Restart the timer in case a channel handler reenters the event loop * before UpdateInterest gets called by Tcl_NotifyChannel. @@ -9810,8 +9814,8 @@ CopyData( if ((size == 0) && Tcl_Eof(inChan) && !(cmdPtr && (mask == 0))) { break; } - if (cmdPtr && (!Tcl_Eof(inChan) || (mask == 0)) && - !(mask & TCL_READABLE)) { + if (cmdPtr && (!Tcl_Eof(inChan) || (mask == 0)) + && !(mask & TCL_READABLE)) { if (mask & TCL_WRITABLE) { Tcl_DeleteChannelHandler(outChan, CopyEventProc, csPtr); } diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index 92a84b2..d9d2090 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -41,9 +41,9 @@ static Tcl_ExitProc FinalizeIOCmdTSD; static Tcl_TcpAcceptProc AcceptCallbackProc; static Tcl_ObjCmdProc ChanPendingObjCmd; static Tcl_ObjCmdProc ChanTruncateObjCmd; -static void RegisterTcpServerInterpCleanup( - Tcl_Interp *interp, - AcceptCallback *acceptCallbackPtr); +static void RegisterTcpServerInterpCleanup( + Tcl_Interp *interp, + AcceptCallback *acceptCallbackPtr); static Tcl_InterpDeleteProc TcpAcceptCallbacksDeleteProc; static void TcpServerCloseProc(void *callbackData); static void UnregisterTcpServerInterpCleanupProc( @@ -421,11 +421,11 @@ Tcl_ReadObjCmd( if (i < objc) { if ((TclGetWideIntFromObj(NULL, objv[i], &toRead) != TCL_OK) || (toRead < 0)) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected non-negative integer but got \"%s\"", - TclGetString(objv[i]))); - Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", (void *)NULL); - return TCL_ERROR; + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "expected non-negative integer but got \"%s\"", + TclGetString(objv[i]))); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "NUMBER", (void *)NULL); + return TCL_ERROR; } } diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c index 74b301b..0bfcb51 100644 --- a/generic/tclIORChan.c +++ b/generic/tclIORChan.c @@ -44,7 +44,7 @@ static void ReflectThread(void *clientData, int action); static int ReflectEventRun(Tcl_Event *ev, int flags); static int ReflectEventDelete(Tcl_Event *ev, void *cd); #endif -static long long ReflectSeekWide(void *clientData, +static long long ReflectSeekWide(void *clientData, long long offset, int mode, int *errorCodePtr); static int ReflectGetOption(void *clientData, Tcl_Interp *interp, const char *optionName, @@ -54,8 +54,8 @@ static int ReflectSetOption(void *clientData, const char *newValue); static int ReflectTruncate(void *clientData, long long length); -static void TimerRunRead(void *clientData); -static void TimerRunWrite(void *clientData); +static void TimerRunRead(void *clientData); +static void TimerRunWrite(void *clientData); /* * The C layer channel type/driver definition used by the reflection. diff --git a/generic/tclIORTrans.c b/generic/tclIORTrans.c index 683b7f2..5d00805 100644 --- a/generic/tclIORTrans.c +++ b/generic/tclIORTrans.c @@ -84,16 +84,16 @@ static const Tcl_ChannelType tclRTransformType = { typedef struct { unsigned char *buf; /* Reference to the buffer area. */ size_t allocated; /* Allocated size of the buffer area. */ - size_t used; /* Number of bytes in the buffer, + size_t used; /* Number of bytes in the buffer, * <= allocated. */ } ResultBuffer; #define ResultLength(r) ((r)->used) /* static int ResultLength(ResultBuffer *r); */ -static inline void ResultClear(ResultBuffer *r); -static inline void ResultInit(ResultBuffer *r); -static inline void ResultAdd(ResultBuffer *r, unsigned char *buf, +static inline void ResultClear(ResultBuffer *r); +static inline void ResultInit(ResultBuffer *r); +static inline void ResultAdd(ResultBuffer *r, unsigned char *buf, size_t toWrite); static inline size_t ResultCopy(ResultBuffer *r, unsigned char *buf, size_t toRead); diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index df2d510..b892d65 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -1340,14 +1340,20 @@ TclFSNormalizeToUniquePath( */ path = Tcl_GetStringFromObj(pathPtr, &i); - if ( (i >= 3) && ( (path[0] == '/' && path[1] == '/') - || (path[0] == '\\' && path[1] == '\\') ) ) { - for ( i = 2; ; i++) { - if (path[i] == '\0') break; - if (path[i] == path[0]) break; + if ((i >= 3) && ((path[0] == '/' && path[1] == '/') + || (path[0] == '\\' && path[1] == '\\'))) { + for (i = 2; ; i++) { + if (path[i] == '\0') { + break; + } + if (path[i] == path[0]) { + break; + } } --i; - if (path[i] == ':') isVfsPath = 1; + if (path[i] == ':') { + isVfsPath = 1; + } } /* diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index e76cca3..438df72 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -203,28 +203,28 @@ Tcl_GetIndexFromObjStruct( if (offset < (Tcl_Size)sizeof(char *)) { if (interp) { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("Invalid %s value %" TCL_SIZE_MODIFIER "d.", - "struct offset", offset)); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Invalid %s value %" TCL_SIZE_MODIFIER "d.", + "struct offset", offset)); } - return TCL_ERROR; + return TCL_ERROR; } /* * See if there is a valid cached result from a previous lookup. */ if (objPtr && !(flags & TCL_INDEX_TEMP_TABLE)) { - irPtr = TclFetchInternalRep(objPtr, &tclIndexType); - if (irPtr) { - indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1; - if ((indexRep->tablePtr == tablePtr) - && (indexRep->offset == offset) - && (indexRep->index != TCL_INDEX_NONE)) { - index = indexRep->index; - goto uncachedDone; + irPtr = TclFetchInternalRep(objPtr, &tclIndexType); + if (irPtr) { + indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1; + if ((indexRep->tablePtr == tablePtr) + && (indexRep->offset == offset) + && (indexRep->index != TCL_INDEX_NONE)) { + index = indexRep->index; + goto uncachedDone; + } } } - } /* * Lookup the value of the object in the table. Accept unique diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 47273d8..9513ee0 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -160,11 +160,12 @@ const Tcl_ObjType tclListType = { }; /* Macros to manipulate the List internal rep */ -#define ListRepIncrRefs(repPtr_) \ - do { \ - (repPtr_)->storePtr->refCount++; \ - if ((repPtr_)->spanPtr) \ - (repPtr_)->spanPtr->refCount++; \ +#define ListRepIncrRefs(repPtr_) \ + do { \ + (repPtr_)->storePtr->refCount++; \ + if ((repPtr_)->spanPtr) { \ + (repPtr_)->spanPtr->refCount++; \ + } \ } while (0) /* Returns number of free unused slots at the back of the ListRep's ListStore */ @@ -466,9 +467,7 @@ MemoryAllocationError( size_t size) /* Size of attempted allocation that failed */ { if (interp != NULL) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf( + Tcl_SetObjResult(interp, Tcl_ObjPrintf( "list construction failed: unable to alloc %" TCL_Z_MODIFIER "u bytes", size)); @@ -817,19 +816,18 @@ ListStoreNew( * *------------------------------------------------------------------------ */ -ListStore * -ListStoreReallocate (ListStore *storePtr, Tcl_Size needed) +static ListStore * +ListStoreReallocate( + ListStore *storePtr, + Tcl_Size needed) { Tcl_Size capacity; if (needed > LIST_MAX) { return NULL; } - storePtr = (ListStore *)TclAttemptReallocElemsEx(storePtr, - needed, - sizeof(Tcl_Obj *), - offsetof(ListStore, slots), - &capacity); + storePtr = (ListStore *) TclAttemptReallocElemsEx(storePtr, + needed, sizeof(Tcl_Obj *), offsetof(ListStore, slots), &capacity); /* Only the capacity has changed, fix it in the header */ if (storePtr) { storePtr->numAllocated = capacity; @@ -873,8 +871,7 @@ ListRepInit( Tcl_Size objc, Tcl_Obj *const objv[], int flags, - ListRep *repPtr - ) + ListRep *repPtr) { ListStore *storePtr; @@ -964,7 +961,10 @@ ListRepInitAttempt( *------------------------------------------------------------------------ */ static void -ListRepClone(ListRep *fromRepPtr, ListRep *toRepPtr, int flags) +ListRepClone( + ListRep *fromRepPtr, + ListRep *toRepPtr, + int flags) { Tcl_Obj **fromObjs; Tcl_Size numFrom; @@ -993,7 +993,9 @@ ListRepClone(ListRep *fromRepPtr, ListRep *toRepPtr, int flags) * *------------------------------------------------------------------------ */ -static void ListRepUnsharedFreeUnreferenced(const ListRep *repPtr) +static void +ListRepUnsharedFreeUnreferenced( + const ListRep *repPtr) { Tcl_Size count; ListStore *storePtr; @@ -1189,8 +1191,7 @@ TclNewListObj2( Tcl_Size objc1, /* Count of objects referenced by objv1. */ Tcl_Obj *const objv1[], /* First array of pointers to Tcl objects. */ Tcl_Size objc2, /* Count of objects referenced by objv2. */ - Tcl_Obj *const objv2[] /* Second array of pointers to Tcl objects. */ -) + Tcl_Obj *const objv2[]) /* Second array of pointers to Tcl objects. */ { Tcl_Obj *listObj; ListStore *storePtr; @@ -1249,7 +1250,7 @@ TclListObjGetRep( Tcl_Interp *interp, /* Used to report errors if not NULL. */ Tcl_Obj *listObj, /* List object for which an element array is * to be returned. */ - ListRep *repPtr) /* Location to store descriptor */ + ListRep *repPtr) /* Location to store descriptor */ { if (!TclHasInternalRep(listObj, &tclListType)) { int result; @@ -1389,13 +1390,13 @@ TclListObjCopy( */ static void ListRepRange( - ListRep *srcRepPtr, /* Contains source of the range */ - Tcl_Size rangeStart, /* Index of first element to include */ - Tcl_Size rangeEnd, /* Index of last element to include */ - int preserveSrcRep, /* If true, srcRepPtr contents must not be - modified (generally because a shared Tcl_Obj - references it) */ - ListRep *rangeRepPtr) /* Output. Must NOT be == srcRepPtr */ + ListRep *srcRepPtr, /* Contains source of the range */ + Tcl_Size rangeStart, /* Index of first element to include */ + Tcl_Size rangeEnd, /* Index of last element to include */ + int preserveSrcRep, /* If true, srcRepPtr contents must not be + * modified (generally because a shared Tcl_Obj + * references it) */ + ListRep *rangeRepPtr) /* Output. Must NOT be == srcRepPtr */ { Tcl_Obj **srcElems; Tcl_Size numSrcElems = ListRepLength(srcRepPtr); @@ -1447,7 +1448,7 @@ ListRepRange( /* T:listrep-1.10.1,2.8.1 */ *rangeRepPtr = *srcRepPtr; /* Not ref counts not incremented */ } else if (rangeStart == 0 && (!preserveSrcRep) - && (!ListRepIsShared(srcRepPtr) && srcRepPtr->spanPtr == NULL)) { + && (!ListRepIsShared(srcRepPtr) && srcRepPtr->spanPtr == NULL)) { /* Option 1 - Special case unshared, exclude end elements, no span */ LIST_ASSERT(srcRepPtr->storePtr->firstUsed == 0); /* If no span */ ListRepElements(srcRepPtr, numSrcElems, srcElems); @@ -1462,13 +1463,12 @@ ListRepRange( srcRepPtr->storePtr->flags = 0; rangeRepPtr->storePtr = srcRepPtr->storePtr; /* Note no incr ref */ rangeRepPtr->spanPtr = NULL; - } else if (ListSpanMerited(rangeLen, - srcRepPtr->storePtr->numUsed, - srcRepPtr->storePtr->numAllocated)) { + } else if (ListSpanMerited(rangeLen, srcRepPtr->storePtr->numUsed, + srcRepPtr->storePtr->numAllocated)) { /* Option 2 - because span would be most efficient */ Tcl_Size spanStart = ListRepStart(srcRepPtr) + rangeStart; if (!preserveSrcRep && srcRepPtr->spanPtr - && srcRepPtr->spanPtr->refCount <= 1) { + && srcRepPtr->spanPtr->refCount <= 1) { /* If span is not shared reuse it */ /* T:listrep-2.7.3,3.{16,18} */ srcRepPtr->spanPtr->spanStart = spanStart; @@ -1495,10 +1495,8 @@ ListRepRange( /* T:listrep-2.{4,6} */ ListRepElements(srcRepPtr, numSrcElems, srcElems); /* TODO - allocate extra space? */ - ListRepInit(rangeLen, - &srcElems[rangeStart], - LISTREP_PANIC_ON_FAIL, - rangeRepPtr); + ListRepInit(rangeLen, &srcElems[rangeStart], LISTREP_PANIC_ON_FAIL, + rangeRepPtr); } else { /* * Option 4 - modify in place. Note that because of the invariant @@ -1585,8 +1583,9 @@ TclListObjRange( ListRep resultRep; int isShared; - if (TclListObjGetRep(interp, listObj, &listRep) != TCL_OK) + if (TclListObjGetRep(interp, listObj, &listRep) != TCL_OK) { return NULL; + } isShared = Tcl_IsShared(listObj); @@ -1745,10 +1744,11 @@ Tcl_ListObjAppendList( * *------------------------------------------------------------------------ */ - int TclListObjAppendElements ( + int + TclListObjAppendElements ( Tcl_Interp *interp, /* Used to report errors if not NULL. */ Tcl_Obj *toObj, /* List object to append */ - Tcl_Size elemCount, /* Number of elements in elemObjs[] */ + Tcl_Size elemCount, /* Number of elements in elemObjs[] */ Tcl_Obj * const elemObjv[]) /* Objects to append to toObj's list. */ { ListRep listRep; @@ -1760,11 +1760,15 @@ Tcl_ListObjAppendList( Tcl_Panic("%s called with shared object", "TclListObjAppendElements"); } - if (TclListObjGetRep(interp, toObj, &listRep) != TCL_OK) - return TCL_ERROR; /* Cannot be converted to a list */ + if (TclListObjGetRep(interp, toObj, &listRep) != TCL_OK) { + /* Cannot be converted to a list */ + return TCL_ERROR; + } - if (elemCount <= 0) - return TCL_OK; /* Nothing to do. Note AFTER check for list above */ + if (elemCount <= 0) { + /* Nothing to do. Note AFTER check for list above */ + return TCL_OK; + } ListRepElements(&listRep, toLen, toObjv); if (elemCount > LIST_MAX || toLen > (LIST_MAX - elemCount)) { @@ -1789,8 +1793,8 @@ Tcl_ListObjAppendList( if (finalLen > listRep.storePtr->numAllocated) { /* T:listrep-1.{2,11},3.6 */ - ListStore *newStorePtr; - newStorePtr = ListStoreReallocate(listRep.storePtr, finalLen); + ListStore *newStorePtr = ListStoreReallocate( + listRep.storePtr, finalLen); if (newStorePtr == NULL) { return MemoryAllocationError(interp, LIST_SIZE(finalLen)); } @@ -1820,10 +1824,10 @@ Tcl_ListObjAppendList( ListRepUnsharedShiftDown(&listRep, shiftCount); } } /* else T:listrep-3.{4,6} */ - ObjArrayCopy(&listRep.storePtr->slots[ListRepStart(&listRep) - + ListRepLength(&listRep)], - elemCount, - elemObjv); + ObjArrayCopy( + &listRep.storePtr->slots[ + ListRepStart(&listRep) + ListRepLength(&listRep)], + elemCount, elemObjv); listRep.storePtr->numUsed = finalLen; if (listRep.spanPtr) { /* T:listrep-3.{4,5,6} */ @@ -1845,12 +1849,9 @@ Tcl_ListObjAppendList( * not leave space in the front either, assuming all appends and no * prepends. */ - if (ListRepInit(finalLen, - NULL, - listRep.spanPtr ? LISTREP_SPACE_FAVOR_BACK - : LISTREP_SPACE_ONLY_BACK, - &listRep) - != TCL_OK) { + if (ListRepInit(finalLen, NULL, + listRep.spanPtr ? LISTREP_SPACE_FAVOR_BACK : LISTREP_SPACE_ONLY_BACK, + &listRep) != TCL_OK) { return MemoryAllocationError(interp, finalLen); } LIST_ASSERT(listRep.storePtr->numAllocated >= finalLen); @@ -1944,10 +1945,10 @@ Tcl_ListObjAppendElement( */ int Tcl_ListObjIndex( - Tcl_Interp *interp, /* Used to report errors if not NULL. */ - Tcl_Obj *listObj, /* List object to index into. */ - Tcl_Size index, /* Index of element to return. */ - Tcl_Obj **objPtrPtr) /* The resulting Tcl_Obj* is stored here. */ + Tcl_Interp *interp, /* Used to report errors if not NULL. */ + Tcl_Obj *listObj, /* List object to index into. */ + Tcl_Size index, /* Index of element to return. */ + Tcl_Obj **objPtrPtr) /* The resulting Tcl_Obj* is stored here. */ { Tcl_Obj **elemObjs; Tcl_Size numElems; @@ -1963,8 +1964,7 @@ Tcl_ListObjIndex( return TclObjTypeIndex(interp, listObj, index, objPtrPtr); } - if (TclListObjGetElements(interp, listObj, &numElems, &elemObjs) - != TCL_OK) { + if (TclListObjGetElements(interp, listObj, &numElems, &elemObjs) != TCL_OK) { return TCL_ERROR; } if ((index < 0) || (index >= numElems)) { @@ -2026,8 +2026,9 @@ Tcl_ListObjLength( return TCL_OK; } -Tcl_Size -ListLength(Tcl_Obj *listPtr) +static Tcl_Size +ListLength( + Tcl_Obj *listPtr) { ListRep listRep; ListObjGetRep(listPtr, &listRep); @@ -2098,11 +2099,13 @@ Tcl_ListObjReplace( if (TclObjTypeHasProc(listObj, replaceProc)) { return TclObjTypeReplace(interp, listObj, first, - numToDelete, numToInsert, insertObjs); + numToDelete, numToInsert, insertObjs); } - if (TclListObjGetRep(interp, listObj, &listRep) != TCL_OK) - return TCL_ERROR; /* Cannot be converted to a list */ + if (TclListObjGetRep(interp, listObj, &listRep) != TCL_OK) { + /* Cannot be converted to a list */ + return TCL_ERROR; + } /* Make limits sane */ origListLen = ListRepLength(&listRep); @@ -2204,16 +2207,14 @@ Tcl_ListObjReplace( * NOTE THIS IS TRUE EVEN IF THE ListStore IS SHARED as it will not * affect the other Tcl_Obj's referencing this ListStore. */ - if (first == 0 && /* (i) */ - ListRepStart(&listRep) == listRep.storePtr->firstUsed && /* (ii) */ - numToInsert <= listRep.storePtr->firstUsed /* (iii) */ - ) { + if (first == 0 && /* (i) */ + ListRepStart(&listRep) == listRep.storePtr->firstUsed && /* (ii) */ + numToInsert <= listRep.storePtr->firstUsed) { /* (iii) */ Tcl_Size newLen; LIST_ASSERT(numToInsert); /* Else would have returned above */ listRep.storePtr->firstUsed -= numToInsert; ObjArrayCopy(&listRep.storePtr->slots[listRep.storePtr->firstUsed], - numToInsert, - insertObjs); + numToInsert, insertObjs); listRep.storePtr->numUsed += numToInsert; newLen = listRep.spanPtr->spanLength + numToInsert; if (listRep.spanPtr && listRep.spanPtr->refCount <= 1) { @@ -2258,7 +2259,7 @@ Tcl_ListObjReplace( ListStoreReallocate(listRep.storePtr, origListLen + lenChange); if (newStorePtr == NULL) { return MemoryAllocationError(interp, - LIST_SIZE(origListLen + lenChange)); + LIST_SIZE(origListLen + lenChange)); } listRep.storePtr = newStorePtr; numFreeSlots = @@ -2278,17 +2279,15 @@ Tcl_ListObjReplace( * (c) The new unshared size is much "smaller" (TODO) than the allocated space * TODO - for unshared case ONLY, consider a "move" based implementation */ - if (ListRepIsShared(&listRep) || /* 3a */ - numFreeSlots < lenChange || /* 3b */ - (origListLen + lenChange) < (listRep.storePtr->numAllocated / 4) /* 3c */ - ) { + if (ListRepIsShared(&listRep) || /* 3a */ + numFreeSlots < lenChange || /* 3b */ + (origListLen + lenChange) < + (listRep.storePtr->numAllocated / 4)) { /* 3c */ ListRep newRep; Tcl_Obj **toObjs; listObjs = &listRep.storePtr->slots[ListRepStart(&listRep)]; - ListRepInit(origListLen + lenChange, - NULL, - LISTREP_PANIC_ON_FAIL | favor, - &newRep); + ListRepInit(origListLen + lenChange, NULL, + LISTREP_PANIC_ON_FAIL | favor, &newRep); toObjs = ListRepSlotPtr(&newRep, 0); if (leadSegmentLen > 0) { /* T:listrep-2.{2,3,13:18},4.{6,9,13:18} */ @@ -2296,15 +2295,13 @@ Tcl_ListObjReplace( } if (numToInsert > 0) { /* T:listrep-2.{1,2,3,10:18},4.{1,2,4,6,10:18} */ - ObjArrayCopy(&toObjs[leadSegmentLen], - numToInsert, - insertObjs); + ObjArrayCopy(&toObjs[leadSegmentLen], numToInsert, + insertObjs); } if (tailSegmentLen > 0) { /* T:listrep-2.{1,2,3,10:15},4.{1,2,4,6,9:12,16:18} */ ObjArrayCopy(&toObjs[leadSegmentLen + numToInsert], - tailSegmentLen, - &listObjs[leadSegmentLen+numToDelete]); + tailSegmentLen, &listObjs[leadSegmentLen+numToDelete]); } newRep.storePtr->numUsed = origListLen + lenChange; if (newRep.spanPtr) { @@ -2400,7 +2397,7 @@ Tcl_ListObjReplace( LIST_ASSERT((leadSpace + tailSpace) >= lenChange); if (leadSpace >= lenChange - && (leadSegmentLen < tailSegmentLen || tailSpace < lenChange)) { + && (leadSegmentLen < tailSegmentLen || tailSpace < lenChange)) { /* Move only lead to the front to make more room */ /* T:listrep-3.25,36,38, */ leadShift = -lenChange; @@ -2529,7 +2526,7 @@ Tcl_ListObjReplace( } else { /* T:listrep-1.{1,3,6.1,13,14,16,18,21} */ listRep.spanPtr = ListSpanNew(listRep.storePtr->firstUsed, - listRep.storePtr->numUsed); + listRep.storePtr->numUsed); } } @@ -2568,7 +2565,7 @@ TclLindexList( Tcl_Obj *listObj, /* List being unpacked. */ Tcl_Obj *argObj) /* Index or index list. */ { - Tcl_Size index; /* Index into the list. */ + Tcl_Size index; /* Index into the list. */ Tcl_Obj *indexListCopy; Tcl_Obj **indexObjs; Tcl_Size numIndexObjs; @@ -2580,8 +2577,8 @@ TclLindexList( * see TIP#22 and TIP#33 for the details. */ if (!TclHasInternalRep(argObj, &tclListType) - && TclGetIntForIndexM(NULL, argObj, TCL_SIZE_MAX - 1, &index) - == TCL_OK) { + && TclGetIntForIndexM(NULL, argObj, TCL_SIZE_MAX - 1, + &index) == TCL_OK) { /* * argPtr designates a single index. */ @@ -2658,7 +2655,8 @@ TclLindexFlat( Tcl_Obj *elemObj = listObj; /* for lindex without indices return list */ for (i=0 ; i (int) (sizeof(pendingInvalidates) / sizeof(pendingInvalidates[0]))) { + if (indexCount > (int) (sizeof(pendingInvalidates) / + sizeof(pendingInvalidates[0]))) { pendingInvalidatesPtr = (Tcl_Obj **) Tcl_Alloc(indexCount * sizeof(*pendingInvalidatesPtr)); } @@ -2940,8 +2938,8 @@ TclLsetFlat( * Check for the possible error conditions... */ - if (TclListObjGetElements(interp, subListObj, &elemCount, &elemPtrs) - != TCL_OK) { + if (TclListObjGetElements(interp, subListObj, + &elemCount, &elemPtrs) != TCL_OK) { /* ...the sublist we're indexing into isn't a list at all. */ result = TCL_ERROR; break; @@ -2952,8 +2950,8 @@ TclLsetFlat( * post-increments, avoid '*indexArray++' here. */ - if (TclGetIntForIndexM(interp, *indexArray, elemCount - 1, &index) - != TCL_OK) { + if (TclGetIntForIndexM(interp, *indexArray, elemCount - 1, + &index) != TCL_OK) { /* ...the index we're trying to use isn't an index at all. */ result = TCL_ERROR; indexArray++; /* Why bother with this increment? TBD */ @@ -2970,18 +2968,14 @@ TclLsetFlat( index = 0; } if (index < 0 || index > elemCount - || (valueObj == NULL && index >= elemCount)) { + || (valueObj == NULL && index >= elemCount)) { /* ...the index points outside the sublist. */ if (interp != NULL) { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("index \"%s\" out of range", - Tcl_GetString(indexArray[-1]))); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "index \"%s\" out of range", + Tcl_GetString(indexArray[-1]))); Tcl_SetErrorCode(interp, - "TCL", - "VALUE", - "INDEX" - "OUTOFRANGE", - (void *)NULL); + "TCL", "VALUE", "INDEX" "OUTOFRANGE", (void *)NULL); } result = TCL_ERROR; break; @@ -3076,8 +3070,9 @@ TclLsetFlat( } } - if (pendingInvalidatesPtr != pendingInvalidates) + if (pendingInvalidatesPtr != pendingInvalidates) { Tcl_Free(pendingInvalidatesPtr); + } if (result != TCL_OK) { /* @@ -3320,9 +3315,8 @@ SetListFromAny( Tcl_DictObjSize(NULL, objPtr, &size); /* TODO - leave space in front and/or back? */ - if (ListRepInitAttempt( - interp, size > 0 ? 2 * size : 1, NULL, &listRep) - != TCL_OK) { + if (ListRepInitAttempt(interp, size > 0 ? 2 * size : 1, NULL, + &listRep) != TCL_OK) { return TCL_ERROR; } @@ -3382,8 +3376,7 @@ SetListFromAny( estCount += (estCount == 0); /* Smallest list struct holds 1 * element. */ /* TODO - allocate additional space? */ - if (ListRepInitAttempt(interp, estCount, NULL, &listRep) - != TCL_OK) { + if (ListRepInitAttempt(interp, estCount, NULL, &listRep) != TCL_OK) { return TCL_ERROR; } @@ -3402,7 +3395,7 @@ SetListFromAny( if (TCL_OK != TclFindElement(interp, nextElem, limit - nextElem, &elemStart, &nextElem, &elemSize, &literal)) { -fail: + fail: while (--elemPtrs >= listRep.storePtr->slots) { Tcl_DecrRefCount(*elemPtrs); } @@ -3578,7 +3571,10 @@ UpdateStringOfList( *------------------------------------------------------------------------ */ Tcl_Obj * -TclListTestObj(size_t length, size_t leadingSpace, size_t endSpace) +TclListTestObj( + size_t length, + size_t leadingSpace, + size_t endSpace) { ListRep listRep; size_t capacity; diff --git a/generic/tclLoad.c b/generic/tclLoad.c index a2d1919..a689833 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -92,17 +92,17 @@ typedef struct InterpLibrary { static void LoadCleanupProc(void *clientData, Tcl_Interp *interp); -static int IsStatic (LoadedLibrary *libraryPtr); +static int IsStatic(LoadedLibrary *libraryPtr); static int UnloadLibrary(Tcl_Interp *interp, Tcl_Interp *target, LoadedLibrary *library, int keepLibrary, const char *fullFileName, int interpExiting); static int -IsStatic (LoadedLibrary *libraryPtr) { - int res; - res = (libraryPtr->fileName[0] == '\0'); - return res; +IsStatic( + LoadedLibrary *libraryPtr) +{ + return (libraryPtr->fileName[0] == '\0'); } /* diff --git a/generic/tclOO.c b/generic/tclOO.c index 1d72fb0..a028e07 100644 --- a/generic/tclOO.c +++ b/generic/tclOO.c @@ -1389,7 +1389,10 @@ TclOODecrRefCount( * * ---------------------------------------------------------------------- */ -int TclOOObjectDestroyed(Object *oPtr) { +int +TclOOObjectDestroyed( + Object *oPtr) +{ return (oPtr->namespacePtr == NULL); } diff --git a/generic/tclOOMethod.c b/generic/tclOOMethod.c index b03bbdb..a414ec2 100644 --- a/generic/tclOOMethod.c +++ b/generic/tclOOMethod.c @@ -761,9 +761,8 @@ InvokeProcedureMethod( * the next thing in the chain. */ - if (TclOOObjectDestroyed(((CallContext *)context)->oPtr) || - Tcl_InterpDeleted(interp) - ) { + if (TclOOObjectDestroyed(((CallContext *)context)->oPtr) + || Tcl_InterpDeleted(interp)) { return TclNRObjectContextInvokeNext(interp, context, objc, objv, Tcl_ObjectContextSkippedArgs(context)); } diff --git a/generic/tclObj.c b/generic/tclObj.c index 2be7bca..85b3155 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -4088,7 +4088,9 @@ TclCompareObjKeys( * If the object pointers are the same then they match. * OPT: this comparison was moved to the caller - if (objPtr1 == objPtr2) return 1; + if (objPtr1 == objPtr2) { + return 1; + } */ /* @@ -4277,7 +4279,7 @@ Tcl_GetCommandFromObj( TclGetCurrentNamespace(interp); if ((resPtr->refNsPtr == NULL) - || ((refNsPtr == resPtr->refNsPtr) + || ((refNsPtr == resPtr->refNsPtr) && (resPtr->refNsId == refNsPtr->nsId) && (resPtr->refNsCmdEpoch == refNsPtr->cmdRefEpoch))) { return (Tcl_Command) cmdPtr; diff --git a/generic/tclParse.c b/generic/tclParse.c index 6417514..84200ac 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -120,7 +120,7 @@ const unsigned char tclCharTypeTable[] = { * Prototypes for local functions defined in this file: */ -static int CommandComplete(const char *script, Tcl_Size numBytes); +static int CommandComplete(const char *script, Tcl_Size numBytes); static Tcl_Size ParseComment(const char *src, Tcl_Size numBytes, Tcl_Parse *parsePtr); static int ParseTokens(const char *src, Tcl_Size numBytes, int mask, diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c index 249e399..9dc0583 100644 --- a/generic/tclPathObj.c +++ b/generic/tclPathObj.c @@ -276,8 +276,7 @@ TclFSNormalizeAbsolutePath( */ if (tclPlatform != TCL_PLATFORM_WINDOWS - && Tcl_FSGetPathType(linkObj) - == TCL_PATH_RELATIVE) { + && Tcl_FSGetPathType(linkObj) == TCL_PATH_RELATIVE) { /* * We need to follow this link which is relative * to retVal's directory. This means concatenating @@ -406,8 +405,9 @@ TclFSNormalizeAbsolutePath( Tcl_Size len; const char *path = Tcl_GetStringFromObj(retVal, &len); if (zipVolumeLen) { - if (len == (zipVolumeLen - 1)) + if (len == (zipVolumeLen - 1)) { needTrailingSlash = 1; + } } else { if (len == 2 && path[0] != 0 && path[1] == ':') { needTrailingSlash = 1; @@ -2593,9 +2593,8 @@ TclResolveTildePath( if (split == 1) { /* No user name specified -> current user */ - if (MakeTildeRelativePath( - interp, NULL, path[1] ? 2 + path : NULL, &resolvedPath) - != TCL_OK) { + if (MakeTildeRelativePath(interp, NULL, path[1] ? 2 + path : NULL, + &resolvedPath) != TCL_OK) { return NULL; } } else { @@ -2608,11 +2607,9 @@ TclResolveTildePath( expandedUser = Tcl_DStringValue(&userName); /* path[split] is / or \0 */ - if (MakeTildeRelativePath(interp, - expandedUser, - path[split] ? &path[split+1] : NULL, - &resolvedPath) - != TCL_OK) { + if (MakeTildeRelativePath(interp, expandedUser, + path[split] ? &path[split+1] : NULL, + &resolvedPath) != TCL_OK) { Tcl_DStringFree(&userName); return NULL; } diff --git a/generic/tclProc.c b/generic/tclProc.c index 2e424fa..419b9eb 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.c @@ -608,8 +608,7 @@ TclCreateProc( const char *value = Tcl_GetStringFromObj(fieldValues[1], &valueLength); if ((valueLength != tmpLength) - || memcmp(value, tmpPtr, tmpLength) != 0 - ) { + || memcmp(value, tmpPtr, tmpLength) != 0) { Tcl_Obj *errorObj = Tcl_ObjPrintf( "procedure \"%s\": formal parameter \"", procName); Tcl_AppendObjToObj(errorObj, fieldValues[0]); @@ -1546,8 +1545,7 @@ TclPushProcCallFrame( || (codePtr->compileEpoch != iPtr->compileEpoch) || (codePtr->nsPtr != nsPtr) || (codePtr->nsEpoch != nsPtr->resolverEpoch) - || ((codePtr->procPtr != procPtr) && procPtr->bodyPtr->bytes) - ) { + || ((codePtr->procPtr != procPtr) && procPtr->bodyPtr->bytes)) { goto doCompilation; } } else { @@ -1934,8 +1932,7 @@ TclProcCompileProc( && (codePtr->compileEpoch == iPtr->compileEpoch) && (codePtr->nsPtr == nsPtr) && (codePtr->nsEpoch == nsPtr->resolverEpoch) - && ((codePtr->procPtr == procPtr) || !bodyPtr->bytes) - ) { + && ((codePtr->procPtr == procPtr) || !bodyPtr->bytes)) { return TCL_OK; } diff --git a/generic/tclProcess.c b/generic/tclProcess.c index 719f2e9..968e191 100644 --- a/generic/tclProcess.c +++ b/generic/tclProcess.c @@ -30,10 +30,11 @@ typedef struct ProcessInfo { int purge; /* Purge eventualy. */ TclProcessWaitStatus status;/* Process status. */ int code; /* Error code, exit status or signal - number. */ + * number. */ Tcl_Obj *msg; /* Error message. */ Tcl_Obj *error; /* Error code. */ } ProcessInfo; + static Tcl_HashTable infoTablePerPid; static Tcl_HashTable infoTablePerResolvedPid; static int infoTablesInitialized = 0; /* 0 means not yet initialized. */ @@ -76,7 +77,7 @@ void InitProcessInfo( ProcessInfo *info, /* Structure to initialize. */ Tcl_Pid pid, /* Process id. */ - Tcl_Size resolvedPid) /* Resolved process id. */ + Tcl_Size resolvedPid) /* Resolved process id. */ { info->pid = pid; info->resolvedPid = resolvedPid; @@ -144,8 +145,7 @@ FreeProcessInfo( int RefreshProcessInfo( ProcessInfo *info, /* Structure to refresh. */ - int options /* Options passed to WaitProcessStatus. */ -) + int options) /* Options passed to WaitProcessStatus. */ { if (info->status == TCL_PROCESS_UNCHANGED) { /* @@ -154,8 +154,12 @@ RefreshProcessInfo( info->status = WaitProcessStatus(info->pid, info->resolvedPid, options, &info->code, &info->msg, &info->error); - if (info->msg) Tcl_IncrRefCount(info->msg); - if (info->error) Tcl_IncrRefCount(info->error); + if (info->msg) { + Tcl_IncrRefCount(info->msg); + } + if (info->error) { + Tcl_IncrRefCount(info->error); + } return (info->status != TCL_PROCESS_UNCHANGED); } else { /* @@ -192,8 +196,7 @@ WaitProcessStatus( * - errno in case of error. * - non-zero exit code for abormal exit. * - signal number if killed or suspended. - * - Tcl_WaitPid status in all other cases. - */ + * - Tcl_WaitPid status in all other cases. */ Tcl_Obj **msgObjPtr, /* If non-NULL, will receive error message. */ Tcl_Obj **errorObjPtr) /* If non-NULL, will receive error code. */ { @@ -229,9 +232,13 @@ WaitProcessStatus( msg = "child process lost (is SIGCHLD ignored or trapped?)"; } - if (codePtr) *codePtr = errno; - if (msgObjPtr) *msgObjPtr = Tcl_ObjPrintf( - "error waiting for process to exit: %s", msg); + if (codePtr) { + *codePtr = errno; + } + if (msgObjPtr) { + *msgObjPtr = Tcl_ObjPrintf( + "error waiting for process to exit: %s", msg); + } if (errorObjPtr) { errorStrings[0] = Tcl_NewStringObj("POSIX", -1); errorStrings[1] = Tcl_NewStringObj(Tcl_ErrnoId(), -1); @@ -240,14 +247,20 @@ WaitProcessStatus( } return TCL_PROCESS_ERROR; } else if (WIFEXITED(waitStatus)) { - if (codePtr) *codePtr = WEXITSTATUS(waitStatus); + if (codePtr) { + *codePtr = WEXITSTATUS(waitStatus); + } if (!WEXITSTATUS(waitStatus)) { /* * Normal exit. */ - if (msgObjPtr) *msgObjPtr = NULL; - if (errorObjPtr) *errorObjPtr = NULL; + if (msgObjPtr) { + *msgObjPtr = NULL; + } + if (errorObjPtr) { + *errorObjPtr = NULL; + } } else { /* * CHILDSTATUS pid code @@ -255,8 +268,10 @@ WaitProcessStatus( * Child exited with a non-zero exit status. */ - if (msgObjPtr) *msgObjPtr = Tcl_NewStringObj( - "child process exited abnormally", -1); + if (msgObjPtr) { + *msgObjPtr = Tcl_NewStringObj( + "child process exited abnormally", -1); + } if (errorObjPtr) { errorStrings[0] = Tcl_NewStringObj("CHILDSTATUS", -1); TclNewIntObj(errorStrings[1], resolvedPid); @@ -273,9 +288,12 @@ WaitProcessStatus( */ msg = Tcl_SignalMsg(WTERMSIG(waitStatus)); - if (codePtr) *codePtr = WTERMSIG(waitStatus); - if (msgObjPtr) *msgObjPtr = Tcl_ObjPrintf( - "child killed: %s", msg); + if (codePtr) { + *codePtr = WTERMSIG(waitStatus); + } + if (msgObjPtr) { + *msgObjPtr = Tcl_ObjPrintf("child killed: %s", msg); + } if (errorObjPtr) { errorStrings[0] = Tcl_NewStringObj("CHILDKILLED", -1); TclNewIntObj(errorStrings[1], resolvedPid); @@ -292,9 +310,12 @@ WaitProcessStatus( */ msg = Tcl_SignalMsg(WSTOPSIG(waitStatus)); - if (codePtr) *codePtr = WSTOPSIG(waitStatus); - if (msgObjPtr) *msgObjPtr = Tcl_ObjPrintf( - "child suspended: %s", msg); + if (codePtr) { + *codePtr = WSTOPSIG(waitStatus); + } + if (msgObjPtr) { + *msgObjPtr = Tcl_ObjPrintf("child suspended: %s", msg); + } if (errorObjPtr) { errorStrings[0] = Tcl_NewStringObj("CHILDSUSP", -1); TclNewIntObj(errorStrings[1], resolvedPid); @@ -310,9 +331,13 @@ WaitProcessStatus( * Child wait status didn't make sense. */ - if (codePtr) *codePtr = waitStatus; - if (msgObjPtr) *msgObjPtr = Tcl_NewStringObj( - "child wait status didn't make sense\n", -1); + if (codePtr) { + *codePtr = waitStatus; + } + if (msgObjPtr) { + *msgObjPtr = Tcl_NewStringObj( + "child wait status didn't make sense\n", -1); + } if (errorObjPtr) { errorStrings[0] = Tcl_NewStringObj("TCL", -1); errorStrings[1] = Tcl_NewStringObj("OPERATION", -1); @@ -815,7 +840,9 @@ TclProcessCreated( info = (ProcessInfo *) Tcl_GetHashValue(entry); entry2 = Tcl_FindHashEntry(&infoTablePerResolvedPid, INT2PTR(resolvedPid)); - if (entry2) Tcl_DeleteHashEntry(entry2); + if (entry2) { + Tcl_DeleteHashEntry(entry2); + } FreeProcessInfo(info); } @@ -886,9 +913,13 @@ TclProcessWait( result = WaitProcessStatus(pid, TclpGetPid(pid), options, codePtr, msgObjPtr, errorObjPtr); - if (msgObjPtr && *msgObjPtr) Tcl_IncrRefCount(*msgObjPtr); - if (errorObjPtr && *errorObjPtr) Tcl_IncrRefCount(*errorObjPtr); - Tcl_MutexUnlock(&infoTablesMutex); + if (msgObjPtr && *msgObjPtr) { + Tcl_IncrRefCount(*msgObjPtr); + } + if (errorObjPtr && *errorObjPtr) { + Tcl_IncrRefCount(*errorObjPtr); + } + Tcl_MutexUnlock(&infoTablesMutex); return result; } @@ -898,8 +929,8 @@ TclProcessWait( * Process has completed but TclProcessWait has already been called, * so report no change. */ - Tcl_MutexUnlock(&infoTablesMutex); + Tcl_MutexUnlock(&infoTablesMutex); return TCL_PROCESS_UNCHANGED; } @@ -908,8 +939,8 @@ TclProcessWait( /* * No change, stop there. */ - Tcl_MutexUnlock(&infoTablesMutex); + Tcl_MutexUnlock(&infoTablesMutex); return TCL_PROCESS_UNCHANGED; } @@ -918,11 +949,21 @@ TclProcessWait( */ result = info->status; - if (codePtr) *codePtr = info->code; - if (msgObjPtr) *msgObjPtr = info->msg; - if (errorObjPtr) *errorObjPtr = info->error; - if (msgObjPtr && *msgObjPtr) Tcl_IncrRefCount(*msgObjPtr); - if (errorObjPtr && *errorObjPtr) Tcl_IncrRefCount(*errorObjPtr); + if (codePtr) { + *codePtr = info->code; + } + if (msgObjPtr) { + *msgObjPtr = info->msg; + } + if (errorObjPtr) { + *errorObjPtr = info->error; + } + if (msgObjPtr && *msgObjPtr) { + Tcl_IncrRefCount(*msgObjPtr); + } + if (errorObjPtr && *errorObjPtr) { + Tcl_IncrRefCount(*errorObjPtr); + } if (autopurge) { /* @@ -945,3 +986,11 @@ TclProcessWait( Tcl_MutexUnlock(&infoTablesMutex); return result; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index 83cd415..49deee6 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -529,8 +529,8 @@ Tcl_RegExpMatchObj( */ if (!(re = Tcl_GetRegExpFromObj(interp, patternObj, - TCL_REG_ADVANCED | TCL_REG_NOSUB)) - && !(re = Tcl_GetRegExpFromObj(interp, patternObj, TCL_REG_ADVANCED))) { + TCL_REG_ADVANCED | TCL_REG_NOSUB)) && + !(re = Tcl_GetRegExpFromObj(interp, patternObj, TCL_REG_ADVANCED))) { return -1; } return Tcl_RegExpExecObj(interp, re, textObj, 0 /* offset */, diff --git a/generic/tclScan.c b/generic/tclScan.c index 3dcc9ea..1fc7e97 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -923,7 +923,7 @@ Tcl_ScanObjCmd( width = ~0; } if (TCL_OK != TclParseNumber(NULL, objPtr, NULL, string, width, - &end, TCL_PARSE_INTEGER_ONLY | TCL_PARSE_NO_UNDERSCORE | parseFlag)) { + &end, TCL_PARSE_INTEGER_ONLY | TCL_PARSE_NO_UNDERSCORE | parseFlag)) { Tcl_DecrRefCount(objPtr); if (width < 0) { if (*end == '\0') { diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index 4ea590a..87aab60 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -308,7 +308,7 @@ static double MakeNaN(int signum, Tcl_WideUInt tag); #endif static double RefineApproximation(double approx, mp_int *exactSignificand, int exponent); -static mp_err MulPow5(mp_int *, unsigned, mp_int *) MP_WUR; +static mp_err MulPow5(mp_int *, unsigned, mp_int *) MP_WUR; static int NormalizeRightward(Tcl_WideUInt *); static int RequiredPrecision(Tcl_WideUInt); static void DoubleToExpAndSig(double, Tcl_WideUInt *, int *, @@ -592,18 +592,18 @@ TclParseNumber( * V * example: 5___6 */ - for (before=(p-1); - (before && *before=='_'); - before=(before>p ? (before-1):NULL)); - for (after=(p+1); - (after && *after && *after=='_'); - after=(*after&&*after=='_')?(after+1):NULL); + for (before = (p - 1); + (before && *before == '_'); + before = (before > p ? (before - 1) : NULL)); + for (after = (p + 1); + (after && *after && *after == '_'); + after = (*after && *after == '_') ? (after + 1) : NULL); switch (state) { case ZERO_B: case BINARY: if ((before && (*before != '0' && *before != '1')) || - (after && (*after != '0' && *after != '1'))) { + (after && (*after != '0' && *after != '1'))) { /* Not a valid digit */ goto endgame; } @@ -611,7 +611,7 @@ TclParseNumber( case ZERO_O: case OCTAL: if (((before && (*before < '0' || '7' < *before))) || - ((after && (*after < '0' || '7' < *after)))) { + ((after && (*after < '0' || '7' < *after)))) { goto endgame; } break; @@ -624,7 +624,7 @@ TclParseNumber( case EXPONENT_SIGNUM: case EXPONENT: if ((!before || isdigit(UCHAR(*before))) && - (!after || isdigit(UCHAR(*after)))) { + (!after || isdigit(UCHAR(*after)))) { break; } if (after && *after=='(') { @@ -635,7 +635,7 @@ TclParseNumber( case ZERO_X: case HEXADECIMAL: if ( (!before || isxdigit(UCHAR(*before))) && - (!after || isxdigit(UCHAR(*after)))) { + (!after || isxdigit(UCHAR(*after)))) { break; } goto endgame; diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 42eaa8d..4f1a145 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -490,7 +490,7 @@ TclCheckEmptyString( } if (TclIsPureByteArray(objPtr) - && Tcl_GetCharLength(objPtr) == 0) { + && Tcl_GetCharLength(objPtr) == 0) { return TCL_EMPTYSTRING_YES; } @@ -1394,10 +1394,8 @@ Tcl_AppendObjToObj( return; } - if ( - TclIsPureByteArray(appendObjPtr) - && (TclIsPureByteArray(objPtr) || objPtr->bytes == &tclEmptyString) - ) { + if (TclIsPureByteArray(appendObjPtr) + && (TclIsPureByteArray(objPtr) || objPtr->bytes == &tclEmptyString)) { /* * Both bytearray objects are pure, so the second internal bytearray value * can be appended to the first, with no need to modify the "bytes" field. @@ -2192,7 +2190,9 @@ Tcl_AppendFormatToObj( } cmpResult = mp_cmp_d(&big, 0); isNegative = (cmpResult == MP_LT); - if (cmpResult == MP_EQ) gotHash = 0; + if (cmpResult == MP_EQ) { + gotHash = 0; + } if (ch == 'u') { if (isNegative) { mp_clear(&big); @@ -2209,7 +2209,9 @@ Tcl_AppendFormatToObj( goto error; } isNegative = (w < (Tcl_WideInt) 0); - if (w == (Tcl_WideInt) 0) gotHash = 0; + if (w == (Tcl_WideInt) 0) { + gotHash = 0; + } #endif } else if (TclGetLongFromObj(NULL, segment, &l) != TCL_OK) { if (TclGetWideBitsFromObj(interp, segment, &w) != TCL_OK) { @@ -2220,18 +2222,26 @@ Tcl_AppendFormatToObj( if (useShort) { s = (short) l; isNegative = (s < (short) 0); - if (s == (short) 0) gotHash = 0; + if (s == (short) 0) { + gotHash = 0; + } } else { isNegative = (l < (long) 0); - if (l == (long) 0) gotHash = 0; + if (l == (long) 0) { + gotHash = 0; + } } } else if (useShort) { s = (short) l; isNegative = (s < (short) 0); - if (s == (short) 0) gotHash = 0; + if (s == (short) 0) { + gotHash = 0; + } } else { isNegative = (l < (long) 0); - if (l == (long) 0) gotHash = 0; + if (l == (long) 0) { + gotHash = 0; + } } TclNewObj(segment); @@ -2544,7 +2554,9 @@ Tcl_AppendFormatToObj( char *q = TclGetString(segment) + 1; *q = 'x'; q = strchr(q, 'P'); - if (q) *q = 'p'; + if (q) { + *q = 'p'; + } } break; } @@ -3275,11 +3287,11 @@ TclStringCat( Tcl_Obj *objPtr = *ov++; if (objPtr->bytes == NULL - && TclCheckEmptyString(objPtr) != TCL_EMPTYSTRING_YES) { + && TclCheckEmptyString(objPtr) != TCL_EMPTYSTRING_YES) { /* No string rep; Take the chance we can avoid making it */ pendingPtr = objPtr; } else { - (void)Tcl_GetStringFromObj(objPtr, &length); /* PANIC? */ + (void) Tcl_GetStringFromObj(objPtr, &length); /* PANIC? */ } } while (--oc && (length == 0) && (pendingPtr == NULL)); diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 78c2607..6b1dea2 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -305,7 +305,7 @@ TclWinNoBackslash(char *path) return path; } -void *TclWinGetTclInstance() +void *TclWinGetTclInstance(void) { void *hInstance = NULL; GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, @@ -330,8 +330,8 @@ static int exprInt(Tcl_Interp *interp, const char *expr, int *ptr){ long longValue; int result = Tcl_ExprLong(interp, expr, &longValue); if (result == TCL_OK) { - if ((longValue >= (long)(INT_MIN)) - && (longValue <= (long)(UINT_MAX))) { + if ((longValue >= (long)(INT_MIN)) + && (longValue <= (long)(UINT_MAX))) { *ptr = (int)longValue; } else { Tcl_SetObjResult(interp, Tcl_NewStringObj( @@ -346,8 +346,8 @@ static int exprIntObj(Tcl_Interp *interp, Tcl_Obj*expr, int *ptr){ long longValue; int result = Tcl_ExprLongObj(interp, expr, &longValue); if (result == TCL_OK) { - if ((longValue >= (long)(INT_MIN)) - && (longValue <= (long)(UINT_MAX))) { + if ((longValue >= (long)(INT_MIN)) + && (longValue <= (long)(UINT_MAX))) { *ptr = (int)longValue; } else { Tcl_SetObjResult(interp, Tcl_NewStringObj( diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index c94a0be..1714aad 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -49,17 +49,24 @@ static Tcl_ObjCmdProc TestbigdataCmd; #define VARPTR_KEY "TCLOBJTEST_VARPTR" #define NUMBER_OF_OBJECT_VARS 20 -static void VarPtrDeleteProc(void *clientData, TCL_UNUSED(Tcl_Interp *)) +static void +VarPtrDeleteProc( + void *clientData, + TCL_UNUSED(Tcl_Interp *)) { int i; Tcl_Obj **varPtr = (Tcl_Obj **) clientData; for (i = 0; i < NUMBER_OF_OBJECT_VARS; i++) { - if (varPtr[i]) Tcl_DecrRefCount(varPtr[i]); + if (varPtr[i]) { + Tcl_DecrRefCount(varPtr[i]); + } } Tcl_Free(varPtr); } -static Tcl_Obj **GetVarPtr(Tcl_Interp *interp) +static Tcl_Obj ** +GetVarPtr( + Tcl_Interp *interp) { Tcl_InterpDeleteProc *proc; @@ -1653,12 +1660,9 @@ TestbigdataCmd ( /* Need one byte for nul terminator */ Tcl_Size limit = TCL_SIZE_MAX-1; if (len < 0 || len > limit) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf( + Tcl_SetObjResult(interp, Tcl_ObjPrintf( "%s is greater than max permitted length %" TCL_SIZE_MODIFIER "d", - Tcl_GetString(objv[2]), - limit)); + Tcl_GetString(objv[2]), limit)); return TCL_ERROR; } diff --git a/generic/tclTrace.c b/generic/tclTrace.c index 0a9e47a..bea59a6 100644 --- a/generic/tclTrace.c +++ b/generic/tclTrace.c @@ -1985,7 +1985,8 @@ typedef struct { void *clientData; } TraceWrapperInfo; -static int traceWrapperProc( +static int +traceWrapperProc( void *clientData, Tcl_Interp *interp, Tcl_Size level, @@ -2001,7 +2002,9 @@ static int traceWrapperProc( return info->proc(info->clientData, interp, (int)level, command, commandInfo, objc, objv); } -static void traceWrapperDelProc(void *clientData) +static void +traceWrapperDelProc( + void *clientData) { TraceWrapperInfo *info = (TraceWrapperInfo *)clientData; clientData = info->clientData; @@ -2396,7 +2399,7 @@ TclCheckArrayTraces( int code = TCL_OK; if (varPtr && (varPtr->flags & VAR_TRACED_ARRAY) - && (TclIsVarArray(varPtr) || TclIsVarUndefined(varPtr))) { + && (TclIsVarArray(varPtr) || TclIsVarUndefined(varPtr))) { Interp *iPtr = (Interp *)interp; code = TclObjCallVarTraces(iPtr, arrayPtr, varPtr, name, NULL, diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 0babf4d..3dede09 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -234,8 +234,8 @@ Tcl_UniCharToUtf( ((ch & 0xF800) == 0xD800)) { if (ch & 0x0400) { /* Low surrogate */ - if ( (0x80 == (0xC0 & buf[0])) - && (0 == (0xCF & buf[1]))) { + if ( (0x80 == (0xC0 & buf[0])) + && (0 == (0xCF & buf[1]))) { /* Previous Tcl_UniChar was a high surrogate, so combine */ buf[2] = (char) (0x80 | (0x3F & ch)); buf[1] |= (char) (0x80 | (0x0F & (ch >> 6))); @@ -246,12 +246,11 @@ Tcl_UniCharToUtf( /* High surrogate */ /* Add 0x10000 to the raw number encoded in the surrogate - * pair in order to get the code point. - */ + * pair in order to get the code point. */ ch += 0x40; /* Fill buffer with specific 3-byte (invalid) byte combination, - so following low surrogate can recognize it and combine */ + * so following low surrogate can recognize it and combine */ buf[2] = (char) ((ch << 4) & 0x30); buf[1] = (char) (0x80 | (0x3F & (ch >> 2))); buf[0] = (char) (0xF0 | (0x07 & (ch >> 8))); @@ -268,9 +267,9 @@ Tcl_UniCharToUtf( return 4; } } else if (ch == -1) { - if ( (0x80 == (0xC0 & buf[0])) - && (0 == (0xCF & buf[1])) - && (0xF0 == (0xF8 & buf[-1]))) { + if ( (0x80 == (0xC0 & buf[0])) + && (0 == (0xCF & buf[1])) + && (0xF0 == (0xF8 & buf[-1]))) { ch = 0xD7C0 + ((0x07 & buf[-1]) << 8) + ((0x3F & buf[0]) << 2) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 99d1010..efe7ea9 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1978,7 +1978,7 @@ Tcl_ConcatObj( objPtr = objv[i]; if (TclListObjIsCanonical(objPtr) || - TclObjTypeHasProc(objPtr,indexProc)) { + TclObjTypeHasProc(objPtr, indexProc)) { continue; } (void)Tcl_GetStringFromObj(objPtr, &length); @@ -1991,7 +1991,7 @@ Tcl_ConcatObj( for (i = 0; i < objc; i++) { objPtr = objv[i]; if (!TclListObjIsCanonical(objPtr) && - !TclObjTypeHasProc(objPtr,indexProc)) { + !TclObjTypeHasProc(objPtr, indexProc)) { continue; } if (resPtr) { @@ -2137,7 +2137,7 @@ Tcl_StringCaseMatch( * Skip all successive *'s in the pattern */ - while (*(++pattern) == '*') {} + while (*(++pattern) == '*'); p = *pattern; if (p == '\0') { return 1; @@ -2398,7 +2398,7 @@ TclByteArrayMatch( } } if (TclByteArrayMatch(string, stringEnd - string, - pattern, patternEnd - pattern, 0)) { + pattern, patternEnd - pattern, 0)) { return 1; } if (string == stringEnd) { @@ -3531,7 +3531,6 @@ GetEndOffsetFromObj( * This relies on TclGetString() returning a NUL-terminated string. */ if ((TclMaxListLength(bytes, TCL_INDEX_NONE, NULL) > 1) - /* If it's possible, do the full list parse. */ && (TCL_OK == TclListObjLength(NULL, objPtr, &length)) && (length > 1)) { @@ -3657,7 +3656,7 @@ GetEndOffsetFromObj( /* Parse the integer offset */ if (TCL_OK != TclParseNumber(NULL, objPtr, NULL, - bytes+4, length-4, NULL, TCL_PARSE_INTEGER_ONLY)) { + bytes + 4, length - 4, NULL, TCL_PARSE_INTEGER_ONLY)) { /* Not a recognized integer format */ goto parseError; } @@ -3866,7 +3865,7 @@ TclIndexEncode( * the position after the end and so do not raise an error. */ if ((sizeof(int) != sizeof(Tcl_Size)) && - (wide > INT_MAX) && (wide < WIDE_MAX-1)) { + (wide > INT_MAX) && (wide < WIDE_MAX-1)) { /* 2(a,b) on 64-bit systems*/ goto rangeerror; } @@ -3896,7 +3895,7 @@ TclIndexEncode( * and so do not raise an error. */ if ((sizeof(int) != sizeof(Tcl_Size)) && - (wide > (ENDVALUE - LIST_MAX)) && (wide <= INT_MAX)) { + (wide > (ENDVALUE - LIST_MAX)) && (wide <= INT_MAX)) { /* 1(c), 4(a,b) on 64-bit systems */ goto rangeerror; } @@ -3976,25 +3975,21 @@ TclIndexDecode( *------------------------------------------------------------------------ */ int -TclCommandWordLimitError ( +TclCommandWordLimitError( Tcl_Interp *interp, /* May be NULL */ Tcl_Size count) /* If <= 0, "unknown" */ { if (interp) { if (count > 0) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf("Number of words (%" TCL_SIZE_MODIFIER - "d) in command exceeds limit %" TCL_SIZE_MODIFIER - "d.", - count, - (Tcl_Size)INT_MAX)); - } - else { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("Number of words in command exceeds " - "limit %" TCL_SIZE_MODIFIER "d.", - (Tcl_Size)INT_MAX)); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Number of words (%" TCL_SIZE_MODIFIER + "d) in command exceeds limit %" TCL_SIZE_MODIFIER "d.", + count, (Tcl_Size)INT_MAX)); + } else { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Number of words in command exceeds limit %" + TCL_SIZE_MODIFIER "d.", + (Tcl_Size)INT_MAX)); } } return TCL_ERROR; /* Always */ diff --git a/generic/tclVar.c b/generic/tclVar.c index 9f1fbbf..1f5431c 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -986,7 +986,7 @@ TclLookupSimpleVar( localNameStr = Tcl_GetStringFromObj(objPtr, &localLen); if ((varLen == localLen) && (varName[0] == localNameStr[0]) - && !memcmp(varName, localNameStr, varLen)) { + && !memcmp(varName, localNameStr, varLen)) { *indexPtr = i; return (Var *) &varFramePtr->compiledLocals[i]; } @@ -5496,7 +5496,7 @@ TclDeleteVars( } for (varPtr = VarHashFirstVar(tablePtr, &search); varPtr != NULL; - varPtr = VarHashFirstVar(tablePtr, &search)) { + varPtr = VarHashFirstVar(tablePtr, &search)) { UnsetVarStruct(varPtr, NULL, iPtr, VarHashGetKey(varPtr), NULL, flags, -1); VarHashDeleteEntry(varPtr); diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index d9e6299..3aaeb6c 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -267,7 +267,11 @@ typedef struct ZipChannel { int mode; /* O_WRITE, O_APPEND, O_TRUNC etc.*/ unsigned long keys[3]; /* Key for decryption */ } ZipChannel; -static inline int ZipChannelWritable(ZipChannel *info) { + +static inline int +ZipChannelWritable( + ZipChannel *info) +{ return (info->mode & (O_WRONLY | O_RDWR)) != 0; } @@ -467,7 +471,9 @@ static Tcl_ChannelType ZipChannelType = { * *------------------------------------------------------------------------ */ -int TclIsZipfsPath (const char *path) +int +TclIsZipfsPath( + const char *path) { #ifdef _WIN32 return strncmp(path, ZIPFS_VOLUME, ZIPFS_VOLUME_LEN) ? 0 : ZIPFS_VOLUME_LEN; @@ -475,7 +481,7 @@ int TclIsZipfsPath (const char *path) int i; for (i = 0; i < ZIPFS_VOLUME_LEN; ++i) { if (path[i] != ZIPFS_VOLUME[i] && - (path[i] != '\\' || ZIPFS_VOLUME[i] != '/')) { + (path[i] != '\\' || ZIPFS_VOLUME[i] != '/')) { return 0; } } @@ -755,10 +761,10 @@ CountSlashes( * *------------------------------------------------------------------------ */ -static int IsCryptHeaderValid( - ZipEntry *z, - unsigned char cryptHeader[ZIP_CRYPT_HDR_LEN] - ) +static int +IsCryptHeaderValid( + ZipEntry *z, + unsigned char cryptHeader[ZIP_CRYPT_HDR_LEN]) { /* * There are multiple possibilities. The last one or two bytes of the @@ -1029,8 +1035,8 @@ NormalizeMountPoint(Tcl_Interp *interp, invalidMountPath: if (interp) { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("Invalid mount path \"%s\"", mountPath)); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Invalid mount path \"%s\"", mountPath)); ZIPFS_ERROR_CODE(interp, "MOUNT_PATH"); } @@ -1199,7 +1205,9 @@ ZipFSLookupZip( *------------------------------------------------------------------------ */ static int -ContainsMountPoint (const char *path, int pathLen) +ContainsMountPoint( + const char *path, + int pathLen) { Tcl_HashEntry *hPtr; Tcl_HashSearch search; @@ -1207,15 +1215,16 @@ ContainsMountPoint (const char *path, int pathLen) if (ZipFS.zipHash.numEntries == 0) { return 0; } - if (pathLen < 0) + if (pathLen < 0) { pathLen = strlen(path); + } /* * We are looking for the case where the path is //zipfs:/a/b * and there is a mount point //zipfs:/a/b/c/.. below it */ for (hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &search); hPtr; - hPtr = Tcl_NextHashEntry(&search)) { + hPtr = Tcl_NextHashEntry(&search)) { ZipFile *zf = (ZipFile *) Tcl_GetHashValue(hPtr); if (zf->mountPointLen == 0) { @@ -1229,8 +1238,8 @@ ContainsMountPoint (const char *path, int pathLen) for (z = zf->topEnts; z; z = z->tnext) { int lenz = (int) strlen(z->name); if ((lenz >= pathLen) && - (z->name[pathLen] == '/' || z->name[pathLen] == '\0') && - (strncmp(z->name, path, pathLen) == 0)) { + (z->name[pathLen] == '/' || z->name[pathLen] == '\0') && + (strncmp(z->name, path, pathLen) == 0)) { return 1; } } @@ -1477,7 +1486,7 @@ ZipFSFindTOC( * the EOCD. Note this automatically means cdirZipOffset+cdirSize < zf->length. */ if (!(cdirZipOffset <= (size_t)eocdDataOffset && - cdirSize <= eocdDataOffset - cdirZipOffset)) { + cdirSize <= eocdDataOffset - cdirZipOffset)) { if (!needZip) { /* Simply point to end od data */ zf->directoryOffset = zf->baseOffset = zf->passOffset = zf->length; @@ -1525,7 +1534,7 @@ ZipFSFindTOC( size_t localhdr_off = ZipReadInt(start, end, dirEntry + ZIP_CENTRAL_LOCALHDR_OFFS); const unsigned char *localP = zf->data + zf->baseOffset + localhdr_off; if (localP > (cdirStart - ZIP_LOCAL_HEADER_LEN) || - ZipReadInt(start, end, localP) != ZIP_LOCAL_HEADER_SIG) { + ZipReadInt(start, end, localP) != ZIP_LOCAL_HEADER_SIG) { ZIPFS_ERROR(interp, "Failed to find local header"); ZIPFS_ERROR_CODE(interp, "LCL_HDR"); goto error; @@ -1650,8 +1659,8 @@ ZipFSOpenArchive( } /* What's the magic about 64 * 1024 * 1024 ? */ if ((zf->length <= ZIP_CENTRAL_END_LEN) || - (zf->length - ZIP_CENTRAL_END_LEN) > - (64 * 1024 * 1024 - ZIP_CENTRAL_END_LEN)) { + (zf->length - ZIP_CENTRAL_END_LEN) > + (64 * 1024 * 1024 - ZIP_CENTRAL_END_LEN)) { ZIPFS_ERROR(interp, "illegal file size"); ZIPFS_ERROR_CODE(interp, "FILE_SIZE"); goto error; @@ -2344,27 +2353,24 @@ TclZipfs_Mount( Tcl_IncrRefCount(zipPathObj); normZipPathObj = Tcl_FSGetNormalizedPath(interp, zipPathObj); if (normZipPathObj == NULL) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf("could not normalize zip filename \"%s\"", zipname)); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "could not normalize zip filename \"%s\"", zipname)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "NORMALIZE", (void *)NULL); ret = TCL_ERROR; } else { Tcl_IncrRefCount(normZipPathObj); const char *normPath = Tcl_GetString(normZipPathObj); if (passwd == NULL || - (ret = IsPasswordValid(interp, passwd, strlen(passwd))) == - TCL_OK) { + (ret = IsPasswordValid(interp, passwd, + strlen(passwd))) == TCL_OK) { zf = AllocateZipFile(interp, strlen(mountPoint)); if (zf == NULL) { ret = TCL_ERROR; - } - else { + } else { ret = ZipFSOpenArchive(interp, normPath, 1, zf); if (ret != TCL_OK) { Tcl_Free(zf); - } - else { + } else { ret = ZipFSCatalogFilesystem( interp, zf, mountPoint, passwd, normPath); /* Note zf is already freed on error! */ @@ -2440,8 +2446,8 @@ TclZipfs_MountBuffer( */ ret = TCL_ERROR; if ((datalen <= ZIP_CENTRAL_END_LEN) || - (datalen - ZIP_CENTRAL_END_LEN) > - (64 * 1024 * 1024 - ZIP_CENTRAL_END_LEN)) { + (datalen - ZIP_CENTRAL_END_LEN) > + (64 * 1024 * 1024 - ZIP_CENTRAL_END_LEN)) { ZIPFS_ERROR(interp, "illegal file size"); ZIPFS_ERROR_CODE(interp, "FILE_SIZE"); goto done; @@ -4086,10 +4092,9 @@ ZipFSInfoObjCmd( } else { Tcl_SetErrno(ENOENT); if (interp) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf("path \"%s\" not found in any zipfs volume", - filename)); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "path \"%s\" not found in any zipfs volume", + filename)); } ret = TCL_ERROR; } @@ -4293,7 +4298,7 @@ TclZipfs_TclLibrary(void) #elif !defined(NO_DLFCN_H) Dl_info dlinfo; if (dladdr((const void *)TclZipfs_TclLibrary, &dlinfo) && (dlinfo.dli_fname != NULL) - && (ZipfsAppHookFindTclInit(dlinfo.dli_fname) == TCL_OK)) { + && (ZipfsAppHookFindTclInit(dlinfo.dli_fname) == TCL_OK)) { return ScriptLibrarySetup(zipfs_literal_tcl_library); } #else @@ -4746,9 +4751,9 @@ ZipChannelOpen( if ((ZipFS.wrmax <= 0) && wr) { Tcl_SetErrno(EACCES); if (interp) { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("writes not permitted: %s", - Tcl_PosixError(interp))); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "writes not permitted: %s", + Tcl_PosixError(interp))); } return NULL; } @@ -4756,11 +4761,10 @@ ZipChannelOpen( if ((mode & (O_APPEND|O_TRUNC)) && !wr) { Tcl_SetErrno(EINVAL); if (interp) { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("Invalid flags 0x%x. O_APPEND and " - "O_TRUNC require write access: %s", - mode, - Tcl_PosixError(interp))); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Invalid flags 0x%x. O_APPEND and " + "O_TRUNC require write access: %s", + mode, Tcl_PosixError(interp))); } return NULL; } @@ -4774,17 +4778,16 @@ ZipChannelOpen( if (!z) { Tcl_SetErrno(wr ? ENOTSUP : ENOENT); if (interp) { - Tcl_SetObjResult(interp, - Tcl_ObjPrintf("file \"%s\" not %s: %s", - filename, - wr ? "created" : "found", - Tcl_PosixError(interp))); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "file \"%s\" not %s: %s", + filename, wr ? "created" : "found", + Tcl_PosixError(interp))); } goto error; } if (z->numBytes < 0 || z->numCompressedBytes < 0 || - z->offset >= z->zipFilePtr->length) { + z->offset >= z->zipFilePtr->length) { /* Normally this should only happen for zip64. */ ZIPFS_ERROR(interp, "file size error (may be zip64)"); ZIPFS_ERROR_CODE(interp, "FILE_SIZE"); @@ -4815,8 +4818,9 @@ ZipChannelOpen( goto error; } flags = TCL_WRITABLE; - if (mode & O_RDWR) + if (mode & O_RDWR) { flags |= TCL_READABLE; + } } else { /* Read-only */ flags |= TCL_READABLE; @@ -4949,9 +4953,8 @@ InitWritableChannel( if (z->isEncrypted) { assert(z->numCompressedBytes >= ZIP_CRYPT_HDR_LEN); /* caller should have checked*/ - if (DecodeCryptHeader( - interp, z, info->keys, z->zipFilePtr->data + z->offset) != - TCL_OK) { + if (DecodeCryptHeader(interp, z, info->keys, + z->zipFilePtr->data + z->offset) != TCL_OK) { goto error_cleanup; } } @@ -5017,12 +5020,13 @@ InitWritableChannel( err = inflate(&stream, Z_SYNC_FLUSH); inflateEnd(&stream); if ((err != Z_STREAM_END) && - ((err != Z_OK) || (stream.avail_in != 0))) { + ((err != Z_OK) || (stream.avail_in != 0))) { goto corruptionError; } /* Even if decompression succeeded, counts should be as expected */ - if ((int) stream.total_out != z->numBytes) + if ((int) stream.total_out != z->numBytes) { goto corruptionError; + } info->numBytes = z->numBytes; if (cbuf) { Tcl_Free(cbuf); @@ -5032,8 +5036,9 @@ InitWritableChannel( * Need to decrypt some otherwise-simple stored data. */ if (z->numCompressedBytes <= ZIP_CRYPT_HDR_LEN || - (z->numCompressedBytes - ZIP_CRYPT_HDR_LEN) != z->numBytes) + (z->numCompressedBytes - ZIP_CRYPT_HDR_LEN) != z->numBytes) { goto corruptionError; + } int len = z->numCompressedBytes - ZIP_CRYPT_HDR_LEN; assert(len <= info->ubufSize); for (i = 0; i < len; i++) { @@ -5187,8 +5192,9 @@ InitReadableChannel( goto corruptionError; } /* Even if decompression succeeded, counts should be as expected */ - if ((int) stream.total_out != z->numBytes) + if ((int) stream.total_out != z->numBytes) { goto corruptionError; + } if (ubuf) { info->isEncrypted = 0; @@ -5203,8 +5209,9 @@ InitReadableChannel( * on it, and it can be randomly accessed later. */ if (z->numCompressedBytes <= ZIP_CRYPT_HDR_LEN || - (z->numCompressedBytes - ZIP_CRYPT_HDR_LEN) != z->numBytes) + (z->numCompressedBytes - ZIP_CRYPT_HDR_LEN) != z->numBytes) { goto corruptionError; + } len = z->numCompressedBytes - ZIP_CRYPT_HDR_LEN; ubuf = (unsigned char *) Tcl_AttemptAlloc(len); if (ubuf == NULL) { @@ -5545,7 +5552,7 @@ ZipFSMatchInDirectoryProc( return TCL_ERROR; } if ((wanted & (TCL_GLOB_TYPE_DIR | TCL_GLOB_TYPE_FILE | - TCL_GLOB_TYPE_MOUNT)) == 0) { + TCL_GLOB_TYPE_MOUNT)) == 0) { /* Not looking for files,dirs,mounts. zipfs cannot have others */ return TCL_OK; } @@ -5609,8 +5616,8 @@ ZipFSMatchInDirectoryProc( /* TODO - can't seem to get to this code from script for tests. */ /* Follow logic of what tclUnixFile.c does */ if ((wanted == (TCL_GLOB_TYPE_DIR | TCL_GLOB_TYPE_FILE)) || - (wanted == TCL_GLOB_TYPE_DIR && z->isDirectory) || - (wanted == TCL_GLOB_TYPE_FILE && !z->isDirectory)) { + (wanted == TCL_GLOB_TYPE_DIR && z->isDirectory) || + (wanted == TCL_GLOB_TYPE_FILE && !z->isDirectory)) { Tcl_ListObjAppendElement(NULL, result, pathPtr); } goto end; @@ -5655,17 +5662,17 @@ ZipFSMatchInDirectoryProc( Tcl_HashSearch search; if (foundInHash) { for (hPtr = Tcl_FirstHashEntry(&ZipFS.fileHash, &search); hPtr; - hPtr = Tcl_NextHashEntry(&search)) { + hPtr = Tcl_NextHashEntry(&search)) { z = (ZipEntry *)Tcl_GetHashValue(hPtr); if ((wanted == (TCL_GLOB_TYPE_DIR | TCL_GLOB_TYPE_FILE)) || - (wanted == TCL_GLOB_TYPE_DIR && z->isDirectory) || - (wanted == TCL_GLOB_TYPE_FILE && !z->isDirectory)) { + (wanted == TCL_GLOB_TYPE_DIR && z->isDirectory) || + (wanted == TCL_GLOB_TYPE_FILE && !z->isDirectory)) { if ((z->depth == scnt) && - ((z->flags & ZE_F_VOLUME) == 0) /* Bug 14db54d81e */ - && Tcl_StringCaseMatch(z->name, pat, 0)) { - Tcl_CreateHashEntry( - &duplicates, z->name + strip, ¬Duplicate); + ((z->flags & ZE_F_VOLUME) == 0) /* Bug 14db54d81e */ + && Tcl_StringCaseMatch(z->name, pat, 0)) { + Tcl_CreateHashEntry(&duplicates, z->name + strip, + ¬Duplicate); assert(notDuplicate); AppendWithPrefix(result, prefixBuf, z->name + strip, -1); } @@ -5682,16 +5689,16 @@ ZipFSMatchInDirectoryProc( Tcl_DString ds; Tcl_DStringInit(&ds); for (hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &search); hPtr; - hPtr = Tcl_NextHashEntry(&search)) { + hPtr = Tcl_NextHashEntry(&search)) { ZipFile *zf = (ZipFile *)Tcl_GetHashValue(hPtr); if (Tcl_StringCaseMatch(zf->mountPoint, pat, 0)) { const char *tail = zf->mountPoint + len; - if (*tail == '\0') + if (*tail == '\0') { continue; + } const char *end = strchr(tail, '/'); - Tcl_DStringAppend(&ds, - zf->mountPoint + strip, - end ? (Tcl_Size)(end - zf->mountPoint) : -1); + Tcl_DStringAppend(&ds, zf->mountPoint + strip, + end ? (Tcl_Size)(end - zf->mountPoint) : -1); const char *matchedPath = Tcl_DStringValue(&ds); (void)Tcl_CreateHashEntry( &duplicates, matchedPath, ¬Duplicate); @@ -6328,7 +6335,8 @@ ZipfsAppHookFindTclInit( * *------------------------------------------------------------------------ */ -void TclZipfsFinalize(void) +void +TclZipfsFinalize(void) { WriteLock(); if (!ZipFS.initialized) { @@ -6560,7 +6568,9 @@ TclZipfs_TclLibrary(void) return NULL; } -int TclIsZipfsPath (const char *path) +int +TclIsZipfsPath( + TCL_UNUSED(const char *)) /* path */ { return 0; } diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c index 7525abe..6aa14b2 100644 --- a/unix/tclLoadDyld.c +++ b/unix/tclLoadDyld.c @@ -257,8 +257,12 @@ TclpDlopen( &dyldObjFileImage); if (err == NSObjectFileImageSuccess && dyldObjFileImage) { int nsflags = NSLINKMODULE_OPTION_RETURN_ON_ERROR; - if (!(flags & 1)) nsflags |= NSLINKMODULE_OPTION_PRIVATE; - if (!(flags & 2)) nsflags |= NSLINKMODULE_OPTION_BINDNOW; + if (!(flags & 1)) { + nsflags |= NSLINKMODULE_OPTION_PRIVATE; + } + if (!(flags & 2)) { + nsflags |= NSLINKMODULE_OPTION_BINDNOW; + } module = NSLinkModule(dyldObjFileImage, nativePath, nsflags); NSDestroyObjectFileImage(dyldObjFileImage); if (module) { @@ -654,8 +658,12 @@ TclpLoadMemory( * Extract the module we want from the image of the object file. */ - if (!(flags & 1)) nsflags |= NSLINKMODULE_OPTION_PRIVATE; - if (!(flags & 2)) nsflags |= NSLINKMODULE_OPTION_BINDNOW; + if (!(flags & 1)) { + nsflags |= NSLINKMODULE_OPTION_PRIVATE; + } + if (!(flags & 2)) { + nsflags |= NSLINKMODULE_OPTION_BINDNOW; + } module = NSLinkModule(dyldObjFileImage, "[Memory Based Bundle]", nsflags); NSDestroyObjectFileImage(dyldObjFileImage); if (!module) { diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 36ed409..78ed008 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -1322,7 +1322,6 @@ TcpConnect( for (statePtr->myaddr = statePtr->myaddrlist; statePtr->myaddr != NULL; statePtr->myaddr = statePtr->myaddr->ai_next) { - /* * No need to try combinations of local and remote addresses of * different families. diff --git a/unix/tclUnixTest.c b/unix/tclUnixTest.c index 133cdf6..cdb1caa 100644 --- a/unix/tclUnixTest.c +++ b/unix/tclUnixTest.c @@ -72,7 +72,7 @@ static Tcl_ObjCmdProc TestfindexecutableCmd; static Tcl_ObjCmdProc TestforkCmd; static Tcl_ObjCmdProc TestgotsigCmd; static Tcl_FileProc TestFileHandlerProc; -static void AlarmHandler(int signum); +static void AlarmHandler(int signum); /* *---------------------------------------------------------------------- diff --git a/unix/tclXtNotify.c b/unix/tclXtNotify.c index aa88760..8ca2c5f 100644 --- a/unix/tclXtNotify.c +++ b/unix/tclXtNotify.c @@ -91,7 +91,7 @@ static int WaitForEvent(const Tcl_Time * timePtr); * Functions defined in this file for use by users of the Xt Notifier: */ -MODULE_SCOPE void InitNotifier(void); +MODULE_SCOPE void InitNotifier(void); MODULE_SCOPE XtAppContext TclSetAppContext(XtAppContext ctx); /* diff --git a/unix/tclXtTest.c b/unix/tclXtTest.c index 09f454c..c6bcc18 100644 --- a/unix/tclXtTest.c +++ b/unix/tclXtTest.c @@ -21,7 +21,7 @@ static Tcl_ObjCmdProc TesteventloopCmd; * Functions defined in tclXtNotify.c for use by users of the Xt Notifier: */ -extern void InitNotifier(void); +extern void InitNotifier(void); extern XtAppContext TclSetAppContext(XtAppContext ctx); /* diff --git a/win/tclWinChan.c b/win/tclWinChan.c index 5f03138..6413adb 100644 --- a/win/tclWinChan.c +++ b/win/tclWinChan.c @@ -98,7 +98,7 @@ static int FileTruncateProc(void *instanceData, long long length); static DWORD FileGetType(HANDLE handle); static int NativeIsComPort(const WCHAR *nativeName); -static Tcl_Channel OpenFileChannel(HANDLE handle, char *channelName, +static Tcl_Channel OpenFileChannel(HANDLE handle, char *channelName, int permissions, int appendMode); /* diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c index acd5851..146f6b8 100644 --- a/win/tclWinConsole.c +++ b/win/tclWinConsole.c @@ -178,8 +178,8 @@ typedef struct ConsoleHandleInfo { typedef struct ConsoleChannelInfo { HANDLE handle; /* Console handle */ Tcl_ThreadId threadId; /* Id of owning thread */ - struct ConsoleChannelInfo - *nextWatchingChannelPtr; /* Pointer to next channel watching events. */ + struct ConsoleChannelInfo *nextWatchingChannelPtr; + /* Pointer to next channel watching events. */ Tcl_Channel channel; /* Pointer to channel structure. */ DWORD initMode; /* Initial console mode. */ int numRefs; /* See comments above */ @@ -201,50 +201,51 @@ typedef struct ConsoleChannelInfo { */ typedef struct { - Tcl_Event header; /* Information that is standard for all events. */ - ConsoleChannelInfo *chanInfoPtr; /* Pointer to console info structure. Note - * that we still have to verify that the - * console exists before dereferencing this - * pointer. */ + Tcl_Event header; /* Information that is standard for all events. */ + ConsoleChannelInfo *chanInfoPtr; + /* Pointer to console info structure. Note + * that we still have to verify that the + * console exists before dereferencing this + * pointer. */ } ConsoleEvent; /* * Declarations for functions used only in this file. */ -static int ConsoleBlockModeProc(void *instanceData, int mode); -static void ConsoleCheckProc(void *clientData, int flags); -static int ConsoleCloseProc(void *instanceData, - Tcl_Interp *interp, int flags); -static int ConsoleEventProc(Tcl_Event *evPtr, int flags); -static void ConsoleExitHandler(void *clientData); -static int ConsoleGetHandleProc(void *instanceData, - int direction, void **handlePtr); -static int ConsoleGetOptionProc(void *instanceData, - Tcl_Interp *interp, const char *optionName, - Tcl_DString *dsPtr); -static void ConsoleInit(void); -static int ConsoleInputProc(void *instanceData, char *buf, - int toRead, int *errorCode); -static int ConsoleOutputProc(void *instanceData, - const char *buf, int toWrite, int *errorCode); -static int ConsoleSetOptionProc(void *instanceData, - Tcl_Interp *interp, const char *optionName, - const char *value); -static void ConsoleSetupProc(void *clientData, int flags); -static void ConsoleWatchProc(void *instanceData, int mask); -static void ProcExitHandler(void *clientData); -static void ConsoleThreadActionProc(void *instanceData, int action); -static DWORD ReadConsoleChars(HANDLE hConsole, WCHAR *lpBuffer, - Tcl_Size nChars, Tcl_Size *nCharsReadPtr); -static DWORD WriteConsoleChars(HANDLE hConsole, - const WCHAR *lpBuffer, Tcl_Size nChars, - Tcl_Size *nCharsWritten); -static void RingBufferInit(RingBuffer *ringPtr, Tcl_Size capacity); -static void RingBufferClear(RingBuffer *ringPtr); -static Tcl_Size RingBufferIn(RingBuffer *ringPtr, const char *srcPtr, +static int ConsoleBlockModeProc(void *instanceData, int mode); +static void ConsoleCheckProc(void *clientData, int flags); +static int ConsoleCloseProc(void *instanceData, + Tcl_Interp *interp, int flags); +static int ConsoleEventProc(Tcl_Event *evPtr, int flags); +static void ConsoleExitHandler(void *clientData); +static int ConsoleGetHandleProc(void *instanceData, + int direction, void **handlePtr); +static int ConsoleGetOptionProc(void *instanceData, + Tcl_Interp *interp, const char *optionName, + Tcl_DString *dsPtr); +static void ConsoleInit(void); +static int ConsoleInputProc(void *instanceData, char *buf, + int toRead, int *errorCode); +static int ConsoleOutputProc(void *instanceData, + const char *buf, int toWrite, int *errorCode); +static int ConsoleSetOptionProc(void *instanceData, + Tcl_Interp *interp, const char *optionName, + const char *value); +static void ConsoleSetupProc(void *clientData, int flags); +static void ConsoleWatchProc(void *instanceData, int mask); +static void ProcExitHandler(void *clientData); +static void ConsoleThreadActionProc(void *instanceData, int action); +static DWORD ReadConsoleChars(HANDLE hConsole, WCHAR *lpBuffer, + Tcl_Size nChars, Tcl_Size *nCharsReadPtr); +static DWORD WriteConsoleChars(HANDLE hConsole, + const WCHAR *lpBuffer, Tcl_Size nChars, + Tcl_Size *nCharsWritten); +static void RingBufferInit(RingBuffer *ringPtr, Tcl_Size capacity); +static void RingBufferClear(RingBuffer *ringPtr); +static Tcl_Size RingBufferIn(RingBuffer *ringPtr, const char *srcPtr, Tcl_Size srcLen, int partialCopyOk); -static Tcl_Size RingBufferOut(RingBuffer *ringPtr, char *dstPtr, +static Tcl_Size RingBufferOut(RingBuffer *ringPtr, char *dstPtr, Tcl_Size dstCapacity, int partialCopyOk); static ConsoleHandleInfo *AllocateConsoleHandleInfo(HANDLE consoleHandle, int permissions); @@ -253,7 +254,7 @@ static DWORD WINAPI ConsoleReaderThread(LPVOID arg); static DWORD WINAPI ConsoleWriterThread(LPVOID arg); static void NudgeWatchers(HANDLE consoleHandle); #ifndef NDEBUG -static int RingBufferCheck(const RingBuffer *ringPtr); +static int RingBufferCheck(const RingBuffer *ringPtr); #endif /* @@ -333,12 +334,14 @@ static const Tcl_ChannelType consoleChannelType = { *------------------------------------------------------------------------ */ static void -RingBufferInit(RingBuffer *ringPtr, Tcl_Size capacity) +RingBufferInit( + RingBuffer *ringPtr, + Tcl_Size capacity) { if (capacity <= 0 || capacity > TCL_SIZE_MAX) { Tcl_Panic("Internal error: invalid ring buffer capacity requested."); } - ringPtr->bufPtr = (char *)Tcl_Alloc(capacity); + ringPtr->bufPtr = (char *) Tcl_Alloc(capacity); ringPtr->capacity = capacity; ringPtr->start = 0; ringPtr->length = 0; @@ -360,7 +363,8 @@ RingBufferInit(RingBuffer *ringPtr, Tcl_Size capacity) *------------------------------------------------------------------------ */ static void -RingBufferClear(RingBuffer *ringPtr) +RingBufferClear( + RingBuffer *ringPtr) { if (ringPtr->bufPtr) { Tcl_Free(ringPtr->bufPtr); @@ -389,10 +393,9 @@ RingBufferClear(RingBuffer *ringPtr) static Tcl_Size RingBufferIn( RingBuffer *ringPtr, - const char *srcPtr, /* Source to be copied */ - Tcl_Size srcLen, /* Length of source */ - int partialCopyOk /* If true, partial copy is permitted */ - ) + const char *srcPtr, /* Source to be copied */ + Tcl_Size srcLen, /* Length of source */ + int partialCopyOk) /* If true, partial copy is permitted */ { Tcl_Size freeSpace; @@ -450,10 +453,11 @@ RingBufferIn( *------------------------------------------------------------------------ */ static Tcl_Size -RingBufferOut(RingBuffer *ringPtr, - char *dstPtr, /* Buffer for output data. May be NULL */ - Tcl_Size dstCapacity, /* Size of buffer */ - int partialCopyOk) /* If true, return what's available */ +RingBufferOut( + RingBuffer *ringPtr, + char *dstPtr, /* Buffer for output data. May be NULL */ + Tcl_Size dstCapacity, /* Size of buffer */ + int partialCopyOk) /* If true, return what's available */ { Tcl_Size leadLen; @@ -502,7 +506,8 @@ RingBufferOut(RingBuffer *ringPtr, #ifndef NDEBUG static int -RingBufferCheck(const RingBuffer *ringPtr) +RingBufferCheck( + const RingBuffer *ringPtr) { return (ringPtr->bufPtr != NULL && ringPtr->capacity == CONSOLE_BUFFER_SIZE && ringPtr->start < ringPtr->capacity @@ -560,13 +565,14 @@ ReadConsoleChars( result = ReadConsoleW(hConsole, lpBuffer, nChars, &nRead, NULL); if (result) { if ((nRead == 0 || nRead == (DWORD)-1) - && GetLastError() == ERROR_OPERATION_ABORTED) { + && GetLastError() == ERROR_OPERATION_ABORTED) { nRead = 0; } *nCharsReadPtr = nRead; return 0; - } else + } else { return GetLastError(); + } } /* @@ -721,19 +727,21 @@ ProcExitHandler( * As above. *------------------------------------------------------------------------ */ -void NudgeWatchers (HANDLE consoleHandle) +static void +NudgeWatchers( + HANDLE consoleHandle) { ConsoleChannelInfo *chanInfoPtr; AcquireSRWLockShared(&gConsoleLock); /* Shared-read lock */ for (chanInfoPtr = gWatchingChannelList; chanInfoPtr; - chanInfoPtr = chanInfoPtr->nextWatchingChannelPtr) { + chanInfoPtr = chanInfoPtr->nextWatchingChannelPtr) { /* * Notify channels interested in our handle AND that have * a thread attached. * No lock needed for chanInfoPtr. See ConsoleChannelInfo. */ if (chanInfoPtr->handle == consoleHandle - && chanInfoPtr->threadId != NULL) { + && chanInfoPtr->threadId != NULL) { Tcl_ThreadAlert(chanInfoPtr->threadId); } } @@ -779,7 +787,7 @@ ConsoleSetupProc( AcquireSRWLockShared(&gConsoleLock); /* READ lock - no data modification */ for (chanInfoPtr = gWatchingChannelList; block && chanInfoPtr != NULL; - chanInfoPtr = chanInfoPtr->nextWatchingChannelPtr) { + chanInfoPtr = chanInfoPtr->nextWatchingChannelPtr) { ConsoleHandleInfo *handleInfoPtr; handleInfoPtr = FindConsoleInfo(chanInfoPtr); if (handleInfoPtr != NULL) { @@ -787,7 +795,7 @@ ConsoleSetupProc( /* Remember at most one of READABLE, WRITABLE set */ if (chanInfoPtr->watchMask & TCL_READABLE) { if (RingBufferLength(&handleInfoPtr->buffer) > 0 - || handleInfoPtr->lastError != ERROR_SUCCESS) { + || handleInfoPtr->lastError != ERROR_SUCCESS) { block = 0; /* Input data available */ } } else if (chanInfoPtr->watchMask & TCL_WRITABLE) { @@ -874,7 +882,7 @@ ConsoleCheckProc( /* Rememeber channel is read or write, never both */ if (chanInfoPtr->watchMask & TCL_READABLE) { if (RingBufferLength(&handleInfoPtr->buffer) > 0 - || handleInfoPtr->lastError != ERROR_SUCCESS) { + || handleInfoPtr->lastError != ERROR_SUCCESS) { needEvent = 1; /* Input data available or error/EOF */ } /* @@ -925,7 +933,7 @@ ConsoleCheckProc( static int ConsoleBlockModeProc( - void *instanceData, /* Instance data for channel. */ + void *instanceData, /* Instance data for channel. */ int mode) /* TCL_MODE_BLOCKING or * TCL_MODE_NONBLOCKING. */ { @@ -985,9 +993,9 @@ ConsoleCloseProc( * still close the handle. That's historical behavior on all platforms. */ if (!TclInThreadExit() - || ((GetStdHandle(STD_INPUT_HANDLE) != chanInfoPtr->handle) - && (GetStdHandle(STD_OUTPUT_HANDLE) != chanInfoPtr->handle) - && (GetStdHandle(STD_ERROR_HANDLE) != chanInfoPtr->handle))) { + || ( (GetStdHandle(STD_INPUT_HANDLE) != chanInfoPtr->handle) + && (GetStdHandle(STD_OUTPUT_HANDLE) != chanInfoPtr->handle) + && (GetStdHandle(STD_ERROR_HANDLE) != chanInfoPtr->handle))) { closeHandle = 1; } else { closeHandle = 0; @@ -997,7 +1005,7 @@ ConsoleCloseProc( /* Remove channel from watchers' list */ for (nextPtrPtr = &gWatchingChannelList; *nextPtrPtr != NULL; - nextPtrPtr = &(*nextPtrPtr)->nextWatchingChannelPtr) { + nextPtrPtr = &(*nextPtrPtr)->nextWatchingChannelPtr) { if (*nextPtrPtr == (ConsoleChannelInfo *) chanInfoPtr) { *nextPtrPtr = (*nextPtrPtr)->nextWatchingChannelPtr; break; @@ -1084,7 +1092,7 @@ ConsoleCloseProc( */ static int ConsoleInputProc( - void *instanceData, /* Console state. */ + void *instanceData, /* Console state. */ char *bufPtr, /* Where to store data read. */ int bufSize, /* How much space is available in the * buffer? */ @@ -1165,16 +1173,14 @@ ConsoleInputProc( * default is 4K which is < INPUT_BUFFER_SIZE and will rarely be * increased on stdin. */ - if ((1 & (size_t)bufPtr) == 0 /* aligned buffer */ - && (1 & bufSize) == 0 /* Even number of bytes */ - && bufSize > INPUT_BUFFER_SIZE) { + if ((1 & (size_t)bufPtr) == 0 /* aligned buffer */ + && (1 & bufSize) == 0 /* Even number of bytes */ + && bufSize > INPUT_BUFFER_SIZE) { DWORD lastError; Tcl_Size numChars; ReleaseSRWLockExclusive(&handleInfoPtr->lock); lastError = ReadConsoleChars(chanInfoPtr->handle, - (WCHAR *)bufPtr, - bufSize / sizeof(WCHAR), - &numChars); + (WCHAR *)bufPtr, bufSize / sizeof(WCHAR), &numChars); /* NOTE lock released so DON'T break. Return instead */ if (lastError != ERROR_SUCCESS) { Tcl_WinConvertError(lastError); @@ -1202,9 +1208,7 @@ ConsoleInputProc( handleInfoPtr->flags |= CONSOLE_DATA_AWAITED; WakeConditionVariable(&handleInfoPtr->consoleThreadCV); if (!SleepConditionVariableSRW(&handleInfoPtr->interpThreadCV, - &handleInfoPtr->lock, - INFINITE, - 0)) { + &handleInfoPtr->lock, INFINITE, 0)) { Tcl_WinConvertError(GetLastError()); *errorCode = Tcl_GetErrno(); numRead = -1; @@ -1216,7 +1220,7 @@ ConsoleInputProc( /* We read data. Ask for more if either async or watching for reads */ if ((chanInfoPtr->flags & CONSOLE_ASYNC) - || (chanInfoPtr->watchMask & TCL_READABLE)) { + || (chanInfoPtr->watchMask & TCL_READABLE)) { handleInfoPtr->flags |= CONSOLE_DATA_AWAITED; WakeConditionVariable(&handleInfoPtr->consoleThreadCV); } @@ -1244,7 +1248,7 @@ ConsoleInputProc( */ static int ConsoleOutputProc( - void *instanceData, /* Console state. */ + void *instanceData, /* Console state. */ const char *buf, /* The data buffer. */ int toWrite, /* How many bytes to write? */ int *errorCode) /* Where to store error code. */ @@ -1301,15 +1305,12 @@ ConsoleOutputProc( * The ring buffer deals with cases (3) and (4). It would be harder * to duplicate that here. */ - if ((chanInfoPtr->flags & CONSOLE_ASYNC) /* Case (1) */ - || RingBufferLength(&handleInfoPtr->buffer) != 0 /* Case (2) */ - || (toWrite & 1) != 0 /* Case (3) */ - || (PTR2INT(buf) & 1) != 0 /* Case (4) */ - ) { + if ((chanInfoPtr->flags & CONSOLE_ASYNC) /* Case (1) */ + || RingBufferLength(&handleInfoPtr->buffer) != 0 /* Case (2) */ + || (toWrite & 1) != 0 /* Case (3) */ + || (PTR2INT(buf) & 1) != 0) { /* Case (4) */ numWritten += RingBufferIn(&handleInfoPtr->buffer, - numWritten + buf, - toWrite - numWritten, - 1); + numWritten + buf, toWrite - numWritten, 1); if (numWritten == toWrite || chanInfoPtr->flags & CONSOLE_ASYNC) { /* All done or async, just accept whatever was written */ break; @@ -1321,9 +1322,7 @@ ConsoleOutputProc( */ WakeConditionVariable(&handleInfoPtr->consoleThreadCV); if (!SleepConditionVariableSRW(&handleInfoPtr->interpThreadCV, - &handleInfoPtr->lock, - INFINITE, - 0)) { + &handleInfoPtr->lock, INFINITE, 0)) { /* Report the error */ Tcl_WinConvertError(GetLastError()); *errorCode = Tcl_GetErrno(); @@ -1336,11 +1335,10 @@ ConsoleOutputProc( HANDLE consoleHandle = handleInfoPtr->console; /* Unlock before blocking in WriteConsole */ ReleaseSRWLockExclusive(&handleInfoPtr->lock); - /* UNLOCKED so return, DON'T break out of loop as it will unlock again! */ + /* UNLOCKED so return, DON'T break out of loop as it will unlock + * again! */ winStatus = WriteConsoleChars(consoleHandle, - (WCHAR *)buf, - toWrite / sizeof(WCHAR), - &numWritten); + (WCHAR *)buf, toWrite / sizeof(WCHAR), &numWritten); if (winStatus == ERROR_SUCCESS) { return numWritten * sizeof(WCHAR); } else { @@ -1414,9 +1412,8 @@ ConsoleEventProc( * still owned by this thread AND is still watching events. */ if (chanInfoPtr->channel && chanInfoPtr->threadId == Tcl_GetCurrentThread() - && (chanInfoPtr->watchMask & (TCL_READABLE|TCL_WRITABLE))) { - ConsoleHandleInfo *handleInfoPtr; - handleInfoPtr = FindConsoleInfo(chanInfoPtr); + && (chanInfoPtr->watchMask & (TCL_READABLE|TCL_WRITABLE))) { + ConsoleHandleInfo *handleInfoPtr = FindConsoleInfo(chanInfoPtr); if (handleInfoPtr == NULL) { /* Console was closed. EOF->read event only (not write) */ if (chanInfoPtr->watchMask & TCL_READABLE) { @@ -1426,10 +1423,10 @@ ConsoleEventProc( AcquireSRWLockShared(&handleInfoPtr->lock); /* Remember at most one of READABLE, WRITABLE set */ if ((chanInfoPtr->watchMask & TCL_READABLE) - && RingBufferLength(&handleInfoPtr->buffer)) { + && RingBufferLength(&handleInfoPtr->buffer)) { mask = TCL_READABLE; } else if ((chanInfoPtr->watchMask & TCL_WRITABLE) - && RingBufferHasFreeSpace(&handleInfoPtr->buffer)) { + && RingBufferHasFreeSpace(&handleInfoPtr->buffer)) { /* Generate write event space available */ mask = TCL_WRITABLE; } @@ -1484,10 +1481,9 @@ ConsoleEventProc( static void ConsoleWatchProc( - void *instanceData, /* Console state. */ + void *instanceData, /* Console state. */ int newMask) /* What events to watch for, one of - * of TCL_READABLE, TCL_WRITABLE - */ + * of TCL_READABLE, TCL_WRITABLE */ { ConsoleChannelInfo **nextPtrPtr, *ptr; ConsoleChannelInfo *chanInfoPtr = (ConsoleChannelInfo *)instanceData; @@ -1513,8 +1509,7 @@ ConsoleWatchProc( * that we are looking for data since it will not do reads until * it knows someone is awaiting. */ - ConsoleHandleInfo *handleInfoPtr; - handleInfoPtr = FindConsoleInfo(chanInfoPtr); + ConsoleHandleInfo *handleInfoPtr = FindConsoleInfo(chanInfoPtr); if (handleInfoPtr) { AcquireSRWLockExclusive(&handleInfoPtr->lock); handleInfoPtr->flags |= CONSOLE_DATA_AWAITED; @@ -1560,9 +1555,9 @@ ConsoleWatchProc( static int ConsoleGetHandleProc( - void *instanceData, /* The console state. */ + void *instanceData, /* The console state. */ TCL_UNUSED(int) /*direction*/, - void **handlePtr) /* Where to store the handle. */ + void **handlePtr) /* Where to store the handle. */ { ConsoleChannelInfo *chanInfoPtr = (ConsoleChannelInfo *)instanceData; @@ -1590,7 +1585,8 @@ ConsoleGetHandleProc( *------------------------------------------------------------------------ */ static int - ConsoleDataAvailable (HANDLE consoleHandle) + ConsoleDataAvailable( + HANDLE consoleHandle) { INPUT_RECORD input[10]; DWORD count; @@ -1599,9 +1595,8 @@ ConsoleGetHandleProc( /* * Need at least one keyboard event. */ - if (PeekConsoleInputW( - consoleHandle, input, sizeof(input) / sizeof(input[0]), &count) - == FALSE) { + if (PeekConsoleInputW(consoleHandle, input, + sizeof(input) / sizeof(input[0]), &count) == FALSE) { return -1; } /* @@ -1612,11 +1607,12 @@ ConsoleGetHandleProc( * down somewhere in the unread buffer. I suppose we could expand the * buffer but not worth... */ - if (count == (sizeof(input)/sizeof(input[0]))) + if (count == (sizeof(input)/sizeof(input[0]))) { return 1; + } for (i = 0; i < count; ++i) { if (input[i].EventType == KEY_EVENT - && input[i].Event.KeyEvent.bKeyDown) { + && input[i].Event.KeyEvent.bKeyDown) { return 1; } } @@ -1685,9 +1681,8 @@ ConsoleReaderThread( assert((inputLen - inputOffset) > 0); nStored = RingBufferIn(&handleInfoPtr->buffer, - inputOffset + inputChars, - inputLen - inputOffset, - 1); + inputOffset + inputChars, inputLen - inputOffset, + 1); inputOffset += nStored; if (inputOffset == inputLen) { /* Temp buffer now empty */ @@ -1746,21 +1741,19 @@ ConsoleReaderThread( * data. */ if (lastReadSize == sizeof(inputChars) - || ((handleInfoPtr->flags & CONSOLE_DATA_AWAITED) + || ((handleInfoPtr->flags & CONSOLE_DATA_AWAITED) && ConsoleDataAvailable(handleInfoPtr->console))) { DWORD error; /* Do not hold the lock while blocked in console */ ReleaseSRWLockExclusive(&handleInfoPtr->lock); error = ReadConsoleChars(handleInfoPtr->console, - (WCHAR *)inputChars, - sizeof(inputChars) / sizeof(WCHAR), - &inputLen); + (WCHAR *)inputChars, sizeof(inputChars) / sizeof(WCHAR), + &inputLen); AcquireSRWLockExclusive(&handleInfoPtr->lock); if (error == 0) { inputLen *= sizeof(WCHAR); lastReadSize = inputLen; - } - else { + } else { /* * We only store the last error. It is up to channel * handlers whether to close or not in case of errors. @@ -1771,8 +1764,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 @@ -1783,9 +1775,7 @@ ConsoleReaderThread( sleepTime = handleInfoPtr->flags & CONSOLE_DATA_AWAITED ? 50 : INFINITE; SleepConditionVariableSRW(&handleInfoPtr->consoleThreadCV, - &handleInfoPtr->lock, - sleepTime, - 0); + &handleInfoPtr->lock, sleepTime, 0); } /* Loop again to check for exit or wait for readers to wake us */ @@ -1802,7 +1792,7 @@ ConsoleReaderThread( ReleaseSRWLockExclusive(&handleInfoPtr->lock); AcquireSRWLockExclusive(&gConsoleLock); /* Modifying - exclusive lock */ for (iterator = &gConsoleHandleInfoList; *iterator; - iterator = &(*iterator)->nextPtr) { + iterator = &(*iterator)->nextPtr) { if (*iterator == handleInfoPtr) { *iterator = handleInfoPtr->nextPtr; break; @@ -1814,7 +1804,7 @@ ConsoleReaderThread( RingBufferClear(&handleInfoPtr->buffer); if (handleInfoPtr->console != INVALID_HANDLE_VALUE - && handleInfoPtr->lastError != ERROR_INVALID_HANDLE) { + && handleInfoPtr->lastError != ERROR_INVALID_HANDLE) { SetConsoleMode(handleInfoPtr->console, handleInfoPtr->initMode); /* * NOTE: we do not call CloseHandle(handleInfoPtr->console) here. @@ -1847,7 +1837,8 @@ ConsoleReaderThread( *---------------------------------------------------------------------- */ static DWORD WINAPI -ConsoleWriterThread(LPVOID arg) +ConsoleWriterThread( + LPVOID arg) { ConsoleHandleInfo *handleInfoPtr = (ConsoleHandleInfo *) arg; ConsoleHandleInfo **iterator; @@ -1900,9 +1891,7 @@ ConsoleWriterThread(LPVOID arg) /* Wake up any threads waiting synchronously. */ WakeConditionVariable(&handleInfoPtr->interpThreadCV); success = SleepConditionVariableSRW(&handleInfoPtr->consoleThreadCV, - &handleInfoPtr->lock, - INFINITE, - 0); + &handleInfoPtr->lock, INFINITE, 0); /* Note: lock has been acquired again! */ if (!success && GetLastError() != ERROR_TIMEOUT) { /* TODO - what can be done? Should not happen */ @@ -1926,9 +1915,7 @@ ConsoleWriterThread(LPVOID arg) Tcl_Size numWChars = numBytes / sizeof(WCHAR); DWORD status; status = WriteConsoleChars(handleInfoPtr->console, - (WCHAR *)(offset + buffer), - numWChars, - &numWChars); + (WCHAR *)(offset + buffer), numWChars, &numWChars); if (status != 0) { /* Only overwrite if no previous error */ if (handleInfoPtr->lastError == 0) { @@ -1973,7 +1960,7 @@ ConsoleWriterThread(LPVOID arg) ReleaseSRWLockExclusive(&handleInfoPtr->lock); AcquireSRWLockExclusive(&gConsoleLock); /* Modifying - exclusive lock */ for (iterator = &gConsoleHandleInfoList; *iterator; - iterator = &(*iterator)->nextPtr) { + iterator = &(*iterator)->nextPtr) { if (*iterator == handleInfoPtr) { *iterator = handleInfoPtr->nextPtr; break; @@ -2019,8 +2006,7 @@ AllocateConsoleHandleInfo( ConsoleHandleInfo *handleInfoPtr; DWORD consoleMode; - - handleInfoPtr = (ConsoleHandleInfo *)Tcl_Alloc(sizeof(*handleInfoPtr)); + handleInfoPtr = (ConsoleHandleInfo *) Tcl_Alloc(sizeof(*handleInfoPtr)); memset(handleInfoPtr, 0, sizeof(*handleInfoPtr)); memset(handleInfoPtr, 0, sizeof(*handleInfoPtr)); handleInfoPtr->console = consoleHandle; @@ -2427,30 +2413,26 @@ ConsoleGetOptionProc( valid = 1; if (!GetConsoleScreenBufferInfo(chanInfoPtr->handle, - &consoleInfo)) { + &consoleInfo)) { Tcl_WinConvertError(GetLastError()); if (interp != NULL) { - Tcl_SetObjResult( - interp, - Tcl_ObjPrintf("couldn't read console size: %s", - Tcl_PosixError(interp))); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "couldn't read console size: %s", + Tcl_PosixError(interp))); } return TCL_ERROR; } Tcl_DStringStartSublist(dsPtr); - snprintf(buf, sizeof(buf), - "%d", + snprintf(buf, sizeof(buf), "%d", consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1); Tcl_DStringAppendElement(dsPtr, buf); - snprintf(buf, sizeof(buf), - "%d", + snprintf(buf, sizeof(buf), "%d", consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1); Tcl_DStringAppendElement(dsPtr, buf); Tcl_DStringEndSublist(dsPtr); } } - if (valid) { return TCL_OK; } diff --git a/win/tclWinFCmd.c b/win/tclWinFCmd.c index 4cb23ea..7ce3b4c 100644 --- a/win/tclWinFCmd.c +++ b/win/tclWinFCmd.c @@ -411,8 +411,7 @@ DoRenameFile( * directory back, for completeness. */ - if (MoveFileW(nativeSrc, - nativeDst) != FALSE) { + if (MoveFileW(nativeSrc, nativeDst) != FALSE) { return TCL_OK; } @@ -697,8 +696,7 @@ DoCopyFile( if (dstAttr & FILE_ATTRIBUTE_READONLY) { SetFileAttributesW(nativeDst, dstAttr & ~((DWORD)FILE_ATTRIBUTE_READONLY)); - if (CopyFileW(nativeSrc, nativeDst, - 0) != FALSE) { + if (CopyFileW(nativeSrc, nativeDst, 0) != FALSE) { return TCL_OK; } @@ -794,8 +792,7 @@ TclpDeleteFile( int res = SetFileAttributesW(path, attr & ~((DWORD) FILE_ATTRIBUTE_READONLY)); - if ((res != 0) && - (DeleteFileW(path) != FALSE)) { + if ((res != 0) && (DeleteFileW(path) != FALSE)) { return TCL_OK; } Tcl_WinConvertError(GetLastError()); @@ -1082,8 +1079,7 @@ DoRemoveJustDirectory( if (attr & FILE_ATTRIBUTE_READONLY) { attr &= ~FILE_ATTRIBUTE_READONLY; - if (SetFileAttributesW(nativePath, - attr) == FALSE) { + if (SetFileAttributesW(nativePath, attr) == FALSE) { goto end; } if (RemoveDirectoryW(nativePath) != FALSE) { @@ -1120,7 +1116,9 @@ DoRemoveJustDirectory( Tcl_DStringInit(errorPtr); p = Tcl_WCharToUtfDString(nativePath, TCL_INDEX_NONE, errorPtr); for (; *p; ++p) { - if (*p == '\\') *p = '/'; + if (*p == '\\') { + *p = '/'; + } } } return TCL_ERROR; @@ -1381,8 +1379,7 @@ TraversalCopy( if (DoCreateDirectory(nativeDst) == TCL_OK) { DWORD attr = GetFileAttributesW(nativeSrc); - if (SetFileAttributesW(nativeDst, - attr) != FALSE) { + if (SetFileAttributesW(nativeDst, attr) != FALSE) { return TCL_OK; } Tcl_WinConvertError(GetLastError()); diff --git a/win/tclWinFile.c b/win/tclWinFile.c index c0dd4fd..baf0734 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -149,7 +149,7 @@ typedef struct { * Other typedefs required by this code. */ -static __time64_t ToCTime(FILETIME fileTime); +static __time64_t ToCTime(FILETIME fileTime); static void FromCTime(__time64_t posixTime, FILETIME *fileTime); /* @@ -972,7 +972,7 @@ TclpMatchInDirectory( attr = GetFileAttributesW(native); if ((attr == INVALID_FILE_ATTRIBUTES) - || ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)) { + || ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)) { return TCL_OK; } diff --git a/win/tclWinInit.c b/win/tclWinInit.c index b506111..ca0c904 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -591,9 +591,7 @@ TclpFindVariable( Tcl_UtfToUpper(nameUpper); Tcl_DStringInit(&envString); - for (i = 0, env = _wenviron[i]; - env != NULL; - i++, env = _wenviron[i]) { + for (i = 0, env = _wenviron[i]; env != NULL; i++, env = _wenviron[i]) { /* * Chop the env string off after the equal sign, then Convert the name * to all upper case, so we do not have to convert all the characters diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c index 265c8e7..62590ef 100644 --- a/win/tclWinLoad.c +++ b/win/tclWinLoad.c @@ -114,7 +114,7 @@ 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 { lastError = firstError; diff --git a/win/tclWinNotify.c b/win/tclWinNotify.c index de4f8f2..758276e 100644 --- a/win/tclWinNotify.c +++ b/win/tclWinNotify.c @@ -57,8 +57,8 @@ static CRITICAL_SECTION notifierMutex; * Static routines defined in this file. */ -static LRESULT CALLBACK NotifierProc(HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam); +static LRESULT CALLBACK NotifierProc(HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam); /* *---------------------------------------------------------------------- diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index bce4d52..1b2e946 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -1321,7 +1321,7 @@ ApplicationType( ext = strrchr(fullName, '.'); if ((ext != NULL) && - (strcasecmp(ext, ".cmd") == 0 || strcasecmp(ext, ".bat") == 0)) { + (strcasecmp(ext, ".cmd") == 0 || strcasecmp(ext, ".bat") == 0)) { applType = APPL_DOS; break; } diff --git a/win/tclWinReg.c b/win/tclWinReg.c index 9ef62c6..a0b4e90 100644 --- a/win/tclWinReg.c +++ b/win/tclWinReg.c @@ -853,7 +853,7 @@ GetValue( Tcl_NewStringObj(Tcl_DStringValue(&buf), Tcl_DStringLength(&buf))); - while (*wp++ != 0) {/* empty body */} + while (*wp++ != 0); /* empty loop body */ p = (char *) wp; Tcl_DStringFree(&buf); } @@ -937,7 +937,6 @@ GetValueNames( size = MAX_KEY_LENGTH; while (RegEnumValueW(key,index, (WCHAR *)Tcl_DStringValue(&buffer), &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - Tcl_DStringInit(&ds); Tcl_WCharToUtfDString((const WCHAR *)Tcl_DStringValue(&buffer), size, &ds); name = Tcl_DStringValue(&ds); diff --git a/win/tclWinSock.c b/win/tclWinSock.c index d600f1f..17b6004 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -429,7 +429,7 @@ Tcl_GetHostName(void) */ void -TclInitSockets() +TclInitSockets(void) { /* Then Per thread initialization. */ DWORD id; @@ -1203,7 +1203,7 @@ TcpSetOptionProc( return TCL_OK; } if ((len > 1) && (optionName[1] == 'n') && - (strncmp(optionName, "-nodelay", len) == 0)) { + (strncmp(optionName, "-nodelay", len) == 0)) { BOOL boolVar; int rtn; @@ -2268,7 +2268,7 @@ Tcl_OpenTcpServerEx( ioctlsocket(sock, (long) FIONBIO, &flag); SendSelectMessage(tsdPtr, SELECT, statePtr); if (Tcl_SetChannelOption(interp, statePtr->channel, "-eofchar", "") - == TCL_ERROR) { + == TCL_ERROR) { Tcl_CloseEx(NULL, statePtr->channel, 0); return NULL; } diff --git a/win/tclWinTest.c b/win/tclWinTest.c index 1b679a9..999c5ba 100644 --- a/win/tclWinTest.c +++ b/win/tclWinTest.c @@ -454,8 +454,8 @@ TestplatformChmod( } /* Get process SID */ - if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dw) && - GetLastError() != ERROR_INSUFFICIENT_BUFFER) { + if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dw) + && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { goto done; } pTokenUser = (TOKEN_USER *)Tcl_Alloc(dw); @@ -464,9 +464,8 @@ TestplatformChmod( } aceEntry[nSids].sidLen = GetLengthSid(pTokenUser->User.Sid); aceEntry[nSids].pSid = Tcl_Alloc(aceEntry[nSids].sidLen); - if (!CopySid(aceEntry[nSids].sidLen, - aceEntry[nSids].pSid, - pTokenUser->User.Sid)) { + if (!CopySid(aceEntry[nSids].sidLen, aceEntry[nSids].pSid, + pTokenUser->User.Sid)) { Tcl_Free(aceEntry[nSids].pSid); /* Since we have not ++'ed nSids */ goto done; } -- cgit v0.12