Commit b7676178 authored by Kurt Hindenburg's avatar Kurt Hindenburg

uncrustify using kf5 config

parent 9bd78534
......@@ -39,29 +39,33 @@
using namespace Konsole;
KeyboardTranslatorWriter::KeyboardTranslatorWriter(QIODevice* destination)
: _destination(destination)
, _writer(0)
KeyboardTranslatorWriter::KeyboardTranslatorWriter(QIODevice *destination) :
_destination(destination),
_writer(0)
{
Q_ASSERT(destination && destination->isWritable());
_writer = new QTextStream(_destination);
}
KeyboardTranslatorWriter::~KeyboardTranslatorWriter()
{
delete _writer;
}
void KeyboardTranslatorWriter::writeHeader(const QString& description)
void KeyboardTranslatorWriter::writeHeader(const QString &description)
{
*_writer << "keyboard \"" << description << '\"' << '\n';
}
void KeyboardTranslatorWriter::writeEntry(const KeyboardTranslator::Entry& entry)
void KeyboardTranslatorWriter::writeEntry(const KeyboardTranslator::Entry &entry)
{
QString result;
if (entry.command() != KeyboardTranslator::NoCommand)
if (entry.command() != KeyboardTranslator::NoCommand) {
result = entry.resultToString();
else
} else {
result = QLatin1Char('\"') + entry.resultToString() + QLatin1Char('\"');
}
*_writer << "key " << entry.conditionToString() << " : " << result << '\n';
}
......@@ -85,17 +89,18 @@ void KeyboardTranslatorWriter::writeEntry(const KeyboardTranslator::Entry& entry
// already been removed)
//
KeyboardTranslatorReader::KeyboardTranslatorReader(QIODevice* source)
: _source(source)
, _description(QString())
, _nextEntry()
, _hasNext(false)
KeyboardTranslatorReader::KeyboardTranslatorReader(QIODevice *source) :
_source(source),
_description(QString()),
_nextEntry(),
_hasNext(false)
{
// read input until we find the description
while (_description.isEmpty() && !source->atEnd()) {
QList<Token> tokens = tokenize(QString::fromLocal8Bit(source->readLine()));
if (!tokens.isEmpty() && tokens.first().type == Token::TitleKeyword)
if (!tokens.isEmpty() && tokens.first().type == Token::TitleKeyword) {
_description = i18n(tokens[1].text.toUtf8().constData());
}
}
// read first entry (if any)
readNext();
......@@ -107,7 +112,7 @@ void KeyboardTranslatorReader::readNext()
{
// find next entry
while (!_source->atEnd()) {
const QList<Token>& tokens = tokenize(QString::fromLocal8Bit(_source->readLine()));
const QList<Token> &tokens = tokenize(QString::fromLocal8Bit(_source->readLine()));
if (!tokens.isEmpty() && tokens.first().type == Token::KeyKeyword) {
KeyboardTranslator::States flags = KeyboardTranslator::NoState;
KeyboardTranslator::States flagMask = KeyboardTranslator::NoState;
......@@ -131,8 +136,10 @@ void KeyboardTranslatorReader::readNext()
text = tokens[2].text.toLocal8Bit();
} else if (tokens[2].type == Token::Command) {
// identify command
if (!parseAsCommand(tokens[2].text, command))
qCDebug(KonsoleDebug) << "Key" << tokens[1].text << ", Command" << tokens[2].text << "not understood. ";
if (!parseAsCommand(tokens[2].text, command)) {
qCDebug(KonsoleDebug) << "Key" << tokens[1].text << ", Command"
<< tokens[2].text << "not understood. ";
}
}
KeyboardTranslator::Entry newEntry;
......@@ -155,34 +162,35 @@ void KeyboardTranslatorReader::readNext()
_hasNext = false;
}
bool KeyboardTranslatorReader::parseAsCommand(const QString& text, KeyboardTranslator::Command& command)
bool KeyboardTranslatorReader::parseAsCommand(const QString &text,
KeyboardTranslator::Command &command)
{
if (text.compare(QLatin1String("erase"), Qt::CaseInsensitive) == 0)
if (text.compare(QLatin1String("erase"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::EraseCommand;
else if (text.compare(QLatin1String("scrollpageup"), Qt::CaseInsensitive) == 0)
} else if (text.compare(QLatin1String("scrollpageup"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollPageUpCommand;
else if (text.compare(QLatin1String("scrollpagedown"), Qt::CaseInsensitive) == 0)
} else if (text.compare(QLatin1String("scrollpagedown"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollPageDownCommand;
else if (text.compare(QLatin1String("scrolllineup"), Qt::CaseInsensitive) == 0)
} else if (text.compare(QLatin1String("scrolllineup"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollLineUpCommand;
else if (text.compare(QLatin1String("scrolllinedown"), Qt::CaseInsensitive) == 0)
} else if (text.compare(QLatin1String("scrolllinedown"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollLineDownCommand;
else if (text.compare(QLatin1String("scrolluptotop"), Qt::CaseInsensitive) == 0)
} else if (text.compare(QLatin1String("scrolluptotop"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollUpToTopCommand;
else if (text.compare(QLatin1String("scrolldowntobottom"), Qt::CaseInsensitive) == 0)
} else if (text.compare(QLatin1String("scrolldowntobottom"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollDownToBottomCommand;
else
} else {
return false;
}
return true;
}
bool KeyboardTranslatorReader::decodeSequence(const QString& text,
int& keyCode,
Qt::KeyboardModifiers& modifiers,
Qt::KeyboardModifiers& modifierMask,
KeyboardTranslator::States& flags,
KeyboardTranslator::States& flagMask)
bool KeyboardTranslatorReader::decodeSequence(const QString &text, int &keyCode,
Qt::KeyboardModifiers &modifiers,
Qt::KeyboardModifiers &modifierMask,
KeyboardTranslator::States &flags,
KeyboardTranslator::States &flagMask)
{
bool isWanted = true;
QString buffer;
......@@ -192,8 +200,8 @@ bool KeyboardTranslatorReader::decodeSequence(const QString& text,
KeyboardTranslator::States tempFlags = flags;
KeyboardTranslator::States tempFlagMask = flagMask;
for (int i = 0 ; i < text.count() ; i++) {
const QChar& ch = text[i];
for (int i = 0; i < text.count(); i++) {
const QChar &ch = text[i];
const bool isFirstLetter = (i == 0);
const bool isLastLetter = (i == text.count() - 1);
bool endOfItem = true;
......@@ -212,13 +220,15 @@ bool KeyboardTranslatorReader::decodeSequence(const QString& text,
if (parseAsModifier(buffer, itemModifier)) {
tempModifierMask |= itemModifier;
if (isWanted)
if (isWanted) {
tempModifiers |= itemModifier;
}
} else if (parseAsStateFlag(buffer, itemFlag)) {
tempFlagMask |= itemFlag;
if (isWanted)
if (isWanted) {
tempFlags |= itemFlag;
}
} else if (parseAsKeyCode(buffer, itemKeyCode)) {
keyCode = itemKeyCode;
} else {
......@@ -230,10 +240,11 @@ bool KeyboardTranslatorReader::decodeSequence(const QString& text,
// check if this is a wanted / not-wanted flag and update the
// state ready for the next item
if (ch == QLatin1Char('+'))
if (ch == QLatin1Char('+')) {
isWanted = true;
else if (ch == QLatin1Char('-'))
} else if (ch == QLatin1Char('-')) {
isWanted = false;
}
}
modifiers = tempModifiers;
......@@ -244,43 +255,48 @@ bool KeyboardTranslatorReader::decodeSequence(const QString& text,
return true;
}
bool KeyboardTranslatorReader::parseAsModifier(const QString& item , Qt::KeyboardModifier& modifier)
bool KeyboardTranslatorReader::parseAsModifier(const QString &item, Qt::KeyboardModifier &modifier)
{
if (item == QLatin1String("shift"))
if (item == QLatin1String("shift")) {
modifier = Qt::ShiftModifier;
else if (item == QLatin1String("ctrl") || item == QLatin1String("control"))
} else if (item == QLatin1String("ctrl") || item == QLatin1String("control")) {
modifier = Qt::ControlModifier;
else if (item == QLatin1String("alt"))
} else if (item == QLatin1String("alt")) {
modifier = Qt::AltModifier;
else if (item == QLatin1String("meta"))
} else if (item == QLatin1String("meta")) {
modifier = Qt::MetaModifier;
else if (item == QLatin1String("keypad"))
} else if (item == QLatin1String("keypad")) {
modifier = Qt::KeypadModifier;
else
} else {
return false;
}
return true;
}
bool KeyboardTranslatorReader::parseAsStateFlag(const QString& item , KeyboardTranslator::State& flag)
bool KeyboardTranslatorReader::parseAsStateFlag(const QString &item,
KeyboardTranslator::State &flag)
{
if (item == QLatin1String("appcukeys") || item == QLatin1String("appcursorkeys"))
if (item == QLatin1String("appcukeys") || item == QLatin1String("appcursorkeys")) {
flag = KeyboardTranslator::CursorKeysState;
else if (item == QLatin1String("ansi"))
} else if (item == QLatin1String("ansi")) {
flag = KeyboardTranslator::AnsiState;
else if (item == QLatin1String("newline"))
} else if (item == QLatin1String("newline")) {
flag = KeyboardTranslator::NewLineState;
else if (item == QLatin1String("appscreen"))
} else if (item == QLatin1String("appscreen")) {
flag = KeyboardTranslator::AlternateScreenState;
else if (item == QLatin1String("anymod") || item == QLatin1String("anymodifier"))
} else if (item == QLatin1String("anymod") || item == QLatin1String("anymodifier")) {
flag = KeyboardTranslator::AnyModifierState;
else if (item == QLatin1String("appkeypad"))
} else if (item == QLatin1String("appkeypad")) {
flag = KeyboardTranslator::ApplicationKeypadState;
else
} else {
return false;
}
return true;
}
bool KeyboardTranslatorReader::parseAsKeyCode(const QString& item , int& keyCode)
bool KeyboardTranslatorReader::parseAsKeyCode(const QString &item, int &keyCode)
{
QKeySequence sequence = QKeySequence::fromString(item);
if (!sequence.isEmpty()) {
......@@ -300,12 +316,14 @@ QString KeyboardTranslatorReader::description() const
{
return _description;
}
bool KeyboardTranslatorReader::hasNextEntry()
{
return _hasNext;
}
KeyboardTranslator::Entry KeyboardTranslatorReader::createEntry(const QString& condition ,
const QString& result)
KeyboardTranslator::Entry KeyboardTranslatorReader::createEntry(const QString &condition,
const QString &result)
{
QString entryString(QStringLiteral("keyboard \"temporary\"\nkey "));
entryString.append(condition);
......@@ -315,10 +333,11 @@ KeyboardTranslator::Entry KeyboardTranslatorReader::createEntry(const QString& c
// otherwise the result will be treated as a string to echo when the key sequence
// specified by 'condition' is pressed
KeyboardTranslator::Command command;
if (parseAsCommand(result, command))
if (parseAsCommand(result, command)) {
entryString.append(result);
else
} else {
entryString.append(QLatin1Char('\"') + result + QLatin1Char('\"'));
}
QByteArray array = entryString.toUtf8();
QBuffer buffer(&array);
......@@ -326,8 +345,9 @@ KeyboardTranslator::Entry KeyboardTranslatorReader::createEntry(const QString& c
KeyboardTranslatorReader reader(&buffer);
KeyboardTranslator::Entry entry;
if (reader.hasNextEntry())
if (reader.hasNextEntry()) {
entry = reader.nextEntry();
}
return entry;
}
......@@ -339,11 +359,13 @@ KeyboardTranslator::Entry KeyboardTranslatorReader::nextEntry()
readNext();
return entry;
}
bool KeyboardTranslatorReader::parseError()
{
return false;
}
QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const QString& line)
QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const QString &line)
{
QString text = line;
......@@ -352,21 +374,25 @@ QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const
int commentPos = -1;
for (int i = text.length() - 1; i >= 0; i--) {
QChar ch = text[i];
if (ch == QLatin1Char('\"'))
if (ch == QLatin1Char('\"')) {
inQuotes = !inQuotes;
else if (ch == QLatin1Char('#') && !inQuotes)
} else if (ch == QLatin1Char('#') && !inQuotes) {
commentPos = i;
}
}
if (commentPos != -1)
if (commentPos != -1) {
text.remove(commentPos, text.length());
}
text = text.simplified();
// title line: keyboard "title"
static const QRegularExpression title(QStringLiteral("keyboard\\s+\"(.*)\""), QRegularExpression::OptimizeOnFirstUsageOption);
static const QRegularExpression title(QStringLiteral("keyboard\\s+\"(.*)\""),
QRegularExpression::OptimizeOnFirstUsageOption);
// key line: key KeySequence : "output"
// key line: key KeySequence : command
static const QRegularExpression key(QStringLiteral("key\\s+([\\w\\+\\s\\-\\*\\.]+)\\s*:\\s*(\"(.*)\"|\\w+)"), QRegularExpression::OptimizeOnFirstUsageOption);
static const QRegularExpression key(QStringLiteral("key\\s+([\\w\\+\\s\\-\\*\\.]+)\\s*:\\s*(\"(.*)\"|\\w+)"),
QRegularExpression::OptimizeOnFirstUsageOption);
QList<Token> list;
if (text.isEmpty()) {
......@@ -376,8 +402,8 @@ QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const
QRegularExpressionMatch titleMatch(title.match(text));
if (titleMatch.hasMatch()) {
Token titleToken = { Token::TitleKeyword , QString() };
Token textToken = { Token::TitleText , titleMatch.captured(1) };
Token titleToken = { Token::TitleKeyword, QString() };
Token textToken = { Token::TitleText, titleMatch.captured(1) };
list << titleToken << textToken;
return list;
......@@ -385,101 +411,121 @@ QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const
QRegularExpressionMatch keyMatch(key.match(text));
if (!keyMatch.hasMatch()) {
qCDebug(KonsoleDebug) << "Line in keyboard translator file could not be understood:" << text;
qCDebug(KonsoleDebug) << "Line in keyboard translator file could not be understood:"
<< text;
return list;
}
Token keyToken = { Token::KeyKeyword , QString() };
Token keyToken = { Token::KeyKeyword, QString() };
QString sequenceTokenString = keyMatch.captured(1);
Token sequenceToken = { Token::KeySequence , sequenceTokenString.remove(QLatin1Char(' ')) };
Token sequenceToken = { Token::KeySequence, sequenceTokenString.remove(QLatin1Char(' ')) };
list << keyToken << sequenceToken;
if (keyMatch.capturedRef(3).isEmpty()) {
// capturedTexts().at(2) is a command
Token commandToken = { Token::Command , keyMatch.captured(2) };
Token commandToken = { Token::Command, keyMatch.captured(2) };
list << commandToken;
} else {
// capturedTexts().at(3) is the output string
Token outputToken = { Token::OutputText , keyMatch.captured(3) };
Token outputToken = { Token::OutputText, keyMatch.captured(3) };
list << outputToken;
}
return list;
}
KeyboardTranslator::Entry::Entry()
: _keyCode(0)
, _modifiers(Qt::NoModifier)
, _modifierMask(Qt::NoModifier)
, _state(NoState)
, _stateMask(NoState)
, _command(NoCommand)
, _text(QByteArray())
KeyboardTranslator::Entry::Entry() :
_keyCode(0),
_modifiers(Qt::NoModifier),
_modifierMask(Qt::NoModifier),
_state(NoState),
_stateMask(NoState),
_command(NoCommand),
_text(QByteArray())
{
}
bool KeyboardTranslator::Entry::operator==(const Entry& rhs) const
bool KeyboardTranslator::Entry::operator==(const Entry &rhs) const
{
return _keyCode == rhs._keyCode &&
_modifiers == rhs._modifiers &&
_modifierMask == rhs._modifierMask &&
_state == rhs._state &&
_stateMask == rhs._stateMask &&
_command == rhs._command &&
_text == rhs._text;
return _keyCode == rhs._keyCode
&& _modifiers == rhs._modifiers
&& _modifierMask == rhs._modifierMask
&& _state == rhs._state
&& _stateMask == rhs._stateMask
&& _command == rhs._command
&& _text == rhs._text;
}
bool KeyboardTranslator::Entry::matches(int testKeyCode,
Qt::KeyboardModifiers testKeyboardModifiers,
States testState) const
{
if (_keyCode != testKeyCode)
if (_keyCode != testKeyCode) {
return false;
}
if ((testKeyboardModifiers & _modifierMask) != (_modifiers & _modifierMask))
if ((testKeyboardModifiers & _modifierMask) != (_modifiers & _modifierMask)) {
return false;
}
// if testKeyboardModifiers is non-zero, the 'any modifier' state is implicit
if (testKeyboardModifiers != 0)
if (testKeyboardModifiers != 0) {
testState |= AnyModifierState;
}
if ((testState & _stateMask) != (_state & _stateMask))
if ((testState & _stateMask) != (_state & _stateMask)) {
return false;
}
// special handling for the 'Any Modifier' state, which checks for the presence of
// any or no modifiers. In this context, the 'keypad' modifier does not count.
bool anyModifiersSet = (testKeyboardModifiers != 0)
&& (testKeyboardModifiers != Qt::KeypadModifier);
bool wantAnyModifier = (_state & KeyboardTranslator::AnyModifierState) != 0;
if ((_stateMask & KeyboardTranslator::AnyModifierState) != 0) {
if (wantAnyModifier != anyModifiersSet)
bool wantAnyModifier = (_state &KeyboardTranslator::AnyModifierState) != 0;
if ((_stateMask &KeyboardTranslator::AnyModifierState) != 0) {
if (wantAnyModifier != anyModifiersSet) {
return false;
}
}
return true;
}
QByteArray KeyboardTranslator::Entry::escapedText(bool expandWildCards,
Qt::KeyboardModifiers keyboardModifiers) const
Qt::KeyboardModifiers keyboardModifiers) const
{
QByteArray result(text(expandWildCards, keyboardModifiers));
for (int i = 0 ; i < result.count() ; i++) {
for (int i = 0; i < result.count(); i++) {
const char ch = result[i];
char replacement = 0;
switch (ch) {
case 27 : replacement = 'E'; break;
case 8 : replacement = 'b'; break;
case 12 : replacement = 'f'; break;
case 9 : replacement = 't'; break;
case 13 : replacement = 'r'; break;
case 10 : replacement = 'n'; break;
case 27:
replacement = 'E';
break;
case 8:
replacement = 'b';
break;
case 12:
replacement = 'f';
break;
case 9:
replacement = 't';
break;
case 13:
replacement = 'r';
break;
case 10:
replacement = 'n';
break;
default:
// any character which is not printable is replaced by an equivalent
// \xhh escape sequence (where 'hh' are the corresponding hex digits)
if (!QChar(QLatin1Char(ch)).isPrint())
if (!QChar(QLatin1Char(ch)).isPrint()) {
replacement = 'x';
}
}
if (replacement == 'x') {
......@@ -493,11 +539,12 @@ QByteArray KeyboardTranslator::Entry::escapedText(bool expandWildCards,
return result;
}
QByteArray KeyboardTranslator::Entry::unescape(const QByteArray& input) const
QByteArray KeyboardTranslator::Entry::unescape(const QByteArray &input) const
{
QByteArray result(input);
for (int i = 0 ; i < result.count() - 1 ; i++) {
for (int i = 0; i < result.count() - 1; i++) {
QByteRef ch = result[i];
if (ch == '\\') {
char replacement[2] = {0, 0};
......@@ -505,137 +552,163 @@ QByteArray KeyboardTranslator::Entry::unescape(const QByteArray& input) const
bool escapedChar = true;
switch (result[i + 1]) {
case 'E' : replacement[0] = 27; break;
case 'b' : replacement[0] = 8 ; break;
case 'f' : replacement[0] = 12; break;
case 't' : replacement[0] = 9 ; break;
case 'r' : replacement[0] = 13; break;
case 'n' : replacement[0] = 10; break;
case 'x' : {
case 'E':
replacement[0] = 27;
break;
case 'b':
replacement[0] = 8;
break;
case 'f':
replacement[0] = 12;
break;
case 't':
replacement[0] = 9;
break;
case 'r':
replacement[0] = 13;
break;
case 'n':
replacement[0] = 10;
break;
case 'x':
{
// format is \xh or \xhh where 'h' is a hexadecimal
// digit from 0-9 or A-F which should be replaced
// with the corresponding character value
char hexDigits[3] = {0};
if ((i < result.count() - 2) && (isxdigit(result[i + 2]) != 0))
if ((i < result.count() - 2) && (isxdigit(result[i + 2]) != 0)) {
hexDigits[0] = result[i + 2];
if ((i < result.count() - 3) && (isxdigit(result[i + 3]) != 0))
}
if ((i < result.count() - 3) && (isxdigit(result[i + 3]) != 0)) {
hexDigits[1] = result[i + 3];
}
unsigned charValue = 0;
sscanf(hexDigits, "%2x", &charValue);
replacement[0] = static_cast<char>(charValue);
charsToRemove = 2 + qstrlen(hexDigits);
break;
}
break;
default:
escapedChar = false;
}
if (escapedChar)
result.replace(i, charsToRemove, replacement, 1);
if (escapedChar) {
result.replace(i, charsToRemove, replacement, 1);
}
}
}
return result;
}
void KeyboardTranslator::Entry::insertModifier(QString& item , int modifier) const
void KeyboardTranslator::Entry::insertModifier(QString &item, int modifier) const
{
if ((modifier & _modifierMask) == 0u)
if ((modifier & _modifierMask) == 0u) {
return;
}
if ((modifier & _modifiers) != 0u)
if ((modifier & _modifiers) != 0u) {
item += QLatin1Char('+');
else
} else {
item += QLatin1Char('-');
}
if (modifier == Qt::ShiftModifier)
if (modifier == Qt::ShiftModifier) {
item += QLatin1String("Shift");
else if (modifier == Qt::ControlModifier)
} else if (modifier == Qt::ControlModifier) {
item += QLatin1String("Ctrl");
else if (modifier == Qt::AltModifier)
} else if (modifier == Qt::AltModifier) {
item += QLatin1String("Alt");
else if (modifier == Qt::MetaModifier)
} else if (modifier == Qt::MetaModifier) {
item += QLatin1String("Meta");
else if (modifier == Qt::KeypadModifier)