From 8cc3c8dbcc8bd130f161afaf0c4ccc36562ff705 Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 2 May 2012 10:11:14 +0000 Subject: Update of Patch 2445648 to trunk tip. Implementation of TIP 106: Add Encoding Abilities to the [dde] Command --- doc/dde.n | 22 ++++++++++--- win/tclWinDde.c | 100 ++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 83 insertions(+), 39 deletions(-) diff --git a/doc/dde.n b/doc/dde.n index a02c582..60dd058 100644 --- a/doc/dde.n +++ b/doc/dde.n @@ -17,9 +17,11 @@ dde \- Execute a Dynamic Data Exchange command .sp \fBdde servername\fR ?\fB\-force\fR? ?\fB\-handler \fIproc\fR? ?\fB\-\|\-\fR? ?\fItopic\fR? .sp -\fBdde execute\fR ?\fB\-async\fR? \fIservice topic data\fR +.VS 8.6 +\fBdde execute\fR ?\fB\-async\fR? ?\fB\-binary\fR? \fIservice topic data\fR .sp -\fBdde poke\fR \fIservice topic item data\fR +\fBdde poke\fR ?\fB\-binary\fR? \fIservice topic item data\fR +.VE 8.6 .sp \fBdde request\fR ?\fB\-binary\fR? \fIservice topic item\fR .sp @@ -69,7 +71,7 @@ procedure is called with all the arguments provided by the remote call. .RE .TP -\fBdde execute\fR ?\fB\-async\fR? \fIservice topic data\fR +\fBdde execute\fR ?\fB\-async\fR? ?\fB\-binary\fR? \fIservice topic data\fR . \fBdde execute\fR takes the \fIdata\fR and sends it to the server indicated by \fIservice\fR with the topic indicated by \fItopic\fR. Typically, @@ -80,8 +82,13 @@ script is run in the application. The \fB\-async\fR option requests asynchronous invocation. The command returns an error message if the script did not run, unless the \fB\-async\fR flag was used, in which case the command returns immediately with no error. +.VS 8.6 +The \fB\-binary\fR option treats \fIdata\fR as binary data, otherwise an utf-8 +string is sent. Combining \fB-binary\fR with the result of +\fBencoding convertto\fR may be used to send data in arbitrary encodings. +.VE 8.6 .TP -\fBdde poke \fIservice topic item data\fR +\fBdde poke ?\fB\-binary\fR? \fIservice topic item data\fR . \fBdde poke\fR passes the \fIdata\fR to the server indicated by \fIservice\fR using the \fItopic\fR and \fIitem\fR specified. Typically, @@ -90,6 +97,10 @@ specific but can be a command to the server or the name of a file to work on. The \fIitem\fR is also application specific and is often not used, but it must always be non-null. The \fIdata\fR field is given to the remote application. +.VS 8.6 +The \fB\-binary\fR option treats \fIdata\fR as binary data, otherwise an utf-8 +string is sent. +.VE 8.6 .TP \fBdde request\fR ?\fB\-binary\fR? \fIservice topic item\fR . @@ -168,3 +179,6 @@ package require dde tk(n), winfo(n), send(n) .SH KEYWORDS application, dde, name, remote execution +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/win/tclWinDde.c b/win/tclWinDde.c index 71b03a9..e917570 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -1164,13 +1164,19 @@ DdeObjCmd( DDE_SERVERNAME_EXACT, DDE_SERVERNAME_HANDLER, DDE_SERVERNAME_LAST, }; static const char *const ddeExecOptions[] = { - "-async", NULL + "-async", "-binary", NULL + }; + enum DdeExecOptions { + DDE_EXEC_ASYNC, DDE_EXEC_BINARY + }; + static const char *const ddePokeOptions[] = { + "-binary", NULL }; static const char *const ddeReqOptions[] = { "-binary", NULL }; - int index, i, length; + int index, i, length, argIndex; int async = 0, binary = 0, exact = 0; int result = TCL_OK, firstArg = 0; HSZ ddeService = NULL, ddeTopic = NULL, ddeItem = NULL, ddeCookie = NULL; @@ -1198,7 +1204,6 @@ DdeObjCmd( switch ((enum DdeSubcommands) index) { case DDE_SERVERNAME: for (i = 2; i < objc; i++) { - int argIndex; if (Tcl_GetIndexFromObj(interp, objv[i], ddeSrvOptions, "option", 0, &argIndex) != TCL_OK) { /* @@ -1245,39 +1250,52 @@ DdeObjCmd( if (objc == 5) { firstArg = 2; break; - } else if (objc == 6) { - int dummy; - if (Tcl_GetIndexFromObj(NULL, objv[2], ddeExecOptions, "option", 0, - &dummy) == TCL_OK) { - async = 1; - firstArg = 3; - break; + } else if (objc >= 6 && objc <= 7) { + firstArg = objc - 3; + for (i = 2; i < firstArg; i++) { + if (Tcl_GetIndexFromObj(NULL, objv[2], ddeExecOptions, + "option", 0, &argIndex) != TCL_OK) { + return TCL_ERROR; + } + if (argIndex == DDE_EXEC_ASYNC) { + async = 1; + } else { + binary = 1; + } } + break; } /* otherwise... */ Tcl_WrongNumArgs(interp, 2, objv, - "?-async? serviceName topicName value"); + "?-async? ?-binary? serviceName topicName value"); return TCL_ERROR; case DDE_POKE: - if (objc != 6) { - Tcl_WrongNumArgs(interp, 2, objv, - "serviceName topicName item value"); - return TCL_ERROR; + if (objc == 6) { + firstArg = 2; + break; + } else if ((objc == 7) && (Tcl_GetIndexFromObj(NULL, objv[2], + ddePokeOptions, "option", 0, &argIndex) == TCL_OK)) { + binary = 1; + firstArg = 3; + break; } - firstArg = 2; - break; + + /* + * Otherwise... + */ + + Tcl_WrongNumArgs(interp, 2, objv, + "serviceName ?-binary? topicName item value"); + return TCL_ERROR; case DDE_REQUEST: if (objc == 5) { firstArg = 2; break; - } else if (objc == 6) { - int dummy; - if (Tcl_GetIndexFromObj(NULL, objv[2], ddeReqOptions, "option", 0, - &dummy) == TCL_OK) { - binary = 1; - firstArg = 3; - break; - } + } else if ((objc == 6) && (Tcl_GetIndexFromObj(NULL, objv[2], + ddeReqOptions, "option", 0, &argIndex) == TCL_OK)) { + binary = 1; + firstArg = 3; + break; } /* @@ -1300,11 +1318,9 @@ DdeObjCmd( Tcl_WrongNumArgs(interp, 2, objv, "?-async? serviceName args"); return TCL_ERROR; } else { - int dummy; - firstArg = 2; if (Tcl_GetIndexFromObj(NULL, objv[2], ddeExecOptions, "option", - 0, &dummy) == TCL_OK) { + 0, &argIndex) == TCL_OK) { if (objc < 5) { goto wrongDdeEvalArgs; } @@ -1353,8 +1369,15 @@ DdeObjCmd( case DDE_EXECUTE: { int dataLength; - BYTE *dataString = (BYTE *) Tcl_GetStringFromObj( - objv[firstArg + 2], &dataLength); + BYTE *dataString; + + if (binary) { + dataString = (BYTE *) + Tcl_GetByteArrayFromObj(objv[firstArg + 2], &dataLength); + } else { + dataString = (BYTE *) + Tcl_GetStringFromObj(objv[firstArg + 2], &dataLength); + } if (dataLength == 0) { Tcl_SetObjResult(interp, @@ -1415,6 +1438,7 @@ DdeObjCmd( result = TCL_ERROR; } else { Tcl_Obj *returnObjPtr; + ddeItem = DdeCreateStringHandleA(ddeInstance, (void *) itemString, CP_WINANSI); if (ddeItem != NULL) { @@ -1428,10 +1452,11 @@ DdeObjCmd( const BYTE *dataString = DdeAccessData(ddeData, &tmp); if (binary) { - returnObjPtr = Tcl_NewByteArrayObj(dataString, - (int) tmp); + returnObjPtr = + Tcl_NewByteArrayObj(dataString, (int) tmp); } else { - returnObjPtr = Tcl_NewStringObj((char*)dataString,-1); + returnObjPtr = + Tcl_NewStringObj((char *) dataString, -1); } DdeUnaccessData(ddeData); DdeFreeDataHandle(ddeData); @@ -1457,8 +1482,13 @@ DdeObjCmd( result = TCL_ERROR; goto cleanup; } - dataString = (BYTE *) Tcl_GetStringFromObj(objv[firstArg + 3], - &length); + if (binary) { + dataString = (BYTE *) + Tcl_GetByteArrayFromObj(objv[firstArg + 3], &length); + } else { + dataString = (BYTE *) + Tcl_GetStringFromObj(objv[firstArg + 3], &length); + } hConv = DdeConnect(ddeInstance, ddeService, ddeTopic, NULL); DdeFreeStringHandle(ddeInstance, ddeService); -- cgit v0.12 From 21ffddf58f04c4a455f133435b83bc79da913805 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 3 May 2012 09:29:06 +0000 Subject: add some tests --- tests/winDde.test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/winDde.test b/tests/winDde.test index ca50a96..bd5ef73 100644 --- a/tests/winDde.test +++ b/tests/winDde.test @@ -156,6 +156,20 @@ test winDde-3.5 {DDE request locally} {win dde} { dde execute TclEval self {set a "foo"} dde request -binary TclEval self a } "foo\x00" +# Set variable a to A with diaeresis (unicode C4) by relying on the fact +# that utf8 is sent (e.g. "c3 84" on the wire) +test winDde-3.6 {DDE request utf8} {win dde} { + set a "not set" + dde execute TclEval self "set a \xc4" + scan $a %c +} 196 +# Set variable a to A with diaeresis (unicode C4) using binary execute +# and compose utf-8 (e.g. "c3 84" ) manualy +test winDde-3.7 {DDE request binary} {win dde} { + set a "not set" + dde execute -binary TclEval self "set a \xc3\x84" + scan $a %c +} 196 # ------------------------------------------------------------------------- -- cgit v0.12 From 8622e716bb6d347375ac273af7b73c6f7952f223 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 8 May 2012 09:07:07 +0000 Subject: fix test-cases winDde 5.1 and 5.3 --- tests/winDde.test | 4 ++-- win/tclWinDde.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/winDde.test b/tests/winDde.test index bd5ef73..d4a3a79 100644 --- a/tests/winDde.test +++ b/tests/winDde.test @@ -216,13 +216,13 @@ test winDde-4.4 {DDE eval remotely} {stdio win dde} { test winDde-5.1 {check for bad arguments} -constraints {win dde} -body { dde execute "" "" "" "" -} -returnCodes error -result {wrong # args: should be "dde execute ?-async? serviceName topicName value"} +} -returnCodes error -result {ambiguous option "": must be -async or -binary} test winDde-5.2 {check for bad arguments} -constraints {win dde} -body { dde execute "" "" "" } -returnCodes error -result {cannot execute null data} test winDde-5.3 {check for bad arguments} -constraints {win dde} -body { dde execute -foo "" "" "" -} -returnCodes error -result {wrong # args: should be "dde execute ?-async? serviceName topicName value"} +} -returnCodes error -result {bad option "-foo": must be -async or -binary} test winDde-5.4 {DDE eval bad arguments} -constraints {win dde} -body { dde eval "" "foo" } -returnCodes error -result {invalid service name ""} diff --git a/win/tclWinDde.c b/win/tclWinDde.c index e917570..83c2aa3 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -1253,7 +1253,7 @@ DdeObjCmd( } else if (objc >= 6 && objc <= 7) { firstArg = objc - 3; for (i = 2; i < firstArg; i++) { - if (Tcl_GetIndexFromObj(NULL, objv[2], ddeExecOptions, + if (Tcl_GetIndexFromObj(interp, objv[2], ddeExecOptions, "option", 0, &argIndex) != TCL_OK) { return TCL_ERROR; } -- cgit v0.12 From a55cf4a7e5aa5b506929c232ed2a3c8402a41852 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 8 May 2012 09:26:53 +0000 Subject: another bug: [dde eval -async -binary] didn't work --- tests/winDde.test | 4 ++-- win/tclWinDde.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/winDde.test b/tests/winDde.test index d4a3a79..729b05e 100644 --- a/tests/winDde.test +++ b/tests/winDde.test @@ -216,13 +216,13 @@ test winDde-4.4 {DDE eval remotely} {stdio win dde} { test winDde-5.1 {check for bad arguments} -constraints {win dde} -body { dde execute "" "" "" "" -} -returnCodes error -result {ambiguous option "": must be -async or -binary} +} -returnCodes error -result {wrong # args: should be "dde execute ?-async? ?-binary? serviceName topicName value"} test winDde-5.2 {check for bad arguments} -constraints {win dde} -body { dde execute "" "" "" } -returnCodes error -result {cannot execute null data} test winDde-5.3 {check for bad arguments} -constraints {win dde} -body { dde execute -foo "" "" "" -} -returnCodes error -result {bad option "-foo": must be -async or -binary} +} -returnCodes error -result {wrong # args: should be "dde execute ?-async? ?-binary? serviceName topicName value"} test winDde-5.4 {DDE eval bad arguments} -constraints {win dde} -body { dde eval "" "foo" } -returnCodes error -result {invalid service name ""} diff --git a/win/tclWinDde.c b/win/tclWinDde.c index 83c2aa3..11e713b 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -1253,9 +1253,9 @@ DdeObjCmd( } else if (objc >= 6 && objc <= 7) { firstArg = objc - 3; for (i = 2; i < firstArg; i++) { - if (Tcl_GetIndexFromObj(interp, objv[2], ddeExecOptions, + if (Tcl_GetIndexFromObj(interp, objv[i], ddeExecOptions, "option", 0, &argIndex) != TCL_OK) { - return TCL_ERROR; + goto wrongDdeExecuteArgs; } if (argIndex == DDE_EXEC_ASYNC) { async = 1; @@ -1266,6 +1266,7 @@ DdeObjCmd( break; } /* otherwise... */ + wrongDdeExecuteArgs: Tcl_WrongNumArgs(interp, 2, objv, "?-async? ?-binary? serviceName topicName value"); return TCL_ERROR; -- cgit v0.12 From 2f53eeab0b9831c99ec00b1728bcd2821e3d46ea Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 11 May 2012 12:50:31 +0000 Subject: fix handling of closing '\0' for -binary data update dde version to 1.4.0 --- library/dde/pkgIndex.tcl | 6 +++--- tests/winDde.test | 2 +- win/Makefile.in | 12 ++++++------ win/configure | 4 ++-- win/configure.in | 4 ++-- win/tclWinDde.c | 10 ++++++---- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/library/dde/pkgIndex.tcl b/library/dde/pkgIndex.tcl index ce92028..1370567 100644 --- a/library/dde/pkgIndex.tcl +++ b/library/dde/pkgIndex.tcl @@ -1,7 +1,7 @@ -if {![package vsatisfies [package provide Tcl] 8.5]} return +if {![package vsatisfies [package provide Tcl] 8.4]} return if {[string compare [info sharedlibextension] .dll]} return if {[::tcl::pkgconfig get debug]} { - package ifneeded dde 1.3.3 [list load [file join $dir tcldde13g.dll] dde] + package ifneeded dde 1.4.0 [list load [file join $dir tcldde14g.dll] dde] } else { - package ifneeded dde 1.3.3 [list load [file join $dir tcldde13.dll] dde] + package ifneeded dde 1.4.0 [list load [file join $dir tcldde14.dll] dde] } diff --git a/tests/winDde.test b/tests/winDde.test index 729b05e..bc64a24 100644 --- a/tests/winDde.test +++ b/tests/winDde.test @@ -167,7 +167,7 @@ test winDde-3.6 {DDE request utf8} {win dde} { # and compose utf-8 (e.g. "c3 84" ) manualy test winDde-3.7 {DDE request binary} {win dde} { set a "not set" - dde execute -binary TclEval self "set a \xc3\x84" + dde execute -binary TclEval self "set a \xc3\x84\x00" scan $a %c } 196 diff --git a/win/Makefile.in b/win/Makefile.in index 8492b8f..111f455 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -606,23 +606,23 @@ install-binaries: binaries done @if [ -f $(DDE_DLL_FILE) ]; then \ echo installing $(DDE_DLL_FILE); \ - $(COPY) $(DDE_DLL_FILE) $(LIB_INSTALL_DIR)/dde1.3; \ + $(COPY) $(DDE_DLL_FILE) $(LIB_INSTALL_DIR)/dde${DDEDOTVER}; \ $(COPY) $(ROOT_DIR)/library/dde/pkgIndex.tcl \ - $(LIB_INSTALL_DIR)/dde1.3; \ + $(LIB_INSTALL_DIR)/dde${DDEDOTVER}; \ fi @if [ -f $(DDE_LIB_FILE) ]; then \ echo installing $(DDE_LIB_FILE); \ - $(COPY) $(DDE_LIB_FILE) $(LIB_INSTALL_DIR)/dde1.3; \ + $(COPY) $(DDE_LIB_FILE) $(LIB_INSTALL_DIR)/dde${DDEDOTVER}; \ fi @if [ -f $(REG_DLL_FILE) ]; then \ echo installing $(REG_DLL_FILE); \ - $(COPY) $(REG_DLL_FILE) $(LIB_INSTALL_DIR)/reg1.3; \ + $(COPY) $(REG_DLL_FILE) $(LIB_INSTALL_DIR)/reg${REGDOTVER}; \ $(COPY) $(ROOT_DIR)/library/reg/pkgIndex.tcl \ - $(LIB_INSTALL_DIR)/reg1.3; \ + $(LIB_INSTALL_DIR)/reg${REGDOTVER}; \ fi @if [ -f $(REG_LIB_FILE) ]; then \ echo installing $(REG_LIB_FILE); \ - $(COPY) $(REG_LIB_FILE) $(LIB_INSTALL_DIR)/reg1.3; \ + $(COPY) $(REG_LIB_FILE) $(LIB_INSTALL_DIR)/reg${REGDOTVER}; \ fi install-libraries: libraries install-tzdata install-msgs diff --git a/win/configure b/win/configure index 6673ecb..af014b4 100755 --- a/win/configure +++ b/win/configure @@ -1316,8 +1316,8 @@ VER=$TCL_MAJOR_VERSION$TCL_MINOR_VERSION TCL_DDE_VERSION=1.3 TCL_DDE_MAJOR_VERSION=1 -TCL_DDE_MINOR_VERSION=3 -TCL_DDE_PATCH_LEVEL="2" +TCL_DDE_MINOR_VERSION=4 +TCL_DDE_PATCH_LEVEL="0" DDEVER=$TCL_DDE_MAJOR_VERSION$TCL_DDE_MINOR_VERSION TCL_REG_VERSION=1.3 diff --git a/win/configure.in b/win/configure.in index 1bab810..36a996c 100644 --- a/win/configure.in +++ b/win/configure.in @@ -19,8 +19,8 @@ VER=$TCL_MAJOR_VERSION$TCL_MINOR_VERSION TCL_DDE_VERSION=1.3 TCL_DDE_MAJOR_VERSION=1 -TCL_DDE_MINOR_VERSION=3 -TCL_DDE_PATCH_LEVEL="2" +TCL_DDE_MINOR_VERSION=4 +TCL_DDE_PATCH_LEVEL="0" DDEVER=$TCL_DDE_MAJOR_VERSION$TCL_DDE_MINOR_VERSION TCL_REG_VERSION=1.3 diff --git a/win/tclWinDde.c b/win/tclWinDde.c index 387c05a..9645c68 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -88,7 +88,7 @@ static DWORD ddeInstance; /* The application instance handle given to us * by DdeInitialize. */ static int ddeIsServer = 0; -#define TCL_DDE_VERSION "1.3.3" +#define TCL_DDE_VERSION "1.4.0" #define TCL_DDE_PACKAGE_NAME "dde" #define TCL_DDE_SERVICE_NAME TEXT("TclEval") #define TCL_DDE_EXECUTE_RESULT TEXT("$TCLEVAL$EXECUTE$RESULT") @@ -1395,9 +1395,10 @@ DdeObjCmd( } else { dataString = (BYTE *) Tcl_GetStringFromObj(objv[firstArg + 2], &dataLength); + dataLength += 1; } - if (dataLength == 0) { + if (dataLength <= (binary ? 0 : sizeof(TCHAR))) { Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot execute null data", -1)); Tcl_SetErrorCode(interp, "TCL", "DDE", "NULL", NULL); @@ -1415,7 +1416,7 @@ DdeObjCmd( } ddeData = DdeCreateDataHandle(ddeInstance, dataString, - (DWORD) dataLength+1, 0, 0, CF_TEXT, 0); + (DWORD) dataLength, 0, 0, CF_TEXT, 0); if (ddeData != NULL) { if (async) { DdeClientTransaction((LPBYTE) ddeData, 0xFFFFFFFF, hConv, 0, @@ -1504,6 +1505,7 @@ DdeObjCmd( } else { dataString = (BYTE *) Tcl_GetStringFromObj(objv[firstArg + 3], &length); + length += 1; } hConv = DdeConnect(ddeInstance, ddeService, ddeTopic, NULL); @@ -1517,7 +1519,7 @@ DdeObjCmd( ddeItem = DdeCreateStringHandle(ddeInstance, (void *) itemString, CP_WINUNICODE); if (ddeItem != NULL) { - ddeData = DdeClientTransaction(dataString, (DWORD) length+1, + ddeData = DdeClientTransaction(dataString, (DWORD) length, hConv, ddeItem, CF_TEXT, XTYP_POKE, 5000, NULL); if (ddeData == NULL) { SetDdeError(interp); -- cgit v0.12