Attachment "tcl-winunicon.patch" to
ticket [1256872fff]
added by
a_kovalenko
2005-08-11 23:34:21.
diff -Naurd tcl/win/tclWin32Dll.c tcl-winunicon/win/tclWin32Dll.c
--- tcl/win/tclWin32Dll.c 2005-08-11 19:08:27.000000000 +0400
+++ tcl-winunicon/win/tclWin32Dll.c 2005-08-11 20:11:08.000000000 +0400
@@ -118,8 +118,13 @@
/* deleted (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) _utime, */
NULL,
NULL,
+ /* getLongPathNameProc */
+ NULL,
/* Security SDK - not available on 95,98,ME */
- NULL, NULL, NULL, NULL, NULL, NULL
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ /* ReadConsole and WriteConsole */
+ (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleW,
+ (BOOL (WINAPI *)(HANDLE, const VOID*, DWORD, LPDWORD, LPVOID)) WriteConsoleW
};
static TclWinProcs unicodeProcs = {
@@ -171,8 +176,13 @@
/* deleted (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) _wutime, */
NULL,
NULL,
+ /* getLongPathNameProc */
+ NULL,
/* Security SDK - will be filled in on NT,XP,2000,2003 */
- NULL, NULL, NULL, NULL, NULL, NULL
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ /* ReadConsole and WriteConsole */
+ (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleW,
+ (BOOL (WINAPI *)(HANDLE, const VOID*, DWORD, LPDWORD, LPVOID)) WriteConsoleW
};
TclWinProcs *tclWinProcs;
diff -Naurd tcl/win/tclWinConsole.c tcl-winunicon/win/tclWinConsole.c
--- tcl/win/tclWinConsole.c 2005-07-25 02:56:47.000000000 +0400
+++ tcl-winunicon/win/tclWinConsole.c 2005-08-11 19:47:23.000000000 +0400
@@ -54,6 +54,7 @@
* This structure describes per-instance data for a console based channel.
*/
+
typedef struct ConsoleInfo {
HANDLE handle;
int type;
@@ -187,6 +188,45 @@
/*
*----------------------------------------------------------------------
+ *
+ * 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 @@
* 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 @@
* 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 @@
* 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 @@
*/
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 @@
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;
}
diff -Naurd tcl/win/tclWinInt.h tcl-winunicon/win/tclWinInt.h
--- tcl/win/tclWinInt.h 2004-11-03 03:26:59.000000000 +0300
+++ tcl-winunicon/win/tclWinInt.h 2005-08-11 19:58:14.000000000 +0400
@@ -127,6 +127,23 @@
LPDWORD PrivilegeSetLength,
LPDWORD GrantedAccess,
LPBOOL AccessStatus);
+ /*
+ * Unicode console support. WriteConsole and ReadConsole
+ */
+ BOOL (WINAPI *readConsoleProc)(
+ HANDLE hConsoleInput,
+ LPVOID lpBuffer,
+ DWORD nNumberOfCharsToRead,
+ LPDWORD lpNumberOfCharsRead,
+ LPVOID lpReserved
+ );
+ BOOL (WINAPI *writeConsoleProc)(
+ HANDLE hConsoleOutput,
+ const VOID* lpBuffer,
+ DWORD nNumberOfCharsToWrite,
+ LPDWORD lpNumberOfCharsWritten,
+ LPVOID lpReserved
+ );
} TclWinProcs;
MODULE_SCOPE TclWinProcs *tclWinProcs;