program SpaceAliens;	uses		EPPC, AppleEvents, 		ICTypes, ICAPI, ICKeys, ICMappings, ICSubs;	var		quitNow: boolean;		have_opened: boolean;		entries: Handle;	function DoODoc (fss: FSSpec): OSErr;		var			err: OSErr;			ext: Str63;			info: FInfo;			entry: ICMapEntry;			posndx: longint;			ndx: integer;			found: boolean;	begin		err := noErr;		if Pos('.', fss.name) <> 0 then begin			ext := '';			ndx := length(fss.name);			while fss.name[ndx] <> '.' do begin				ext := concat(fss.name[ndx], ext);				ndx := ndx - 1;			end; (* while *)			ext := concat('.', ext);			posndx := 0;			found := false;			repeat				err := ICMapErr(ICMGetEntry(entries, posndx, entry));				if err = noErr then begin					posndx := posndx + entry.total_length;					found := (IUEqualString(entry.extension, ext) = 0);				end; (* if *)			until found or (err <> noErr);			if found then begin				err := HGetFInfo(fss.vRefNum, fss.parID, fss.name, info);				if err = noErr then begin					info.fdCreator := entry.file_creator;					info.fdType := entry.file_type;					err := HSetFInfo(fss.vRefNum, fss.parID, fss.name, info);				end; (* if *)			end			else begin				err := noErr;			end; (* if *)		end; (* if *)		quitNow := true;		DoODoc := err;	end; (* DoODoc *)	function DoOApp: OSErr;	begin		quitNow := true;		DoOApp := noErr;	end;	function DoQuit: OSErr;	begin		quitNow := true;		DoQuit := noErr;	end; (* DoQuit *)	function GotRequiredParams (theAppleEvent: AppleEvent): OSErr;		var			typeCode: DescType;			actualSize: Size;			err: OSErr;	begin		err := AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, typeCode, nil, 0, actualSize);		if err = errAEDescNotFound then			GotRequiredParams := noErr		else if err = noErr then			GotRequiredParams := errAEEventNotHandled		else			GotRequiredParams := err;	end; (* GotRequiredParams *)	function HandleOAPP (theAppleEvent, reply: AppleEvent; refcon: longint): OSErr;		var			oe: OSErr;	begin		oe := GotRequiredParams(theAppleEvent);		oe := DoOApp;		HandleOAPP := oe;	end;	function HandleDocs (theAppleEvent, reply: AppleEvent; refcon: longint): OSErr;		var			myFSS: FSSpec;			docList: AEDescList;			index, itemsInList: longint;			actualSize: Size;			keywd: AEKeyword;			typeCode: descType;			ignoreWPtr: WindowPtr;			oe, ooe: OSErr;	begin		oe := AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);		if oe = noErr then begin			ooe := GotRequiredParams(theAppleEvent);(* now get each alias from the list (as an FSSSpec) and open the associated file. *)			oe := AECountItems(docList, itemsInList);			for index := 1 to itemsInList do begin				ooe := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);(* coercion does alias->fsspec *)				if ooe = noErr then					ooe := DoODoc(myFSS);			end;			ooe := AEDisposeDesc(docList);		end;		HandleDocs := oe;	end; (* HandleDocs *)	function HandleQUIT (theAppleEvent, reply: AppleEvent; refcon: longint): OSErr;		var			oe: OSErr;			errStr: Str255;			willQuit: Boolean;	begin		oe := GotRequiredParams(theAppleEvent);		oe := DoQuit;		HandleQUIT := oe;	end;	function InitAppleEvents: OSErr;		var			aevtErr: OSErr;	begin		aevtErr := noErr;		if (aevtErr = noErr) then			aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, @HandleOAPP, 0, false);		if (aevtErr = noErr) then			aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleDocs, 0, false);		if (aevtErr = noErr) then			aevtErr := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, @HandleQUIT, 0, false);		InitAppleEvents := aevtErr;	end;	var		junkbool: boolean;		event: EventRecord;		err: OSErr;		junk: OSErr;		response: longint;		attr: longint;		instance: ICInstance;begin	if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < $700) then begin		ExitToShell;	end; (* if *)	err := InitAppleEvents;	if err = noErr then begin		err := ICMapErr(ICStart(instance, 'SĠ!'));		if err = noErr then begin			err := ICMapErr(ICFindConfigFile(instance, 0, nil));		end; (* if *)		if err = noErr then begin			err := ICMapErr(ICBegin(instance, icReadOnlyPerm));			if err = noErr then begin				err := ICMapErr(ICGetPrefHandle(instance, kICMapping, attr, entries));				junk := ICMapErr(ICEnd(instance));			end; (* if *)		end; (* if *)		if err = noErr then begin			quitNow := false;			while not quitNow do begin				junkbool := WaitNextEvent(everyEvent, event, maxlongint, nil);				case event.what of					keyDown: 						quitNow := true;					kHighLevelEvent: 						junk := AEProcessAppleEvent(event);					otherwise						;				end; (* case *)			end; (* while *)		end; (* if *)		junk := ICStop(instance);	end; (* if *)	if err <> noErr then begin		SysBeep(10);	end;end. (* SpaceAliens *)