diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2024-03-19 14:56:45 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2024-03-19 14:56:45 (GMT) |
commit | ede8ac42b20edcdd0e6a0353957890b7d7db59ea (patch) | |
tree | bcfa89065ecea0a374bed505c235b77cba3db0a3 /win | |
parent | 4333183b6f023a2b67e14f7f6f01b320c7e34f9f (diff) | |
download | tcl-ede8ac42b20edcdd0e6a0353957890b7d7db59ea.zip tcl-ede8ac42b20edcdd0e6a0353957890b7d7db59ea.tar.gz tcl-ede8ac42b20edcdd0e6a0353957890b7d7db59ea.tar.bz2 |
Fix indentation/brace usage style issues
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinChan.c | 2 | ||||
-rw-r--r-- | win/tclWinConsole.c | 274 | ||||
-rw-r--r-- | win/tclWinFCmd.c | 19 | ||||
-rw-r--r-- | win/tclWinFile.c | 4 | ||||
-rw-r--r-- | win/tclWinInit.c | 4 | ||||
-rw-r--r-- | win/tclWinLoad.c | 2 | ||||
-rw-r--r-- | win/tclWinNotify.c | 4 | ||||
-rw-r--r-- | win/tclWinPipe.c | 2 | ||||
-rw-r--r-- | win/tclWinReg.c | 3 | ||||
-rw-r--r-- | win/tclWinSock.c | 6 | ||||
-rw-r--r-- | win/tclWinTest.c | 9 |
11 files changed, 152 insertions, 177 deletions
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; } |