summaryrefslogtreecommitdiffstats
path: root/win/tclWinConsole.c
diff options
context:
space:
mode:
authorpatthoyts <patthoyts@users.sourceforge.net>2005-11-03 01:16:07 (GMT)
committerpatthoyts <patthoyts@users.sourceforge.net>2005-11-03 01:16:07 (GMT)
commit169a78358af41a6e77a814a0a73f663542c51a6f (patch)
treef66ff8975eeb927aaabd8d0c8e7a6bf2ea2285c2 /win/tclWinConsole.c
parent2ac3a08a98a293de62ed6ae01aa7a7d139660207 (diff)
downloadtcl-169a78358af41a6e77a814a0a73f663542c51a6f.zip
tcl-169a78358af41a6e77a814a0a73f663542c51a6f.tar.gz
tcl-169a78358af41a6e77a814a0a73f663542c51a6f.tar.bz2
* win/tclWin32Dll.c: Applied patch #1256872 to provide unicode
* win/tclWinConsole.c: support in the console on suitable systems. * win/tclWinInt.h: Patch by Anton Kovalenko
Diffstat (limited to 'win/tclWinConsole.c')
-rw-r--r--win/tclWinConsole.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c
index 83ef862..c59bc6f 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.15 2005/07/24 22:56:47 dkf Exp $
+ * RCS: @(#) $Id: tclWinConsole.c,v 1.16 2005/11/03 01:16:07 patthoyts Exp $
*/
#include "tclWinInt.h"
@@ -54,6 +54,7 @@ TCL_DECLARE_MUTEX(consoleMutex)
* This structure describes per-instance data for a console based channel.
*/
+
typedef struct ConsoleInfo {
HANDLE handle;
int type;
@@ -187,6 +188,45 @@ static Tcl_ChannelType consoleChannelType = {
/*
*----------------------------------------------------------------------
+ *
+ * readConsoleBytes, writeConsoleBytes --
+ * Wrapper for ReadConsole{A,W}, that takes and returns number of bytes
+ * instead of number of TCHARS
+ */
+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;
+}
+
+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 --
*
@@ -701,8 +741,8 @@ ConsoleInputProc(
* 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;
}
@@ -788,8 +828,8 @@ ConsoleOutputProc(
* avoids an unnecessary copy.
*/
- if (WriteConsole(infoPtr->handle, buf, toWrite, &bytesWritten,
- NULL) == FALSE) {
+ if (writeConsoleBytes(infoPtr->handle, buf, toWrite, &bytesWritten)
+ == FALSE) {
TclWinConvertError(GetLastError());
goto error;
}
@@ -1133,8 +1173,8 @@ ConsoleReaderThread(LPVOID arg)
* 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.
*/
@@ -1233,7 +1273,7 @@ ConsoleWriterThread(LPVOID arg)
*/
while (toWrite > 0) {
- if (WriteConsole(handle, buf, toWrite, &count, NULL) == FALSE) {
+ if (writeConsoleBytes(handle, buf, toWrite, &count) == FALSE) {
infoPtr->writeError = GetLastError();
break;
} else {
@@ -1363,7 +1403,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;
}