diff options
author | das <das> | 2009-08-24 00:56:00 (GMT) |
---|---|---|
committer | das <das> | 2009-08-24 00:56:00 (GMT) |
commit | 28787944f9f2ad8e4c2cdc29106f88114026fd29 (patch) | |
tree | 1718b6cfd9d929cbe9db0be0b282003ab4082868 | |
parent | 756e87236145fe779fef07a6d805766282070a58 (diff) | |
download | tk-28787944f9f2ad8e4c2cdc29106f88114026fd29.zip tk-28787944f9f2ad8e4c2cdc29106f88114026fd29.tar.gz tk-28787944f9f2ad8e4c2cdc29106f88114026fd29.tar.bz2 |
* macosx/tkMacOSXHLEvents.c (ScriptHandler): Fix "do script" apple
* carbon/tkMacOSXHLEvents.c (ScriptHandler): event handler issues
on recent OS X releases by using AE coercion to 'utf8' for text data
and to 'fsrf' for alias data. (reported by Youness Alaoui on tcl-mac)
-rw-r--r-- | carbon/tkMacOSXHLEvents.c | 80 | ||||
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 72 |
2 files changed, 60 insertions, 92 deletions
diff --git a/carbon/tkMacOSXHLEvents.c b/carbon/tkMacOSXHLEvents.c index 2a79b8d..c9ee7c7 100644 --- a/carbon/tkMacOSXHLEvents.c +++ b/carbon/tkMacOSXHLEvents.c @@ -6,12 +6,12 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2006 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.2 2009/06/29 14:35:01 das Exp $ + * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.3 2009/08/24 00:56:00 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -490,6 +490,7 @@ ScriptHandler( { OSStatus theErr; AEDescList theDesc; + Size size; int tclErr = -1; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; char errString[128]; @@ -502,8 +503,8 @@ ScriptHandler( theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard, &theDesc); if (theErr != noErr) { - sprintf(errString, "AEDoScriptHandler: GetParamDesc error %ld", - theErr); + sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", + (int)theErr); theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString, strlen(errString)); } else if (MissedAnyParameters(event)) { @@ -515,66 +516,49 @@ ScriptHandler( AEPutParamPtr(reply, keyErrorString, typeChar, errString, strlen(errString)); theErr = -1771; - } else if (theDesc.descriptorType == (DescType) typeChar) { - /* - * We've had some data sent to us. Evaluate it. - */ - - Tcl_DString encodedText; - short i; - Size size = AEGetDescDataSize(&theDesc); - char *data = ckalloc(size + 1); - - AEGetDescData(&theDesc, data, size); - data[size] = 0; - for (i = 0; i < size; i++) { - if (data[i] == '\r') { - data[i] = '\n'; - } - } - AEReplaceDescData(theDesc.descriptorType, data, size + 1, &theDesc); - Tcl_ExternalToUtfDString(NULL, data, size, &encodedText); - tclErr = Tcl_EvalEx(interp, Tcl_DStringValue(&encodedText), - Tcl_DStringLength(&encodedText), TCL_EVAL_GLOBAL); - Tcl_DStringFree(&encodedText); - } else if (theDesc.descriptorType == (DescType) typeAlias) { + } else if (theDesc.descriptorType == (DescType) typeAlias && + AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL, + 0, &size) == noErr && size == sizeof(FSRef)) { /* * We've had a file sent to us. Source it. */ - Boolean dummy; FSRef file; - Size theSize = AEGetDescDataSize(&theDesc); - AliasPtr alias = (AliasPtr) ckalloc(theSize); - - if (alias) { - AEGetDescData(&theDesc, alias, theSize); - - theErr = FSResolveAlias(NULL, &alias, &file, &dummy); - ckfree((char*)alias); - } else { - theErr = memFullErr; - } + theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file, + size, NULL); if (theErr == noErr) { Tcl_DString scriptName; theErr = FSRefToDString(&file, &scriptName); if (theErr == noErr) { - Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName)); + tclErr = Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName)); Tcl_DStringFree(&scriptName); + } else { + sprintf(errString, "AEDoScriptHandler: file not found"); + AEPutParamPtr(reply, keyErrorString, typeChar, errString, + strlen(errString)); } - } else { - sprintf(errString, "AEDoScriptHandler: file not found"); - AEPutParamPtr(reply, keyErrorString, typeChar, errString, - strlen(errString)); + } + } else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, NULL, + 0, &size) == noErr && size) { + /* + * We've had some data sent to us. Evaluate it. + */ + + char *data = ckalloc(size + 1); + theErr = AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, data, + size, NULL); + if (theErr == noErr) { + tclErr = Tcl_EvalEx(interp, data, size, TCL_EVAL_GLOBAL); } } else { /* * Umm, don't recognize what we've got... */ - sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s'," - " must be 'alis' or 'TEXT'", (char*) &theDesc.descriptorType); + sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s', " + "must be 'alis' or coercable to 'utf8'", + (char*) &theDesc.descriptorType); AEPutParamPtr(reply, keyErrorString, typeChar, errString, strlen(errString)); theErr = -1770; @@ -593,7 +577,7 @@ ScriptHandler( AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen); } else { AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen); - AEPutParamPtr(reply, keyErrorNumber, typeInteger, (Ptr) &tclErr, + AEPutParamPtr(reply, keyErrorNumber, typeSInt32, (Ptr) &tclErr, sizeof(int)); } } @@ -663,7 +647,7 @@ MissedAnyParameters( Size actualSize; OSStatus err; - err = ChkErr(AEGetAttributePtr, theEvent, keyMissedKeywordAttr, + err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); return (err != errAEDescNotFound); diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 9fee118..6157d48 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.21 2009/07/06 20:29:21 dkf Exp $ + * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.22 2009/08/24 00:56:00 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -506,6 +506,7 @@ ScriptHandler( { OSStatus theErr; AEDescList theDesc; + Size size; int tclErr = -1; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; char errString[128]; @@ -531,66 +532,49 @@ ScriptHandler( AEPutParamPtr(reply, keyErrorString, typeChar, errString, strlen(errString)); theErr = -1771; - } else if (theDesc.descriptorType == (DescType) typeChar) { - /* - * We've had some data sent to us. Evaluate it. - */ - - Tcl_DString encodedText; - short i; - Size size = AEGetDescDataSize(&theDesc); - char *data = ckalloc(size + 1); - - AEGetDescData(&theDesc, data, size); - data[size] = 0; - for (i = 0; i < size; i++) { - if (data[i] == '\r') { - data[i] = '\n'; - } - } - AEReplaceDescData(theDesc.descriptorType, data, size + 1, &theDesc); - Tcl_ExternalToUtfDString(NULL, data, size, &encodedText); - tclErr = Tcl_EvalEx(interp, Tcl_DStringValue(&encodedText), - Tcl_DStringLength(&encodedText), TCL_EVAL_GLOBAL); - Tcl_DStringFree(&encodedText); - } else if (theDesc.descriptorType == (DescType) typeAlias) { + } else if (theDesc.descriptorType == (DescType) typeAlias && + AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL, + 0, &size) == noErr && size == sizeof(FSRef)) { /* * We've had a file sent to us. Source it. */ - Boolean dummy; FSRef file; - Size theSize = AEGetDescDataSize(&theDesc); - AliasPtr alias = (AliasPtr) ckalloc(theSize); - - if (alias) { - AEGetDescData(&theDesc, alias, theSize); - - theErr = FSResolveAlias(NULL, &alias, &file, &dummy); - ckfree((char*)alias); - } else { - theErr = memFullErr; - } + theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file, + size, NULL); if (theErr == noErr) { Tcl_DString scriptName; theErr = FSRefToDString(&file, &scriptName); if (theErr == noErr) { - Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName)); + tclErr = Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName)); Tcl_DStringFree(&scriptName); + } else { + sprintf(errString, "AEDoScriptHandler: file not found"); + AEPutParamPtr(reply, keyErrorString, typeChar, errString, + strlen(errString)); } - } else { - sprintf(errString, "AEDoScriptHandler: file not found"); - AEPutParamPtr(reply, keyErrorString, typeChar, errString, - strlen(errString)); + } + } else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, NULL, + 0, &size) == noErr && size) { + /* + * We've had some data sent to us. Evaluate it. + */ + + char *data = ckalloc(size + 1); + theErr = AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, data, + size, NULL); + if (theErr == noErr) { + tclErr = Tcl_EvalEx(interp, data, size, TCL_EVAL_GLOBAL); } } else { /* * Umm, don't recognize what we've got... */ - sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s'," - " must be 'alis' or 'TEXT'", (char*) &theDesc.descriptorType); + sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s', " + "must be 'alis' or coercable to 'utf8'", + (char*) &theDesc.descriptorType); AEPutParamPtr(reply, keyErrorString, typeChar, errString, strlen(errString)); theErr = -1770; @@ -679,7 +663,7 @@ MissedAnyParameters( Size actualSize; OSStatus err; - err = ChkErr(AEGetAttributePtr, theEvent, keyMissedKeywordAttr, + err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); return (err != errAEDescNotFound); |