/* $Header: tyrathect:Development:Perl::RCS:missing.c,v 1.2 1994/05/04 02:12:43 neeri Exp $ * *    Copyright (c) 1996 Matthias Neeracher * *    You may distribute under the terms of the Perl Artistic License, *    as specified in the README file. * * $Log: missing.c,v $ */#define MAC_CONTEXT#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include <Types.h>#include <Memory.h>#include <Processes.h>#include <TFileSpec.h>typedef LaunchPBPtr			LaunchParam;typedef ProcessInfoRecPtr	ProcessInfo;static ProcessInfo NewProcessInfo(){	ProcessInfo	pi;	pi = (ProcessInfo) malloc(sizeof(ProcessInfoRec)+sizeof(FSSpec)+36);	pi->processInfoLength	=	sizeof(ProcessInfoRec);	pi->processName			=	(StringPtr)((char *)pi+sizeof(ProcessInfoRec));	pi->processAppSpec		=	(FSSpecPtr)((char *)pi+sizeof(ProcessInfoRec)+36);		return pi;}static void * SvUNTIE(SV * sv, char * package){	MAGIC * mg ;	SV * deref;	if (SvROK(sv)) {		deref = (SV*)SvRV(sv);    	if (!SvOBJECT(deref))			sv = deref;	}    if (SvMAGICAL(sv)) {        if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)            mg = mg_find(sv, 'P') ;        else            mg = mg_find(sv, 'q') ;        if (mg)            sv = mg->mg_obj;	}		if (sv_isa(sv, package)) {	    IV tmp = SvIV((SV*)SvRV(sv));	    return (void *) tmp;	}	else	    croak("parameter is not of type %s", package);		return 0;}MODULE = Mac::Processes	PACKAGE = LaunchParam=head1 NAMEMac::Processes - Extension description=head2 LaunchParamThis Perl hash maps onto the fields of a Launch Parameter Block I<(Consult the manual)>.The fields are: C<launchFileFlags>,C<launchControlFlags>,C<launchAppSpec>,C<launchAvailableSize>,C<launchProcessSN>,C<launchPreferredSize>,C<launchMinimumSize>.=over 4=item TIEHASH NAMEReturns LaunchParam.=cutLaunchParamTIEHASH(name)	char *	name	CODE:	RETVAL = (LaunchParam) malloc(sizeof(LaunchParamBlockRec)+sizeof(FSSpec));	RETVAL->launchBlockID			=	extendedBlock;	RETVAL->launchEPBLength			=	extendedBlockLen;	RETVAL->launchAppSpec			=	(FSSpecPtr)((char *)RETVAL+sizeof(LaunchParamBlockRec));	RETVAL->launchAppParameters	=	nil;	OUTPUT:	RETVAL=item DESTROY LPB=cutvoidDESTROY(lpb)	LaunchParam	lpb	CODE:	free(lpb);=item FETCH LPB, FIELDReturns a string.=cutSV *FETCH(lpb, field)	LaunchParam	lpb	char *		field	CODE:	switch (field[6]) {	case 'F':		if (!strcmp(field, "launchFileFlags"))			RETVAL = newSViv(lpb->launchFileFlags);		else			goto invalidField;		break;	case 'C':		if (!strcmp(field, "launchControlFlags"))			RETVAL = newSViv(lpb->launchControlFlags);		else			goto invalidField;		break;	case 'A':		if (!strcmp(field, "launchAppSpec"))			RETVAL = newSVpv(FSp2FullPath(lpb->launchAppSpec), 0);		else if (!strcmp(field, "launchAvailableSize"))			RETVAL = newSViv((long) lpb->launchAvailableSize);		else			goto invalidField;		break;	case 'P':		if (!strcmp(field, "launchProcessSN"))			RETVAL = 				newSVnv(					lpb->launchProcessSN.highLongOfPSN * 4294967296.0				 + lpb->launchProcessSN.lowLongOfPSN);		else if (!strcmp(field, "launchPreferredSize"))			RETVAL = newSViv((long) lpb->launchPreferredSize);		else			goto invalidField;		break;	case 'M':		if (!strcmp(field, "launchMinimumSize"))			RETVAL = newSViv(lpb->launchMinimumSize);		else			goto invalidField;		break;	default:invalidField:			croak("LaunchParamBlockRec has no field named %s", field);	}	OUTPUT:	RETVAL=item STORE LPB, FIELD, VALUE=cutvoidSTORE(lpb, field, value)	LaunchParam	lpb	char *		field	SV *			value	CODE:	switch (field[6]) {	case 'F':		if (!strcmp(field, "launchFileFlags"))			lpb->launchFileFlags = SvIV(value);		else			goto invalidField;		break;	case 'C':		if (!strcmp(field, "launchControlFlags"))			lpb->launchControlFlags = SvIV(value);		else			goto invalidField;		break;	case 'A':		if (!strcmp(field, "launchAppSpec"))			Path2FSSpec((char *) SvPV(value,na), lpb->launchAppSpec);		else if (!strcmp(field, "launchAvailableSize"))			lpb->launchAvailableSize = SvIV(value);		else			goto invalidField;		break;	case 'P':		if (!strcmp(field, "launchProcessSN")) {			double psn = SvNV(value);			double low = fmod(psn, 4294967296.0);				lpb->launchProcessSN.lowLongOfPSN = (long) low;			lpb->launchProcessSN.highLongOfPSN = (long) ((psn - low)/4294967296.0);		} else if (!strcmp(field, "launchPreferredSize"))			lpb->launchPreferredSize = SvIV(value);		else			goto invalidField;		break;	case 'M':		if (!strcmp(field, "launchMinimumSize"))			lpb->launchMinimumSize = SvIV(value);		else			goto invalidField;		break;	default:invalidField:			croak("LaunchParam has no field named %s", field);	}=item FIRSTKEYThis function is not implemented: LaunchParamBlockRec::FIRSTKEY is not implemented=cutvoidFIRSTKEY()	CODE:	croak("LaunchParam::FIRSTKEY is not implemented");=item NEXTKEYThis function is not implemented: LaunchParamBlockRec::NEXTKEY is not implemented=cutvoidNEXTKEY()	CODE:	croak("LaunchParam::NEXTKEY is not implemented");=item EXISTSThis function is not implemented: LaunchParamBlockRec::EXISTS is not implemented=cutvoidEXISTS()	CODE:	croak("LaunchParam::EXISTS is not implemented");=item DELETEThis function is not implemented: LaunchParamBlockRec::DELETE is not implemented=cutvoidDELETE()	CODE:	croak("LaunchParam::DELETE is not implemented");=item CLEARThis function is not implemented: LaunchParamBlockRec::CLEAR is not implemented=cutvoidCLEAR()	CODE:	croak("LaunchParam::CLEAR is not implemented");MODULE = Mac::Processes	PACKAGE = ProcessInfo=head2 ProcessInfoThis Perl hash allows access to the C<ProcessInfo> structure.B<(Consult your manual)>.The field names are: C<processName>, C<processNumber>, C<processType>,C<processSignature>, C<processSize>, C<processMode>, C<processLocation>, C<processLauncher>, C<processLaunchDate>, C<processActiveTime>, C<processAppSpec>.=over 4=cut=item TIEHASH NAME, [PI]Returns ProcessInfo.=cutProcessInfoTIEHASH(name, pi=NULL)	char *		name	ProcessInfo	pi	CODE:	if (pi)		RETVAL = pi;	else		RETVAL = NewProcessInfo();	OUTPUT:	RETVAL=item DESTROY PI=cutvoidDESTROY(pi)	ProcessInfo	pi	CODE:	free(pi);=item FETCH PI, FIELDReturns a string.=cutSV *FETCH(pi, field)	ProcessInfo	pi	char *		field	CODE:	switch (field[7]) {	case 'N':		if (!strcmp(field, "processName"))			RETVAL = newSVpv((char *) pi->processName+1, *pi->processName);		else if (!strcmp(field, "processNumber"))			RETVAL = 				newSVnv(					pi->processNumber.highLongOfPSN * 4294967296.0				 + pi->processNumber.lowLongOfPSN);		else			goto invalidField;		break;	case 'T':		if (!strcmp(field, "processType"))			RETVAL = newSVpv((char *)&pi->processType, 4);		else			goto invalidField;		break;	case 'S':		if (!strcmp(field, "processSignature"))			RETVAL = newSVpv((char *)&pi->processSignature, 4);		else if (!strcmp(field, "processSize"))			RETVAL = newSViv((long) pi->processSize);		else			goto invalidField;		break;	case 'M':		if (!strcmp(field, "processMode"))			RETVAL = newSViv((long) pi->processMode);		else			goto invalidField;		break;	case 'L':		if (!strcmp(field, "processLocation"))			RETVAL = newSViv((long) pi->processLocation);		else if (!strcmp(field, "processLauncher"))			RETVAL = 				newSVnv(					pi->processLauncher.highLongOfPSN * 4294967296.0				 + pi->processLauncher.lowLongOfPSN);		else if (!strcmp(field, "processLaunchDate"))			RETVAL = newSVnv((double) pi->processLaunchDate);		else			goto invalidField;		break;	case 'A':		if (!strcmp(field, "processActiveTime"))			RETVAL = newSViv((long) pi->processActiveTime);		else if (!strcmp(field, "processAppSpec"))			RETVAL = newSVpv(FSp2FullPath(pi->processAppSpec), 0);		else			goto invalidField;		break;	default:invalidField:			croak("ProcessInfo has no field named %s", field);	}	OUTPUT:	RETVAL=item STOREThis function is not implemented: ProcessInfoRec::STORE is not implemented=cutvoidSTORE()	CODE:	croak("ProcessInfo::STORE is not implemented");=item FIRSTKEYThis function is not implemented: ProcessInfoRec::FIRSTKEY is not implemented=cutvoidFIRSTKEY()	CODE:	croak("ProcessInfo::FIRSTKEY is not implemented");=item NEXTKEYThis function is not implemented: ProcessInfoRec::NEXTKEY is not implemented=cutvoidNEXTKEY()	CODE:	croak("ProcessInfo::NEXTKEY is not implemented");=item EXISTSThis function is not implemented: ProcessInfoRec::EXISTS is not implemented=cutvoidEXISTS()	CODE:	croak("ProcessInfo::EXISTS is not implemented");=item DELETEThis function is not implemented: ProcessInfoRec::DELETE is not implemented=cutvoidDELETE()	CODE:	croak("ProcessInfo::DELETE is not implemented");=item CLEARThis function is not implemented: ProcessInfoRec::CLEAR is not implemented=cutvoidCLEAR()	CODE:	croak("ProcessInfo::CLEAR is not implemented");=head2 Mac::Processes=cutMODULE = Mac::Processes	PACKAGE = Mac::Processes=item LaunchApplication LAUNCHPARAMSThe LaunchApplication function launches the application from the specified fileand returns the process serial number, preferred partition size, and minimumpartition size if the application is successfully launched.Returns zero on failure.=cutMacOSRetLaunchApplication(LaunchParams)	LaunchParam LaunchParams = (LaunchParam) SvUNTIE(ST(0), "LaunchParam");=item LaunchDeskAccessory PFILESPEC, PDANAMEThe LaunchDeskAccessory function searches the resource fork of the file specifiedby the pFileSpec parameter for the desk accessory with the 'DRVR' resource namespecified in the pDAName parameter. If the 'DRVR' resource name is found,LaunchDeskAccessory launches the corresponding desk accessory. If the deskaccessory is already open, it is brought to the front.Returns zero on failure.=cutMacOSRetLaunchDeskAccessory(pFileSpec, pDAName)	SV *		pFileSpec	Str255	pDAName	PREINIT:	FSSpec	spec;	FSSpec *	fssp = nil;	CODE:	if (SvTRUE(pFileSpec) && Path2FSSpec(SvPV(pFileSpec,na), &spec))		fssp = &spec;	RETVAL = LaunchDeskAccessory(fssp, pDAName);	OUTPUT:	RETVAL=item GetCurrentProcessThe GetCurrentProcess function returns the process serialnumber of the process that is currently running, that is, the one currentlyaccessing the CPU.Return C<undef> if an error was detected.=cutProcessSerialNumberGetCurrentProcess()	CODE:	if (gLastMacOSErr = GetCurrentProcess(&RETVAL)) {		XSRETURN_UNDEF;	}	OUTPUT:	RETVAL	=item GetFrontProcessThe GetFrontProcess function returns the process serialnumber of the process running in the foreground.Return C<undef> if an error was detected.=cutProcessSerialNumberGetFrontProcess()	CODE:	if (gLastMacOSErr = GetFrontProcess(&RETVAL)) {		XSRETURN_UNDEF;	}	OUTPUT:	RETVAL	=item GetNextProcess PSNGet information about the next process, if any, in the Process ManagerŐs internallist of open processes.Return C<undef> if an error was detected.=cutProcessSerialNumberGetNextProcess(PSN)	ProcessSerialNumber	PSN	CODE:	if (gLastMacOSErr = GetNextProcess(&PSN)) {		XSRETURN_UNDEF;	} else		RETVAL = PSN;	OUTPUT:	RETVAL	=item _GetProcessInformation PSNThe GetProcessInformation function returns, in a process information record,information about the specified process. The information returned in the infoparameter includes the applicationŐs name as it appears in the Application menu,the type and signature of the application, the address of the applicationpartition, the number of bytes in the application partition, the number of freebytes in the application heap, the application that launched the application, thetime at which the application was launched, and the location of the applicationfile.Return C<undef> if an error was detected.=cutProcessInfo_GetProcessInformation(PSN)	ProcessSerialNumber	PSN	CODE:	RETVAL = NewProcessInfo();	if (gLastMacOSErr = GetProcessInformation(&PSN, RETVAL)) {		free(RETVAL);		XSRETURN_UNDEF;	} 	OUTPUT:	RETVAL	=item SetFrontProcess PSNThe SetFrontProcess function schedules the specified process to move to theforeground. The specified process moves to the foreground after the currentforeground process makes a subsequent call to WaitNextEvent or EventAvail.Returns zero on failure.=cutMacOSRetSetFrontProcess(PSN)	ProcessSerialNumber	&PSN=item WakeUpProcess PSNThe WakeUpProcess function makes a process suspended by WaitNextEvent() eligible toreceive CPU time. A process is suspended when the value of the sleep parameter inthe WaitNextEvent() function is not 0 and no events for that process are pending inthe event queue. This process remains suspended until the time specified in thesleep parameter expires or an event becomes available for that process. You canuse WakeUpProcess to make the process eligible for execution before the timespecified in the sleep parameter expires.Returns zero on failure.=cutMacOSRetWakeUpProcess(PSN)	ProcessSerialNumber	&PSN=item SameProcess PSN1, PSN2The SameProcess function compares two process serial numbers and determineswhether they refer to the same process.Return C<undef> if an error was detected.=cutBooleanSameProcess(PSN1, PSN2)	ProcessSerialNumber	PSN1	ProcessSerialNumber	PSN2	CODE:	if (gLastMacOSErr = SameProcess(&PSN1, &PSN2, &RETVAL)) {		XSRETURN_UNDEF;	} =item ExitToShellThis function is not implemented: ExitToShell() unsupported. Use exit.=cutvoidExitToShell()	CODE:	croak("ExitToShell() unsupported. Use exit.");