home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-03-05 | 3.0 KB | 111 lines | [TEXT/TPAS] |
- {$R-}
-
- (*
- GetCreator -- map OSType to creator name
- By Dan Winkler. DO NOT call the author! Contact Apple Developer
- Support on AppleLink "MacDTS" or on MCI "MacTech".
-
- ⌐Apple Computer, Inc. 1987
- All Rights Reserved.
-
- Modified for Turbo Pascal by Brian Liebowitz
-
- You must install the DHDR resources called PasXFCN and PasXCMD
- into your copy of Turbo before compiling this XCMD. You must also
- have compiled the unit HyperXCMD and moved it into the Turbo progam,
- and the file XCMDGlue.inc must be accessible. After compiling,use
- ResEdit to change the ID from 300, and to copy the XCMD or XFCN into
- your stack or Hypercard.
-
-
- *)
-
- Program Getcreator;
-
- {$U-} { Don't include runtime units}
- {$D PasXFCN} {Compile as XFCN}
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
-
- PROCEDURE PasXFCN(paramPtr: XCmdPtr);
- VAR creator: OSType;
- appName: Str255;
-
- {$I XCmdGlue.inc }
-
- FUNCTION CreatorToString(creator: OsType): Str255;
-
- { Given a document's 4-byte creator, find the application's name. }
- { Opens APPL resource 0 in DeskTop, and scans table for first match. }
- { Returns empty string if can't open desktop or creator not found. }
-
- LABEL 9;
-
- TYPE ApplRecord = RECORD
- creator: OsType;
- directory: LongInt;
- fileName: Str255;
- END;
-
- VAR refNum: INTEGER;
- errNum: INTEGER;
- hndl: HANDLE;
- applPtr: ^ApplRecord;
- size,limit: LongInt;
- bump: INTEGER;
- wdParams: WDPBRec;
- result: INTEGER;
-
- BEGIN
- CreatorToString := '';
- IF creator = 'APPL' THEN EXIT;
- SetResLoad(FALSE); { avoid slow preloads }
-
- (** refNum := OpenResFile('DeskTop'); **)
-
- { set up working directory for current path }
- ZeroBytes(@wdParams,SizeOf(wdParams));
- WITH wdParams DO
- BEGIN
- ioWDProcID := $4552494B; { 'ERIK' so finder will delete later }
- ioWDDirID := 2; { root }
- END;
- result := PBOpenWD(@wdParams,FALSE);
- refNum := OpenRFPerm('DeskTop',wdParams.ioVRefNum,fsRdPerm);
-
- SetResLoad(TRUE);
- IF refnum = -1 THEN EXIT;
- hndl := GetResource('APPL',0);
- IF hndl = NIL THEN GOTO 9;
- size := SizeResource(hndl);
- applPtr := Pointer(hndl^);
- limit := ORD(applPtr) + size;
- REPEAT
- IF applPtr^.creator = creator THEN { we found it }
- BEGIN
- CreatorToString := applPtr^.fileName;
- GOTO 9;
- END;
- bump := 9 + Length(applPtr^.fileName);
- IF ODD(bump) THEN bump := bump + 1;
- applPtr := Pointer(ORD(applPtr) + bump);
- UNTIL ORD(applPtr) >= limit;
- 9: CloseResFile(refNum);
- END;
-
- BEGIN
- WITH paramPtr^ DO
- BEGIN
- IF paramCount < 1 THEN EXIT;
- BlockMove(params[1]^,@creator,4);
- appName := CreatorToString(creator);
- IF appName <> '' THEN returnValue := PasToZero(appName);
- END;
- END;
-
- BEGIN
- END.
-
- (*Remember to change the ID of this resource from 300*)
-
-