diff options
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinDde.c | 189 | ||||
-rwxr-xr-x | win/tclWinFile.c | 8 | ||||
-rw-r--r-- | win/tclWinInit.c | 22 | ||||
-rw-r--r-- | win/tclWinReg.c | 10 |
4 files changed, 160 insertions, 69 deletions
diff --git a/win/tclWinDde.c b/win/tclWinDde.c index ce0b413..a6cddde 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -743,24 +743,26 @@ DdeServerProc( } if (convPtr != NULL) { + Tcl_DString dsBuf; char *returnString; len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE); Tcl_DStringInit(&dString); + Tcl_DStringInit(&dsBuf); Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1); utilString = (TCHAR *) Tcl_DStringValue(&dString); DdeQueryString(ddeInstance, ddeItem, utilString, (DWORD) len + 1, CP_WINUNICODE); if (_tcsicmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) { - if (uFmt == CF_TEXT) { - returnString = - Tcl_GetStringFromObj(convPtr->returnPackagePtr, &len); - } else { - returnString = (char *) - Tcl_GetUnicodeFromObj(convPtr->returnPackagePtr, &len); - len = sizeof(TCHAR) * len + 1; + returnString = + Tcl_GetStringFromObj(convPtr->returnPackagePtr, &len); + if (uFmt != CF_TEXT) { + Tcl_WinUtfToTChar(returnString, len, &dsBuf); + returnString = Tcl_DStringValue(&dsBuf); + len = Tcl_DStringLength(&dsBuf) + 1; } - ddeReturn = DdeCreateDataHandle(ddeInstance, (BYTE *)returnString, + ddeReturn = DdeCreateDataHandle(ddeInstance, + (BYTE *)returnString, (DWORD) len+1, 0, ddeItem, uFmt, 0); } else { if (Tcl_IsSafe(convPtr->riPtr->interp)) { @@ -768,18 +770,18 @@ DdeServerProc( } else { Tcl_DString ds; Tcl_Obj *variableObjPtr; + Tcl_WinTCharToUtf(utilString, -1, &ds); variableObjPtr = Tcl_GetVar2Ex( convPtr->riPtr->interp, Tcl_DStringValue(&ds), NULL, TCL_GLOBAL_ONLY); if (variableObjPtr != NULL) { - if (uFmt == CF_TEXT) { - returnString = Tcl_GetStringFromObj( - variableObjPtr, &len); - } else { - returnString = (char *) Tcl_GetUnicodeFromObj( - variableObjPtr, &len); - len = sizeof(TCHAR) * len + 1; + returnString = Tcl_GetStringFromObj( + variableObjPtr, &len); + if (uFmt != CF_TEXT) { + Tcl_WinUtfToTChar(returnString, len, &dsBuf); + returnString = Tcl_DStringValue(&dsBuf); + len = Tcl_DStringLength(&dsBuf) + 1; } ddeReturn = DdeCreateDataHandle(ddeInstance, (BYTE *)returnString, (DWORD) len+1, 0, ddeItem, @@ -790,6 +792,7 @@ DdeServerProc( Tcl_DStringFree(&ds); } } + Tcl_DStringFree(&dsBuf); Tcl_DStringFree(&dString); } return ddeReturn; @@ -814,7 +817,7 @@ DdeServerProc( } if (convPtr && !Tcl_IsSafe(convPtr->riPtr->interp)) { - Tcl_DString ds; + Tcl_DString ds, ds2; Tcl_Obj *variableObjPtr; len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE); @@ -825,15 +828,16 @@ DdeServerProc( CP_WINUNICODE); Tcl_WinTCharToUtf(utilString, -1, &ds); utilString = (TCHAR *) DdeAccessData(hData, &dlen); - if (uFmt == CF_TEXT) { - variableObjPtr = Tcl_NewStringObj((char *)utilString, -1); - } else { - variableObjPtr = Tcl_NewUnicodeObj(utilString, -1); + if (uFmt != CF_TEXT) { + Tcl_WinTCharToUtf(utilString, -1, &ds2); + utilString = (TCHAR *) Tcl_DStringValue(&ds2); } + variableObjPtr = Tcl_NewStringObj((char *)utilString, -1); Tcl_SetVar2Ex(convPtr->riPtr->interp, Tcl_DStringValue(&ds), NULL, variableObjPtr, TCL_GLOBAL_ONLY); + Tcl_DStringFree(&ds2); Tcl_DStringFree(&ds); Tcl_DStringFree(&dString); ddeReturn = (HDDEDATA) DDE_FACK; @@ -874,8 +878,12 @@ DdeServerProc( ddeObjectPtr = Tcl_NewStringObj(string, dlen); } else { /* unicode */ - dlen >>= 1; - ddeObjectPtr = Tcl_NewUnicodeObj((Tcl_UniChar *)utilString, dlen - 1); + Tcl_DString dsBuf; + + Tcl_WinTCharToUtf(utilString, dlen, &dsBuf); + ddeObjectPtr = Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf)); + Tcl_DStringFree(&dsBuf); } Tcl_IncrRefCount(ddeObjectPtr); DdeUnaccessData(hData); @@ -1300,6 +1308,9 @@ DdeObjCmd( const char *string; DWORD ddeResult; Tcl_Obj *objPtr, *handlerPtr = NULL; +#ifdef UNICODE + Tcl_DString serviceBuf, topicBuf, itemBuf; +#endif /* * Initialize DDE server/client @@ -1315,6 +1326,11 @@ DdeObjCmd( return TCL_ERROR; } +#ifdef UNICODE + Tcl_DStringInit(&serviceBuf); + Tcl_DStringInit(&topicBuf); + Tcl_DStringInit(&itemBuf); +#endif switch ((enum DdeSubcommands) index) { case DDE_SERVERNAME: for (i = 2; i < objc; i++) { @@ -1450,7 +1466,11 @@ DdeObjCmd( if (firstArg != 1) { #ifdef UNICODE - serviceName = Tcl_GetUnicodeFromObj(objv[firstArg], &length); + const char *src = Tcl_GetStringFromObj(objv[firstArg], &length); + + Tcl_WinUtfToTChar(src, length, &serviceBuf); + serviceName = (TCHAR *) Tcl_DStringValue(&serviceBuf); + length = Tcl_DStringLength(&serviceBuf); #else serviceName = Tcl_GetStringFromObj(objv[firstArg], &length); #endif @@ -1467,7 +1487,10 @@ DdeObjCmd( if ((index != DDE_SERVERNAME) && (index != DDE_EVAL)) { #ifdef UNICODE - topicName = (TCHAR *) Tcl_GetUnicodeFromObj(objv[firstArg + 1], &length); + const char *src = Tcl_GetStringFromObj(objv[firstArg + 1], &length); + + Tcl_WinUtfToTChar(src, length, &topicBuf); + topicName = (TCHAR *) Tcl_DStringValue(&topicBuf); #else topicName = Tcl_GetStringFromObj(objv[firstArg + 1], &length); #endif @@ -1485,7 +1508,12 @@ DdeObjCmd( handlerPtr); if (serviceName != NULL) { #ifdef UNICODE - Tcl_SetObjResult(interp, Tcl_NewUnicodeObj((Tcl_UniChar *) serviceName, -1)); + Tcl_DString dsBuf; + + Tcl_WinTCharToUtf(serviceName, -1, &dsBuf); + Tcl_SetObjResult(interp, Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf))); + Tcl_DStringFree(&dsBuf); #else Tcl_SetObjResult(interp, Tcl_NewStringObj(serviceName, -1)); #endif @@ -1496,20 +1524,26 @@ DdeObjCmd( case DDE_EXECUTE: { int dataLength; - const Tcl_UniChar *dataString; + const TCHAR *dataString; + Tcl_DString dsBuf; if (flags & DDE_FLAG_BINARY) { - dataString = (const Tcl_UniChar *) + Tcl_DStringInit(&dsBuf); + dataString = (const TCHAR *) Tcl_GetByteArrayFromObj(objv[firstArg + 2], &dataLength); } else { - dataString = - Tcl_GetUnicodeFromObj(objv[firstArg + 2], &dataLength); - dataLength = (dataLength + 1) * sizeof(Tcl_UniChar); + const char *src; + + src = Tcl_GetStringFromObj(objv[firstArg + 2], &dataLength); + dataString = (const TCHAR *) + Tcl_WinUtfToTChar(src, dataLength, &dsBuf); + dataLength = Tcl_DStringLength(&dsBuf) + sizeof (TCHAR); } if (dataLength <= 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot execute null data", -1)); + Tcl_DStringFree(&dsBuf); Tcl_SetErrorCode(interp, "TCL", "DDE", "NULL", NULL); result = TCL_ERROR; break; @@ -1519,21 +1553,26 @@ DdeObjCmd( DdeFreeStringHandle(ddeInstance, ddeTopic); if (hConv == NULL) { + Tcl_DStringFree(&dsBuf); SetDdeError(interp); result = TCL_ERROR; break; } ddeData = DdeCreateDataHandle(ddeInstance, (BYTE *) dataString, - (DWORD) dataLength, 0, 0, (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, 0); + (DWORD) dataLength, 0, 0, + (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, 0); if (ddeData != NULL) { if (flags & DDE_FLAG_ASYNC) { DdeClientTransaction((LPBYTE) ddeData, 0xFFFFFFFF, hConv, 0, - (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, XTYP_EXECUTE, TIMEOUT_ASYNC, &ddeResult); + (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, + XTYP_EXECUTE, TIMEOUT_ASYNC, &ddeResult); DdeAbandonTransaction(ddeInstance, hConv, ddeResult); } else { ddeReturn = DdeClientTransaction((LPBYTE) ddeData, 0xFFFFFFFF, - hConv, 0, (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, XTYP_EXECUTE, 30000, NULL); + hConv, 0, + (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, + XTYP_EXECUTE, 30000, NULL); if (ddeReturn == 0) { SetDdeError(interp); result = TCL_ERROR; @@ -1544,12 +1583,17 @@ DdeObjCmd( SetDdeError(interp); result = TCL_ERROR; } + Tcl_DStringFree(&dsBuf); break; } case DDE_REQUEST: { #ifdef UNICODE - const TCHAR *itemString = (TCHAR *) Tcl_GetUnicodeFromObj(objv[firstArg + 2], - &length); + const TCHAR *itemString; + const char *src; + + src = Tcl_GetStringFromObj(objv[firstArg + 2], &length); + itemString = (const TCHAR *) Tcl_WinUtfToTChar(src, length, &itemBuf); + length = Tcl_DStringLength(&itemBuf); #else const TCHAR *itemString = Tcl_GetStringFromObj(objv[firstArg + 2], &length); @@ -1575,24 +1619,27 @@ DdeObjCmd( CP_WINUNICODE); if (ddeItem != NULL) { ddeData = DdeClientTransaction(NULL, 0, hConv, ddeItem, - (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, XTYP_REQUEST, 5000, NULL); + (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, + XTYP_REQUEST, 5000, NULL); if (ddeData == NULL) { SetDdeError(interp); result = TCL_ERROR; } else { DWORD tmp; - const Tcl_UniChar *dataString = (const Tcl_UniChar *) DdeAccessData(ddeData, &tmp); + const TCHAR *dataString = + (const TCHAR *) DdeAccessData(ddeData, &tmp); if (flags & DDE_FLAG_BINARY) { returnObjPtr = - Tcl_NewByteArrayObj((BYTE *) dataString, (int) tmp); + Tcl_NewByteArrayObj((BYTE *) dataString, (int) tmp); } else { - tmp >>= 1; - if (tmp && !dataString[(tmp-1)]) { - --tmp; - } - returnObjPtr = Tcl_NewUnicodeObj(dataString, - (int) tmp); + Tcl_DString dsBuf; + + Tcl_WinTCharToUtf(dataString, tmp, &dsBuf); + returnObjPtr = + Tcl_NewStringObj(Tcl_DStringValue(&dsBuf), + Tcl_DStringLength(&dsBuf)); + Tcl_DStringFree(&dsBuf); } DdeUnaccessData(ddeData); DdeFreeDataHandle(ddeData); @@ -1607,14 +1654,19 @@ DdeObjCmd( break; } case DDE_POKE: { + Tcl_DString dsBuf; + BYTE *dataString; #ifdef UNICODE - const TCHAR *itemString = (TCHAR *) Tcl_GetUnicodeFromObj(objv[firstArg + 2], - &length); + const TCHAR *itemString; + const char *src; + + src = Tcl_GetStringFromObj(objv[firstArg + 2], &length); + itemString = (const TCHAR *) Tcl_WinUtfToTChar(src, length, &itemBuf); + length = Tcl_DStringLength(&itemBuf); #else const TCHAR *itemString = Tcl_GetStringFromObj(objv[firstArg + 2], &length); #endif - BYTE *dataString; if (length == 0) { Tcl_SetObjResult(interp, @@ -1624,12 +1676,15 @@ DdeObjCmd( goto cleanup; } if (flags & DDE_FLAG_BINARY) { + Tcl_DStringInit(&dsBuf); dataString = (BYTE *) Tcl_GetByteArrayFromObj(objv[firstArg + 3], &length); } else { + const char *data = + Tcl_GetStringFromObj(objv[firstArg + 3], &length); dataString = (BYTE *) - Tcl_GetUnicodeFromObj(objv[firstArg + 3], &length); - length = 2 * length + 1; + Tcl_WinUtfToTChar(data, length, &dsBuf); + length = Tcl_DStringLength(&dsBuf) + sizeof (TCHAR); } hConv = DdeConnect(ddeInstance, ddeService, ddeTopic, NULL); @@ -1644,7 +1699,9 @@ DdeObjCmd( CP_WINUNICODE); if (ddeItem != NULL) { ddeData = DdeClientTransaction(dataString, (DWORD) length, - hConv, ddeItem, (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, XTYP_POKE, 5000, NULL); + hConv, ddeItem, + (flags & DDE_FLAG_BINARY) ? CF_TEXT : CF_UNICODETEXT, + XTYP_POKE, 5000, NULL); if (ddeData == NULL) { SetDdeError(interp); result = TCL_ERROR; @@ -1772,6 +1829,8 @@ DdeObjCmd( Tcl_Release(riPtr); Tcl_Release(sendInterp); } else { + Tcl_DString dsBuf; + /* * This is a non-local request. Send the script to the server and * poll it for a result. @@ -1787,14 +1846,17 @@ DdeObjCmd( } objPtr = Tcl_ConcatObj(objc, objv); - string = (const char *) Tcl_GetUnicodeFromObj(objPtr, &length); - ddeItemData = DdeCreateDataHandle(ddeInstance, - (BYTE *) string, (DWORD) 2*length+2, 0, 0, CF_UNICODETEXT, 0); + string = Tcl_GetStringFromObj(objPtr, &length); + Tcl_WinUtfToTChar(string, length, &dsBuf); + string = Tcl_DStringValue(&dsBuf); + length = Tcl_DStringLength(&dsBuf) + sizeof (TCHAR); + ddeItemData = DdeCreateDataHandle(ddeInstance, (BYTE *) string, + (DWORD) length, 0, 0, CF_UNICODETEXT, 0); if (flags & DDE_FLAG_ASYNC) { ddeData = DdeClientTransaction((LPBYTE) ddeItemData, - 0xFFFFFFFF, hConv, 0, - CF_UNICODETEXT, XTYP_EXECUTE, TIMEOUT_ASYNC, &ddeResult); + 0xFFFFFFFF, hConv, 0, CF_UNICODETEXT, + XTYP_EXECUTE, TIMEOUT_ASYNC, &ddeResult); DdeAbandonTransaction(ddeInstance, hConv, ddeResult); } else { ddeData = DdeClientTransaction((LPBYTE) ddeItemData, @@ -1818,7 +1880,8 @@ DdeObjCmd( if (!(flags & DDE_FLAG_ASYNC)) { Tcl_Obj *resultPtr; - Tcl_UniChar *ddeDataString; + TCHAR *ddeDataString; + Tcl_DString buffer; /* * The return handle has a two or four element list in it. The @@ -1829,12 +1892,13 @@ DdeObjCmd( * variable "errorInfo". */ - resultPtr = Tcl_NewObj(); length = DdeGetData(ddeData, NULL, 0, 0); - ddeDataString = ckalloc(length); + ddeDataString = (TCHAR *) ckalloc(length); DdeGetData(ddeData, (BYTE *) ddeDataString, (DWORD) length, 0); - length = (length >> 1) - 1; - resultPtr = Tcl_NewUnicodeObj(ddeDataString, length); + Tcl_WinTCharToUtf(ddeDataString, length, &buffer); + resultPtr = Tcl_NewStringObj(Tcl_DStringValue(&buffer), + Tcl_DStringLength(&buffer)); + Tcl_DStringFree(&buffer); ckfree(ddeDataString); if (Tcl_ListObjIndex(NULL, resultPtr, 0, &objPtr) != TCL_OK) { @@ -1887,6 +1951,11 @@ DdeObjCmd( if (hConv != NULL) { DdeDisconnect(hConv); } +#ifdef UNICODE + Tcl_DStringFree(&itemBuf); + Tcl_DStringFree(&topicBuf); + Tcl_DStringFree(&serviceBuf); +#endif return result; } diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 25c6ea4..ae684f3 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1449,18 +1449,18 @@ TclpGetUserHome( domain = strchr(name, '@'); if (domain != NULL) { Tcl_DStringInit(&ds); - wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds); + wName = (WCHAR *) Tcl_WinUtfToTChar(domain + 1, -1, &ds); badDomain = NetGetDCName(NULL, wName, (LPBYTE *) wDomainPtr); Tcl_DStringFree(&ds); nameLen = domain - name; } if (badDomain == 0) { Tcl_DStringInit(&ds); - wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); + wName = (WCHAR *) Tcl_WinUtfToTChar(name, nameLen, &ds); if (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) uiPtrPtr) == 0) { wHomeDir = uiPtr->usri1_home_dir; if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) { - Tcl_UniCharToUtfDString(wHomeDir, lstrlenW(wHomeDir), + Tcl_WinTCharToUtf((TCHAR *) wHomeDir, lstrlenW(wHomeDir), bufferPtr); } else { /* @@ -1472,7 +1472,7 @@ TclpGetUserHome( for (i = 0; i < size; ++i){ if (buf[i] == '\\') buf[i] = '/'; } - Tcl_UniCharToUtfDString(buf, size-1, bufferPtr); + Tcl_WinTCharToUtf(buf, size-1, bufferPtr); Tcl_DStringAppend(bufferPtr, "/", -1); Tcl_DStringAppend(bufferPtr, name, -1); } diff --git a/win/tclWinInit.c b/win/tclWinInit.c index 8b600f6..3eb9814 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -440,7 +440,29 @@ ToUtf( start = dst; while (*wSrc != '\0') { +#if TCL_UTF_MAX >= 4 + Tcl_UniChar ch = *wSrc; + + if ((ch & 0xF800) == 0xD800) { + if (ch & 0x0400) { + /* Low surrogate */ + dst[3] = (char) ((ch | 0x80) & 0xBF); + dst[2] |= (char) (((ch >> 6) | 0x80) & 0x8F); + dst += 4; + } else { + /* High surrogate */ + ch += 0x40; + dst[2] = (char) (((ch << 4) | 0x80) & 0xB0); + dst[1] = (char) (((ch >> 2) | 0x80) & 0xBF); + dst[0] = (char) (((ch >> 8) | 0xF0) & 0xF7); + /* dst not incremented! */ + } + } else { + dst += Tcl_UniCharToUtf(ch, dst); + } +#else dst += Tcl_UniCharToUtf(*wSrc, dst); +#endif wSrc++; } *dst = '\0'; diff --git a/win/tclWinReg.c b/win/tclWinReg.c index 56aa991..8017647 100644 --- a/win/tclWinReg.c +++ b/win/tclWinReg.c @@ -803,17 +803,17 @@ GetValue( * we get bogus data. */ - while ((p < end) && *((Tcl_UniChar *) p) != 0) { - Tcl_UniChar *up; + while ((p < end) && *((WCHAR *) p) != 0) { + WCHAR *wp; Tcl_WinTCharToUtf((TCHAR *) p, -1, &buf); Tcl_ListObjAppendElement(interp, resultPtr, Tcl_NewStringObj(Tcl_DStringValue(&buf), Tcl_DStringLength(&buf))); - up = (Tcl_UniChar *) p; + wp = (WCHAR *) p; - while (*up++ != 0) {/* empty body */} - p = (char *) up; + while (*wp++ != 0) {/* empty body */} + p = (char *) wp; Tcl_DStringFree(&buf); } Tcl_SetObjResult(interp, resultPtr); |