diff options
Diffstat (limited to 'carbon/tkMacOSXHLEvents.c')
-rw-r--r-- | carbon/tkMacOSXHLEvents.c | 80 |
1 files changed, 32 insertions, 48 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); |