From 7ef929a5331e888efbd2ba9167f7fc3e2ccf735b Mon Sep 17 00:00:00 2001 From: hobbs Date: Tue, 28 Mar 2006 21:02:36 +0000 Subject: * win/tclWinConsole.c: revert 2005-11-03 [Patch 1256872] change to add win32 unicode console support as it broke the ability to modify the encoding to the console. --- ChangeLog | 6 ++++ win/tclWinConsole.c | 85 ++++++----------------------------------------------- 2 files changed, 15 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index e76ab1d..0fa0b54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-03-28 Jeff Hobbs + + * win/tclWinConsole.c: revert 2005-11-03 [Patch 1256872] change + to add win32 unicode console support as it broke the ability to + modify the encoding to the console. + 2006-03-28 Daniel Steffen * unix/tclUnixFCmd.c (TclpObjNormalizePath): deal with *BSD/Darwin diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c index fa38a6c..56920bf 100644 --- a/win/tclWinConsole.c +++ b/win/tclWinConsole.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinConsole.c,v 1.11.2.2 2005/11/03 11:53:59 patthoyts Exp $ + * RCS: @(#) $Id: tclWinConsole.c,v 1.11.2.3 2006/03/28 21:02:37 hobbs Exp $ */ #include "tclWinInt.h" @@ -190,70 +190,6 @@ static Tcl_ChannelType consoleChannelType = { /* *---------------------------------------------------------------------- * - * readConsoleBytes -- - * - * Wrapper for ReadConsole{A,W}, that takes and returns number of - * bytes instead of number of TCHARS - * - * Results: - * FALSE if there was a problem else TRUE - * - * Side effects: - * Reads characters from the console. - * - *---------------------------------------------------------------------- - */ - -static BOOL -readConsoleBytes(HANDLE hConsole, LPVOID lpBuffer, - DWORD nbytes, LPDWORD nbytesread) -{ - DWORD ntchars; - BOOL result; - int tcharsize; - tcharsize = tclWinProcs->useWide? 2 : 1; - result = tclWinProcs->readConsoleProc( - hConsole, lpBuffer, nbytes / tcharsize, &ntchars, NULL); - if (nbytesread) - *nbytesread = (ntchars*tcharsize); - return result; -} - -/* - *---------------------------------------------------------------------- - * - * writeConsoleBytes -- - * - * Wrapper for WriteConsole{A,W}, that takes and returns number of - * bytes instead of number of TCHARS - * - * Results: - * FALSE if there was a problem else TRUE - * - * Side effects: - * Writes characters from the console. - * - *---------------------------------------------------------------------- - */ - -static BOOL -writeConsoleBytes(HANDLE hConsole, const VOID *lpBuffer, - DWORD nbytes, LPDWORD nbyteswritten) -{ - DWORD ntchars; - BOOL result; - int tcharsize; - tcharsize = tclWinProcs->useWide? 2 : 1; - result = tclWinProcs->writeConsoleProc( - hConsole, lpBuffer, nbytes / tcharsize, &ntchars, NULL); - if (nbyteswritten) - *nbyteswritten = (ntchars*tcharsize); - return result; -} - -/* - *---------------------------------------------------------------------- - * * ConsoleInit -- * * This function initializes the static variables for this file. @@ -769,8 +705,8 @@ ConsoleInputProc( * at least one byte is available or an EOF occurs. */ - if (readConsoleBytes(infoPtr->handle, (LPVOID) buf, - (DWORD) bufSize, &count) == TRUE) { + if (ReadConsole(infoPtr->handle, (LPVOID) buf, (DWORD) bufSize, &count, + (LPOVERLAPPED) NULL) == TRUE) { buf[count] = '\0'; return count; } @@ -856,8 +792,8 @@ ConsoleOutputProc( * This avoids an unnecessary copy. */ - if (writeConsoleBytes(infoPtr->handle, (LPVOID) buf, (DWORD) toWrite, - &bytesWritten) == FALSE) { + if (WriteFile(infoPtr->handle, (LPVOID) buf, (DWORD) toWrite, + &bytesWritten, (LPOVERLAPPED) NULL) == FALSE) { TclWinConvertError(GetLastError()); goto error; } @@ -1208,8 +1144,8 @@ ConsoleReaderThread(LPVOID arg) * Look for data on the console, but first ignore any events * that are not KEY_EVENTs */ - if (readConsoleBytes(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE, - (LPDWORD) &infoPtr->bytesRead) != FALSE) { + if (ReadConsoleA(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE, + (LPDWORD) &infoPtr->bytesRead, NULL) != FALSE) { /* * Data was stored in the buffer. */ @@ -1304,7 +1240,7 @@ ConsoleWriterThread(LPVOID arg) */ while (toWrite > 0) { - if (writeConsoleBytes(handle, buf, toWrite, &count) == FALSE) { + if (WriteConsoleA(handle, buf, toWrite, &count, NULL) == FALSE) { infoPtr->writeError = GetLastError(); break; } else { @@ -1431,10 +1367,7 @@ TclWinOpenConsoleChannel(handle, channelName, permissions) Tcl_SetChannelOption(NULL, infoPtr->channel, "-translation", "auto"); Tcl_SetChannelOption(NULL, infoPtr->channel, "-eofchar", "\032 {}"); - if (tclWinProcs->useWide) - Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", "unicode"); - else - Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding); + Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding); return infoPtr->channel; } -- cgit v0.12