K&R formatting
This commit is contained in:
+412
-345
@@ -84,105 +84,113 @@ FIXME: There is noticeable decrease in speed, also. Perhaps,
|
||||
*/
|
||||
|
||||
HistoryFile::HistoryFile()
|
||||
: ion(-1),
|
||||
length(0),
|
||||
fileMap(0) {
|
||||
if (tmpFile.open()) {
|
||||
tmpFile.setAutoRemove(true);
|
||||
ion = tmpFile.handle();
|
||||
}
|
||||
: ion(-1),
|
||||
length(0),
|
||||
fileMap(0)
|
||||
{
|
||||
if (tmpFile.open()) {
|
||||
tmpFile.setAutoRemove(true);
|
||||
ion = tmpFile.handle();
|
||||
}
|
||||
}
|
||||
|
||||
HistoryFile::~HistoryFile() {
|
||||
if (fileMap) {
|
||||
unmap();
|
||||
}
|
||||
HistoryFile::~HistoryFile()
|
||||
{
|
||||
if (fileMap) {
|
||||
unmap();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Mapping the entire file in will cause problems if the history file becomes exceedingly large,
|
||||
//(ie. larger than available memory). HistoryFile::map() should only map in sections of the file at a time,
|
||||
//to avoid this.
|
||||
void HistoryFile::map() {
|
||||
assert( fileMap == 0 );
|
||||
void HistoryFile::map()
|
||||
{
|
||||
assert( fileMap == 0 );
|
||||
|
||||
fileMap = (char *)mmap( 0 , length , PROT_READ , MAP_PRIVATE , ion , 0 );
|
||||
fileMap = (char *)mmap( 0 , length , PROT_READ , MAP_PRIVATE , ion , 0 );
|
||||
|
||||
//if mmap'ing fails, fall back to the read-lseek combination
|
||||
if ( fileMap == MAP_FAILED ) {
|
||||
readWriteBalance = 0;
|
||||
fileMap = 0;
|
||||
qDebug() << ": mmap'ing history failed. errno = " << errno;
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryFile::unmap() {
|
||||
int result = munmap( fileMap , length );
|
||||
assert( result == 0 );
|
||||
|
||||
fileMap = 0;
|
||||
}
|
||||
|
||||
bool HistoryFile::isMapped() {
|
||||
return (fileMap != 0);
|
||||
}
|
||||
|
||||
void HistoryFile::add(const unsigned char * bytes, int len) {
|
||||
if ( fileMap ) {
|
||||
unmap();
|
||||
}
|
||||
|
||||
readWriteBalance++;
|
||||
|
||||
int rc = 0;
|
||||
|
||||
rc = lseek(ion,length,SEEK_SET);
|
||||
if (rc < 0) {
|
||||
perror("HistoryFile::add.seek");
|
||||
return;
|
||||
}
|
||||
rc = write(ion,bytes,len);
|
||||
if (rc < 0) {
|
||||
perror("HistoryFile::add.write");
|
||||
return;
|
||||
}
|
||||
length += rc;
|
||||
}
|
||||
|
||||
void HistoryFile::get(unsigned char * bytes, int len, int loc) {
|
||||
//count number of get() calls vs. number of add() calls.
|
||||
//If there are many more get() calls compared with add()
|
||||
//calls (decided by using MAP_THRESHOLD) then mmap the log
|
||||
//file to improve performance.
|
||||
readWriteBalance--;
|
||||
if ( !fileMap && readWriteBalance < MAP_THRESHOLD ) {
|
||||
map();
|
||||
}
|
||||
|
||||
if ( fileMap ) {
|
||||
for (int i=0; i<len; i++) {
|
||||
bytes[i]=fileMap[loc+i];
|
||||
//if mmap'ing fails, fall back to the read-lseek combination
|
||||
if ( fileMap == MAP_FAILED ) {
|
||||
readWriteBalance = 0;
|
||||
fileMap = 0;
|
||||
qDebug() << ": mmap'ing history failed. errno = " << errno;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
void HistoryFile::unmap()
|
||||
{
|
||||
int result = munmap( fileMap , length );
|
||||
assert( result == 0 );
|
||||
|
||||
fileMap = 0;
|
||||
}
|
||||
|
||||
bool HistoryFile::isMapped()
|
||||
{
|
||||
return (fileMap != 0);
|
||||
}
|
||||
|
||||
void HistoryFile::add(const unsigned char * bytes, int len)
|
||||
{
|
||||
if ( fileMap ) {
|
||||
unmap();
|
||||
}
|
||||
|
||||
readWriteBalance++;
|
||||
|
||||
int rc = 0;
|
||||
|
||||
if (loc < 0 || len < 0 || loc + len > length) {
|
||||
fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc);
|
||||
}
|
||||
rc = lseek(ion,loc,SEEK_SET);
|
||||
rc = lseek(ion,length,SEEK_SET);
|
||||
if (rc < 0) {
|
||||
perror("HistoryFile::get.seek");
|
||||
return;
|
||||
perror("HistoryFile::add.seek");
|
||||
return;
|
||||
}
|
||||
rc = read(ion,bytes,len);
|
||||
rc = write(ion,bytes,len);
|
||||
if (rc < 0) {
|
||||
perror("HistoryFile::get.read");
|
||||
return;
|
||||
perror("HistoryFile::add.write");
|
||||
return;
|
||||
}
|
||||
}
|
||||
length += rc;
|
||||
}
|
||||
|
||||
int HistoryFile::len() {
|
||||
return length;
|
||||
void HistoryFile::get(unsigned char * bytes, int len, int loc)
|
||||
{
|
||||
//count number of get() calls vs. number of add() calls.
|
||||
//If there are many more get() calls compared with add()
|
||||
//calls (decided by using MAP_THRESHOLD) then mmap the log
|
||||
//file to improve performance.
|
||||
readWriteBalance--;
|
||||
if ( !fileMap && readWriteBalance < MAP_THRESHOLD ) {
|
||||
map();
|
||||
}
|
||||
|
||||
if ( fileMap ) {
|
||||
for (int i=0; i<len; i++) {
|
||||
bytes[i]=fileMap[loc+i];
|
||||
}
|
||||
} else {
|
||||
int rc = 0;
|
||||
|
||||
if (loc < 0 || len < 0 || loc + len > length) {
|
||||
fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc);
|
||||
}
|
||||
rc = lseek(ion,loc,SEEK_SET);
|
||||
if (rc < 0) {
|
||||
perror("HistoryFile::get.seek");
|
||||
return;
|
||||
}
|
||||
rc = read(ion,bytes,len);
|
||||
if (rc < 0) {
|
||||
perror("HistoryFile::get.read");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int HistoryFile::len()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,15 +198,18 @@ int HistoryFile::len() {
|
||||
|
||||
|
||||
HistoryScroll::HistoryScroll(HistoryType * t)
|
||||
: m_histType(t) {
|
||||
: m_histType(t)
|
||||
{
|
||||
}
|
||||
|
||||
HistoryScroll::~HistoryScroll() {
|
||||
delete m_histType;
|
||||
HistoryScroll::~HistoryScroll()
|
||||
{
|
||||
delete m_histType;
|
||||
}
|
||||
|
||||
bool HistoryScroll::hasScroll() {
|
||||
return true;
|
||||
bool HistoryScroll::hasScroll()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// History Scroll File //////////////////////////////////////
|
||||
@@ -215,426 +226,482 @@ bool HistoryScroll::hasScroll() {
|
||||
*/
|
||||
|
||||
HistoryScrollFile::HistoryScrollFile(const QString & logFileName)
|
||||
: HistoryScroll(new HistoryTypeFile(logFileName)),
|
||||
m_logFileName(logFileName) {
|
||||
: HistoryScroll(new HistoryTypeFile(logFileName)),
|
||||
m_logFileName(logFileName)
|
||||
{
|
||||
}
|
||||
|
||||
HistoryScrollFile::~HistoryScrollFile() {
|
||||
HistoryScrollFile::~HistoryScrollFile()
|
||||
{
|
||||
}
|
||||
|
||||
int HistoryScrollFile::getLines() {
|
||||
return index.len() / sizeof(int);
|
||||
int HistoryScrollFile::getLines()
|
||||
{
|
||||
return index.len() / sizeof(int);
|
||||
}
|
||||
|
||||
int HistoryScrollFile::getLineLen(int lineno) {
|
||||
return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(Character);
|
||||
int HistoryScrollFile::getLineLen(int lineno)
|
||||
{
|
||||
return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(Character);
|
||||
}
|
||||
|
||||
bool HistoryScrollFile::isWrappedLine(int lineno) {
|
||||
if (lineno>=0 && lineno <= getLines()) {
|
||||
unsigned char flag;
|
||||
lineflags.get((unsigned char *)&flag,sizeof(unsigned char),(lineno)*sizeof(unsigned char));
|
||||
return flag;
|
||||
}
|
||||
return false;
|
||||
bool HistoryScrollFile::isWrappedLine(int lineno)
|
||||
{
|
||||
if (lineno>=0 && lineno <= getLines()) {
|
||||
unsigned char flag;
|
||||
lineflags.get((unsigned char *)&flag,sizeof(unsigned char),(lineno)*sizeof(unsigned char));
|
||||
return flag;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int HistoryScrollFile::startOfLine(int lineno) {
|
||||
if (lineno <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (lineno <= getLines()) {
|
||||
int HistoryScrollFile::startOfLine(int lineno)
|
||||
{
|
||||
if (lineno <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (lineno <= getLines()) {
|
||||
|
||||
if (!index.isMapped()) {
|
||||
index.map();
|
||||
if (!index.isMapped()) {
|
||||
index.map();
|
||||
}
|
||||
|
||||
int res;
|
||||
index.get((unsigned char *)&res,sizeof(int),(lineno-1)*sizeof(int));
|
||||
return res;
|
||||
}
|
||||
return cells.len();
|
||||
}
|
||||
|
||||
void HistoryScrollFile::getCells(int lineno, int colno, int count, Character res[])
|
||||
{
|
||||
cells.get((unsigned char *)res,count*sizeof(Character),startOfLine(lineno)+colno*sizeof(Character));
|
||||
}
|
||||
|
||||
void HistoryScrollFile::addCells(const Character text[], int count)
|
||||
{
|
||||
cells.add((unsigned char *)text,count*sizeof(Character));
|
||||
}
|
||||
|
||||
void HistoryScrollFile::addLine(bool previousWrapped)
|
||||
{
|
||||
if (index.isMapped()) {
|
||||
index.unmap();
|
||||
}
|
||||
|
||||
int res;
|
||||
index.get((unsigned char *)&res,sizeof(int),(lineno-1)*sizeof(int));
|
||||
return res;
|
||||
}
|
||||
return cells.len();
|
||||
}
|
||||
|
||||
void HistoryScrollFile::getCells(int lineno, int colno, int count, Character res[]) {
|
||||
cells.get((unsigned char *)res,count*sizeof(Character),startOfLine(lineno)+colno*sizeof(Character));
|
||||
}
|
||||
|
||||
void HistoryScrollFile::addCells(const Character text[], int count) {
|
||||
cells.add((unsigned char *)text,count*sizeof(Character));
|
||||
}
|
||||
|
||||
void HistoryScrollFile::addLine(bool previousWrapped) {
|
||||
if (index.isMapped()) {
|
||||
index.unmap();
|
||||
}
|
||||
|
||||
int locn = cells.len();
|
||||
index.add((unsigned char *)&locn,sizeof(int));
|
||||
unsigned char flags = previousWrapped ? 0x01 : 0x00;
|
||||
lineflags.add((unsigned char *)&flags,sizeof(unsigned char));
|
||||
int locn = cells.len();
|
||||
index.add((unsigned char *)&locn,sizeof(int));
|
||||
unsigned char flags = previousWrapped ? 0x01 : 0x00;
|
||||
lineflags.add((unsigned char *)&flags,sizeof(unsigned char));
|
||||
}
|
||||
|
||||
|
||||
// History Scroll Buffer //////////////////////////////////////
|
||||
HistoryScrollBuffer::HistoryScrollBuffer(unsigned int maxLineCount)
|
||||
: HistoryScroll(new HistoryTypeBuffer(maxLineCount))
|
||||
,_historyBuffer()
|
||||
,_maxLineCount(0)
|
||||
,_usedLines(0)
|
||||
,_head(0) {
|
||||
setMaxNbLines(maxLineCount);
|
||||
: HistoryScroll(new HistoryTypeBuffer(maxLineCount))
|
||||
,_historyBuffer()
|
||||
,_maxLineCount(0)
|
||||
,_usedLines(0)
|
||||
,_head(0)
|
||||
{
|
||||
setMaxNbLines(maxLineCount);
|
||||
}
|
||||
|
||||
HistoryScrollBuffer::~HistoryScrollBuffer() {
|
||||
delete[] _historyBuffer;
|
||||
HistoryScrollBuffer::~HistoryScrollBuffer()
|
||||
{
|
||||
delete[] _historyBuffer;
|
||||
}
|
||||
|
||||
void HistoryScrollBuffer::addCellsVector(const QVector<Character>& cells) {
|
||||
_head++;
|
||||
if ( _usedLines < _maxLineCount ) {
|
||||
_usedLines++;
|
||||
}
|
||||
void HistoryScrollBuffer::addCellsVector(const QVector<Character>& cells)
|
||||
{
|
||||
_head++;
|
||||
if ( _usedLines < _maxLineCount ) {
|
||||
_usedLines++;
|
||||
}
|
||||
|
||||
if ( _head >= _maxLineCount ) {
|
||||
_head = 0;
|
||||
}
|
||||
if ( _head >= _maxLineCount ) {
|
||||
_head = 0;
|
||||
}
|
||||
|
||||
_historyBuffer[bufferIndex(_usedLines-1)] = cells;
|
||||
_wrappedLine[bufferIndex(_usedLines-1)] = false;
|
||||
_historyBuffer[bufferIndex(_usedLines-1)] = cells;
|
||||
_wrappedLine[bufferIndex(_usedLines-1)] = false;
|
||||
}
|
||||
void HistoryScrollBuffer::addCells(const Character a[], int count) {
|
||||
HistoryLine newLine(count);
|
||||
qCopy(a,a+count,newLine.begin());
|
||||
void HistoryScrollBuffer::addCells(const Character a[], int count)
|
||||
{
|
||||
HistoryLine newLine(count);
|
||||
qCopy(a,a+count,newLine.begin());
|
||||
|
||||
addCellsVector(newLine);
|
||||
addCellsVector(newLine);
|
||||
}
|
||||
|
||||
void HistoryScrollBuffer::addLine(bool previousWrapped) {
|
||||
_wrappedLine[bufferIndex(_usedLines-1)] = previousWrapped;
|
||||
void HistoryScrollBuffer::addLine(bool previousWrapped)
|
||||
{
|
||||
_wrappedLine[bufferIndex(_usedLines-1)] = previousWrapped;
|
||||
}
|
||||
|
||||
int HistoryScrollBuffer::getLines() {
|
||||
return _usedLines;
|
||||
int HistoryScrollBuffer::getLines()
|
||||
{
|
||||
return _usedLines;
|
||||
}
|
||||
|
||||
int HistoryScrollBuffer::getLineLen(int lineNumber) {
|
||||
Q_ASSERT( lineNumber >= 0 && lineNumber < _maxLineCount );
|
||||
int HistoryScrollBuffer::getLineLen(int lineNumber)
|
||||
{
|
||||
Q_ASSERT( lineNumber >= 0 && lineNumber < _maxLineCount );
|
||||
|
||||
if ( lineNumber < _usedLines ) {
|
||||
return _historyBuffer[bufferIndex(lineNumber)].size();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
if ( lineNumber < _usedLines ) {
|
||||
return _historyBuffer[bufferIndex(lineNumber)].size();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool HistoryScrollBuffer::isWrappedLine(int lineNumber) {
|
||||
Q_ASSERT( lineNumber >= 0 && lineNumber < _maxLineCount );
|
||||
bool HistoryScrollBuffer::isWrappedLine(int lineNumber)
|
||||
{
|
||||
Q_ASSERT( lineNumber >= 0 && lineNumber < _maxLineCount );
|
||||
|
||||
if (lineNumber < _usedLines) {
|
||||
//kDebug() << "Line" << lineNumber << "wrapped is" << _wrappedLine[bufferIndex(lineNumber)];
|
||||
return _wrappedLine[bufferIndex(lineNumber)];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (lineNumber < _usedLines) {
|
||||
//kDebug() << "Line" << lineNumber << "wrapped is" << _wrappedLine[bufferIndex(lineNumber)];
|
||||
return _wrappedLine[bufferIndex(lineNumber)];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryScrollBuffer::getCells(int lineNumber, int startColumn, int count, Character * buffer) {
|
||||
if ( count == 0 ) {
|
||||
return;
|
||||
}
|
||||
void HistoryScrollBuffer::getCells(int lineNumber, int startColumn, int count, Character * buffer)
|
||||
{
|
||||
if ( count == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT( lineNumber < _maxLineCount );
|
||||
Q_ASSERT( lineNumber < _maxLineCount );
|
||||
|
||||
if (lineNumber >= _usedLines) {
|
||||
memset(buffer, 0, count * sizeof(Character));
|
||||
return;
|
||||
}
|
||||
if (lineNumber >= _usedLines) {
|
||||
memset(buffer, 0, count * sizeof(Character));
|
||||
return;
|
||||
}
|
||||
|
||||
const HistoryLine & line = _historyBuffer[bufferIndex(lineNumber)];
|
||||
const HistoryLine & line = _historyBuffer[bufferIndex(lineNumber)];
|
||||
|
||||
//kDebug() << "startCol " << startColumn;
|
||||
//kDebug() << "line.size() " << line.size();
|
||||
//kDebug() << "count " << count;
|
||||
//kDebug() << "startCol " << startColumn;
|
||||
//kDebug() << "line.size() " << line.size();
|
||||
//kDebug() << "count " << count;
|
||||
|
||||
Q_ASSERT( startColumn <= line.size() - count );
|
||||
Q_ASSERT( startColumn <= line.size() - count );
|
||||
|
||||
memcpy(buffer, line.constData() + startColumn , count * sizeof(Character));
|
||||
memcpy(buffer, line.constData() + startColumn , count * sizeof(Character));
|
||||
}
|
||||
|
||||
void HistoryScrollBuffer::setMaxNbLines(unsigned int lineCount) {
|
||||
HistoryLine * oldBuffer = _historyBuffer;
|
||||
HistoryLine * newBuffer = new HistoryLine[lineCount];
|
||||
void HistoryScrollBuffer::setMaxNbLines(unsigned int lineCount)
|
||||
{
|
||||
HistoryLine * oldBuffer = _historyBuffer;
|
||||
HistoryLine * newBuffer = new HistoryLine[lineCount];
|
||||
|
||||
for ( int i = 0 ; i < qMin(_usedLines,(int)lineCount) ; i++ ) {
|
||||
newBuffer[i] = oldBuffer[bufferIndex(i)];
|
||||
}
|
||||
for ( int i = 0 ; i < qMin(_usedLines,(int)lineCount) ; i++ ) {
|
||||
newBuffer[i] = oldBuffer[bufferIndex(i)];
|
||||
}
|
||||
|
||||
_usedLines = qMin(_usedLines,(int)lineCount);
|
||||
_maxLineCount = lineCount;
|
||||
_head = ( _usedLines == _maxLineCount ) ? 0 : _usedLines-1;
|
||||
_usedLines = qMin(_usedLines,(int)lineCount);
|
||||
_maxLineCount = lineCount;
|
||||
_head = ( _usedLines == _maxLineCount ) ? 0 : _usedLines-1;
|
||||
|
||||
_historyBuffer = newBuffer;
|
||||
delete[] oldBuffer;
|
||||
_historyBuffer = newBuffer;
|
||||
delete[] oldBuffer;
|
||||
|
||||
_wrappedLine.resize(lineCount);
|
||||
_wrappedLine.resize(lineCount);
|
||||
}
|
||||
|
||||
int HistoryScrollBuffer::bufferIndex(int lineNumber) {
|
||||
Q_ASSERT( lineNumber >= 0 );
|
||||
Q_ASSERT( lineNumber < _maxLineCount );
|
||||
Q_ASSERT( (_usedLines == _maxLineCount) || lineNumber <= _head );
|
||||
int HistoryScrollBuffer::bufferIndex(int lineNumber)
|
||||
{
|
||||
Q_ASSERT( lineNumber >= 0 );
|
||||
Q_ASSERT( lineNumber < _maxLineCount );
|
||||
Q_ASSERT( (_usedLines == _maxLineCount) || lineNumber <= _head );
|
||||
|
||||
if ( _usedLines == _maxLineCount ) {
|
||||
return (_head+lineNumber+1) % _maxLineCount;
|
||||
} else {
|
||||
return lineNumber;
|
||||
}
|
||||
if ( _usedLines == _maxLineCount ) {
|
||||
return (_head+lineNumber+1) % _maxLineCount;
|
||||
} else {
|
||||
return lineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// History Scroll None //////////////////////////////////////
|
||||
|
||||
HistoryScrollNone::HistoryScrollNone()
|
||||
: HistoryScroll(new HistoryTypeNone()) {
|
||||
: HistoryScroll(new HistoryTypeNone())
|
||||
{
|
||||
}
|
||||
|
||||
HistoryScrollNone::~HistoryScrollNone() {
|
||||
HistoryScrollNone::~HistoryScrollNone()
|
||||
{
|
||||
}
|
||||
|
||||
bool HistoryScrollNone::hasScroll() {
|
||||
return false;
|
||||
bool HistoryScrollNone::hasScroll()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int HistoryScrollNone::getLines() {
|
||||
return 0;
|
||||
int HistoryScrollNone::getLines()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HistoryScrollNone::getLineLen(int) {
|
||||
return 0;
|
||||
int HistoryScrollNone::getLineLen(int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool HistoryScrollNone::isWrappedLine(int /*lineno*/) {
|
||||
return false;
|
||||
bool HistoryScrollNone::isWrappedLine(int /*lineno*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void HistoryScrollNone::getCells(int, int, int, Character []) {
|
||||
void HistoryScrollNone::getCells(int, int, int, Character [])
|
||||
{
|
||||
}
|
||||
|
||||
void HistoryScrollNone::addCells(const Character [], int) {
|
||||
void HistoryScrollNone::addCells(const Character [], int)
|
||||
{
|
||||
}
|
||||
|
||||
void HistoryScrollNone::addLine(bool) {
|
||||
void HistoryScrollNone::addLine(bool)
|
||||
{
|
||||
}
|
||||
|
||||
// History Scroll BlockArray //////////////////////////////////////
|
||||
|
||||
HistoryScrollBlockArray::HistoryScrollBlockArray(size_t size)
|
||||
: HistoryScroll(new HistoryTypeBlockArray(size)) {
|
||||
m_blockArray.setHistorySize(size); // nb. of lines.
|
||||
: HistoryScroll(new HistoryTypeBlockArray(size))
|
||||
{
|
||||
m_blockArray.setHistorySize(size); // nb. of lines.
|
||||
}
|
||||
|
||||
HistoryScrollBlockArray::~HistoryScrollBlockArray() {
|
||||
HistoryScrollBlockArray::~HistoryScrollBlockArray()
|
||||
{
|
||||
}
|
||||
|
||||
int HistoryScrollBlockArray::getLines() {
|
||||
return m_lineLengths.count();
|
||||
int HistoryScrollBlockArray::getLines()
|
||||
{
|
||||
return m_lineLengths.count();
|
||||
}
|
||||
|
||||
int HistoryScrollBlockArray::getLineLen(int lineno) {
|
||||
if ( m_lineLengths.contains(lineno) ) {
|
||||
return m_lineLengths[lineno];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
int HistoryScrollBlockArray::getLineLen(int lineno)
|
||||
{
|
||||
if ( m_lineLengths.contains(lineno) ) {
|
||||
return m_lineLengths[lineno];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool HistoryScrollBlockArray::isWrappedLine(int /*lineno*/) {
|
||||
return false;
|
||||
bool HistoryScrollBlockArray::isWrappedLine(int /*lineno*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void HistoryScrollBlockArray::getCells(int lineno, int colno,
|
||||
int count, Character res[]) {
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
int count, Character res[])
|
||||
{
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Block * b = m_blockArray.at(lineno);
|
||||
const Block * b = m_blockArray.at(lineno);
|
||||
|
||||
if (!b) {
|
||||
memset(res, 0, count * sizeof(Character)); // still better than random data
|
||||
return;
|
||||
}
|
||||
if (!b) {
|
||||
memset(res, 0, count * sizeof(Character)); // still better than random data
|
||||
return;
|
||||
}
|
||||
|
||||
assert(((colno + count) * sizeof(Character)) < ENTRIES);
|
||||
memcpy(res, b->data + (colno * sizeof(Character)), count * sizeof(Character));
|
||||
assert(((colno + count) * sizeof(Character)) < ENTRIES);
|
||||
memcpy(res, b->data + (colno * sizeof(Character)), count * sizeof(Character));
|
||||
}
|
||||
|
||||
void HistoryScrollBlockArray::addCells(const Character a[], int count) {
|
||||
Block * b = m_blockArray.lastBlock();
|
||||
void HistoryScrollBlockArray::addCells(const Character a[], int count)
|
||||
{
|
||||
Block * b = m_blockArray.lastBlock();
|
||||
|
||||
if (!b) {
|
||||
return;
|
||||
}
|
||||
if (!b) {
|
||||
return;
|
||||
}
|
||||
|
||||
// put cells in block's data
|
||||
assert((count * sizeof(Character)) < ENTRIES);
|
||||
// put cells in block's data
|
||||
assert((count * sizeof(Character)) < ENTRIES);
|
||||
|
||||
memset(b->data, 0, ENTRIES);
|
||||
memset(b->data, 0, ENTRIES);
|
||||
|
||||
memcpy(b->data, a, count * sizeof(Character));
|
||||
b->size = count * sizeof(Character);
|
||||
memcpy(b->data, a, count * sizeof(Character));
|
||||
b->size = count * sizeof(Character);
|
||||
|
||||
size_t res = m_blockArray.newBlock();
|
||||
assert (res > 0);
|
||||
Q_UNUSED( res );
|
||||
size_t res = m_blockArray.newBlock();
|
||||
assert (res > 0);
|
||||
Q_UNUSED( res );
|
||||
|
||||
m_lineLengths.insert(m_blockArray.getCurrent(), count);
|
||||
m_lineLengths.insert(m_blockArray.getCurrent(), count);
|
||||
}
|
||||
|
||||
void HistoryScrollBlockArray::addLine(bool) {
|
||||
void HistoryScrollBlockArray::addLine(bool)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// History Types
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
HistoryType::HistoryType() {
|
||||
HistoryType::HistoryType()
|
||||
{
|
||||
}
|
||||
|
||||
HistoryType::~HistoryType() {
|
||||
HistoryType::~HistoryType()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
HistoryTypeNone::HistoryTypeNone() {
|
||||
HistoryTypeNone::HistoryTypeNone()
|
||||
{
|
||||
}
|
||||
|
||||
bool HistoryTypeNone::isEnabled() const {
|
||||
return false;
|
||||
bool HistoryTypeNone::isEnabled() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HistoryScroll * HistoryTypeNone::scroll(HistoryScroll * old) const {
|
||||
delete old;
|
||||
return new HistoryScrollNone();
|
||||
HistoryScroll * HistoryTypeNone::scroll(HistoryScroll * old) const
|
||||
{
|
||||
delete old;
|
||||
return new HistoryScrollNone();
|
||||
}
|
||||
|
||||
int HistoryTypeNone::maximumLineCount() const {
|
||||
return 0;
|
||||
int HistoryTypeNone::maximumLineCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
HistoryTypeBlockArray::HistoryTypeBlockArray(size_t size)
|
||||
: m_size(size) {
|
||||
: m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
bool HistoryTypeBlockArray::isEnabled() const {
|
||||
return true;
|
||||
bool HistoryTypeBlockArray::isEnabled() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int HistoryTypeBlockArray::maximumLineCount() const {
|
||||
return m_size;
|
||||
int HistoryTypeBlockArray::maximumLineCount() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
HistoryScroll * HistoryTypeBlockArray::scroll(HistoryScroll * old) const {
|
||||
delete old;
|
||||
return new HistoryScrollBlockArray(m_size);
|
||||
HistoryScroll * HistoryTypeBlockArray::scroll(HistoryScroll * old) const
|
||||
{
|
||||
delete old;
|
||||
return new HistoryScrollBlockArray(m_size);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
HistoryTypeBuffer::HistoryTypeBuffer(unsigned int nbLines)
|
||||
: m_nbLines(nbLines) {
|
||||
: m_nbLines(nbLines)
|
||||
{
|
||||
}
|
||||
|
||||
bool HistoryTypeBuffer::isEnabled() const {
|
||||
return true;
|
||||
bool HistoryTypeBuffer::isEnabled() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int HistoryTypeBuffer::maximumLineCount() const {
|
||||
return m_nbLines;
|
||||
int HistoryTypeBuffer::maximumLineCount() const
|
||||
{
|
||||
return m_nbLines;
|
||||
}
|
||||
|
||||
HistoryScroll * HistoryTypeBuffer::scroll(HistoryScroll * old) const {
|
||||
if (old) {
|
||||
HistoryScrollBuffer * oldBuffer = dynamic_cast<HistoryScrollBuffer *>(old);
|
||||
if (oldBuffer) {
|
||||
oldBuffer->setMaxNbLines(m_nbLines);
|
||||
return oldBuffer;
|
||||
}
|
||||
HistoryScroll * HistoryTypeBuffer::scroll(HistoryScroll * old) const
|
||||
{
|
||||
if (old) {
|
||||
HistoryScrollBuffer * oldBuffer = dynamic_cast<HistoryScrollBuffer *>(old);
|
||||
if (oldBuffer) {
|
||||
oldBuffer->setMaxNbLines(m_nbLines);
|
||||
return oldBuffer;
|
||||
}
|
||||
|
||||
HistoryScroll * newScroll = new HistoryScrollBuffer(m_nbLines);
|
||||
int lines = old->getLines();
|
||||
int startLine = 0;
|
||||
if (lines > (int) m_nbLines) {
|
||||
startLine = lines - m_nbLines;
|
||||
}
|
||||
HistoryScroll * newScroll = new HistoryScrollBuffer(m_nbLines);
|
||||
int lines = old->getLines();
|
||||
int startLine = 0;
|
||||
if (lines > (int) m_nbLines) {
|
||||
startLine = lines - m_nbLines;
|
||||
}
|
||||
|
||||
Character line[LINE_SIZE];
|
||||
for(int i = startLine; i < lines; i++) {
|
||||
int size = old->getLineLen(i);
|
||||
if (size > LINE_SIZE) {
|
||||
Character * tmp_line = new Character[size];
|
||||
old->getCells(i, 0, size, tmp_line);
|
||||
newScroll->addCells(tmp_line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
delete [] tmp_line;
|
||||
} else {
|
||||
old->getCells(i, 0, size, line);
|
||||
newScroll->addCells(line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
}
|
||||
Character line[LINE_SIZE];
|
||||
for (int i = startLine; i < lines; i++) {
|
||||
int size = old->getLineLen(i);
|
||||
if (size > LINE_SIZE) {
|
||||
Character * tmp_line = new Character[size];
|
||||
old->getCells(i, 0, size, tmp_line);
|
||||
newScroll->addCells(tmp_line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
delete [] tmp_line;
|
||||
} else {
|
||||
old->getCells(i, 0, size, line);
|
||||
newScroll->addCells(line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
}
|
||||
}
|
||||
delete old;
|
||||
return newScroll;
|
||||
}
|
||||
delete old;
|
||||
return newScroll;
|
||||
}
|
||||
return new HistoryScrollBuffer(m_nbLines);
|
||||
return new HistoryScrollBuffer(m_nbLines);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
HistoryTypeFile::HistoryTypeFile(const QString & fileName)
|
||||
: m_fileName(fileName) {
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
bool HistoryTypeFile::isEnabled() const {
|
||||
return true;
|
||||
bool HistoryTypeFile::isEnabled() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const QString & HistoryTypeFile::getFileName() const {
|
||||
return m_fileName;
|
||||
const QString & HistoryTypeFile::getFileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
HistoryScroll * HistoryTypeFile::scroll(HistoryScroll * old) const {
|
||||
if (dynamic_cast<HistoryFile *>(old)) {
|
||||
return old; // Unchanged.
|
||||
}
|
||||
|
||||
HistoryScroll * newScroll = new HistoryScrollFile(m_fileName);
|
||||
|
||||
Character line[LINE_SIZE];
|
||||
int lines = (old != 0) ? old->getLines() : 0;
|
||||
for(int i = 0; i < lines; i++) {
|
||||
int size = old->getLineLen(i);
|
||||
if (size > LINE_SIZE) {
|
||||
Character * tmp_line = new Character[size];
|
||||
old->getCells(i, 0, size, tmp_line);
|
||||
newScroll->addCells(tmp_line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
delete [] tmp_line;
|
||||
} else {
|
||||
old->getCells(i, 0, size, line);
|
||||
newScroll->addCells(line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
HistoryScroll * HistoryTypeFile::scroll(HistoryScroll * old) const
|
||||
{
|
||||
if (dynamic_cast<HistoryFile *>(old)) {
|
||||
return old; // Unchanged.
|
||||
}
|
||||
}
|
||||
|
||||
delete old;
|
||||
return newScroll;
|
||||
HistoryScroll * newScroll = new HistoryScrollFile(m_fileName);
|
||||
|
||||
Character line[LINE_SIZE];
|
||||
int lines = (old != 0) ? old->getLines() : 0;
|
||||
for (int i = 0; i < lines; i++) {
|
||||
int size = old->getLineLen(i);
|
||||
if (size > LINE_SIZE) {
|
||||
Character * tmp_line = new Character[size];
|
||||
old->getCells(i, 0, size, tmp_line);
|
||||
newScroll->addCells(tmp_line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
delete [] tmp_line;
|
||||
} else {
|
||||
old->getCells(i, 0, size, line);
|
||||
newScroll->addCells(line, size);
|
||||
newScroll->addLine(old->isWrappedLine(i));
|
||||
}
|
||||
}
|
||||
|
||||
delete old;
|
||||
return newScroll;
|
||||
}
|
||||
|
||||
int HistoryTypeFile::maximumLineCount() const {
|
||||
return 0;
|
||||
int HistoryTypeFile::maximumLineCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user