K&R formatting
This commit is contained in:
+161
-166
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of Konsole, an X terminal.
|
||||
|
||||
Copyright (C) 2007 Robert Knight <robertknight@gmail.com>
|
||||
Copyright (C) 2007 Robert Knight <robertknight@gmail.com>
|
||||
Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
|
||||
Copyright (C) 1996 by Matthias Ettrich <ettrich@kde.org>
|
||||
|
||||
@@ -63,24 +63,24 @@ using namespace Konsole;
|
||||
*/
|
||||
|
||||
Emulation::Emulation() :
|
||||
_currentScreen(0),
|
||||
_codec(0),
|
||||
_decoder(0),
|
||||
_keyTranslator(0),
|
||||
_usesMouse(false)
|
||||
_currentScreen(0),
|
||||
_codec(0),
|
||||
_decoder(0),
|
||||
_keyTranslator(0),
|
||||
_usesMouse(false)
|
||||
{
|
||||
|
||||
// create screens with a default size
|
||||
_screen[0] = new Screen(40,80);
|
||||
_screen[1] = new Screen(40,80);
|
||||
_currentScreen = _screen[0];
|
||||
// create screens with a default size
|
||||
_screen[0] = new Screen(40,80);
|
||||
_screen[1] = new Screen(40,80);
|
||||
_currentScreen = _screen[0];
|
||||
|
||||
QObject::connect(&_bulkTimer1, SIGNAL(timeout()), this, SLOT(showBulk()) );
|
||||
QObject::connect(&_bulkTimer2, SIGNAL(timeout()), this, SLOT(showBulk()) );
|
||||
|
||||
// listen for mouse status changes
|
||||
connect( this , SIGNAL(programUsesMouseChanged(bool)) ,
|
||||
SLOT(usesMouseChanged(bool)) );
|
||||
QObject::connect(&_bulkTimer1, SIGNAL(timeout()), this, SLOT(showBulk()) );
|
||||
QObject::connect(&_bulkTimer2, SIGNAL(timeout()), this, SLOT(showBulk()) );
|
||||
|
||||
// listen for mouse status changes
|
||||
connect( this , SIGNAL(programUsesMouseChanged(bool)) ,
|
||||
SLOT(usesMouseChanged(bool)) );
|
||||
}
|
||||
|
||||
bool Emulation::programUsesMouse() const
|
||||
@@ -112,16 +112,15 @@ ScreenWindow* Emulation::createWindow()
|
||||
|
||||
Emulation::~Emulation()
|
||||
{
|
||||
QListIterator<ScreenWindow*> windowIter(_windows);
|
||||
QListIterator<ScreenWindow*> windowIter(_windows);
|
||||
|
||||
while (windowIter.hasNext())
|
||||
{
|
||||
delete windowIter.next();
|
||||
}
|
||||
while (windowIter.hasNext()) {
|
||||
delete windowIter.next();
|
||||
}
|
||||
|
||||
delete _screen[0];
|
||||
delete _screen[1];
|
||||
delete _decoder;
|
||||
delete _screen[0];
|
||||
delete _screen[1];
|
||||
delete _decoder;
|
||||
}
|
||||
|
||||
/*! change between primary and alternate _screen
|
||||
@@ -129,19 +128,17 @@ Emulation::~Emulation()
|
||||
|
||||
void Emulation::setScreen(int n)
|
||||
{
|
||||
Screen *old = _currentScreen;
|
||||
_currentScreen = _screen[n&1];
|
||||
if (_currentScreen != old)
|
||||
{
|
||||
old->setBusySelecting(false);
|
||||
Screen *old = _currentScreen;
|
||||
_currentScreen = _screen[n&1];
|
||||
if (_currentScreen != old) {
|
||||
old->setBusySelecting(false);
|
||||
|
||||
// tell all windows onto this emulation to switch to the newly active _screen
|
||||
QListIterator<ScreenWindow*> windowIter(_windows);
|
||||
while ( windowIter.hasNext() )
|
||||
{
|
||||
windowIter.next()->setScreen(_currentScreen);
|
||||
}
|
||||
}
|
||||
// tell all windows onto this emulation to switch to the newly active _screen
|
||||
QListIterator<ScreenWindow*> windowIter(_windows);
|
||||
while ( windowIter.hasNext() ) {
|
||||
windowIter.next()->setScreen(_currentScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Emulation::clearHistory()
|
||||
@@ -150,25 +147,25 @@ void Emulation::clearHistory()
|
||||
}
|
||||
void Emulation::setHistory(const HistoryType& t)
|
||||
{
|
||||
_screen[0]->setScroll(t);
|
||||
_screen[0]->setScroll(t);
|
||||
|
||||
showBulk();
|
||||
showBulk();
|
||||
}
|
||||
|
||||
const HistoryType& Emulation::history()
|
||||
{
|
||||
return _screen[0]->getScroll();
|
||||
return _screen[0]->getScroll();
|
||||
}
|
||||
|
||||
void Emulation::setCodec(const QTextCodec * qtc)
|
||||
{
|
||||
Q_ASSERT( qtc );
|
||||
Q_ASSERT( qtc );
|
||||
|
||||
_codec = qtc;
|
||||
delete _decoder;
|
||||
_decoder = _codec->makeDecoder();
|
||||
_codec = qtc;
|
||||
delete _decoder;
|
||||
_decoder = _codec->makeDecoder();
|
||||
|
||||
emit useUtf8Request(utf8());
|
||||
emit useUtf8Request(utf8());
|
||||
}
|
||||
|
||||
void Emulation::setCodec(EmulationCodec codec)
|
||||
@@ -181,12 +178,12 @@ void Emulation::setCodec(EmulationCodec codec)
|
||||
|
||||
void Emulation::setKeyBindings(const QString& name)
|
||||
{
|
||||
_keyTranslator = KeyboardTranslatorManager::instance()->findTranslator(name);
|
||||
_keyTranslator = KeyboardTranslatorManager::instance()->findTranslator(name);
|
||||
}
|
||||
|
||||
QString Emulation::keyBindings()
|
||||
{
|
||||
return _keyTranslator->name();
|
||||
return _keyTranslator->name();
|
||||
}
|
||||
|
||||
|
||||
@@ -206,17 +203,27 @@ void Emulation::receiveChar(int c)
|
||||
// process application unicode input to terminal
|
||||
// this is a trivial scanner
|
||||
{
|
||||
c &= 0xff;
|
||||
switch (c)
|
||||
{
|
||||
case '\b' : _currentScreen->BackSpace(); break;
|
||||
case '\t' : _currentScreen->Tabulate(); break;
|
||||
case '\n' : _currentScreen->NewLine(); break;
|
||||
case '\r' : _currentScreen->Return(); break;
|
||||
case 0x07 : emit stateSet(NOTIFYBELL);
|
||||
break;
|
||||
default : _currentScreen->ShowCharacter(c); break;
|
||||
};
|
||||
c &= 0xff;
|
||||
switch (c) {
|
||||
case '\b' :
|
||||
_currentScreen->BackSpace();
|
||||
break;
|
||||
case '\t' :
|
||||
_currentScreen->Tabulate();
|
||||
break;
|
||||
case '\n' :
|
||||
_currentScreen->NewLine();
|
||||
break;
|
||||
case '\r' :
|
||||
_currentScreen->Return();
|
||||
break;
|
||||
case 0x07 :
|
||||
emit stateSet(NOTIFYBELL);
|
||||
break;
|
||||
default :
|
||||
_currentScreen->ShowCharacter(c);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -230,16 +237,15 @@ void Emulation::receiveChar(int c)
|
||||
|
||||
void Emulation::sendKeyEvent( QKeyEvent* ev )
|
||||
{
|
||||
emit stateSet(NOTIFYNORMAL);
|
||||
|
||||
if (!ev->text().isEmpty())
|
||||
{ // A block of text
|
||||
// Note that the text is proper unicode.
|
||||
// We should do a conversion here, but since this
|
||||
// routine will never be used, we simply emit plain ascii.
|
||||
//emit sendBlock(ev->text().toAscii(),ev->text().length());
|
||||
emit sendData(ev->text().toUtf8(),ev->text().length());
|
||||
}
|
||||
emit stateSet(NOTIFYNORMAL);
|
||||
|
||||
if (!ev->text().isEmpty()) { // A block of text
|
||||
// Note that the text is proper unicode.
|
||||
// We should do a conversion here, but since this
|
||||
// routine will never be used, we simply emit plain ascii.
|
||||
//emit sendBlock(ev->text().toAscii(),ev->text().length());
|
||||
emit sendData(ev->text().toUtf8(),ev->text().length());
|
||||
}
|
||||
}
|
||||
|
||||
void Emulation::sendString(const char*,int)
|
||||
@@ -261,29 +267,26 @@ TODO: Character composition from the old code. See #96536
|
||||
|
||||
void Emulation::receiveData(const char* text, int length)
|
||||
{
|
||||
emit stateSet(NOTIFYACTIVITY);
|
||||
emit stateSet(NOTIFYACTIVITY);
|
||||
|
||||
bufferedUpdate();
|
||||
|
||||
bufferedUpdate();
|
||||
|
||||
QString unicodeText = _decoder->toUnicode(text,length);
|
||||
|
||||
//send characters to terminal emulator
|
||||
for (int i=0;i<unicodeText.length();i++)
|
||||
{
|
||||
receiveChar(unicodeText[i].unicode());
|
||||
}
|
||||
//send characters to terminal emulator
|
||||
for (int i=0; i<unicodeText.length(); i++) {
|
||||
receiveChar(unicodeText[i].unicode());
|
||||
}
|
||||
|
||||
//look for z-modem indicator
|
||||
//-- someone who understands more about z-modems that I do may be able to move
|
||||
//this check into the above for loop?
|
||||
for (int i=0;i<length;i++)
|
||||
{
|
||||
if (text[i] == '\030')
|
||||
{
|
||||
if ((length-i-1 > 3) && (strncmp(text+i+1, "B00", 3) == 0))
|
||||
emit zmodemDetected();
|
||||
}
|
||||
}
|
||||
//look for z-modem indicator
|
||||
//-- someone who understands more about z-modems that I do may be able to move
|
||||
//this check into the above for loop?
|
||||
for (int i=0; i<length; i++) {
|
||||
if (text[i] == '\030') {
|
||||
if ((length-i-1 > 3) && (strncmp(text+i+1, "B00", 3) == 0))
|
||||
emit zmodemDetected();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//OLDER VERSION
|
||||
@@ -294,13 +297,13 @@ void Emulation::receiveData(const char* text, int length)
|
||||
//
|
||||
//There is something about stopping the _decoder if "we get a control code halfway a multi-byte sequence" (see below)
|
||||
//which hasn't been ported into the newer function (above). Hopefully someone who understands this better
|
||||
//can find an alternative way of handling the check.
|
||||
//can find an alternative way of handling the check.
|
||||
|
||||
|
||||
/*void Emulation::onRcvBlock(const char *s, int len)
|
||||
{
|
||||
emit notifySessionState(NOTIFYACTIVITY);
|
||||
|
||||
|
||||
bufferedUpdate();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
@@ -338,49 +341,52 @@ void Emulation::receiveData(const char* text, int length)
|
||||
// Selection --------------------------------------------------------------- --
|
||||
|
||||
#if 0
|
||||
void Emulation::onSelectionBegin(const int x, const int y, const bool columnmode) {
|
||||
if (!connected) return;
|
||||
_currentScreen->setSelectionStart( x,y,columnmode);
|
||||
showBulk();
|
||||
void Emulation::onSelectionBegin(const int x, const int y, const bool columnmode)
|
||||
{
|
||||
if (!connected) return;
|
||||
_currentScreen->setSelectionStart( x,y,columnmode);
|
||||
showBulk();
|
||||
}
|
||||
|
||||
void Emulation::onSelectionExtend(const int x, const int y) {
|
||||
if (!connected) return;
|
||||
_currentScreen->setSelectionEnd(x,y);
|
||||
showBulk();
|
||||
void Emulation::onSelectionExtend(const int x, const int y)
|
||||
{
|
||||
if (!connected) return;
|
||||
_currentScreen->setSelectionEnd(x,y);
|
||||
showBulk();
|
||||
}
|
||||
|
||||
void Emulation::setSelection(const bool preserve_line_breaks) {
|
||||
if (!connected) return;
|
||||
QString t = _currentScreen->selectedText(preserve_line_breaks);
|
||||
if (!t.isNull())
|
||||
{
|
||||
QListIterator< TerminalDisplay* > viewIter(_views);
|
||||
void Emulation::setSelection(const bool preserve_line_breaks)
|
||||
{
|
||||
if (!connected) return;
|
||||
QString t = _currentScreen->selectedText(preserve_line_breaks);
|
||||
if (!t.isNull()) {
|
||||
QListIterator< TerminalDisplay* > viewIter(_views);
|
||||
|
||||
while (viewIter.hasNext())
|
||||
viewIter.next()->setSelection(t);
|
||||
}
|
||||
while (viewIter.hasNext())
|
||||
viewIter.next()->setSelection(t);
|
||||
}
|
||||
}
|
||||
|
||||
void Emulation::testIsSelected(const int x, const int y, bool &selected)
|
||||
{
|
||||
if (!connected) return;
|
||||
selected=_currentScreen->isSelected(x,y);
|
||||
if (!connected) return;
|
||||
selected=_currentScreen->isSelected(x,y);
|
||||
}
|
||||
|
||||
void Emulation::clearSelection() {
|
||||
if (!connected) return;
|
||||
_currentScreen->clearSelection();
|
||||
showBulk();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Emulation::writeToStream( TerminalCharacterDecoder* _decoder ,
|
||||
int startLine ,
|
||||
int endLine)
|
||||
void Emulation::clearSelection()
|
||||
{
|
||||
_currentScreen->writeToStream(_decoder,startLine,endLine);
|
||||
if (!connected) return;
|
||||
_currentScreen->clearSelection();
|
||||
showBulk();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Emulation::writeToStream( TerminalCharacterDecoder* _decoder ,
|
||||
int startLine ,
|
||||
int endLine)
|
||||
{
|
||||
_currentScreen->writeToStream(_decoder,startLine,endLine);
|
||||
}
|
||||
|
||||
int Emulation::lineCount()
|
||||
@@ -409,44 +415,42 @@ void Emulation::showBulk()
|
||||
|
||||
void Emulation::bufferedUpdate()
|
||||
{
|
||||
_bulkTimer1.setSingleShot(true);
|
||||
_bulkTimer1.start(BULK_TIMEOUT1);
|
||||
if (!_bulkTimer2.isActive())
|
||||
{
|
||||
_bulkTimer2.setSingleShot(true);
|
||||
_bulkTimer2.start(BULK_TIMEOUT2);
|
||||
}
|
||||
_bulkTimer1.setSingleShot(true);
|
||||
_bulkTimer1.start(BULK_TIMEOUT1);
|
||||
if (!_bulkTimer2.isActive()) {
|
||||
_bulkTimer2.setSingleShot(true);
|
||||
_bulkTimer2.start(BULK_TIMEOUT2);
|
||||
}
|
||||
}
|
||||
|
||||
char Emulation::getErase() const
|
||||
{
|
||||
return '\b';
|
||||
return '\b';
|
||||
}
|
||||
|
||||
void Emulation::setImageSize(int lines, int columns)
|
||||
{
|
||||
//kDebug() << "Resizing image to: " << lines << "by" << columns << QTime::currentTime().msec();
|
||||
Q_ASSERT( lines > 0 );
|
||||
Q_ASSERT( columns > 0 );
|
||||
//kDebug() << "Resizing image to: " << lines << "by" << columns << QTime::currentTime().msec();
|
||||
Q_ASSERT( lines > 0 );
|
||||
Q_ASSERT( columns > 0 );
|
||||
|
||||
_screen[0]->resizeImage(lines,columns);
|
||||
_screen[1]->resizeImage(lines,columns);
|
||||
_screen[0]->resizeImage(lines,columns);
|
||||
_screen[1]->resizeImage(lines,columns);
|
||||
|
||||
emit imageSizeChanged(lines,columns);
|
||||
emit imageSizeChanged(lines,columns);
|
||||
|
||||
bufferedUpdate();
|
||||
bufferedUpdate();
|
||||
}
|
||||
|
||||
QSize Emulation::imageSize()
|
||||
{
|
||||
return QSize(_currentScreen->getColumns(), _currentScreen->getLines());
|
||||
return QSize(_currentScreen->getColumns(), _currentScreen->getLines());
|
||||
}
|
||||
|
||||
ushort ExtendedCharTable::extendedCharHash(ushort* unicodePoints , ushort length) const
|
||||
{
|
||||
ushort hash = 0;
|
||||
for ( ushort i = 0 ; i < length ; i++ )
|
||||
{
|
||||
for ( ushort i = 0 ; i < length ; i++ ) {
|
||||
hash = 31*hash + unicodePoints[i];
|
||||
}
|
||||
return hash;
|
||||
@@ -455,17 +459,16 @@ bool ExtendedCharTable::extendedCharMatch(ushort hash , ushort* unicodePoints ,
|
||||
{
|
||||
ushort* entry = extendedCharTable[hash];
|
||||
|
||||
// compare given length with stored sequence length ( given as the first ushort in the
|
||||
// stored buffer )
|
||||
if ( entry == 0 || entry[0] != length )
|
||||
return false;
|
||||
// compare given length with stored sequence length ( given as the first ushort in the
|
||||
// stored buffer )
|
||||
if ( entry == 0 || entry[0] != length )
|
||||
return false;
|
||||
// if the lengths match, each character must be checked. the stored buffer starts at
|
||||
// entry[1]
|
||||
for ( int i = 0 ; i < length ; i++ )
|
||||
{
|
||||
for ( int i = 0 ; i < length ; i++ ) {
|
||||
if ( entry[i+1] != unicodePoints[i] )
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
ushort ExtendedCharTable::createExtendedChar(ushort* unicodePoints , ushort length)
|
||||
@@ -474,30 +477,26 @@ ushort ExtendedCharTable::createExtendedChar(ushort* unicodePoints , ushort leng
|
||||
ushort hash = extendedCharHash(unicodePoints,length);
|
||||
|
||||
// check existing entry for match
|
||||
while ( extendedCharTable.contains(hash) )
|
||||
{
|
||||
if ( extendedCharMatch(hash,unicodePoints,length) )
|
||||
{
|
||||
// this sequence already has an entry in the table,
|
||||
while ( extendedCharTable.contains(hash) ) {
|
||||
if ( extendedCharMatch(hash,unicodePoints,length) ) {
|
||||
// this sequence already has an entry in the table,
|
||||
// return its hash
|
||||
return hash;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// if hash is already used by another, different sequence of unicode character
|
||||
// points then try next hash
|
||||
hash++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add the new sequence to the table and
|
||||
// return that index
|
||||
|
||||
// add the new sequence to the table and
|
||||
// return that index
|
||||
ushort* buffer = new ushort[length+1];
|
||||
buffer[0] = length;
|
||||
for ( int i = 0 ; i < length ; i++ )
|
||||
buffer[i+1] = unicodePoints[i];
|
||||
|
||||
buffer[i+1] = unicodePoints[i];
|
||||
|
||||
extendedCharTable.insert(hash,buffer);
|
||||
|
||||
return hash;
|
||||
@@ -509,13 +508,10 @@ ushort* ExtendedCharTable::lookupExtendedChar(ushort hash , ushort& length) cons
|
||||
// argument and return a pointer to the character sequence
|
||||
|
||||
ushort* buffer = extendedCharTable[hash];
|
||||
if ( buffer )
|
||||
{
|
||||
if ( buffer ) {
|
||||
length = buffer[0];
|
||||
return buffer+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
length = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -528,8 +524,7 @@ ExtendedCharTable::~ExtendedCharTable()
|
||||
{
|
||||
// free all allocated character buffers
|
||||
QHashIterator<ushort,ushort*> iter(extendedCharTable);
|
||||
while ( iter.hasNext() )
|
||||
{
|
||||
while ( iter.hasNext() ) {
|
||||
iter.next();
|
||||
delete[] iter.value();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user