summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXHLEvents.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXHLEvents.c')
-rw-r--r--macosx/tkMacOSXHLEvents.c433
1 files changed, 241 insertions, 192 deletions
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index 3c6ffd0..9671ab9 100644
--- a/macosx/tkMacOSXHLEvents.c
+++ b/macosx/tkMacOSXHLEvents.c
@@ -1,11 +1,11 @@
/*
* tkMacOSXHLEvents.c --
*
- * Implements high level event support for the Macintosh. Currently,
- * the only event that really does anything is the Quit event.
+ * Implements high level event support for the Macintosh. Currently, the
+ * only event that really does anything is the Quit event.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
- * Copyright 2001, Apple Computer, Inc.
+ * Copyright 2001-2009, Apple Inc.
* Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net>
*
* See the file "license.terms" for information on usage and redistribution
@@ -15,47 +15,62 @@
#include "tkMacOSXPrivate.h"
/*
- * This is a Tcl_Event structure that the Quit AppleEvent handler
- * uses to schedule the ReallyKillMe function.
+ * This is a Tcl_Event structure that the Quit AppleEvent handler uses to
+ * schedule the ReallyKillMe function.
*/
typedef struct KillEvent {
- Tcl_Event header; /* Information that is standard for
- * all events. */
- Tcl_Interp *interp; /* Interp that was passed to the
- * Quit AppleEvent */
+ Tcl_Event header; /* Information that is standard for all
+ * events. */
+ Tcl_Interp *interp; /* Interp that was passed to the Quit
+ * AppleEvent */
} KillEvent;
/*
* Static functions used only in this file.
*/
-static OSErr QuitHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-static OSErr OappHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-static OSErr RappHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-static OSErr OdocHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-static OSErr PrintHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-static OSErr ScriptHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-static OSErr PrefsHandler(const AppleEvent * event, AppleEvent * reply,
- long handlerRefcon);
-
-static int MissedAnyParameters(const AppleEvent *theEvent);
-static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
-static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
+static OSErr QuitHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static OSErr OappHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static OSErr RappHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static OSErr OdocHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static OSErr PrintHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static OSErr ScriptHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static OSErr PrefsHandler(const AppleEvent *event,
+ AppleEvent *reply, SRefCon handlerRefcon);
+static int MissedAnyParameters(const AppleEvent *theEvent);
+static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
+static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
+
+#pragma mark TKApplication(TKHLEvents)
+
+@implementation TKApplication(TKHLEvents)
+
+- (void)terminate:(id)sender {
+ QuitHandler(NULL, NULL, (SRefCon) _eventInterp);
+}
+
+- (void)preferences:(id)sender {
+ PrefsHandler(NULL, NULL, (SRefCon) _eventInterp);
+}
+
+@end
+
+#pragma mark -
/*
*----------------------------------------------------------------------
*
* TkMacOSXInitAppleEvents --
*
- * Initilize the Apple Events on the Macintosh. This registers the
- * core event handlers.
+ * Initilize the Apple Events on the Macintosh. This registers the core
+ * event handlers.
*
* Results:
* None.
@@ -68,10 +83,11 @@ static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
void
TkMacOSXInitAppleEvents(
- Tcl_Interp *interp) /* Interp to handle basic events. */
+ Tcl_Interp *interp) /* Interp to handle basic events. */
{
- AEEventHandlerUPP OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP,
- PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP, PrefsHandlerUPP;
+ AEEventHandlerUPP OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP;
+ AEEventHandlerUPP PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP;
+ AEEventHandlerUPP PrefsHandlerUPP;
static Boolean initialized = FALSE;
if (!initialized) {
@@ -80,34 +96,35 @@ TkMacOSXInitAppleEvents(
/*
* Install event handlers for the core apple events.
*/
+
QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler);
ChkErr(AEInstallEventHandler, kCoreEventClass, kAEQuitApplication,
- QuitHandlerUPP, (long) interp, false);
+ QuitHandlerUPP, (SRefCon) interp, false);
OappHandlerUPP = NewAEEventHandlerUPP(OappHandler);
ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenApplication,
- OappHandlerUPP, (long) interp, false);
+ OappHandlerUPP, (SRefCon) interp, false);
RappHandlerUPP = NewAEEventHandlerUPP(RappHandler);
ChkErr(AEInstallEventHandler, kCoreEventClass, kAEReopenApplication,
- RappHandlerUPP, (long) interp, false);
+ RappHandlerUPP, (SRefCon) interp, false);
OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler);
ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenDocuments,
- OdocHandlerUPP, (long) interp, false);
+ OdocHandlerUPP, (SRefCon) interp, false);
PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler);
ChkErr(AEInstallEventHandler, kCoreEventClass, kAEPrintDocuments,
- PrintHandlerUPP, (long) interp, false);
+ PrintHandlerUPP, (SRefCon) interp, false);
PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler);
ChkErr(AEInstallEventHandler, kCoreEventClass, kAEShowPreferences,
- PrefsHandlerUPP, (long) interp, false);
+ PrefsHandlerUPP, (SRefCon) interp, false);
if (interp) {
ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler);
ChkErr(AEInstallEventHandler, kAEMiscStandards, kAEDoScript,
- ScriptHandlerUPP, (long) interp, false);
+ ScriptHandlerUPP, (SRefCon) interp, false);
}
}
}
@@ -130,9 +147,9 @@ TkMacOSXInitAppleEvents(
int
TkMacOSXDoHLEvent(
- EventRecord *theEvent)
+ void *theEvent)
{
- return AEProcessAppleEvent(theEvent);
+ return AEProcessAppleEvent((EventRecord *)theEvent);
}
/*
@@ -151,21 +168,22 @@ TkMacOSXDoHLEvent(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
QuitHandler(
- const AppleEvent * event,
- AppleEvent * reply,
- long handlerRefcon)
+ const AppleEvent *event,
+ AppleEvent *reply,
+ SRefCon handlerRefcon)
{
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
KillEvent *eventPtr;
if (interp) {
/*
- * Call the exit command from the event loop, since you are not supposed
- * to call ExitToShell in an Apple Event Handler. We put this at the head
- * of Tcl's event queue because this message usually comes when the Mac is
- * shutting down, and we want to kill the shell as quickly as possible.
+ * Call the exit command from the event loop, since you are not
+ * supposed to call ExitToShell in an Apple Event Handler. We put this
+ * at the head of Tcl's event queue because this message usually comes
+ * when the Mac is shutting down, and we want to kill the shell as
+ * quickly as possible.
*/
eventPtr = (KillEvent *) ckalloc(sizeof(KillEvent));
@@ -193,18 +211,21 @@ QuitHandler(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
OappHandler(
- const AppleEvent * event,
- AppleEvent * reply,
- long handlerRefcon)
+ const AppleEvent *event,
+ AppleEvent *reply,
+ SRefCon handlerRefcon)
{
Tcl_CmdInfo dummy;
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
if (interp &&
- Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)) {
- Tcl_EvalEx(interp, "::tk::mac::OpenApplication", -1, TCL_EVAL_GLOBAL);
+ Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)){
+ int code = Tcl_EvalEx(interp, "::tk::mac::OpenApplication", -1, TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundError(interp);
+ }
}
return noErr;
}
@@ -225,20 +246,23 @@ OappHandler(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
RappHandler(
- const AppleEvent * event,
- AppleEvent * reply,
- long handlerRefcon)
+ const AppleEvent *event,
+ AppleEvent *reply,
+ SRefCon handlerRefcon)
{
Tcl_CmdInfo dummy;
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
ProcessSerialNumber thePSN = {0, kCurrentProcess};
OSStatus err = ChkErr(SetFrontProcess, &thePSN);
- if (interp &&
- Tcl_GetCommandInfo(interp, "::tk::mac::ReopenApplication", &dummy)) {
- Tcl_EvalEx(interp, "::tk::mac::ReopenApplication", -1, TCL_EVAL_GLOBAL);
+ if (interp && Tcl_GetCommandInfo(interp,
+ "::tk::mac::ReopenApplication", &dummy)) {
+ int code = Tcl_EvalEx(interp, "::tk::mac::ReopenApplication", -1, TCL_EVAL_GLOBAL);
+ if (code != TCL_OK){
+ Tcl_BackgroundError(interp);
+ }
}
return err;
}
@@ -248,8 +272,8 @@ RappHandler(
*
* PrefsHandler --
*
- * This is the 'pref' core Apple event handler.
- * Called when the user selects 'Preferences...' in MacOS X
+ * This is the 'pref' core Apple event handler. Called when the user
+ * selects 'Preferences...' in MacOS X
*
* Results:
* None.
@@ -260,18 +284,21 @@ RappHandler(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
PrefsHandler(
- const AppleEvent * event,
- AppleEvent * reply,
- long handlerRefcon)
+ const AppleEvent *event,
+ AppleEvent *reply,
+ SRefCon handlerRefcon)
{
Tcl_CmdInfo dummy;
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
if (interp &&
- Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)) {
- Tcl_EvalEx(interp, "::tk::mac::ShowPreferences", -1, TCL_EVAL_GLOBAL);
+ Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)){
+ int code = Tcl_EvalEx(interp, "::tk::mac::ShowPreferences", -1, TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundError(interp);
+ }
}
return noErr;
}
@@ -292,75 +319,77 @@ PrefsHandler(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
OdocHandler(
- const AppleEvent * event,
- AppleEvent * reply,
- long handlerRefcon)
+ const AppleEvent *event,
+ AppleEvent *reply,
+ SRefCon handlerRefcon)
{
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
AEDescList fileSpecList;
FSRef file;
- OSStatus err;
DescType type;
Size actual;
- long count;
+ long count, index;
AEKeyword keyword;
- long index;
- Tcl_DString command;
- Tcl_DString pathName;
+ Tcl_DString command, pathName;
Tcl_CmdInfo dummy;
+ int code;
/*
- * Don't bother if we don't have an interp or
- * the open document procedure doesn't exist.
+ * Don't bother if we don't have an interp or the open document procedure
+ * doesn't exist.
*/
- if ((interp == NULL) ||
- (Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) == 0) {
- return noErr;
+ if (!interp ||
+ !Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) {
+ return noErr;
}
/*
- * If we get any errors wil retrieving our parameters
- * we just return with no error.
+ * If we get any errors while retrieving our parameters we just return with
+ * no error.
*/
- err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
- &fileSpecList);
- if (err != noErr) {
+ if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
+ &fileSpecList) != noErr) {
return noErr;
}
-
- err = MissedAnyParameters(event);
- if (err != noErr) {
+ if (MissedAnyParameters(event) != noErr) {
return noErr;
}
-
- err = ChkErr(AECountItems, &fileSpecList, &count);
- if (err != noErr) {
+ if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
return noErr;
}
+ /*
+ * Convert our parameters into a script to evaluate, skipping things that
+ * we can't handle right.
+ */
+
Tcl_DStringInit(&command);
Tcl_DStringAppend(&command, "::tk::mac::OpenDocument", -1);
for (index = 1; index <= count; index++) {
- err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef,
- &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual);
- if ( err != noErr ) {
+ if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
+ &type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
continue;
}
- err = ChkErr(FSRefToDString, &file, &pathName);
- if (err == noErr) {
+ if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
Tcl_DStringFree(&pathName);
}
}
- Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command),
- TCL_EVAL_GLOBAL);
+ /*
+ * Now handle the event by evaluating a script.
+ */
+ code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
+ Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundError(interp);
+ }
Tcl_DStringFree(&command);
return noErr;
}
@@ -381,75 +410,72 @@ OdocHandler(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
PrintHandler(
const AppleEvent * event,
AppleEvent * reply,
- long handlerRefcon)
+ SRefCon handlerRefcon)
{
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
AEDescList fileSpecList;
FSRef file;
- OSStatus err;
DescType type;
Size actual;
- long count;
+ long count, index;
AEKeyword keyword;
- long index;
- Tcl_DString command;
- Tcl_DString pathName;
+ Tcl_DString command, pathName;
Tcl_CmdInfo dummy;
+ int code;
/*
- * Don't bother if we don't have an interp or
- * the print document procedure doesn't exist.
+ * Don't bother if we don't have an interp or the print document procedure
+ * doesn't exist.
*/
- if ((interp == NULL) ||
- (Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) == 0) {
- return noErr;
+ if (!interp ||
+ !Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) {
+ return noErr;
}
/*
- * If we get any errors wil retrieving our parameters
- * we just return with no error.
+ * If we get any errors while retrieving our parameters we just return with
+ * no error.
*/
- err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
- &fileSpecList);
- if (err != noErr) {
+ if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
+ &fileSpecList) != noErr) {
return noErr;
}
-
- err = ChkErr(MissedAnyParameters, event);
- if (err != noErr) {
+ if (ChkErr(MissedAnyParameters, event) != noErr) {
return noErr;
}
-
- err = ChkErr(AECountItems, &fileSpecList, &count);
- if (err != noErr) {
+ if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
return noErr;
}
Tcl_DStringInit(&command);
Tcl_DStringAppend(&command, "::tk::mac::PrintDocument", -1);
for (index = 1; index <= count; index++) {
- err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
- &type, (Ptr) &file, sizeof(FSRef), &actual);
- if ( err != noErr ) {
+ if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
+ &type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
continue;
}
- err = ChkErr(FSRefToDString, &file, &pathName);
- if (err == noErr) {
+ if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
Tcl_DStringFree(&pathName);
}
}
- Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command),
- TCL_EVAL_GLOBAL);
+ /*
+ * Now handle the event by evaluating a script.
+ */
+ code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
+ Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundError(interp);
+ }
Tcl_DStringFree(&command);
return noErr;
}
@@ -470,23 +496,24 @@ PrintHandler(
*----------------------------------------------------------------------
*/
-OSErr
+static OSErr
ScriptHandler(
- const AppleEvent * event,
- AppleEvent * reply,
- long handlerRefcon)
+ const AppleEvent *event,
+ AppleEvent *reply,
+ SRefCon handlerRefcon)
{
OSStatus theErr;
AEDescList theDesc;
+ Size size;
int tclErr = -1;
- Tcl_Interp *interp;
+ Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
char errString[128];
- interp = (Tcl_Interp *) handlerRefcon;
-
/*
- * The do script event receives one parameter that should be data or a file.
+ * The do script event receives one parameter that should be data or a
+ * file.
*/
+
theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard,
&theDesc);
if (theErr != noErr) {
@@ -495,73 +522,81 @@ ScriptHandler(
theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
strlen(errString));
} else if (MissedAnyParameters(event)) {
+ /*
+ * Return error if parameter is missing.
+ */
+
sprintf(errString, "AEDoScriptHandler: extra parameters");
AEPutParamPtr(reply, keyErrorString, typeChar, errString,
strlen(errString));
theErr = -1771;
- } else {
- Size size;
+ } 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.
+ */
- if (theDesc.descriptorType == (DescType)typeAlias &&
- AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL,
- 0, &size) == noErr && size == sizeof(FSRef)) {
- FSRef file;
+ FSRef file;
+ theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file,
+ size, NULL);
+ if (theErr == noErr) {
+ Tcl_DString scriptName;
- theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL,
- &file, size, NULL);
+ theErr = FSRefToDString(&file, &scriptName);
if (theErr == noErr) {
- Tcl_DString scriptName;
-
- theErr = FSRefToDString(&file, &scriptName);
- if (theErr == noErr) {
- tclErr = Tcl_EvalFile(interp,
- Tcl_DStringValue(&scriptName));
- Tcl_DStringFree(&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));
+ AEPutParamPtr(reply, keyErrorString, typeChar, errString,
+ strlen(errString));
}
- } else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL,
- NULL, 0, &size) == noErr && size) {
- char *data = ckalloc(size + 1);
+ }
+ } else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, NULL,
+ 0, &size) == noErr && size) {
+ /*
+ * We've had some data sent to us. Evaluate it.
+ */
- theErr = AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL,
- data, size, NULL);
- if (theErr == noErr) {
- tclErr = Tcl_EvalEx(interp, data, size, TCL_EVAL_GLOBAL);
- }
- } else {
- 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;
+ 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 coercable to 'utf8'",
+ (char*) &theDesc.descriptorType);
+ AEPutParamPtr(reply, keyErrorString, typeChar, errString,
+ strlen(errString));
+ theErr = -1770;
}
/*
* If we actually go to run Tcl code - put the result in the reply.
*/
+
if (tclErr >= 0) {
- if (tclErr == TCL_OK) {
- AEPutParamPtr(reply, keyDirectObject, typeChar,
- Tcl_GetStringResult(interp),
- strlen(Tcl_GetStringResult(interp)));
+ int reslen;
+ const char *result =
+ Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &reslen);
+
+ if (tclErr == TCL_OK) {
+ AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen);
} else {
- AEPutParamPtr(reply, keyErrorString, typeChar,
- Tcl_GetStringResult(interp),
- strlen(Tcl_GetStringResult(interp)));
- AEPutParamPtr(reply, keyErrorNumber, typeSInt32,
- (Ptr) &tclErr, sizeof(int));
+ AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen);
+ AEPutParamPtr(reply, keyErrorNumber, typeSInt32, (Ptr) &tclErr,
+ sizeof(int));
}
}
AEDisposeDesc(&theDesc);
-
return theErr;
}
@@ -570,8 +605,8 @@ ScriptHandler(
*
* ReallyKillMe --
*
- * This proc tries to kill the shell by running exit,
- * called from an event scheduled by the "Quit" AppleEvent handler.
+ * This proc tries to kill the shell by running exit, called from an
+ * event scheduled by the "Quit" AppleEvent handler.
*
* Results:
* Runs the "exit" command which might kill the shell.
@@ -589,10 +624,15 @@ ReallyKillMe(
{
Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
Tcl_CmdInfo dummy;
- if (Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy)) {
- Tcl_EvalEx(interp, "::tk::mac::Quit", -1, TCL_EVAL_GLOBAL);
- } else {
- Tcl_EvalEx(interp, "exit", -1, TCL_EVAL_GLOBAL);
+ int quit = Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy);
+ int code = Tcl_EvalEx(interp, quit ? "::tk::mac::Quit" : "exit", -1, TCL_EVAL_GLOBAL);
+
+ if (code != TCL_OK) {
+ /*
+ * Should be never reached...
+ */
+
+ Tcl_BackgroundError(interp);
}
return 1;
}
@@ -613,7 +653,7 @@ ReallyKillMe(
*----------------------------------------------------------------------
*/
-int
+static int
MissedAnyParameters(
const AppleEvent *theEvent)
{
@@ -643,7 +683,7 @@ MissedAnyParameters(
*----------------------------------------------------------------------
*/
-OSStatus
+static OSStatus
FSRefToDString(
const FSRef *fsref,
Tcl_DString *ds)
@@ -657,3 +697,12 @@ FSRefToDString(
}
return err;
}
+
+/*
+ * Local Variables:
+ * mode: objc
+ * c-basic-offset: 4
+ * fill-column: 79
+ * coding: utf-8
+ * End:
+ */