diff options
author | patthoyts <patthoyts@users.sourceforge.net> | 2005-11-03 11:53:59 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@users.sourceforge.net> | 2005-11-03 11:53:59 (GMT) |
commit | 70b0f37994c80b2ecf30178e140a144d45afcb8b (patch) | |
tree | cbda3650576addc11f3653bb42bdef4e139abdc9 /win/tclWinConsole.c | |
parent | 239e8679aa5bc2c3e8db30277a67a2df86fc893a (diff) | |
download | tcl-70b0f37994c80b2ecf30178e140a144d45afcb8b.zip tcl-70b0f37994c80b2ecf30178e140a144d45afcb8b.tar.gz tcl-70b0f37994c80b2ecf30178e140a144d45afcb8b.tar.bz2 |
* win/tclWin32Dll.c: Backported Anton Kovalenko's patch #1256872
* win/tclWinConsole.c: to give unicode console support on
* win/tclWinInt.h: suitable systems (eg: NT/XP)
Diffstat (limited to 'win/tclWinConsole.c')
-rw-r--r-- | win/tclWinConsole.c | 85 |
1 files changed, 76 insertions, 9 deletions
diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c index 2370a22..fa38a6c 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.1 2005/01/27 22:53:37 andreas_kupries Exp $ + * RCS: @(#) $Id: tclWinConsole.c,v 1.11.2.2 2005/11/03 11:53:59 patthoyts Exp $ */ #include "tclWinInt.h" @@ -190,6 +190,70 @@ 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. @@ -705,8 +769,8 @@ ConsoleInputProc( * at least one byte is available or an EOF occurs. */ - if (ReadConsole(infoPtr->handle, (LPVOID) buf, (DWORD) bufSize, &count, - (LPOVERLAPPED) NULL) == TRUE) { + if (readConsoleBytes(infoPtr->handle, (LPVOID) buf, + (DWORD) bufSize, &count) == TRUE) { buf[count] = '\0'; return count; } @@ -792,8 +856,8 @@ ConsoleOutputProc( * This avoids an unnecessary copy. */ - if (WriteFile(infoPtr->handle, (LPVOID) buf, (DWORD) toWrite, - &bytesWritten, (LPOVERLAPPED) NULL) == FALSE) { + if (writeConsoleBytes(infoPtr->handle, (LPVOID) buf, (DWORD) toWrite, + &bytesWritten) == FALSE) { TclWinConvertError(GetLastError()); goto error; } @@ -1144,8 +1208,8 @@ ConsoleReaderThread(LPVOID arg) * Look for data on the console, but first ignore any events * that are not KEY_EVENTs */ - if (ReadConsoleA(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE, - (LPDWORD) &infoPtr->bytesRead, NULL) != FALSE) { + if (readConsoleBytes(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE, + (LPDWORD) &infoPtr->bytesRead) != FALSE) { /* * Data was stored in the buffer. */ @@ -1240,7 +1304,7 @@ ConsoleWriterThread(LPVOID arg) */ while (toWrite > 0) { - if (WriteConsoleA(handle, buf, toWrite, &count, NULL) == FALSE) { + if (writeConsoleBytes(handle, buf, toWrite, &count) == FALSE) { infoPtr->writeError = GetLastError(); break; } else { @@ -1367,7 +1431,10 @@ TclWinOpenConsoleChannel(handle, channelName, permissions) Tcl_SetChannelOption(NULL, infoPtr->channel, "-translation", "auto"); Tcl_SetChannelOption(NULL, infoPtr->channel, "-eofchar", "\032 {}"); - Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding); + if (tclWinProcs->useWide) + Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", "unicode"); + else + Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding); return infoPtr->channel; } |