File: MacFileUtils.c

package info (click to toggle)
audacity 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 86,844 kB
  • sloc: ansic: 225,005; cpp: 221,240; sh: 27,327; python: 16,896; makefile: 8,186; lisp: 8,002; perl: 317; xml: 307; sed: 16
file content (81 lines) | stat: -rw-r--r-- 3,276 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Routines that deal with some mac file system stuff -EAD

#include <Files.h>
#include <TextUtils.h>
#include <string.h>
//#include "MiscellaneousUtilities.h"

//=========================================================================
// Function prototypes
//=========================================================================

void set_mac_file_type(char *filename);
void GetFullPath(FSSpec *theSpec, StringPtr theName);
void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName);



//=========================================================================
// Set the output soundfile type and creator
//=========================================================================

void set_mac_file_type(char *filename)
{
    Str255	fName;
    FSSpec	fSpec;
    FInfo	fFInfo;
    
    fFInfo.fdType = 'AIFF';
    fFInfo.fdCreator = 'Sd2a';

    BlockMoveData(filename, &fName[1], 256);
    fName[0] = strlen(filename);
    FSMakeFSSpec(0, 0, fName, &fSpec);
    FSpSetFInfo(&fSpec, &fFInfo);
}

//==================================================================================================================================
// void GetFullPath(FSSpec *theSpec, StringPtr theName)
//==================================================================================================================================
// Extracts the full pathname for the file pointed to by theSpec and returns it in theName.
//==================================================================================================================================

void GetFullPath(FSSpec *theSpec, StringPtr theName)
{
    *theName = 0;
    if (theSpec->parID != 1) PathNameFromDirID(theSpec->parID, theSpec->vRefNum, theName);
    // was: pstrcat(theName, theSpec->name);
    strcat(P2CStr(theName), P2CStr(theSpec->name));
    C2PStr((char *) theName);
    C2PStr((char *) theSpec->name);
    //pstrcat(theName, "\p:");
    theName[*theName + 1] = 0;
}

//==================================================================================================================================
// void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
//==================================================================================================================================
// Given a vRefNum and a directory ID, creates a full path specification.
//==================================================================================================================================

void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName)
{
    Str255 directoryName;
    DirInfo block;
    OSErr err;
    fullPathName[0] = 0;
    block.ioDrDirID = block.ioDrParID = dirID;
    block.ioNamePtr = directoryName;
    do {
        block.ioVRefNum = vRefNum;
        block.ioFDirIndex = -1;
        block.ioDrDirID = block.ioDrParID;
        err = PBGetCatInfo((CInfoPBPtr)&block, false);
        //pstrcat(directoryName, (StringPtr)"\p:");
        //pstrinsert(fullPathName, directoryName);
        strcat(P2CStr(directoryName), ":");
        strcat((char *) directoryName, (char *) fullPathName);
        strcpy((char *)fullPathName, (char *) directoryName);
    } while (block.ioDrDirID != 2);
    C2PStr((char *) fullPathName);
}