Skip to content

Commit

Permalink
lxqt#472 Applying clang-format to all source files
Browse files Browse the repository at this point in the history
  • Loading branch information
francescmm committed Apr 10, 2022
1 parent 0bcb646 commit 0ec75ec
Show file tree
Hide file tree
Showing 52 changed files with 7,803 additions and 7,816 deletions.
72 changes: 34 additions & 38 deletions lib/BlockArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,24 @@
#include <unistd.h>
#include <cstdio>


using namespace Konsole;

static int blocksize = 0;

BlockArray::BlockArray()
: size(0),
current(size_t(-1)),
index(size_t(-1)),
lastmap(nullptr),
lastmap_index(size_t(-1)),
lastblock(nullptr), ion(-1),
length(0)
: size(0),
current(size_t(-1)),
index(size_t(-1)),
lastmap(nullptr),
lastmap_index(size_t(-1)),
lastblock(nullptr),
ion(-1),
length(0)
{
// lastmap_index = index = current = size_t(-1);
if (blocksize == 0) {
blocksize = ((sizeof(Block) / getpagesize()) + 1) * getpagesize();
}

}

BlockArray::~BlockArray()
Expand All @@ -59,7 +58,7 @@ BlockArray::~BlockArray()
Q_ASSERT(!lastblock);
}

size_t BlockArray::append(Block * block)
size_t BlockArray::append(Block *block)
{
if (!size) {
return size_t(-1);
Expand Down Expand Up @@ -106,7 +105,7 @@ size_t BlockArray::newBlock()
return index + 1;
}

Block * BlockArray::lastBlock() const
Block *BlockArray::lastBlock() const
{
return lastblock;
}
Expand All @@ -126,7 +125,7 @@ bool BlockArray::has(size_t i) const
return true;
}

const Block * BlockArray::at(size_t i)
const Block *BlockArray::at(size_t i)
{
if (i == index + 1) {
return lastblock;
Expand All @@ -141,17 +140,17 @@ const Block * BlockArray::at(size_t i)
return nullptr;
}

// if (index - i >= length) {
// kDebug(1211) << "BlockArray::at() index - i >= length\n";
// return 0;
// }
// if (index - i >= length) {
// kDebug(1211) << "BlockArray::at() index - i >= length\n";
// return 0;
// }

size_t j = i; // (current - (index - i) + (index/size+1)*size) % size ;

Q_ASSERT(j < size);
unmap();

Block * block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
Block *block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);

if (block == (Block *)-1) {
perror("mmap");
Expand Down Expand Up @@ -183,7 +182,7 @@ bool BlockArray::setSize(size_t newsize)

bool BlockArray::setHistorySize(size_t newsize)
{
// kDebug(1211) << "setHistorySize " << size << " " << newsize;
// kDebug(1211) << "setHistorySize " << size << " " << newsize;

if (size == newsize) {
return false;
Expand All @@ -203,12 +202,12 @@ bool BlockArray::setHistorySize(size_t newsize)
}

if (!size) {
FILE * tmp = tmpfile();
FILE *tmp = tmpfile();
if (!tmp) {
perror("konsole: cannot open temp file.\n");
} else {
ion = dup(fileno(tmp));
if (ion<0) {
if (ion < 0) {
perror("konsole: cannot dup temp file.\n");
fclose(tmp);
}
Expand All @@ -230,14 +229,14 @@ bool BlockArray::setHistorySize(size_t newsize)
return false;
} else {
decreaseBuffer(newsize);
ftruncate(ion, length*blocksize);
ftruncate(ion, length * blocksize);
size = newsize;

return true;
}
}

void moveBlock(FILE * fion, int cursor, int newpos, char * buffer2)
void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2)
{
int res = fseek(fion, cursor * blocksize, SEEK_SET);
if (res) {
Expand Down Expand Up @@ -272,11 +271,11 @@ void BlockArray::decreaseBuffer(size_t newsize)
}

// The Block constructor could do somthing in future...
char * buffer1 = new char[blocksize];
char *buffer1 = new char[blocksize];

FILE * fion = fdopen(dup(ion), "w+b");
FILE *fion = fdopen(dup(ion), "w+b");
if (!fion) {
delete [] buffer1;
delete[] buffer1;
perror("fdopen/dup");
return;
}
Expand All @@ -289,7 +288,7 @@ void BlockArray::decreaseBuffer(size_t newsize)
}

size_t oldpos;
for (size_t i = 0, cursor=firstblock; i < newsize; i++) {
for (size_t i = 0, cursor = firstblock; i < newsize; i++) {
oldpos = (size + cursor + offset) % size;
moveBlock(fion, oldpos, cursor, buffer1);
if (oldpos < newsize) {
Expand All @@ -302,10 +301,9 @@ void BlockArray::decreaseBuffer(size_t newsize)
current = newsize - 1;
length = newsize;

delete [] buffer1;
delete[] buffer1;

fclose(fion);

}

void BlockArray::increaseBuffer()
Expand All @@ -320,8 +318,8 @@ void BlockArray::increaseBuffer()
}

// The Block constructor could do somthing in future...
char * buffer1 = new char[blocksize];
char * buffer2 = new char[blocksize];
char *buffer1 = new char[blocksize];
char *buffer2 = new char[blocksize];

int runs = 1;
int bpr = size; // blocks per run
Expand All @@ -331,11 +329,11 @@ void BlockArray::increaseBuffer()
runs = offset;
}

FILE * fion = fdopen(dup(ion), "w+b");
FILE *fion = fdopen(dup(ion), "w+b");
if (!fion) {
perror("fdopen/dup");
delete [] buffer1;
delete [] buffer2;
delete[] buffer1;
delete[] buffer2;
return;
}

Expand All @@ -352,7 +350,7 @@ void BlockArray::increaseBuffer()
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);
Expand All @@ -369,10 +367,8 @@ void BlockArray::increaseBuffer()
current = size - 1;
length = size;

delete [] buffer1;
delete [] buffer2;
delete[] buffer1;
delete[] buffer2;

fclose(fion);

}

91 changes: 43 additions & 48 deletions lib/BlockArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,83 +28,79 @@
//#error Do not use in KDE 2.1

#define QTERMWIDGET_BLOCKSIZE (1 << 12)
#define ENTRIES ((QTERMWIDGET_BLOCKSIZE - sizeof(size_t) ) / sizeof(unsigned char))
#define ENTRIES ((QTERMWIDGET_BLOCKSIZE - sizeof(size_t)) / sizeof(unsigned char))

namespace Konsole {

struct Block {
Block() {
size = 0;
}
struct Block
{
Block() { size = 0; }
unsigned char data[ENTRIES];
size_t size;
};

// ///////////////////////////////////////////////////////

class BlockArray {
class BlockArray
{
public:
/**
* Creates a history file for holding
* maximal size blocks. If more blocks
* are requested, then it drops earlier
* added ones.
*/
* Creates a history file for holding
* maximal size blocks. If more blocks
* are requested, then it drops earlier
* added ones.
*/
BlockArray();

/// destructor
~BlockArray();

/**
* adds the Block at the end of history.
* This may drop other blocks.
*
* The ownership on the block is transfered.
* An unique index number is returned for accessing
* it later (if not yet dropped then)
*
* Note, that the block may be dropped completely
* if history is turned off.
*/
size_t append(Block * block);
* adds the Block at the end of history.
* This may drop other blocks.
*
* The ownership on the block is transfered.
* An unique index number is returned for accessing
* it later (if not yet dropped then)
*
* Note, that the block may be dropped completely
* if history is turned off.
*/
size_t append(Block *block);

/**
* gets the block at the index. Function may return
* 0 if the block isn't available any more.
*
* The returned block is strictly readonly as only
* maped in memory - and will be invalid on the next
* operation on this class.
*/
const Block * at(size_t index);
* gets the block at the index. Function may return
* 0 if the block isn't available any more.
*
* The returned block is strictly readonly as only
* maped in memory - and will be invalid on the next
* operation on this class.
*/
const Block *at(size_t index);

/**
* reorders blocks as needed. If newsize is null,
* the history is emptied completely. The indices
* returned on append won't change their semantic,
* but they may not be valid after this call.
*/
* reorders blocks as needed. If newsize is null,
* the history is emptied completely. The indices
* returned on append won't change their semantic,
* but they may not be valid after this call.
*/
bool setHistorySize(size_t newsize);

size_t newBlock();

Block * lastBlock() const;
Block *lastBlock() const;

/**
* Convenient function to set the size in KBytes
* instead of blocks
*/
* Convenient function to set the size in KBytes
* instead of blocks
*/
bool setSize(size_t newsize);

size_t len() const {
return length;
}
size_t len() const { return length; }

bool has(size_t index) const;

size_t getCurrent() const {
return current;
}
size_t getCurrent() const { return current; }

private:
void unmap();
Expand All @@ -116,13 +112,12 @@ class BlockArray {
size_t current;
size_t index;

Block * lastmap;
Block *lastmap;
size_t lastmap_index;
Block * lastblock;
Block *lastblock;

int ion;
size_t length;

};

}
Expand Down
Loading

0 comments on commit 0ec75ec

Please sign in to comment.