K&R formatting
This commit is contained in:
+29
-18
@@ -39,13 +39,13 @@ using namespace Konsole;
|
||||
static int blocksize = 0;
|
||||
|
||||
BlockArray::BlockArray()
|
||||
: size(0),
|
||||
current(size_t(-1)),
|
||||
index(size_t(-1)),
|
||||
lastmap(0),
|
||||
lastmap_index(size_t(-1)),
|
||||
lastblock(0), ion(-1),
|
||||
length(0)
|
||||
: size(0),
|
||||
current(size_t(-1)),
|
||||
index(size_t(-1)),
|
||||
lastmap(0),
|
||||
lastmap_index(size_t(-1)),
|
||||
lastblock(0), ion(-1),
|
||||
length(0)
|
||||
{
|
||||
// lastmap_index = index = current = size_t(-1);
|
||||
if (blocksize == 0)
|
||||
@@ -68,8 +68,18 @@ size_t BlockArray::append(Block *block)
|
||||
if (current >= size) current = 0;
|
||||
|
||||
int rc;
|
||||
rc = lseek(ion, current * blocksize, SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); setHistorySize(0); return size_t(-1); }
|
||||
rc = write(ion, block, blocksize); if (rc < 0) { perror("HistoryBuffer::add.write"); setHistorySize(0); return size_t(-1); }
|
||||
rc = lseek(ion, current * blocksize, SEEK_SET);
|
||||
if (rc < 0) {
|
||||
perror("HistoryBuffer::add.seek");
|
||||
setHistorySize(0);
|
||||
return size_t(-1);
|
||||
}
|
||||
rc = write(ion, block, blocksize);
|
||||
if (rc < 0) {
|
||||
perror("HistoryBuffer::add.write");
|
||||
setHistorySize(0);
|
||||
return size_t(-1);
|
||||
}
|
||||
|
||||
length++;
|
||||
if (length > size) length = size;
|
||||
@@ -119,7 +129,7 @@ const Block* BlockArray::at(size_t i)
|
||||
qDebug() << "BlockArray::at() i > index\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// if (index - i >= length) {
|
||||
// kDebug(1211) << "BlockArray::at() index - i >= length\n";
|
||||
// return 0;
|
||||
@@ -132,7 +142,10 @@ const Block* BlockArray::at(size_t i)
|
||||
|
||||
Block *block = (Block*)mmap(0, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
|
||||
|
||||
if (block == (Block*)-1) { perror("mmap"); return 0; }
|
||||
if (block == (Block*)-1) {
|
||||
perror("mmap");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lastmap = block;
|
||||
lastmap_index = i;
|
||||
@@ -201,7 +214,7 @@ bool BlockArray::setHistorySize(size_t newsize)
|
||||
} else {
|
||||
decreaseBuffer(newsize);
|
||||
if (ftruncate(ion, length*blocksize) == -1)
|
||||
perror("ftruncate");
|
||||
perror("ftruncate");
|
||||
size = newsize;
|
||||
|
||||
return true;
|
||||
@@ -296,14 +309,13 @@ void BlockArray::increaseBuffer()
|
||||
FILE *fion = fdopen(dup(ion), "w+b");
|
||||
if (!fion) {
|
||||
perror("fdopen/dup");
|
||||
delete [] buffer1;
|
||||
delete [] buffer2;
|
||||
delete [] buffer1;
|
||||
delete [] buffer2;
|
||||
return;
|
||||
}
|
||||
|
||||
int res;
|
||||
for (int i = 0; i < runs; i++)
|
||||
{
|
||||
for (int i = 0; i < runs; i++) {
|
||||
// free one block in chain
|
||||
int firstblock = (offset + i) % size;
|
||||
res = fseek(fion, firstblock * blocksize, SEEK_SET);
|
||||
@@ -313,8 +325,7 @@ void BlockArray::increaseBuffer()
|
||||
if (res != 1)
|
||||
perror("fread");
|
||||
int newpos = 0;
|
||||
for (int j = 1, cursor=firstblock; j < bpr; j++)
|
||||
{
|
||||
for (int j = 1, cursor=firstblock; j < bpr; j++) {
|
||||
cursor = (cursor + offset) % size;
|
||||
newpos = (cursor - offset + size) % size;
|
||||
moveBlock(fion, cursor, newpos, buffer2);
|
||||
|
||||
Reference in New Issue
Block a user