-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSave.c
executable file
·70 lines (53 loc) · 1.5 KB
/
Save.c
1
#define TEMP_FILE_NAME "\pM E R G E R T E M P"#define BUFFER_BYTE_SIZE 1024L#define NIL_POINTER 0Lextern int vRefNumTemp;extern OSType saveFileType;extern Boolean fileSaved;void DoSaveFile(void);void DoSaveFile(){ OSErr theErr; int refNumIn, refNumOut; long buffSize, readCount; Ptr buffPtr; SFReply reply; Point thePoint; SetPt(&thePoint, (screenBits.bounds.right-screenBits.bounds.left-304)/2 +screenBits.bounds.left,50); SFPutFile(thePoint,"\pSave file as:","\pUntitled",NIL_POINTER,&reply); if (!reply.good) return; theErr = Create(reply.fName,reply.vRefNum,saveFileType,'TEXT'); if (theErr != noErr) { if (theErr == dupFNErr) { if ((theErr = FSDelete(reply.fName,reply.vRefNum)) == fLckdErr) { theErr = RstFLock(reply.fName,reply.vRefNum); theErr = FSDelete(reply.fName,reply.vRefNum); } theErr = Create(reply.fName,reply.vRefNum,saveFileType,'TEXT'); } } theErr = FSOpen(TEMP_FILE_NAME,vRefNumTemp,&refNumIn); if (theErr != noErr) return; theErr = FSOpen(reply.fName,reply.vRefNum,&refNumOut); if (theErr != noErr) { theErr = FSClose(refNumIn); return; } theErr = SetFPos(refNumIn,fsFromStart,0L); buffPtr = NewPtrClear(BUFFER_BYTE_SIZE); readCount = BUFFER_BYTE_SIZE; while (theErr != eofErr) { theErr = FSRead(refNumIn,&readCount,buffPtr); FSWrite(refNumOut,&readCount,buffPtr); } DisposPtr(buffPtr); theErr = FSClose(refNumOut); theErr = FSClose(refNumIn); fileSaved = TRUE;}