home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / EMBL Search / Sources / GetPath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-04  |  2.7 KB  |  117 lines  |  [TEXT/KAHL]

  1. /*
  2. *********************************************************************
  3. *    
  4. *    GetPath.c
  5. *    acording to TN.SC018
  6. *    Apple Computer Developer Technical Support
  7. *    modified by
  8. *
  9. *    Rainer Fuchs
  10. *    EMBL Data Library
  11. *    Postfach 10.2209
  12. *    D-6900 Heidelberg, FRG
  13. *    E-mail: fuchs@embl-heidelberg.de
  14. *
  15. *    Copyright © 1992 EMBL Data Library
  16. *        
  17. **********************************************************************
  18. *
  19. *
  20.  
  21. /* Definition:
  22.  
  23.     short GetPathFromWD(short vRefNum, Str255 fName,char *fullPathName);
  24.  
  25.     From a working directory reference number vRefNum and a file name fName
  26.     (Pascal string!) GetPathFromWD builds the complete access path.
  27.     Return value:  TRUE (1) or FALSE (0).
  28.         by side effect: fullPathName contains access path (C string!).
  29.                         
  30.     short GetPathFromDirID(short vRefNum,short DirId,Str255 fName,char *fullPathName);
  31.     
  32.     From a directory ID, a real volume reference number GetPathFromDirID and
  33.     a file name (Pascal string !) GetPathFromDirID builds the complete access
  34.     path.
  35.     Return value:  TRUE (1) or FALSE (0).
  36.         by side effect: fullPathName contains access path (C string!).
  37. */
  38.  
  39. #include <String.h>
  40.  
  41. /*
  42. ******************************* Prototypes ***************************
  43. */
  44.  
  45. #include "GetPath.h"
  46.  
  47. static Boolean CheckAUX(void);
  48.  
  49.  
  50.  
  51. static Boolean CheckAUX()
  52. {
  53.     SysEnvRec theWorld;
  54.     short *flagPtr;
  55.     
  56. #define HWCfgFlags    0xA50
  57.  
  58.     SysEnvirons(curSysEnvVers,&theWorld);
  59.     flagPtr= (short *)HWCfgFlags;
  60.     if(*flagPtr & (1<<9))
  61.         return(TRUE);
  62.     else return(FALSE);
  63. }
  64.  
  65. Boolean GetPathFromDirID(short vRefNum,long DirID, StringPtr fName,char *fullPathName)
  66. {
  67.     CInfoPBRec myCPB;
  68.     Str255 directoryName;
  69.     OSErr ret;
  70.  
  71.     strcpy(fullPathName,PtoCstr(fName));
  72.     CtoPstr((char *)fName);
  73.     
  74.     myCPB.dirInfo.ioNamePtr= directoryName;
  75.     myCPB.dirInfo.ioDrParID= DirID;
  76.     myCPB.dirInfo.ioVRefNum= vRefNum;
  77.     myCPB.dirInfo.ioFDirIndex= -1;
  78.     
  79.     do {
  80.         myCPB.dirInfo.ioDrDirID=myCPB.dirInfo.ioDrParID;
  81.         if((ret=PBGetCatInfo(&myCPB,FALSE)) != noErr) return (FALSE);
  82.         
  83.         PtoCstr(directoryName);
  84.         if(CheckAUX()) {
  85.             if(*directoryName != '/') /* if not root */
  86.                 strcat((char *)directoryName,"/");
  87.         }
  88.         else
  89.             strcat((char *)directoryName,":");
  90.         strcat((char *)directoryName,fullPathName);
  91.         strcpy(fullPathName,(char *)directoryName);
  92.     } while (myCPB.dirInfo.ioDrDirID != 2);
  93.     
  94.     return(TRUE);
  95. }
  96.  
  97. Boolean GetPathFromWD(short vRefNum,StringPtr fName,char *fullPathName)
  98. {
  99.     WDPBRec myPB;
  100.     OSErr ret;
  101.     
  102.     /* to work around A/UX 1.1 bug: */
  103.     
  104.     if(CheckAUX() && vRefNum == -1)
  105.         return(GetPathFromDirID(-1,2,fName,fullPathName));
  106.         
  107.     /* get working directory information */
  108.  
  109.     myPB.ioNamePtr=    NULL;
  110.     myPB.ioVRefNum=    vRefNum;
  111.     myPB.ioWDProcID=    0;
  112.     myPB.ioWDIndex=    0;
  113.     
  114.     if((ret=PBGetWDInfo(&myPB,FALSE)) != noErr) return(FALSE);
  115.     
  116.     return(GetPathFromDirID(myPB.ioWDVRefNum,myPB.ioWDDirID,fName,fullPathName));
  117. }