// FILEBUFF.CPP - Routines for handling a parser file buffer #include"adlc.hpp"
//------------------------------FileBuff--------------------------------------- // Create a new parsing buffer
FileBuff::FileBuff( BufferedFile *fptr, ArchDesc& archDesc) : _fp(fptr), _AD(archDesc) {
_err = fseek(_fp->_fp, 0, SEEK_END); // Seek to end of file if (_err) {
file_error(SEMERR, 0, "File seek error reading input file"); exit(1); // Exit on seek error
}
_filepos = ftell(_fp->_fp); // Find offset of end of file
_bufferSize = _filepos + 5; // Filepos points to last char, so add padding
_err = fseek(_fp->_fp, 0, SEEK_SET); // Reset to beginning of file if (_err) {
file_error(SEMERR, 0, "File seek error reading input file\n"); exit(1); // Exit on seek error
}
_filepos = ftell(_fp->_fp); // Reset current file position
_linenum = 0;
_bigbuf = newchar[_bufferSize]; // Create buffer to hold text for parser if( !_bigbuf ) {
file_error(SEMERR, 0, "Buffer allocation failed\n"); exit(1); // Exit on allocation failure
}
*_bigbuf = '\n'; // Lead with a sentinel newline
_buf = _bigbuf+1; // Skip sentinel
_bufmax = _buf; // Buffer is empty
_bufeol = _bigbuf; // _bufeol points at sentinel
_filepos = -1; // filepos is in sync with _bufeol
_bufoff = _offset = 0L; // Offset at file start
_bufmax += fread(_buf, 1, _bufferSize-2, _fp->_fp); // Fill buffer & set end value if (_bufmax == _buf) {
file_error(SEMERR, 0, "File read error, no input read\n"); exit(1); // Exit on read error
}
*_bufmax = '\n'; // End with a sentinel new-line
*(_bufmax+1) = '\0'; // Then end with a sentinel NULL
}
//------------------------------~FileBuff-------------------------------------- // Nuke the FileBuff
FileBuff::~FileBuff() { delete[] _bigbuf;
}
// Check for end of file & return NULL if (_bufeol >= _bufmax) return NULL;
_linenum++;
retval = ++_bufeol; // return character following end of previous line if (*retval == '\0') return NULL; // Check for EOF sentinel // Search for newline character which must end each line for(_filepos++; *_bufeol != '\n'; _bufeol++)
_filepos++; // keep filepos in sync with _bufeol // _bufeol & filepos point at end of current line, so return pointer to start return retval;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.