32 #include <sys/param.h> 45 lastblock(nullptr), ion(-1),
117 qDebug() <<
"BlockArray::at() i > index\n";
133 if (block == (
Block*)-1) { perror(
"mmap");
return nullptr; }
145 if (res < 0) perror(
"munmap");
175 FILE*
tmp = tmpfile();
177 perror(
"konsole: cannot open temp file.\n");
181 perror(
"konsole: cannot dup temp file.\n");
195 if (newsize >
size) {
209 void moveBlock(FILE *fion,
int cursor,
int newpos,
char *buffer2)
214 res = fread(buffer2,
blocksize, 1, fion);
221 res = fwrite(buffer2,
blocksize, 1, fion);
240 FILE *fion = fdopen(dup(
ion),
"w+b");
243 perror(
"fdopen/dup");
255 for (
size_t i = 0, cursor=firstblock;
i < newsize;
i++) {
256 oldpos = (
size + cursor + offset) %
size;
257 moveBlock(fion, oldpos, cursor, buffer1);
258 if (oldpos < newsize) {
289 if (
size % offset == 0) {
294 FILE *fion = fdopen(dup(
ion),
"w+b");
296 perror(
"fdopen/dup");
303 for (
int i = 0;
i < runs;
i++)
306 int firstblock = (offset +
i) %
size;
310 res = fread(buffer1,
blocksize, 1, fion);
314 for (
int j = 1, cursor=firstblock; j < bpr; j++)
316 cursor = (cursor + offset) %
size;
317 newpos = (cursor - offset +
size) %
size;
318 moveBlock(fion, cursor, newpos, buffer2);
323 res = fwrite(buffer1,
blocksize, 1, fion);
size_t append(Block *block)
adds the Block at the end of history.
OCTAVE_EXPORT octave_value_list or both For fclose
void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2)
BlockArray()
Creates a history file for holding maximal size blocks.
bool has(size_t index) const
bool setHistorySize(size_t newsize)
reorders blocks as needed.
bool setSize(size_t newsize)
Convenient function to set the size in KBytes instead of blocks.
void decreaseBuffer(size_t newsize)
Block * lastBlock() const
const Block * at(size_t index)
gets the block at the index.