1 // Routines that deal with some mac file system stuff -EAD
2 
3 #include <Files.h>
4 #include <TextUtils.h>
5 #include <string.h>
6 //#include "MiscellaneousUtilities.h"
7 
8 //=========================================================================
9 // Function prototypes
10 //=========================================================================
11 
12 void set_mac_file_type(char *filename);
13 void GetFullPath(FSSpec *theSpec, StringPtr theName);
14 void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName);
15 
16 
17 
18 //=========================================================================
19 // Set the output soundfile type and creator
20 //=========================================================================
21 
set_mac_file_type(char * filename)22 void set_mac_file_type(char *filename)
23 {
24     Str255	fName;
25     FSSpec	fSpec;
26     FInfo	fFInfo;
27 
28     fFInfo.fdType = 'AIFF';
29     fFInfo.fdCreator = 'Sd2a';
30 
31     BlockMoveData(filename, &fName[1], 256);
32     fName[0] = strlen(filename);
33     FSMakeFSSpec(0, 0, fName, &fSpec);
34     FSpSetFInfo(&fSpec, &fFInfo);
35 }
36 
37 //==================================================================================================================================
38 // void GetFullPath(FSSpec *theSpec, StringPtr theName)
39 //==================================================================================================================================
40 // Extracts the full pathname for the file pointed to by theSpec and returns it in theName.
41 //==================================================================================================================================
42 
GetFullPath(FSSpec * theSpec,StringPtr theName)43 void GetFullPath(FSSpec *theSpec, StringPtr theName)
44 {
45     *theName = 0;
46     if (theSpec->parID != 1) PathNameFromDirID(theSpec->parID, theSpec->vRefNum, theName);
47     // was: pstrcat(theName, theSpec->name);
48     strcat(P2CStr(theName), P2CStr(theSpec->name));
49     C2PStr((char *) theName);
50     C2PStr((char *) theSpec->name);
51     //pstrcat(theName, "\p:");
52     theName[*theName + 1] = 0;
53 }
54 
55 //==================================================================================================================================
56 // void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
57 //==================================================================================================================================
58 // Given a vRefNum and a directory ID, creates a full path specification.
59 //==================================================================================================================================
60 
PathNameFromDirID(long dirID,short vRefNum,StringPtr fullPathName)61 void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
62 {
63     Str255 directoryName;
64     DirInfo block;
65     OSErr err;
66     fullPathName[0] = 0;
67     block.ioDrDirID = block.ioDrParID = dirID;
68     block.ioNamePtr = directoryName;
69     do {
70         block.ioVRefNum = vRefNum;
71         block.ioFDirIndex = -1;
72         block.ioDrDirID = block.ioDrParID;
73         err = PBGetCatInfo((CInfoPBPtr)&block, false);
74         //pstrcat(directoryName, (StringPtr)"\p:");
75         //pstrinsert(fullPathName, directoryName);
76         strcat(P2CStr(directoryName), ":");
77         strcat((char *) directoryName, (char *) fullPathName);
78         strcpy((char *)fullPathName, (char *) directoryName);
79     } while (block.ioDrDirID != 2);
80     C2PStr((char *) fullPathName);
81 }
82