Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 437a0e6

Browse files
committed
Think 6.0 version
1 parent d7047b3 commit 437a0e6

1 file changed

Lines changed: 75 additions & 138 deletions

File tree

Mac/fopenRF.c

Lines changed: 75 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11

22
/*
3-
* fopenRF.c -- Clone of fopen.c to open Mac resource forks.
3+
* fopen.c
44
*
5-
* Copyright (c) 1989 Symantec Corporation. All rights reserved.
5+
* Copyright (c) 1991 Symantec Corporation. All rights reserved.
66
*
77
*/
88

9+
#include <MacHeaders>
10+
911
#include "stdio.h"
1012
#include "errno.h"
1113
#include "string.h"
1214
#include "ansi_private.h"
1315

14-
FILE *fopenRF(char *, char *);
15-
FILE *freopenRF(char *, char *, FILE *);
16-
FILE *__openRF(char *, int, int, FILE *);
17-
18-
#include <Files.h>
16+
extern long _ftype, _fcreator;
1917

2018
#define fcbVPtr(fcb) (* (VCB **) (fcb + 20))
2119
#define fcbDirID(fcb) (* (long *) (fcb + 58))
@@ -27,20 +25,18 @@ static int fileio(FILE *, int);
2725
static int close(FILE *);
2826
static void replace(unsigned char *, size_t, int, int);
2927

28+
FILE *freopenRF();
29+
FILE *__openRF();
3030

3131
FILE *
32-
fopenRF(filename, mode)
33-
char *filename, *mode;
32+
fopenRF(const char *filename, const char *mode)
3433
{
3534
return(freopenRF(filename, mode, __getfile()));
3635
}
3736

3837

3938
FILE *
40-
freopenRF(filename, mode, fp)
41-
char *filename;
42-
register char *mode;
43-
register FILE *fp;
39+
freopenRF(const char *filename, const char *mode, FILE *fp)
4440
{
4541
int omode, oflag;
4642

@@ -83,12 +79,9 @@ register FILE *fp;
8379

8480

8581
FILE *
86-
__openRF(filename, omode, oflag, fp)
87-
char *filename;
88-
int omode, oflag;
89-
register FILE *fp;
82+
__openRF(const char *filename, int omode, int oflag, FILE *fp)
9083
{
91-
ioParam pb;
84+
IOParam pb;
9285
char pname[FILENAME_MAX];
9386

9487
if (fp == NULL)
@@ -106,10 +99,7 @@ register FILE *fp;
10699
/* create file */
107100

108101
if (oflag & F_CREAT) {
109-
asm {
110-
lea pb,a0
111-
_PBCreate
112-
}
102+
PBCreateSync((ParmBlkPtr)&pb);
113103
if (pb.ioResult == noErr)
114104
oflag &= ~F_TRUNC;
115105
else if (pb.ioResult == dupFNErr && !(oflag & F_EXCL))
@@ -120,32 +110,23 @@ register FILE *fp;
120110
}
121111
}
122112

123-
/* open resource file */
113+
/* open file */
124114

125-
asm {
126-
lea pb,a0
127-
_PBOpenRF
128-
}
115+
PBOpenRFSync((ParmBlkPtr)&pb);
129116
if (pb.ioResult) {
130117
errno = pb.ioResult;
131-
if (oflag & F_CREAT) asm {
132-
lea pb,a0
133-
_PBDelete
134-
}
118+
if (oflag & F_CREAT)
119+
PBDeleteSync((ParmBlkPtr)&pb);
135120
return(NULL);
136121
}
137122
fp->refnum = pb.ioRefNum;
138123

139124
/* get/set file length */
140125

141-
if (oflag & F_TRUNC) asm {
142-
lea pb,a0
143-
_PBSetEOF
144-
}
145-
else if (!(oflag & F_CREAT)) asm {
146-
lea pb,a0
147-
_PBGetEOF
148-
}
126+
if (oflag & F_TRUNC)
127+
PBSetEOFSync((ParmBlkPtr)&pb);
128+
else if (!(oflag & F_CREAT))
129+
PBGetEOFSync((ParmBlkPtr)&pb);
149130
fp->len = (fpos_t) pb.ioMisc;
150131

151132
/* initialize rest of FILE structure */
@@ -177,28 +158,22 @@ register FILE *fp;
177158
*/
178159

179160
static void
180-
setfiletype(name, oflag)
181-
StringPtr name;
182-
int oflag;
161+
setfiletype(StringPtr name, int oflag)
183162
{
184-
fileParam pb;
163+
FileParam pb;
185164

186165
pb.ioNamePtr = name;
187166
pb.ioVRefNum = 0;
188167
pb.ioFVersNum = 0;
189168
pb.ioFDirIndex = 0;
190-
asm {
191-
lea pb,a0
192-
_PBGetFInfo
193-
bmi.s @1
169+
if (PBGetFInfoSync((ParmBlkPtr)&pb) == noErr) {
170+
if (oflag & F_BINARY)
171+
pb.ioFlFndrInfo.fdType = _ftype;
172+
else
173+
pb.ioFlFndrInfo.fdType = 'TEXT';
174+
pb.ioFlFndrInfo.fdCreator = _fcreator;
175+
PBSetFInfoSync((ParmBlkPtr)&pb);
194176
}
195-
pb.ioFlFndrInfo.fdType = pb.ioFlFndrInfo.fdCreator = '????';
196-
if (!(oflag & F_BINARY))
197-
pb.ioFlFndrInfo.fdType = 'TEXT';
198-
asm {
199-
lea pb,a0
200-
_PBSetFInfo
201-
@1 }
202177
}
203178

204179

@@ -208,7 +183,7 @@ int oflag;
208183
*/
209184

210185
static void
211-
stdio_exit()
186+
stdio_exit(void)
212187
{
213188
register FILE *fp;
214189
int n;
@@ -224,11 +199,9 @@ stdio_exit()
224199
*/
225200

226201
static int
227-
fileio(fp, i)
228-
register FILE *fp;
229-
int i;
202+
fileio(FILE *fp, int i)
230203
{
231-
ioParam pb;
204+
IOParam pb;
232205

233206
pb.ioRefNum = fp->refnum;
234207
switch (i) {
@@ -240,10 +213,7 @@ int i;
240213
pb.ioReqCount = fp->cnt;
241214
pb.ioPosMode = fp->refnum > 0 ? fsFromStart : fsAtMark;
242215
pb.ioPosOffset = fp->pos - fp->cnt;
243-
asm {
244-
lea pb,a0
245-
_PBRead
246-
}
216+
PBReadSync((ParmBlkPtr)&pb);
247217
if (pb.ioResult == eofErr) {
248218
fp->pos = pb.ioPosOffset;
249219
if (fp->cnt = pb.ioActCount)
@@ -253,11 +223,7 @@ int i;
253223
return(EOF);
254224
}
255225
}
256-
if (pb.ioResult) {
257-
fp->pos -= fp->cnt;
258-
fp->cnt = 0;
259-
}
260-
else if (!fp->binary)
226+
if (!pb.ioResult && !fp->binary)
261227
replace(fp->ptr, fp->cnt, '\r', '\n');
262228
break;
263229

@@ -269,23 +235,13 @@ int i;
269235
pb.ioPosMode = fp->refnum > 0 ? fsFromStart : fsAtMark;
270236
if ((pb.ioPosOffset = fp->pos - fp->cnt) > fp->len) {
271237
pb.ioMisc = (Ptr) pb.ioPosOffset;
272-
asm {
273-
lea pb,a0
274-
_PBSetEOF
275-
bmi.s @1
276-
}
238+
if (PBSetEOFSync((ParmBlkPtr)&pb) != noErr)
239+
break;
277240
}
278241
if (!fp->binary)
279242
replace(fp->ptr, fp->cnt, '\n', '\r');
280-
asm {
281-
lea pb,a0
282-
_PBWrite
283-
@1 }
284-
if (pb.ioResult) {
285-
fp->pos -= fp->cnt;
286-
fp->cnt = 0;
287-
}
288-
else if (pb.ioPosOffset > fp->len)
243+
PBWriteSync((ParmBlkPtr)&pb);
244+
if (!pb.ioResult && pb.ioPosOffset > fp->len)
289245
fp->len = pb.ioPosOffset;
290246
break;
291247

@@ -299,6 +255,10 @@ int i;
299255
/* done */
300256

301257
if (pb.ioResult) {
258+
if (i < 2) {
259+
fp->pos -= fp->cnt;
260+
fp->cnt = 0;
261+
}
302262
fp->err = 1;
303263
errno = pb.ioResult;
304264
return(EOF);
@@ -308,73 +268,52 @@ int i;
308268

309269

310270
static int
311-
close(fp)
312-
register FILE *fp;
271+
close(FILE *fp)
313272
{
314273
HFileParam pb;
315274
Str255 buf;
316275
register char *fcb = FCBSPtr + fp->refnum;
317276
VCB *vcb = fcbVPtr(fcb);
318277
register char *s;
278+
enum { none, MFS, HFS } del = none;
319279

320-
pb.ioNamePtr = buf;
321-
pb.ioFRefNum = fp->refnum;
322280
pb.ioVRefNum = vcb->vcbVRefNum;
323-
pb.ioFVersNum = 0;
281+
if (fp->remove) {
282+
pb.ioNamePtr = buf;
283+
pb.ioFVersNum = 0;
324284

325-
/* close temporary file - HFS */
326-
327-
if (fp->delete && vcb->vcbSigWord == 0x4244) {
328-
pb.ioDirID = fcbDirID(fcb);
329-
s = fcbCName(fcb);
330-
asm {
331-
lea buf,a0
332-
moveq #0,d0
333-
move.b (s),d0
334-
@1 move.b (s)+,(a0)+
335-
dbra d0,@1
336-
lea pb,a0
337-
_PBClose
338-
bmi.s @9
339-
_PBHDelete
285+
/* close temporary file - HFS */
286+
287+
if (vcb->vcbSigWord == 0x4244) {
288+
pb.ioDirID = fcbDirID(fcb);
289+
s = fcbCName(fcb);
290+
memcpy(buf, s, Length(s) + 1);
291+
del = HFS;
340292
}
341-
}
342-
343-
/* close temporary file - MFS */
344293

345-
else if (fp->delete && vcb->vcbSigWord == 0xD2D7) {
346-
pb.ioFDirIndex = 1;
347-
do asm {
348-
lea pb,a0
349-
_PBGetFInfo
350-
bmi.s @2
351-
addq.w #1,pb.ioFDirIndex
352-
} while (pb.ioFRefNum != fp->refnum);
353-
asm {
354-
lea pb,a0
355-
_PBClose
356-
bmi.s @9
357-
_PBDelete
294+
/* close temporary file - MFS */
295+
296+
else if (vcb->vcbSigWord == 0xD2D7) {
297+
for (pb.ioFDirIndex = 1; PBGetFInfoSync((ParmBlkPtr)&pb) == noErr; pb.ioFDirIndex++) {
298+
if (pb.ioFRefNum == fp->refnum) {
299+
del = MFS;
300+
break;
301+
}
302+
}
358303
}
359304
}
360305

361-
/* normal case - just close file */
362-
363-
else {
364-
asm {
365-
@2 lea pb,a0
366-
_PBClose
367-
bmi.s @9
368-
}
369-
}
306+
/* close file and flush volume buffer */
370307

371-
/* flush volume buffer */
372-
373-
pb.ioNamePtr = 0;
374-
asm {
375-
lea pb,a0
376-
_PBFlshVol
377-
@9 }
308+
pb.ioFRefNum = fp->refnum;
309+
if (PBCloseSync((ParmBlkPtr)&pb) == noErr) {
310+
if (del == MFS)
311+
PBDeleteSync((ParmBlkPtr)&pb);
312+
else if (del == HFS)
313+
PBHDeleteSync((HParmBlkPtr)&pb);
314+
pb.ioNamePtr = 0;
315+
PBFlushVolSync((ParmBlkPtr)&pb);
316+
}
378317
return(pb.ioResult);
379318
}
380319

@@ -385,11 +324,9 @@ register FILE *fp;
385324
*/
386325

387326
static void
388-
replace(s, n, c1, c2)
389-
register unsigned char *s;
390-
register size_t n;
391-
register int c1, c2;
327+
replace(register unsigned char *s, register size_t n, register int c1, register int c2)
392328
{
329+
#pragma options(honor_register)
393330
register unsigned char *t;
394331

395332
for (; n && (t = memchr(s, c1, n)); s = t) {

0 commit comments

Comments
 (0)