static void DumpCurrPage( void ) { //==================================== // Dump current page to disk. if( PageFlags & PF_DIRTY ) { if( CurrPage > MaxPage ) { MaxPage = CurrPage; } SDSeek( PageFile, CurrPage, PAGE_SIZE ); ChkIOErr( PageFile, SM_IO_WRITE_ERR ); SDWrite( PageFile, ObjCode, PAGE_SIZE ); ChkIOErr( PageFile, SM_IO_WRITE_ERR ); PageFlags &= ~PF_DIRTY; } }
static void ExBkSpace( void ) { //=========================== ftnfile *fcb; ChkUnitId(); FindFtnFile(); ChkConnected(); ChkExist(); fcb = IOCB->fileinfo; // backspace statement only valid for SEQUENTIAL files. ChkSequential( IO_ABACK ); ChkRecordStructure(); ClrBuff(); if( fcb->eofrecnum != 1 ) { if( fcb->recnum > 1 ) { fcb->recnum--; if( fcb->recnum != fcb->eofrecnum ) { BackSpacef( fcb ); ChkIOErr( fcb ); } } fcb->flags &= ~FTN_EOF; } }
void CloseFile( ftnfile *fcb ) { //================================= // Close a 'ftnfile'. file_handle fh; if( fcb->fileptr == NULL ) return; if( fcb->fileptr == FStdIn ) return; if( fcb->fileptr == FStdOut ) { // check if standard output device redirected to a disk file if( ((a_file *)(fcb->fileptr))->attrs & BUFFERED ) { FlushBuffer( fcb->fileptr ); ChkIOErr( fcb ); } return; } if( fcb->fileptr == FStdErr ) return; Closef( fcb->fileptr ); // save file handle fh = fcb->fileptr; // set file handle in fcb to NULL - we don't want // to get the i/o status from the file handle since // it will no longer be valid if the close succeeded fcb->fileptr = NULL; if( GetIOErr( fcb ) ) { // close failed so restore file handle in fcb fcb->fileptr = fh; IOErr( IO_FILE_PROBLEM ); } }
void SkipLogicalRecord( ftnfile *fcb ) { //========================================= if( fcb->fileptr != NULL ) { FSkipLogical( fcb->fileptr ); ChkIOErr( fcb ); } }
bool CheckLogicalRecord( ftnfile *fcb ) { //========================================= int rc; rc = FCheckLogical( fcb->fileptr ); ChkIOErr( fcb ); return( rc ); }
static void IOStatement( RTCODE stmt ) { //========================================== // don't need label generated for IOSTAT unless it's a READ or WRITE // statement that is not NAMELIST-directed if( ( (stmt != RT_EX_READ) && (stmt != RT_EX_WRITE) ) || NmlSpecified ) { IOStatSpecified = FALSE; } ChkIOErr( CGCall( InitCall( stmt ) ) ); }
void SendEOR( void ) { //================= ftnfile *fcb; int len; bool ifile; fcb = IOCB->fileinfo; ifile = fcb->internal != NULL; if( ifile ) { if( fcb->flags & FTN_EOF ) { IOErr( IO_IFULL ); } if( fcb->recnum >= IOCB->elmts ) { fcb->flags |= FTN_EOF; SendIFBuff( fcb->buffer, fcb->bufflen, fcb->recnum, fcb->internal ); } else { SendIFBuff( fcb->buffer, fcb->bufflen, fcb->recnum, fcb->internal ); memset( fcb->buffer, ' ', fcb->bufflen ); } } else { if( IsFixed() ) { fcb->col = fcb->bufflen; } if( fcb->fileptr != NULL ) { FPutBuff( fcb ); ChkIOErr( fcb ); } } // Write to the listing file after we've written to DB_STD_OUTPUT so // that if we get an error writing to the listing file, the buffer for // DB_STD_OUTPUT will be empty (i.e. when we report the error writing // to the listing file we will need to use DB_STD_OUTPUT's buffer). // Note that we have to set fcb->col to 0 so that the error message // will go at the beginning of the buffer. len = fcb->col; fcb->col = 0; if( ( IOCB->flags & IOF_NOCR ) == 0 ) { UpdateRecNum( fcb ); // eofrecnum used to be updated in ExWrite(). // We MUST set eofrecnum here in case we abort the WRITE and // suicide which will NOT return to ExWrite(). // If we don't do this here, the next time a WRITE is executed // on this unit, we get IO_PAST_EOF error. if( !ifile && !NoEOF( fcb ) ) { if( fcb->accmode <= ACCM_SEQUENTIAL ) { fcb->eofrecnum = fcb->recnum; } } if( !ifile ) { memset( fcb->buffer, ' ', fcb->bufflen ); } } IOCB->flags &= ~IOF_NOCR; }
static void LoadPage( unsigned_16 page ) { //============================================ // Load a page into memory. if( page != CurrPage ) { DumpCurrPage(); SDSeek( PageFile, page, PAGE_SIZE ); ChkIOErr( PageFile, SM_IO_READ_ERR ); SDRead( PageFile, ObjCode, PAGE_SIZE ); // If we seek to the end of the last page in the disk // file (which is the start of a non-existent page file), // we will get end-of-file when we do the read. if( !SDEof( PageFile ) ) { ChkIOErr( PageFile, SM_IO_READ_ERR ); } CurrPage = page; PageFlags = PF_INIT; } }
void InitObj( void ) { //================= // Allocate memory for object code. char *fn; char *tmp; int len; int idx; ObjCode = NULL; // in case FMemAlloc() fails ObjCode = FMemAlloc( PAGE_SIZE ); ObjEnd = ObjCode + PAGE_SIZE; ObjPtr = ObjCode; *(unsigned_16 *)ObjPtr = FC_END_OF_SEQUENCE; // in case no source code in file PageFile = NULL; if( ( ProgSw & PS_DONT_GENERATE ) == 0 ) { fn = PageFileBuff; len = 0; tmp = getenv( "TMP" ); if( tmp != NULL ) { strcpy( fn, tmp ); len += strlen( fn ); fn += len; if( ( fn[-1] != ':' ) && ( fn[-1] != '\\' ) && ( fn[-1] != '/' ) ) { *fn = PATH_SEP; ++fn; ++len; } } strcpy( fn, PageFileName ); len += strlen( fn ); PageFileBuff[ len + 1 ] = NULLCHAR; for( idx = 0; idx <= 25; idx++ ) { PageFileBuff[ len ] = 'a' + idx; if( access( PageFileBuff, 0 ) == -1 ) break; } if( idx == 26 ) { Error( SM_OUT_OF_VM_FILES, PageFileName ); } else { SDSetAttr( PageFileAttrs ); PageFile = SDOpen( PageFileBuff, UPDATE_FILE ); ChkIOErr( PageFile, SM_OPENING_FILE ); } } PageFlags = PF_INIT; CurrPage = 0; MaxPage = 0; }
void DoOpen( void ) { //================ // Do the actual open of a file. ftnfile *fcb; byte action; fcb = IOCB->fileinfo; action = fcb->action; OpenAction( fcb ); fcb->flags &= ~FTN_FSEXIST; if( fcb->fileptr != NULL ) { fcb->flags |= FTN_FSEXIST; } ChkIOErr( fcb ); }
void IOPrologue( void ) { //==================== ftnfile *fcb; byte form; byte accm; IOCB->typ = PT_NOT_STARTED; if( IOCB->flags & BAD_REC ) { IOErr( IO_IREC ); } if( IOCB->set_flags & SET_INTERNAL ) { F_Connect(); } else { ChkUnitId(); FindFtnFile(); if( IOCB->fileinfo == NULL ) { IOCB->set_flags &= ~SET_FILENAME; ConnectFile(); } } fcb = IOCB->fileinfo; if( fcb->action == ACT_DEFAULT ) { fcb->action = ACTION_RW; } ChkIOOperation( fcb ); if( fcb->cctrl == CC_DEFAULT ) { fcb->cctrl = CC_NO; } accm = fcb->accmode; if( accm == ACCM_DEFAULT ) { if( IOCB->set_flags & SET_RECORDNUM ) { accm = ACCM_DIRECT; } else { accm = ACCM_SEQUENTIAL; } fcb->accmode = accm; } else { if( ( accm == ACCM_DIRECT ) && (IOCB->set_flags & SET_RECORDNUM) == 0 ) { IOErr( IO_REC1_ACCM ); } else if( ( ( accm == ACCM_SEQUENTIAL ) || ( accm == ACCM_APPEND ) ) && (IOCB->set_flags & SET_RECORDNUM) ) { IOErr( IO_REC2_ACCM ); } } if( accm == ACCM_DIRECT ) { fcb->recnum = IOCB->recordnum; // set up recordnumber } form = fcb->formatted; if( form == 0 ) { // set up format if it was if( (IOCB->flags & IOF_NOFMT) == 0 ) { // not previously set form = FORMATTED_IO; } else { form = UNFORMATTED_IO; } fcb->formatted = form; } else { if( (form == FORMATTED_IO) && (IOCB->flags & IOF_NOFMT) ) { IOErr( IO_AF1 ); } else if( (form == UNFORMATTED_IO) && (IOCB->flags & IOF_NOFMT) == 0 ) { IOErr( IO_AF2 ); } } if( fcb->internal != NULL ) { fcb->bufflen = fcb->internal->len; fcb->buffer = RChkAlloc( fcb->bufflen ); } else { if( ( accm <= ACCM_SEQUENTIAL ) && ( fcb->eofrecnum != 0 ) && ( fcb->recnum >= fcb->eofrecnum ) && // Consider: READ( 1, *, END=10 ) // ... // 10 WRITE( 1, * ) 'write after EOF' // if an EOF condition was encounterd, we don't want IO_PAST_EOF // on the write (IOCB->flags & IOF_OUTPT) == 0 ) { if( fcb->recnum != fcb->eofrecnum ) { IOErr( IO_PAST_EOF ); } else { fcb->recnum++; SysEOF(); } } _AllocBuffer( fcb ); if( fcb->fileptr == NULL ) { DoOpen(); } if( fcb->accmode == ACCM_DIRECT ) { SeekFile( fcb ); ChkIOErr( fcb ); } fcb->col = 0; } if( (IOCB->flags & IOF_OUTPT) && ( fcb->col == 0 ) ) { memset( fcb->buffer, ' ', fcb->bufflen ); } }