home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!gatech!rutgers!rochester!cornell!uw-beaver!Teknowledge.COM!unix!css-mac1.sri.com!user
- From: mxmora@unix.sri.com (Matthew Xavier Mora)
- Newsgroups: comp.sys.mac.programmer
- Subject: PathNameFromDirID (pascal source)
- Message-ID: <mxmora-140992151534@css-mac1.sri.com>
- Date: 14 Sep 92 22:19:45 GMT
- Sender: news@unix.SRI.COM
- Followup-To: comp.sys.mac.programmer
- Organization: SRI International
- Lines: 80
-
-
- Here is a non system 7 dependant version of the Pathname trilogy.
- It returns a handle, not a lame Str255 of the full pathname.
-
- Why am I posting all this? To get it into the next version of the
- UMPG of course. :-) Hopefullly it will be out before MacWorld SF. Yes I'm
- actively working on it.
-
- If anyone has any code that they would like to share (or update stuff that
- has been in the first volume), send it along and I'll include it, if it
- works.
-
- {-------------------------------------------------------------------------}
- {Path Name From DirID }
- {by Matthew Xavier Mora }
- {9-14-92 }
- {Given a vrefNum and a directory Id, this function will return a handle to}
- {the full path name. It creates the handle as it goes. It does not have }
- {the limited string length (255) problem like the ones I have seen. }
-
- { Also most assumed there would be no errors so it just tested until }
- { block.ioDrDirID = 2. Which for the most part is true but as your }
- { debugging your application you will find that sometimes its not true or }
- { will never get there. }
- { It is based on source code from Apple DTS. }
- { Don't forget to dispose the handle when you are done with it. }
- {-------------------------------------------------------------------------}
-
- function PathNameFromDirID (DirID: longint; vRefnum: integer): Handle;
-
- var
- Block: CInfoPBRec;
- directoryName: str255;
- err: integer;
- HaveAux: boolean;
- h: Handle;
- theSize: Longint;
- delimiter: Char;
- begin
- PathNameFromDirID:=nil;
- haveAUX := false; {Use whatever function to determine if your running
- under AUX}
-
- h := Newhandle(0);
-
- if (h = nil) then
- exit(PathNameFromDirID);
-
- with block do
- begin
- ioNamePtr := @directoryName;
- ioDrParID := DirId;
- end;
-
- repeat
- with block do
- begin
- ioVRefNum := vRefNum;
- ioFDirIndex := -1;
- ioDrDirID := block.ioDrParID;
- end;
- err := PBGetCatInfo(@Block, FALSE);
-
- if haveAUX then
- begin
- if directoryName[1] <> '/' then
- begin
- delimiter := '/';
- end;
- end
- else
- delimiter := ':';
-
- theSize := longint(length(directoryName) + 1);
- directoryName[length(directoryName) + 1] := delimiter;
- theSize := Munger(h, 0, nil, 0, Ptr(ord(@directoryName) + 1), thesize);
- until (block.ioDrDirID = 2) or (err <> noerr);
-
- PathNameFromDirID := h;
- end;
-