home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15470 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  3.0 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!gatech!rutgers!rochester!cornell!uw-beaver!Teknowledge.COM!unix!css-mac1.sri.com!user
  2. From: mxmora@unix.sri.com (Matthew Xavier Mora)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: PathNameFromDirID (pascal source)
  5. Message-ID: <mxmora-140992151534@css-mac1.sri.com>
  6. Date: 14 Sep 92 22:19:45 GMT
  7. Sender: news@unix.SRI.COM
  8. Followup-To: comp.sys.mac.programmer
  9. Organization: SRI International
  10. Lines: 80
  11.  
  12.  
  13. Here is a non system 7 dependant version of the Pathname trilogy.
  14. It returns a handle, not a lame Str255 of the full pathname.
  15.  
  16. Why am I posting all this? To get it into the next version of the 
  17. UMPG of course. :-) Hopefullly it will be out before MacWorld SF. Yes I'm
  18. actively working on it.
  19.  
  20. If anyone has any code that they would like to share (or update stuff that
  21. has been in the first volume), send it along and I'll include it, if it
  22. works.
  23.  
  24. {-------------------------------------------------------------------------}
  25. {Path Name From DirID                                                     }
  26. {by Matthew Xavier Mora                                                   }
  27. {9-14-92                                                                  }
  28. {Given a vrefNum and a directory Id, this function will return a handle to}
  29. {the full path name. It creates the handle as it goes. It does not have   }
  30. {the limited string length (255) problem like the ones I have seen.       }
  31.  
  32. { Also most assumed there would be no errors so it just tested until      }
  33. { block.ioDrDirID = 2. Which for the most part is true but as your        }
  34. { debugging your application you will find that sometimes its not true or }
  35. { will never get there.                                                   }
  36. { It is based on source code from Apple DTS.                              }
  37. { Don't forget to dispose the handle when you are done with it.           }
  38. {-------------------------------------------------------------------------}
  39.  
  40.  function PathNameFromDirID (DirID: longint; vRefnum: integer): Handle;
  41.  
  42.   var
  43.    Block: CInfoPBRec;
  44.    directoryName: str255;
  45.    err: integer;
  46.    HaveAux: boolean;
  47.    h: Handle;
  48.    theSize: Longint;
  49.    delimiter: Char;
  50.  begin
  51.     PathNameFromDirID:=nil;
  52.   haveAUX := false;   {Use whatever function to determine if your running
  53. under AUX}
  54.  
  55.   h := Newhandle(0);
  56.  
  57.   if (h = nil) then 
  58.      exit(PathNameFromDirID);
  59.    
  60.   with block do
  61.    begin
  62.     ioNamePtr := @directoryName;
  63.     ioDrParID := DirId;
  64.    end;
  65.  
  66.   repeat
  67.    with block do
  68.     begin
  69.      ioVRefNum := vRefNum;
  70.      ioFDirIndex := -1;
  71.      ioDrDirID := block.ioDrParID;
  72.     end;
  73.    err := PBGetCatInfo(@Block, FALSE);
  74.  
  75.    if haveAUX then
  76.     begin
  77.      if directoryName[1] <> '/' then
  78.       begin
  79.        delimiter := '/';
  80.       end;
  81.     end
  82.    else
  83.     delimiter := ':';
  84.  
  85.    theSize := longint(length(directoryName) + 1);
  86.    directoryName[length(directoryName) + 1] := delimiter;
  87.    theSize := Munger(h, 0, nil, 0, Ptr(ord(@directoryName) + 1), thesize);
  88.   until (block.ioDrDirID = 2) or (err <> noerr);
  89.  
  90.   PathNameFromDirID := h;
  91.  end;
  92.