Skip to content
Permalink
Browse files

Adding qtermwidget

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10665 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
pcav
pcav committed Apr 27, 2009
1 parent 91372e4 commit 8a18a855f26675e0ab9e8affc1ff9caf42cf58fe
Showing with 21,494 additions and 0 deletions.
  1. +337 −0 src/plugins/grass/qtermwidget/BlockArray.cpp
  2. +125 −0 src/plugins/grass/qtermwidget/BlockArray.h
  3. +210 −0 src/plugins/grass/qtermwidget/Character.h
  4. +301 −0 src/plugins/grass/qtermwidget/CharacterColor.h
  5. +58 −0 src/plugins/grass/qtermwidget/ColorTables.h
  6. +2 −0 src/plugins/grass/qtermwidget/DefaultTranslatorText.h
  7. +543 −0 src/plugins/grass/qtermwidget/Emulation.cpp
  8. +465 −0 src/plugins/grass/qtermwidget/Emulation.h
  9. +74 −0 src/plugins/grass/qtermwidget/ExtendedDefaultTranslator.h
  10. +562 −0 src/plugins/grass/qtermwidget/Filter.cpp
  11. +383 −0 src/plugins/grass/qtermwidget/Filter.h
  12. +698 −0 src/plugins/grass/qtermwidget/History.cpp
  13. +344 −0 src/plugins/grass/qtermwidget/History.h
  14. +903 −0 src/plugins/grass/qtermwidget/KeyboardTranslator.cpp
  15. +657 −0 src/plugins/grass/qtermwidget/KeyboardTranslator.h
  16. +21 −0 src/plugins/grass/qtermwidget/LineFont.h
  17. +786 −0 src/plugins/grass/qtermwidget/LineFont.src
  18. +320 −0 src/plugins/grass/qtermwidget/Pty.cpp
  19. +243 −0 src/plugins/grass/qtermwidget/Pty.h
  20. +1,567 −0 src/plugins/grass/qtermwidget/Screen.cpp
  21. +662 −0 src/plugins/grass/qtermwidget/Screen.h
  22. +296 −0 src/plugins/grass/qtermwidget/ScreenWindow.cpp
  23. +256 −0 src/plugins/grass/qtermwidget/ScreenWindow.h
  24. +1,023 −0 src/plugins/grass/qtermwidget/Session.cpp
  25. +621 −0 src/plugins/grass/qtermwidget/Session.h
  26. +168 −0 src/plugins/grass/qtermwidget/ShellCommand.cpp
  27. +94 −0 src/plugins/grass/qtermwidget/ShellCommand.h
  28. +227 −0 src/plugins/grass/qtermwidget/TerminalCharacterDecoder.cpp
  29. +139 −0 src/plugins/grass/qtermwidget/TerminalCharacterDecoder.h
  30. +2,725 −0 src/plugins/grass/qtermwidget/TerminalDisplay.cpp
  31. +754 −0 src/plugins/grass/qtermwidget/TerminalDisplay.h
  32. +1,266 −0 src/plugins/grass/qtermwidget/Vt102Emulation.cpp
  33. +192 −0 src/plugins/grass/qtermwidget/Vt102Emulation.h
  34. +128 −0 src/plugins/grass/qtermwidget/default.keytab
  35. +1,053 −0 src/plugins/grass/qtermwidget/k3process.cpp
  36. +890 −0 src/plugins/grass/qtermwidget/k3process.h
  37. +334 −0 src/plugins/grass/qtermwidget/k3processcontroller.cpp
  38. +137 −0 src/plugins/grass/qtermwidget/k3processcontroller.h
  39. +133 −0 src/plugins/grass/qtermwidget/kb-layouts/default.keytab
  40. +133 −0 src/plugins/grass/qtermwidget/kb-layouts/linux.keytab
  41. +163 −0 src/plugins/grass/qtermwidget/kb-layouts/vt420pc.keytab
  42. +216 −0 src/plugins/grass/qtermwidget/konsole_wcwidth.cpp
  43. +24 −0 src/plugins/grass/qtermwidget/konsole_wcwidth.h
  44. +624 −0 src/plugins/grass/qtermwidget/kpty.cpp
  45. +188 −0 src/plugins/grass/qtermwidget/kpty.h
  46. +44 −0 src/plugins/grass/qtermwidget/kpty_p.h
  47. +265 −0 src/plugins/grass/qtermwidget/qtermwidget.cpp
  48. +140 −0 src/plugins/grass/qtermwidget/qtermwidget.h
@@ -0,0 +1,337 @@
/*
This file is part of Konsole, an X terminal.
Copyright (C) 2000 by Stephan Kulow <coolo@kde.org>
Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/

// Own
#include "BlockArray.h"

#include <QtCore>

// System
#include <assert.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <unistd.h>
#include <stdio.h>


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)
{
// lastmap_index = index = current = size_t(-1);
if (blocksize == 0)
blocksize = ((sizeof(Block) / getpagesize()) + 1) * getpagesize();

}

BlockArray::~BlockArray()
{
setHistorySize(0);
assert(!lastblock);
}

size_t BlockArray::append(Block *block)
{
if (!size)
return size_t(-1);

++current;
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); }

length++;
if (length > size) length = size;

++index;

delete block;
return current;
}

size_t BlockArray::newBlock()
{
if (!size)
return size_t(-1);
append(lastblock);

lastblock = new Block();
return index + 1;
}

Block *BlockArray::lastBlock() const
{
return lastblock;
}

bool BlockArray::has(size_t i) const
{
if (i == index + 1)
return true;

if (i > index)
return false;
if (index - i >= length)
return false;
return true;
}

const Block* BlockArray::at(size_t i)
{
if (i == index + 1)
return lastblock;

if (i == lastmap_index)
return lastmap;

if (i > index) {
qDebug() << "BlockArray::at() i > index\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 ;

assert(j < size);
unmap();

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

if (block == (Block*)-1) { perror("mmap"); return 0; }

lastmap = block;
lastmap_index = i;

return block;
}

void BlockArray::unmap()
{
if (lastmap) {
int res = munmap((char*)lastmap, blocksize);
if (res < 0) perror("munmap");
}
lastmap = 0;
lastmap_index = size_t(-1);
}

bool BlockArray::setSize(size_t newsize)
{
return setHistorySize(newsize * 1024 / blocksize);
}

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

if (size == newsize)
return false;

unmap();

if (!newsize) {
delete lastblock;
lastblock = 0;
if (ion >= 0) close(ion);
ion = -1;
current = size_t(-1);
return true;
}

if (!size) {
FILE* tmp = tmpfile();
if (!tmp) {
perror("konsole: cannot open temp file.\n");
} else {
ion = dup(fileno(tmp));
if (ion<0) {
perror("konsole: cannot dup temp file.\n");
fclose(tmp);
}
}
if (ion < 0)
return false;

assert(!lastblock);

lastblock = new Block();
size = newsize;
return false;
}

if (newsize > size) {
increaseBuffer();
size = newsize;
return false;
} else {
decreaseBuffer(newsize);
ftruncate(ion, length*blocksize);
size = newsize;

return true;
}
}

void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2)
{
int res = fseek(fion, cursor * blocksize, SEEK_SET);
if (res)
perror("fseek");
res = fread(buffer2, blocksize, 1, fion);
if (res != 1)
perror("fread");

res = fseek(fion, newpos * blocksize, SEEK_SET);
if (res)
perror("fseek");
res = fwrite(buffer2, blocksize, 1, fion);
if (res != 1)
perror("fwrite");
// printf("moving block %d to %d\n", cursor, newpos);
}

void BlockArray::decreaseBuffer(size_t newsize)
{
if (index < newsize) // still fits in whole
return;

int offset = (current - (newsize - 1) + size) % size;

if (!offset)
return;

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

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

int firstblock;
if (current <= newsize) {
firstblock = current + 1;
} else {
firstblock = 0;
}

size_t oldpos;
for (size_t i = 0, cursor=firstblock; i < newsize; i++) {
oldpos = (size + cursor + offset) % size;
moveBlock(fion, oldpos, cursor, buffer1);
if (oldpos < newsize) {
cursor = oldpos;
} else
cursor++;
}

current = newsize - 1;
length = newsize;

delete [] buffer1;

fclose(fion);

}

void BlockArray::increaseBuffer()
{
if (index < size) // not even wrapped once
return;

int offset = (current + size + 1) % size;
if (!offset) // no moving needed
return;

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

int runs = 1;
int bpr = size; // blocks per run

if (size % offset == 0) {
bpr = size / offset;
runs = offset;
}

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

int res;
for (int i = 0; i < runs; i++)
{
// free one block in chain
int firstblock = (offset + i) % size;
res = fseek(fion, firstblock * blocksize, SEEK_SET);
if (res)
perror("fseek");
res = fread(buffer1, blocksize, 1, fion);
if (res != 1)
perror("fread");
int newpos = 0;
for (int j = 1, cursor=firstblock; j < bpr; j++)
{
cursor = (cursor + offset) % size;
newpos = (cursor - offset + size) % size;
moveBlock(fion, cursor, newpos, buffer2);
}
res = fseek(fion, i * blocksize, SEEK_SET);
if (res)
perror("fseek");
res = fwrite(buffer1, blocksize, 1, fion);
if (res != 1)
perror("fwrite");
}
current = size - 1;
length = size;

delete [] buffer1;
delete [] buffer2;

fclose(fion);

}

0 comments on commit 8a18a85

Please sign in to comment.
You can’t perform that action at this time.