home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * AEFunc.c
- *
- * This is a support file for "Grant's CGI Framework".
- * Please see the license agreement that accompanies the distribution package
- * for licensing details.
- *
- * Copyright ©1995,1996 by Grant Neufeld
- * grant@acm.com
- * http://arpp.carleton.ca/grant/
- *
- *****/
-
- #include "MyConfiguration.h"
-
- #include <stdlib.h>
-
- #include "compiler_stuff.h"
- #include "globals.h"
-
- #include "DebugUtil.h"
- #include "EventUtil.h"
- #include "ErrorUtil.h"
- #include "MemoryUtil.h"
- #include "ProcessUtil.h"
-
- #include "AEFunc.h"
-
-
- /*** FUNCTIONS ***/
-
- /* IM:IAC 4-35 */
- OSErr
- AEFuncGotRequiredParams ( AppleEvent *theAppleEvent )
- {
- OSErr theErr;
- DescType returnedType;
- Size actualSize;
-
- theErr = AEGetAttributePtr ( theAppleEvent, keyMissedKeywordAttr, typeWildCard,
- &returnedType, NULL, nil, &actualSize );
- if ( theErr == errAEDescNotFound )
- {
- /* all required parameters were retrieved */
- return noErr;
- }
- else if ( theErr == noErr )
- {
- /* required parameter was missed */
- return errAEParamMissed;
- }
- else
- {
- return theErr;
- }
- } /* AEFuncGotRequiredParams */
-
-
- /* IM:IAC 5-23 */
- pascal Boolean
- AEFuncAEIdleFunc ( const EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn )
- {
- Boolean theResult = false;
-
- switch ( theEvent->what )
- {
- #if kCompileWithForeground
-
- case updateEvt :
- case activateEvt :
- break;
-
- case osEvt :
- /* CustomAdjustCursor ( theEvent->where, theMouseRgn ); */
- doOsEvt ( theEvent );
- break;
-
- #endif /* kCompileWithForeground */
-
-
- case nullEvent :
- /* *mouseRgn = theMouseRgn; */
- *sleepTime = gSleepTicks; /* may need to change to use correct value for app */
-
- /* I'm not 100% certain that this should be here... */
- ProcessGiveTime ( nil );
- break;
- }
-
- return theResult;
- } /* AEFuncAEIdleFunc */
-
-
- #pragma mark -
-
- /* get a string from a parameter */
- OSErr
- AEGetParamString ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, char **theString, char *tempBuffer, long bufferSize )
- {
- OSErr theErr;
- DescType actualType;
- Size actualSize;
-
- my_assert ( theString != NULL, "\pAEGetParamString: theString ptr is NULL" );
- my_assert ( *theString == NULL, "\pAEGetParamString: theString is not pointing to NULL" );
- my_assert ( theAppleEvent != NULL, "\pAEGetParamString: theAppleEvent ptr is NULL" );
- my_assert ( tempBuffer != NULL, "\pAEGetParamString: tempBuffer ptr is NULL" );
-
- theErr = AEGetParamPtr ( theAppleEvent, theAEKeyword, typeChar,
- &actualType, (Ptr)tempBuffer, bufferSize, &actualSize );
-
- if ( theErr == noErr )
- {
- my_assert ( actualSize <= bufferSize, "\pAEGetParamString: actual param size too big" );
-
- /* if the parameter was present, allocate space to copy it into destination string */
- *theString = (char *) MemoryNewPtr ( actualSize + 1, &theErr );
-
- if ( *theString != NULL )
- {
- /* copy the tempBuffer into the destination string */
- BlockMove ( tempBuffer, *theString, actualSize );
-
- /* put a null terminator at the end of the string */
- (*theString)[actualSize] = nil;
- }
- }
-
- return theErr;
- } /* AEGetParamString */
-
-
- /* copy a parameter into an existing string block */
- OSErr
- AEGetParamStringNoAlloc (
- const AppleEvent * theAppleEvent,
- AEKeyword theAEKeyword,
- char * theString,
- long stringSize )
- {
- OSErr theErr;
- DescType actualType;
- Size actualSize;
-
- my_assert ( theString != NULL, "\pAEGetParamString: theString ptr is NULL" );
- my_assert ( theAppleEvent != NULL, "\pAEGetParamString: theAppleEvent ptr is NULL" );
- my_assert ( stringSize != nil, "\pAEGetParamString: stringSize is nil" );
-
- theErr = AEGetParamPtr ( theAppleEvent, theAEKeyword, typeChar,
- &actualType, (Ptr)theString, stringSize, &actualSize );
-
- return theErr;
- } /* AEGetParamString */
-
-
- #pragma segment AppleEvent
- /* get a short from a parameter */
- OSErr
- AEGetParamShort ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, short *theShort, char *tempBuffer, long bufferSize )
- {
- OSErr theErr;
- DescType actualType;
- Size actualSize;
-
- my_assert ( theShort != NULL, "\pAEGetParamShort: theShort ptr is NULL" );
- my_assert ( theAppleEvent != NULL, "\pAEGetParamShort: theAppleEvent ptr is NULL" );
- my_assert ( tempBuffer != NULL, "\pAEGetParamShort: tempBuffer ptr is NULL" );
-
- theErr = AEGetParamPtr
- ( theAppleEvent, theAEKeyword, typeChar, &actualType, (Ptr)tempBuffer, bufferSize, &actualSize );
- if ( theErr == noErr )
- {
- my_assert ( actualSize <= bufferSize, "\pAEGetParamShort: actual param size too big" );
-
- /* terminate the buffer with a null byte so it will be a proper C string */
- tempBuffer[actualSize] = nil;
-
- *theShort = atoi ( tempBuffer );
- }
-
- return theErr;
- } /* AEGetParamShort */
-
-
- /* get a long value from a parameter */
- OSErr
- AEGetParamLong ( const AppleEvent *theAppleEvent, AEKeyword theAEKeyword, long *theLong )
- {
- OSErr theErr;
- DescType actualType;
- Size actualSize;
-
- my_assert ( theLong != NULL, "\pAEGetParamShort: theLong ptr is NULL" );
- my_assert ( theAppleEvent != NULL, "\pAEGetParamShort: theAppleEvent ptr is NULL" );
-
- theErr = AEGetParamPtr
- ( theAppleEvent, theAEKeyword, typeLongInteger, &actualType, (Ptr)theLong, sizeof(long), &actualSize );
- if ( theErr == noErr )
- {
- my_assert ( actualSize <= sizeof(long), "\pAEGetParamLong: actual param size too big" );
- }
-
- return theErr;
- } /* AEGetParamShort */
-
-
- /***** EOF *****/
-