home *** CD-ROM | disk | FTP | other *** search
- /* AppleEventCore.c */
- /*
- * AppleEventCore.c
- * Copyright © 1988-94 Apple Computer Inc. All rights reserved.
- * Note: a lot of these functions are not (yet) used.
- */
- #include "AppleEventCore.h"
- #include <AERegistry.h>
- #include <AppleTalk.h>
- #include <Gestalt.h>
- #include <Dialogs.h>
- #include <Errors.h>
- #include <Script.h>
- #include <TextUtils.h>
-
- #ifndef FALSE
- #define FALSE 0
- #define TRUE 1
- #endif
-
- AECoreGlobals gAECoreGlobals;
- #define GLOBAL (gAECoreGlobals)
- Boolean gHasAppleEvents;
- static AEOpenAppHandlerFunc gAEOpenAppHandlerFunc;
- static AEDocumentHandlerFunc gAEOpenDocHandlerFunc;
- static AEDocumentHandlerFunc gAEPrintDocHandlerFunc;
- static AEQuitAppHandlerFunc gAEQuitAppHandlerFunc;
- static AEDoScriptHandlerFunc gAEDoScriptHandlerFunc;
- static AEUnknownHandlerMsgFunc gAEUnknownHandlerMsgFunc;
-
- static pascal OSErr AEOpenApplication(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- );
- static pascal OSErr AEOpenDocument(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- );
- static pascal OSErr AEPrintDocument(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- );
- static pascal OSErr AEQuit(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- );
- static OSErr AEOpenOrPrint(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon,
- AEDocumentHandlerFunc aeDocumentHandlerFunc
- );
- static pascal OSErr AEUnknownHandler(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- );
- static pascal OSErr AEDoScript(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- );
- static void AEGetMyZone(
- Str32 zoneName
- );
-
- /*
- * Define a table used to install event handlers.
- */
- const static AEHandlerDefRec gAEHandlerDefs[] = {
- { kCoreEventClass, kAEStartRecording, AEIgnore },
- { kCoreEventClass, kAEStopRecording, AEIgnore },
- { kCoreEventClass, kAENotifyRecording, AEIgnore },
- { kCoreEventClass, kAENotifyStopRecording, AEIgnore },
- { kCoreEventClass, kAENotifyStartRecording, AEIgnore },
- { kCoreEventClass, kAEOpenApplication, AEOpenApplication },
- { kCoreEventClass, kAEOpenDocuments, AEOpenDocument },
- { kCoreEventClass, kAEPrintDocuments, AEPrintDocument },
- { kCoreEventClass, kAEQuitApplication, AEQuit },
- { 0, 0, NULL }
- };
-
- #define UNUSED(what) (what)
-
- static void ClearMemory(
- register void *ptr,
- register long size
- );
- #define CLEAR(rec) (ClearMemory(&rec, sizeof rec))
- static void pstrcpy(
- StringPtr dst,
- ConstStr255Param src
- );
- static void pstrcat(
- StringPtr dst,
- ConstStr255Param src
- );
-
- pascal OSErr
- InitializeAppleEvents(
- AEOpenAppHandlerFunc aeOpenAppHandlerFunc,
- AEDocumentHandlerFunc aeOpenDocHandlerFunc,
- AEDocumentHandlerFunc aePrintDocHandlerFunc,
- AEQuitAppHandlerFunc aeQuitAppHandlerFunc,
- AEDoScriptHandlerFunc aeDoScriptHandlerFunc,
- AEUnknownHandlerMsgFunc aeUnknownHandlerMsgFunc,
- long refCon
- )
- {
- long response;
- OSErr status;
-
- status = Gestalt(gestaltAppleEventsAttr, &response);
- gHasAppleEvents = (
- status == noErr
- && (response & (1L << gestaltAppleEventsPresent) != 0)
- );
- status = (gHasAppleEvents == FALSE) ? gestaltUndefSelectorErr : noErr;
- if (status == noErr) {
- gAEOpenAppHandlerFunc = aeOpenAppHandlerFunc;
- gAEOpenDocHandlerFunc = aeOpenDocHandlerFunc;
- gAEPrintDocHandlerFunc = aePrintDocHandlerFunc;
- gAEQuitAppHandlerFunc = aeQuitAppHandlerFunc;
- gAEDoScriptHandlerFunc = aeDoScriptHandlerFunc;
- gAEUnknownHandlerMsgFunc = aeUnknownHandlerMsgFunc;
- status = AEInstallEventHandlers(
- (AEHandlerDefPtr) gAEHandlerDefs, refCon);
- }
- if (status == noErr && aeDoScriptHandlerFunc != NULL) {
- status = AEInstallEventHandler(
- kAEMiscStandards,
- kAEDoScript,
- NewAEEventHandlerProc(AEDoScript),
- 0, /* No refCon */
- FALSE /* Not system event */
- );
- }
- if (status == noErr && aeUnknownHandlerMsgFunc != NULL) {
- status = AEInstallEventHandler(
- typeWildCard,
- typeWildCard,
- NewAEEventHandlerProc(AEUnknownHandler),
- 0, /* No refCon */
- FALSE /* Not system event */
- );
- }
- return (status);
- }
-
- /*
- * Initialize for apple events: and setup the handler callbacks so we process
- * events. Fail if a handler can't be installed. The caller should check
- * gHasAppleEvents to see if they are actually present.
- */
- pascal OSErr
- AEInstallEventHandlers(
- AEHandlerDefPtr aeHandlerDefPtr,
- long refCon
- )
- {
- OSErr status;
-
- status = noErr;
- if (aeHandlerDefPtr != NULL) {
- while (status == noErr && aeHandlerDefPtr->procPtr != NULL) {
- status = AEInstallEventHandler(
- aeHandlerDefPtr->eventClass,
- aeHandlerDefPtr->eventID,
- NewAEEventHandlerProc(aeHandlerDefPtr->procPtr),
- refCon,
- FALSE /* Not system event */
- );
- ++aeHandlerDefPtr;
- }
- }
- return (status);
- }
-
- /*
- * Initialize for apple events: and setup the coercion callbacks so we process
- * events. Fail if a handler can't be installed. The caller should check
- * gHasAppleEvents to see if they are actually present.
- */
- pascal OSErr
- AEInstallCoercionHandlers(
- AECoercionDefPtr aeCoercionDefPtr,
- long refCon
- )
- {
- OSErr status;
-
- status = noErr;
- if (aeCoercionDefPtr != NULL) {
- while (aeCoercionDefPtr->procPtr != NULL) {
- status = AEInstallCoercionHandler(
- aeCoercionDefPtr->fromType,
- aeCoercionDefPtr->toType,
- NewAECoerceDescProc(aeCoercionDefPtr->procPtr),
- refCon,
- FALSE, /* Pass data */
- FALSE /* Not system handler */
- );
- ++aeCoercionDefPtr;
- }
- }
- return (status);
- }
-
- /*
- * Open (initial double-click) the application. The handler is optional.
- */
- static pascal OSErr
- AEOpenApplication(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- OSErr status;
-
- status = AEHandlerSetup(theEvent, theReply, refCon);
- if (status == noErr)
- status = AEGotRequiredParams(theEvent);
- if (status == noErr && gAEOpenAppHandlerFunc != NULL)
- status = (*gAEOpenAppHandlerFunc)(refCon); /* Application specific */
- GLOBAL.currentEventIsAppleEvent = FALSE;
- return (status);
- }
-
-
- /*
- * Open a document. This can be called at application setup, but it can also
- * be called by dropping a document on the application icon.
- */
- static pascal OSErr
- AEOpenDocument(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- OSErr status;
-
- status = AEOpenOrPrint(theEvent, theReply, refCon, gAEOpenDocHandlerFunc);
- return (status);
- }
-
- /*
- * Print a document. This can be called at application setup, but it can also
- * be called by dropping a document on the application icon.
- */
- static pascal OSErr
- AEPrintDocument(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- OSErr status;
-
- status = AEOpenOrPrint(theEvent, theReply, refCon, gAEPrintDocHandlerFunc);
- return (status);
- }
-
- /*
- * This is the common handler for AppleEvent open document and print document.
- * The actual work is done by application-specific code.
- */
- static OSErr
- AEOpenOrPrint(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon,
- AEDocumentHandlerFunc aeDocumentHandlerFunc
- )
- {
- OSErr status;
- AEDesc theDesc;
- long numberOfFiles;
- long iFile;
- AEKeyword ignoredKeyWord;
- DescType ignoredType;
- Size ignoredSize;
- FSSpec theFSS;
-
- theDesc.dataHandle = NULL;;
- status = (aeDocumentHandlerFunc == NULL) ? errAEEventNotHandled : noErr;
- if (status == noErr)
- status = AEHandlerSetup(theEvent, theReply, refCon);
- if (status == noErr)
- status = AEGetParamDesc(theEvent, keyDirectObject, typeAEList, &theDesc);
- if (status == noErr)
- status = AEGotRequiredParams(theEvent);
- if (status == noErr)
- status = AECountItems(&theDesc, &numberOfFiles);
- for (iFile = 1; status == noErr && iFile <= numberOfFiles; iFile++) {
- status = AEGetNthPtr(
- &theDesc,
- iFile,
- typeFSS,
- &ignoredKeyWord,
- &ignoredType,
- (Ptr) &theFSS,
- sizeof theFSS,
- &ignoredSize
- );
- if (status == noErr) {
- /*
- * Note that an error from the handler will terminate all files.
- */
- status = (*aeDocumentHandlerFunc)(&theFSS, refCon);
- }
- }
- (void) AEDisposeDesc(&theDesc);
- GLOBAL.currentEventIsAppleEvent = FALSE;
- return (status);
- }
-
- static pascal OSErr
- AEQuit(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- OSErr status;
-
- status = (gAEQuitAppHandlerFunc == NULL) ? errAEEventNotHandled : noErr;
- if (status == noErr)
- status = AEHandlerSetup(theEvent, theReply, refCon);
- if (status == noErr)
- status = AEGotRequiredParams(theEvent);
- status = (*gAEQuitAppHandlerFunc)(refCon);
- GLOBAL.currentEventIsAppleEvent = FALSE;
- return (status);
- }
-
- /*
- * This handler is called for "scripting on/off" events. They are ignored.
- */
- pascal OSErr
- AEIgnore(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- UNUSED(theEvent);
- UNUSED(theReply);
- UNUSED(refCon);
- GLOBAL.currentEventIsAppleEvent = FALSE;
- return (noErr);
- }
-
- /*
- * Unknown events go here. If the application provides an alert, call it.
- * The initializer has provided a handler functions.
- */
- static pascal OSErr
- AEUnknownHandler(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- OSErr status;
- OSType eventClass;
- OSType eventID;
- OSType typeCode;
- Size actualSize;
- Str255 work;
-
- status = AEHandlerSetup(theEvent, theReply, refCon);
- if (status == noErr) {
- status = AEGetAttributePtr(
- theEvent,
- keyEventClassAttr,
- typeType,
- &typeCode,
- (Ptr) &eventClass,
- sizeof(eventClass),
- &actualSize
- );
- }
- if (status == noErr) {
- AEGetAttributePtr(
- theEvent,
- keyEventIDAttr,
- typeType,
- &typeCode,
- (Ptr) &eventID,
- sizeof(eventID),
- &actualSize
- );
- }
- if (status == noErr) {
- pstrcpy(work, "\pUnknown AppleEvent. Class ");
- BlockMoveData(&eventClass, &work[work[0] + 1], sizeof (OSType));
- work[0] += sizeof (OSType);
- pstrcat(work, "\p, ID ");
- BlockMoveData(&eventID, &work[work[0] + 1], sizeof (OSType));
- work[0] += sizeof (OSType);
- (*gAEUnknownHandlerMsgFunc)(work);
- }
- GLOBAL.currentEventIsAppleEvent = FALSE;
- return (errAEHandlerNotFound);
- }
-
- /*
- * This processes the Do Script event. The application provided a handler.
- */
- static pascal OSErr
- AEDoScript(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- CharsHandle scriptHandle;
- OSErr status;
-
- scriptHandle = NULL;
- status = AEHandlerSetup(theEvent, theReply, refCon);
- if (status == noErr)
- status = AEGetChars(theEvent, keyDirectObject, &scriptHandle);
- if (status == noErr)
- status = AEGotRequiredParams(theEvent);
- if (status == noErr) {
- /*
- * Make sure there's a null trailer.
- */
- status = PtrAndHand("", (Handle) scriptHandle, 1);
- }
- if (status == noErr) {
- MoveHHi((Handle) scriptHandle);
- HLock((Handle) scriptHandle);
- status = (*gAEDoScriptHandlerFunc)(
- (Ptr) *scriptHandle,
- GetHandleSize((Handle) scriptHandle),
- theReply,
- refCon
- );
- }
- if (scriptHandle != NULL) {
- DisposeHandle((Handle) scriptHandle);
- scriptHandle = NULL;
- }
- GLOBAL.currentEventIsAppleEvent = FALSE;
- return (status);
- }
-
- /*
- * Utilities
- */
- /*
- * Build an AppleEvent descriptor for a target address. The addressMode parameter
- * chooses the target:
- * kSelfCurrentProcess direct calls to this application (for scripting)
- * kSelfUsingPSN event-loop based calls to this application (script debug)
- * kOtherApplication dialog-based calls to an external application.
- */
- pascal OSErr
- AEMakeTargetAddress(
- AETargetAddressType aeTargetAddressType,
- AEDesc *theAddress,
- StringPtr targetName
- )
- {
- OSErr status;
- ProcessSerialNumber myPSN;
- StringPtr theTarget;
-
- theTarget = "\p"; /* Bogus initialize for MetroWerks */
- switch (aeTargetAddressType) {
- case kAETargetSelfCurrentProcess:
- /*
- * Note that, if you use this case, the Apple Event
- * Manager will bypass the event loop and call your
- * handlers directly.
- */
- myPSN.highLongOfPSN = 0;
- myPSN.lowLongOfPSN = kCurrentProcess;
- theTarget = "\pLocal direct linkage";
- goto makeDescriptor;
- case kAETargetSelfUsingPSN:
- /*
- * This case always calls through the event loop.
- */
- status = GetCurrentProcess(&myPSN);
- theTarget = "\pLocal linkage through event loop";
- if (status == noErr) {
- makeDescriptor: status = AECreateDesc(
- typeProcessSerialNumber,
- (Ptr) &myPSN,
- sizeof (ProcessSerialNumber),
- theAddress
- );
- }
- break;
- case kAETargetOtherApplication:
- status = AEBrowseForTarget(
- NULL, NULL, NULL, NULL, theAddress, theTarget);
- break;
- }
- if (status == noErr && targetName != NULL)
- BlockMoveData(theTarget, targetName, theTarget[0] + 1);
- return (status);
- }
-
- /*
- * Call the PPC Toolbox browser to locate a target application.
- * dialogPrompt -> "Choose a program to link to" if NULL
- * listHeader -> "Programs"
- * theAddress <- the result
- * targetName <- the application name text for error alerts
- */
- pascal OSErr
- AEBrowseForTarget(
- ConstStr255Param dialogPrompt,
- ConstStr255Param listHeader,
- PPCFilterUPP filterProcUPP,
- ConstStr255Param locNBPType,
- AEDesc *theAddress,
- StringPtr targetName
- )
- {
- LocationNameRec theLoc;
- PortInfoRec theRec;
- OSErr status;
- TargetID theID;
-
- status = PPCBrowser(
- dialogPrompt,
- listHeader,
- FALSE, /* No default */
- &theLoc,
- &theRec,
- filterProcUPP,
- locNBPType
- );
- if (status == noErr) {
- /*
- * Create a target descriptor
- */
- BlockMoveData(
- theRec.name.name,
- targetName,
- theRec.name.name[0] + 1
- );
- theID.name = theRec.name;
- theID.location = theLoc;
- status = AECreateDesc(
- typeTargetID,
- (Ptr) &theID,
- sizeof(theID),
- theAddress
- );
- }
- if (status == noErr)
- ParamText(targetName, "\p", "\p", "\p");
- return (status);
- }
-
- /*
- * Call IPCListPorts to locate a target application.
- * machineName -> the machine to look for
- * targetNameVector -> a vector (NULL terminated) of application name strings.
- * theAddress <- the result
- * targetName <- the application name text for error alerts
- */
- pascal OSErr
- AELocateTarget(
- ConstStr255Param machineName,
- const StringPtr *targetNameVector,
- AEDesc *theAddress,
- StringPtr actualTargetName
- )
- {
- LocationNameRec locationNameRec;
- OSErr status;
- TargetID theID;
- IPCListPortsPBRec ipcListPortsPBRec;
- PPCPortRec ppcPortRec;
- PortInfoRec portInfoRec;
- short i;
- short j;
- #define IPC (ipcListPortsPBRec)
- #define LOC (locationNameRec)
- #define PORT (ppcPortRec)
- #define INFO (portInfoRec)
-
- CLEAR(PORT);
- PORT.nameScript = smRoman;
- pstrcpy(PORT.name, "\p=");
- PORT.portKindSelector = ppcByString;
- pstrcpy(PORT.u.portTypeStr, "\p=");
- CLEAR(LOC);
- LOC.locationKindSelector = ppcNBPLocation;
- pstrcpy(LOC.u.nbpEntity.objStr, (void *) machineName);
- pstrcpy(LOC.u.nbpEntity.typeStr, "\pPPCToolBox");
- AEGetMyZone(LOC.u.nbpEntity.zoneStr);
- status = noErr;
- for (i = 0; status == noErr; i++) {
- CLEAR(IPC);
- IPC.startIndex = i;
- IPC.requestCount = 1;
- IPC.portName = &PORT;
- IPC.locationName = &LOC;
- IPC.bufferPtr = &portInfoRec;
- status = IPCListPorts(&IPC, FALSE);
- if (status == noErr) {
- BlockMoveData(
- INFO.name.name,
- actualTargetName,
- INFO.name.name[0] + 1
- );
- for (j = 0; targetNameVector[j] != NULL; j++) {
- if (EqualString(
- actualTargetName, targetNameVector[j], FALSE, FALSE)) {
- theID.name = INFO.name;
- theID.location = LOC;
- status = AECreateDesc(
- typeTargetID,
- (Ptr) &theID,
- sizeof(theID),
- theAddress
- );
- goto exit;
- }
- }
- }
- }
- exit: return (status);
- #undef IPC
- #undef LOC
- #undef PORT
- #undef INFO
- }
-
- /*
- * This should be called before doing any user-interaction, such as alerts
- * or dialogs. It returns FALSE if interaction is blocked at this time.
- * The application should provide an idle function UPP. For example,
- *
- * pascal Boolean
- * MyAEIdleProc(
- * const EventRecord *theEventPtr,
- * long *sleepTime,
- * RgnHandle *mouseRgn
- * )
- * {
- * if (theEventPtr->what == kHighLevelEvent)
- * return (TRUE);
- * else {
- * *sleepTime = ProcessThisEvent(theEventPtr);
- * return (FALSE);
- * }
- * }
- */
- pascal Boolean
- AEInteractionOK(
- AEIdleUPP aeIdleUPP
- )
- {
- Boolean result;
- OSErr status;
-
- if (GLOBAL.currentEventIsAppleEvent == FALSE)
- result = TRUE;
- else {
- status = AEInteractWithUser(0, NULL, aeIdleUPP);
- result = (status == noErr);
- }
- return (result);
- }
-
- /*
- * AEGotRequiredParams fails if not all required parameters have been extracted.
- * Call this after retrieving all required parameters before actually processing
- * the event. This sets gCurrentAEStatus to noErr if it succeeds.
- *
- * If required parameters remain, return errAEParamMissed.
- */
- pascal OSErr
- AEGotRequiredParams(
- const AppleEvent *theEvent
- )
- {
- DescType descType;
- Size actualSize;
- OSErr status;
-
- status = AEGetAttributePtr(
- theEvent,
- keyMissedKeywordAttr,
- typeWildCard,
- &descType,
- NULL,
- 0,
- &actualSize
- );
- if (status == errAEDescNotFound) {
- GLOBAL.currentAEStatus = noErr;
- status = noErr;
- }
- else {
- status = errAEParamMissed;
- }
- return (status);
- }
-
- /*
- * All apple events call this function initially to store common information.
- */
- pascal OSErr
- AEHandlerSetup(
- const AppleEvent *theEvent,
- AppleEvent *theReply,
- long refCon
- )
- {
- OSErr status;
- DescType actualType;
- Size actualSize;
-
- /*
- * Here's where we add the Frontier "shared script" cancel handler.
- */
- GLOBAL.currentAEEvent = theEvent;
- GLOBAL.currentAEReply = theReply;
- GLOBAL.currentAERefCon = refCon;
- GLOBAL.currentAEStatus = errAEEventNotHandled;
- GLOBAL.currentEventIsAppleEvent = TRUE;
- /*
- * Try to extract the class and type parameters, then switch on the
- * event and process what we can. Note that GLOBAL.currentAEStatus is
- * initializad to an error code: the final caller must set the status to
- * noErr if the event was correctly handled. Normally, this is done
- * by AEGotRequiredParams
- */
- status = AEGetAttributePtr(
- theEvent,
- keyEventClassAttr,
- typeType,
- &actualType,
- (Ptr) &GLOBAL.currentAEEventClass,
- sizeof GLOBAL.currentAEEventClass,
- &actualSize
- );
- if (status == noErr) {
- status = AEGetAttributePtr(
- theEvent,
- keyEventIDAttr,
- typeType,
- &actualType,
- (Ptr) &GLOBAL.currentAEEventID,
- sizeof GLOBAL.currentAEEventID,
- &actualSize
- );
- }
- if (status == noErr) {
- status = AEGetAttributePtr(
- theEvent,
- keyInteractLevelAttr,
- typeInteger,
- &actualType,
- (Ptr) &GLOBAL.currentAEIntractionLevel,
- sizeof GLOBAL.currentAEIntractionLevel,
- &actualSize
- );
- }
- return (status);
- }
-
- /*
- * These functions get and set data in the AppleEvent. They are only needed
- * if we intend to receive events.
- */
-
- /*
- * AEGetShort extracts a signed short integer from the parameter list.
- * Return noErr on success, errAEDescNotFound if the parameter was missing.
- */
- pascal OSErr
- AEGetShort(
- const AppleEvent *theEvent,
- DescType parameterKey,
- short *result
- )
- {
- OSErr status;
- Size actualSize;
- DescType actualType;
-
- status = AEGetParamPtr(
- theEvent,
- parameterKey,
- typeSMInt,
- &actualType,
- (Ptr) result,
- sizeof (short),
- &actualSize
- );
- return (status);
- }
-
- /*
- * AEGetLong extracts an signed short integer from the parameter list.
- */
- pascal OSErr
- AEGetLong(
- const AppleEvent *theEvent,
- DescType parameterKey,
- long *result
- )
- {
- OSErr status;
- Size actualSize;
- DescType actualType;
-
- status = AEGetParamPtr(
- theEvent,
- parameterKey,
- typeInteger,
- &actualType,
- (Ptr) result,
- sizeof (long),
- &actualSize
- );
- return (status);
- }
-
- /*
- * AEGetBoolean extracts a Boolean from the parameter list.
- */
- pascal OSErr
- AEGetBoolean(
- const AppleEvent *theEvent,
- DescType parameterKey,
- Boolean *result
- )
- {
- OSErr status;
- Size actualSize;
- DescType actualType;
-
- status = AEGetParamPtr(
- theEvent,
- parameterKey,
- typeBoolean,
- &actualType,
- (Ptr) result,
- sizeof (Boolean),
- &actualSize
- );
- return (status);
- }
-
- /*
- * GetAEChars extracts a text item from the parameter list, returning it in a
- * newly-allocated CharsHandle. The caller must dispose the handle.
- */
- pascal OSErr
- AEGetChars(
- const AppleEvent *theEvent,
- DescType parameterKey,
- CharsHandle *result
- )
- {
- OSErr status;
- AEDesc theDesc;
-
- status = AEGetParamDesc(
- theEvent,
- parameterKey,
- typeChar,
- &theDesc
- );
- if (status == noErr)
- *result = (CharsHandle) theDesc.dataHandle;
- return (status);
- }
-
- /*
- * GetAEString extracts a Str255 from the parameter list.
- */
- pascal OSErr
- AEGetString(
- const AppleEvent *theEvent,
- DescType parameterKey,
- StringPtr result
- )
- {
- OSErr status;
- Size actualSize;
- DescType actualType;
-
- status = AEGetParamPtr(
- theEvent,
- parameterKey,
- typeChar,
- &actualType,
- (Ptr) &result[1],
- sizeof (Str255) - 1,
- &actualSize
- );
- result[0] = actualSize;
- return (status);
- }
-
- /*
- * AEPutShort stores a short integer into an AppleEvent reply.
- */
- pascal OSErr
- AEPutShort(
- AppleEvent *theReply,
- DescType parameterKey,
- short value
- )
- {
- OSErr status;
-
- status = AEPutParamPtr(
- theReply,
- parameterKey,
- typeSMInt,
- (Ptr) &value,
- sizeof value
- );
- return (status);
- }
-
- /*
- * AEPutBoolean stores a Boolean into the AppleEvent reply.
- */
- pascal OSErr
- AEPutBoolean(
- AppleEvent *theReply,
- DescType parameterKey,
- Boolean value
- )
- {
- OSErr status;
-
- status = AEPutParamPtr(
- theReply,
- parameterKey,
- typeBoolean,
- (Ptr) &value,
- sizeof value
- );
- return (status);
- }
-
- /*
- * AEPutLong stores a long integer into the AppleEvent reply.
- */
- pascal OSErr
- AEPutLong(
- AppleEvent *theReply,
- DescType parameterKey,
- long value
- )
- {
- OSErr status;
-
- status = AEPutParamPtr(
- theReply,
- parameterKey,
- typeInteger,
- (Ptr) &value,
- sizeof value
- );
- return (status);
- }
-
- /*
- * AEPutStringHandle stores a StringHandle into the AppleEvent reply.
- */
- pascal OSErr
- AEPutStringHandle(
- AppleEvent *theReply,
- DescType parameterKey,
- const StringHandle value
- )
- {
- OSErr status;
- short lockState;
-
- lockState = HGetState((Handle) value);
- HLock((Handle) value);
- status = AEPutString(theReply, parameterKey, *value);
- HSetState((Handle) value, lockState);
- return (status);
- }
-
- /*
- * AEPutCharsHandle stores a CharsHandle into the AppleEvent reply.
- */
- pascal OSErr
- AEPutCharsHandle(
- AppleEvent *theReply,
- DescType parameterKey,
- const CharsHandle value
- )
- {
- OSErr status;
- short lockState;
-
- lockState = HGetState((Handle) value);
- HLock((Handle) value);
- status = AEPutParamPtr(
- theReply,
- parameterKey,
- typeChar,
- (Ptr) *value,
- GetHandleSize((Handle) value)
- );
- HSetState((Handle) value, lockState);
- return (status);
- }
-
-
- /*
- * AEPutString stores a Str255 into the AppleEvent reply.
- */
- pascal OSErr
- AEPutString(
- AppleEvent *theReply,
- DescType parameterKey,
- ConstStr255Param value
- )
- {
- OSErr status;
-
- status = AEPutParamPtr(
- theReply,
- parameterKey,
- typeChar,
- (Ptr) &value[1],
- value[0]
- );
- return (status);
- }
-
- /*
- * Local function for AELocateTarget
- */
- static void
- AEGetMyZone(
- Str32 zoneName
- )
- {
- XPPParamBlock pb;
- OSErr status;
- #define PB (pb)
- #define kXPPTimeout 3
- #define kXPPRetry 4
-
- CLEAR(PB);
- PB.XCALL.xppTimeout = kXPPTimeout;
- PB.XCALL.xppRetry = kXPPRetry;
- PB.XCALL.zipBuffPtr = (Ptr) zoneName;
- PB.XCALL.zipInfoField[0] = 0;
- PB.XCALL.zipInfoField[1] = 0;
- status = GetMyZone(&PB, FALSE);
- if (status == noBridgeErr) {
- zoneName[0] = 1;
- zoneName[1] = '*';
- }
- else if (status != noErr) {
- zoneName[0] = 0;
- }
- #undef PB
- }
-
- static void
- ClearMemory(
- void *dataPtr,
- register long size
- )
- {
- register char *ptr;
-
- ptr = (char *) dataPtr;
- while (size > 0) {
- *ptr++ = 0;
- --size;
- }
- }
-
- static void
- pstrcpy(
- StringPtr dst,
- ConstStr255Param src
- )
- {
- BlockMoveData(src, dst, src[0] + 1);
- }
-
- static void
- pstrcat(
- StringPtr dst,
- ConstStr255Param src
- )
- {
- short length;
-
- length = 255 - dst[0];
- if (length > src[0])
- length = src[0];
- BlockMoveData(&src[1], &dst[1] + dst[0], length);
- dst[0] += length;
- }
-
-