home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Harvest C 1.3 / Source Code / fopenMAC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-15  |  3.8 KB  |  136 lines  |  [TEXT/KAHL]

  1. /*
  2.     Harvest C
  3.     Copyright 1992 Eric W. Sink.  All rights reserved.
  4.     
  5.     This file is part of Harvest C.
  6.     
  7.     Harvest C is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU Generic Public License as published by
  9.     the Free Software Foundation; either version 2, or (at your option)
  10.     any later version.
  11.     
  12.     Harvest C is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.     
  17.     You should have received a copy of the GNU General Public License
  18.     along with Harvest C; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.     
  21.     Harvest C is not in any way a product of the Free Software Foundation.
  22.     Harvest C is not GNU software.
  23.     Harvest C is not public domain.
  24.  
  25.     This file may have other copyrights which are applicable as well.
  26.  
  27. */
  28.  
  29. /*
  30.     fopenMAC.c
  31. */
  32.  
  33. #include <stdio.h>
  34.  
  35. char *GetPathName(char *s,char *name,short vRefNum,long dirID)
  36. {
  37.     CInfoPBRec    block;
  38.     Str255 directoryName;
  39.     OSErr err;
  40.     char pname[64];
  41.     
  42.     *s = 0;
  43.     block.dirInfo.ioNamePtr = directoryName;
  44.     block.dirInfo.ioDrParID = dirID;
  45.     
  46.     do {
  47.         block.dirInfo.ioVRefNum = vRefNum;
  48.         block.dirInfo.ioFDirIndex = -1;
  49.         block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
  50.         
  51.         err = PBGetCatInfo(&block,false);
  52.         if (err) break;
  53.         
  54.         ConcatPStrings(directoryName,"\p:");
  55.         ConcatPStrings(directoryName,s);
  56.         CopyPString(directoryName,s);
  57.     } while (block.dirInfo.ioDrDirID != fsRtDirID);
  58.     
  59.     if (name) {
  60.         strcpy(pname,name);
  61.         c2pstr(pname);
  62.         ConcatPStrings(s,pname);
  63.     }
  64.     return s;
  65. }
  66.  
  67. /** PathNameFromWD ************************************************************/
  68. /*
  69. /*    Given an HFS working directory, this routine returns the full pathname
  70. /*    that corresponds to it. It does this by calling PBGetWDInfo to get the
  71. /*    VRefNum and DirID of the real directory. It then calls PathNameFromDirID,
  72. /*    and returns its result.
  73. /*
  74. /******************************************************************************/
  75.  
  76. char *GetPathNameFromWD(char *s,char *name,short vRefNum)
  77. {
  78.  
  79.     WDPBRec    myBlock;
  80.  
  81.     /*
  82.     /* PBGetWDInfo has a bug under A/UX 1.1.  If vRefNum is a real vRefNum
  83.     /* and not a wdRefNum, then it returns garbage.  Since A/UX has only 1
  84.     /* volume (in the Macintosh sense) and only 1 root directory, this can
  85.     /* occur only when a file has been selected in the root directory (/).
  86.     /* So we look for this and hardcode the DirID and vRefNum. */
  87.  
  88.     myBlock.ioNamePtr = NULL;
  89.     myBlock.ioVRefNum = vRefNum;
  90.     myBlock.ioWDIndex = 0;
  91.     myBlock.ioWDProcID = 0;
  92.  
  93.     /* Change the Working Directory number in vRefnum into a real vRefnum */
  94.     /* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
  95.     /* DirID is returned in ioWDDirID. */
  96.  
  97.     PBGetWDInfo(&myBlock,false);
  98.  
  99.     return(GetPathName(s,name,myBlock.ioWDDirID,myBlock.ioWDVRefNum));
  100. }
  101.  
  102. FILE *fopenMAC(char *name,short vRefNum,long dirID,char *mode)
  103. {
  104.     char path[512];
  105.     GetPathName(path,name,vRefNum,dirID);
  106.     p2cstr(path);
  107.     return fopen(path,mode);
  108. }
  109.  
  110. char *GetDirPathFromWD(char *s,short vRefNum, int ftype)
  111. {
  112.  
  113.     WDPBRec    myBlock;
  114.  
  115.     /*
  116.     /* PBGetWDInfo has a bug under A/UX 1.1.  If vRefNum is a real vRefNum
  117.     /* and not a wdRefNum, then it returns garbage.  Since A/UX has only 1
  118.     /* volume (in the Macintosh sense) and only 1 root directory, this can
  119.     /* occur only when a file has been selected in the root directory (/).
  120.     /* So we look for this and hardcode the DirID and vRefNum. */
  121.  
  122.     myBlock.ioNamePtr = NULL;
  123.     myBlock.ioVRefNum = vRefNum;
  124.     myBlock.ioWDIndex = 0;
  125.     myBlock.ioWDProcID = 0;
  126.  
  127.     /* Change the Working Directory number in vRefnum into a real vRefnum */
  128.     /* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
  129.     /* DirID is returned in ioWDDirID. */
  130.  
  131.     PBGetWDInfo(&myBlock,false);
  132.  
  133.     return(GetPathName(s,NULL,myBlock.ioWDDirID,myBlock.ioWDVRefNum));
  134. }
  135.  
  136.