File: mac-file.c

package info (click to toggle)
egoboo 2.22-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,640 kB
  • ctags: 2,570
  • sloc: ansic: 23,989; makefile: 94; sh: 83
file content (228 lines) | stat: -rw-r--r-- 6,221 bytes parent folder | download | duplicates (6)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// mac-file.c

// Egoboo, Copyright (C) 2000 Aaron Bishop

#include "egoboo.h"
#include <Files.h>		/* MacOS specific file stuff */
#include <TextUtils.h>	/* C to Pascal string conversion stuff */



/**> GLOBAL VARIABLES <**/
FSSpec			gFileSpec;
char			gFileType[32];
HFileInfo		gFileInfo;
short			gIndex;
char			gFileName[256];


//---------------------------------------------------------------------------------------------
//File Routines-------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
void make_directory(char *dirname)
{
    // ZZ> This function makes a new directory
    
    FSSpec	fileSpec;
    long	dirID;
    
    // Convert the directory name from a c string to a pascal string for use with the FSSpec
    c2pstr( dirname );
    
    // Create the file spec
    FSMakeFSSpec( 0, 0, ( unsigned char * )dirname, &fileSpec );
    
    // Convert the filename back to a pascal string
    p2cstr( ( unsigned char * )dirname );
    
    FSpDirCreate( &fileSpec, /*ScriptCode scriptTag*/0, &dirID );
    
}

//---------------------------------------------------------------------------------------------
void remove_directory(char *dirname)
{
    // ZZ> This function removes a directory
    
	FSSpec	fileSpec;
    
    // Convert the directory name from a c string to a pascal string for use with the FSSpec
    c2pstr( dirname );
    
    // Create the file spec
    FSMakeFSSpec( 0, 0, ( unsigned char * )dirname, &fileSpec );
    
    // Convert the directory name back to a pascal string
    p2cstr( ( unsigned char * )dirname );
    
    // Delete the file
    FSpDelete( &fileSpec );
    
}

//---------------------------------------------------------------------------------------------
void delete_file(char *filename)
{
    // ZZ> This function deletes a file
    
    FSSpec	fileSpec;
    
    // Convert the filename from a c string to a pascal string for use with the FSSpec
    c2pstr( filename );
    
    // Create the file spec
    FSMakeFSSpec( 0, 0, ( unsigned char * )filename, &fileSpec );
    
    // Convert the filename back to a pascal string
    p2cstr( ( unsigned char * )filename );
    
    // Delete the file
    FSpDelete( &fileSpec );
    
}

//---------------------------------------------------------------------------------------------
void copy_file(char *source, char *dest)
{
    // ZZ> This function copies a file on the local machine
    
    
    
}

//---------------------------------------------------------------------------------------------
void delete_directory(char *dirname)
{
    // ZZ> This function deletes all files in a directory,
    //     and the directory itself
    
    FSSpec	fileSpec;
    
    // Convert the directory name from a c string to a pascal string for use with the FSSpec
    c2pstr( dirname );
    
    // Create the file spec
    FSMakeFSSpec( 0, 0, ( unsigned char * )dirname, &fileSpec );
    
    // Convert the directory name back to a pascal string
    p2cstr( ( unsigned char * )dirname );
    
    // Delete the file
    FSpDelete( &fileSpec );
    
}

//---------------------------------------------------------------------------------------------
void copy_directory(char *dirname, char *todirname)
{
    // ZZ> This function copies all files in a directory
    
    
    
}

//---------------------------------------------------------------------------------------------
void empty_import_directory(void)
{
    // ZZ> This function deletes all the TEMP????.OBJ subdirectories in the IMPORT directory
    
    
    
}

//---------------------------------------------------------------------------------------------
//Directory Functions--------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------
// Read the first directory entry
char *DirGetFirst(char *search)
{
	
	char	tempStr[256];
	char	*beginTypePos;
	
	/* Set the index */
	gIndex = 1;
	
	/* Set up the HFileInfo */
	gFileInfo.ioNamePtr = ( unsigned char * )gFileName;
	gFileInfo.ioVRefNum = 0;
	
	/* get the file type (file extension) */
	beginTypePos = strstr( search, "*" );
	beginTypePos += 1;
	strncpy( gFileType, beginTypePos, strlen( beginTypePos ) );
	
	/* copy the directory name into a new string for some slight modifications */
	strcpy( tempStr, search );
	//strcat( tempStr, "qz" );	/* we need a real or fake file in the directory for this to work */
	
	/* Convert directory from a c string to a pascal string */
	c2pstr( tempStr );
	
	/* Make a filespec to get the directory ID */
	FSMakeFSSpec( 0, 0, ( unsigned char * )tempStr, &gFileSpec );
	
	/* Convert the directory from a pascal string to a c string */
	p2cstr( ( unsigned char * )tempStr );
	
	/* do the search */
	return DirGetNext();
  
}

//---------------------------------------------------------------------------------------------
// Read the next directory entry (NULL if done)
char *DirGetNext(void)
{
	
	OSErr	error = noErr;
	
	/* set up more HFileInfo stuff */
	gFileInfo.ioFDirIndex = gIndex;
	gFileInfo.ioDirID = gFileSpec.parID;
	
	/* do the actual search */
	error = PBGetCatInfo( ( union CInfoPBRec * )&gFileInfo, false );
	if ( error == noErr )
	{
		p2cstr( ( unsigned char * )gFileName );
		gIndex++;
		
		if ( strlen( gFileName ) > 0 )
		{
			if ( strstr( gFileName, gFileType ) != NULL )
				return gFileName;
			else
				return DirGetNext();
		}
	}
	else
		return NULL;
	
	//return gFileName;
	
}

//---------------------------------------------------------------------------------------------
// Close anything left open
void DirClose()
{
	
	/* Not sure if anything is needed here */
	
}

int ClockGetTick()
{
  return(clock());
}

int DirGetAttrib(char *fromdir)
{
	
	/* Not sure on this one yet */
	
	return(0);
}