summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bishop <erroneous@gmail.com>2016-10-27 17:10:19 (GMT)
committerAlex Richardson <arichardson.kde@gmail.com>2016-10-27 17:15:04 (GMT)
commitb455b93cb15fb3af078c48e70f326aa6efe6275e (patch)
tree9241100534143b2e554e2e120ea402f2239aa52a
parent1c5821e0322ed4c593f882b45265725d06ecd2ac (diff)
add encoding="ebcdic" to string structures
fix bug 367863 structures string encoding ebcdic Testing Done: builds, tested example from bug 367863 and it behaves as expected. ctest passes 100% of 54 tests. I only added one test condition to commonparsertest. BUG: 367863 REVIEW: 128795
-rw-r--r--kasten/controllers/CMakeLists.txt2
-rw-r--r--kasten/controllers/test/commonparsertest.cpp2
-rw-r--r--kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.cpp160
-rw-r--r--kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.h55
-rw-r--r--kasten/controllers/view/structures/datatypes/strings/stringdatainformation.cpp5
-rw-r--r--kasten/controllers/view/structures/datatypes/strings/stringdatainformation.h5
-rw-r--r--kasten/controllers/view/structures/parsers/parserutils.cpp3
7 files changed, 230 insertions, 2 deletions
diff --git a/kasten/controllers/CMakeLists.txt b/kasten/controllers/CMakeLists.txt
index 5f98ea7..d26ad38 100644
--- a/kasten/controllers/CMakeLists.txt
+++ b/kasten/controllers/CMakeLists.txt
@@ -374,6 +374,8 @@ set( STRUCTVIEW_TESTED_SRCS
view/structures/datatypes/strings/utf8stringdata.cpp
view/structures/datatypes/strings/utf16stringdata.cpp
view/structures/datatypes/strings/utf32stringdata.cpp
+ view/structures/datatypes/strings/ebcdicstringdata.cpp
+ ../../core/codecs/ebcdic1047charcodec.cpp
view/structures/script/scriptengineinitializer.cpp
view/structures/script/scripthandler.cpp
view/structures/script/scripthandlerinfo.cpp
diff --git a/kasten/controllers/test/commonparsertest.cpp b/kasten/controllers/test/commonparsertest.cpp
index cffaffc..e30dc3b 100644
--- a/kasten/controllers/test/commonparsertest.cpp
+++ b/kasten/controllers/test/commonparsertest.cpp
@@ -2,6 +2,7 @@
* This file is part of the Okteta Kasten Framework, made within the KDE community.
*
* Copyright 2012 Alex Richardson <alex.richardson@gmx.de>
+ * Copyright 2016 Aaron Bishop <erroneous@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -269,6 +270,7 @@ inline void CommonParserTest::testToStringEncoding_data()
QTest::addColumn<int>("expected");
QTest::newRow("ascii") << "ascii" << (int)StringDataInformation::ASCII;
+ QTest::newRow("ebcdic") << "ebcdic" << (int)StringDataInformation::EBCDIC;
QTest::newRow("ascii upper") << "ASCII" << (int)StringDataInformation::ASCII;
QTest::newRow("excess char") << "asciii" << (int)StringDataInformation::InvalidEncoding;
diff --git a/kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.cpp b/kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.cpp
new file mode 100644
index 0000000..7c9f766
--- /dev/null
+++ b/kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.cpp
@@ -0,0 +1,160 @@
+/*
+ * This file is part of the Okteta Kasten Framework, made within the KDE community.
+ *
+ * Copyright 2011 Alex Richardson <alex.richardson@gmx.de>
+ * Copyright 2016 Aaron Bishop <erroneous@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3, or any
+ * later version accepted by the membership of KDE e.V. (or its
+ * successor approved by the membership of KDE e.V.), which shall
+ * act as a proxy defined in Section 6 of version 3 of the license.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "ebcdicstringdata.h"
+#include "stringdatainformation.h"
+#include "../topleveldatainformation.h"
+#include "../../structlogging.h"
+
+#include <character.h>
+#include <codecs/ebcdic1047charcodec.h>
+#include <okteta/abstractbytearraymodel.h>
+
+#include <KLocalizedString>
+#include <QVarLengthArray>
+
+
+EbcdicStringData::EbcdicStringData(StringDataInformation* parent): StringData(parent), mCodec(Okteta::EBCDIC1047CharCodec::create())
+{
+}
+
+EbcdicStringData::~EbcdicStringData()
+{
+ delete mCodec;
+}
+
+qint64 EbcdicStringData::read(Okteta::AbstractByteArrayModel* input, Okteta::Address address, BitCount64 bitsRemaining)
+{
+ const int oldSize = count();
+ if (mMode == CharCount || mMode == ByteCount) //same for ebcdic
+ {
+ mData.reserve(mLength.maxChars);
+ }
+ mParent->topLevelDataInformation()->_childCountAboutToChange(mParent, oldSize, 0);
+ mParent->topLevelDataInformation()->_childCountChanged(mParent, oldSize, 0);
+
+
+ quint64 remaining = bitsRemaining;
+ Okteta::Address addr = address;
+ int count = 0;
+ mEofReached = false;
+ const int oldMax = mData.size();
+ if (((mMode & CharCount) && mLength.maxChars == 0) || ((mMode & ByteCount) && mLength.maxBytes == 0))
+ return 0; //nothing to read
+
+ bool eofAtStart = false;
+ if (bitsRemaining < 8)
+ eofAtStart = true;
+
+ while (true)
+ {
+ if (remaining < 8)
+ {
+ mEofReached = true;
+ break;
+ }
+ uchar val = input->byte(addr);
+ bool terminate = false;
+
+ if (count < oldMax)
+ mData[count] = val;
+ else
+ mData.append(val);
+
+ remaining -= 8;
+ addr++;
+ count++;
+
+ //now check if we have to terminate
+ if (mMode & Sequence)
+ {
+ if ((quint32(val) & 0xff) == mTerminationCodePoint)
+ terminate = true;
+ }
+ if ((mMode & CharCount) || (mMode & ByteCount))
+ {
+ if ((unsigned)count >= mLength.maxChars)
+ terminate = true;
+ }
+ if (mMode == None) {
+ qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "no termination mode set!!";
+ Q_ASSERT(false);
+ }
+ if (terminate)
+ break;
+ }
+
+ mData.resize(count);
+ mParent->topLevelDataInformation()->_childCountAboutToChange(mParent, 0, count);
+ mParent->topLevelDataInformation()->_childCountChanged(mParent, 0, count);
+
+ if (eofAtStart)
+ return -1;
+ return (addr - address) * 8;
+}
+
+BitCount32 EbcdicStringData::sizeAt(uint i) const
+{
+ Q_ASSERT(i < count());
+ Q_UNUSED(i)
+ return 8;
+}
+
+BitCount32 EbcdicStringData::size() const
+{
+ return mData.size() * 8;
+}
+
+QString EbcdicStringData::completeString(bool) const
+{
+ int max = mData.size();
+ QVarLengthArray<QChar> buf(max);
+ for (int i = 0; i < max; ++i) {
+ uchar val = mData.at(i);
+ buf[i] = mCodec->decode(val);
+ }
+ return QString(buf.constData(), max);
+}
+
+QString EbcdicStringData::stringValue(int row) const
+{
+ Q_ASSERT(row >= 0 && row < mData.size());
+ uchar val = mData.at(row);
+ return mCodec->decode(val);
+}
+
+QString EbcdicStringData::charType() const
+{
+ return i18n("EBCDIC char");
+}
+
+uint EbcdicStringData::count() const
+{
+ return mData.size();
+}
+
+QString EbcdicStringData::typeName() const
+{
+ return i18n("EBCDIC string");
+}
diff --git a/kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.h b/kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.h
new file mode 100644
index 0000000..4d30a91
--- /dev/null
+++ b/kasten/controllers/view/structures/datatypes/strings/ebcdicstringdata.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the Okteta Kasten Framework, made within the KDE community.
+ *
+ * Copyright 2011 Alex Richardson <alex.richardson@gmx.de>
+ * Copyright 2016 Aaron Bishop <erroneous@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3, or any
+ * later version accepted by the membership of KDE e.V. (or its
+ * successor approved by the membership of KDE e.V.), which shall
+ * act as a proxy defined in Section 6 of version 3 of the license.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#ifndef EBCDICSTRINGDATA_H
+#define EBCDICSTRINGDATA_H
+
+#include "stringdata.h"
+
+#include <QVector>
+
+namespace Okteta { class CharCodec; }
+
+class EbcdicStringData : public StringData
+{
+public:
+ explicit EbcdicStringData(StringDataInformation* parent);
+ virtual ~EbcdicStringData();
+
+ virtual qint64 read(Okteta::AbstractByteArrayModel* input, Okteta::Address address, BitCount64 bitsRemaining);
+ virtual BitCount32 sizeAt(uint i) const;
+ virtual BitCount32 size() const;
+ virtual QString completeString(bool skipInvalid = false) const;
+ virtual QString stringValue(int row) const;
+ virtual QString charType() const;
+ virtual uint count() const;
+ virtual QString typeName() const;
+
+private:
+ QVector<quint8> mData;
+ Okteta::CharCodec* mCodec;
+};
+
+#endif // EBCDICSTRINGDATA_H
diff --git a/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.cpp b/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.cpp
index 63b12b9..bcc966e 100644
--- a/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.cpp
+++ b/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.cpp
@@ -2,6 +2,7 @@
* This file is part of the Okteta Kasten Framework, made within the KDE community.
*
* Copyright 2011, 2012 Alex Richardson <alex.richardson@gmx.de>
+ * Copyright 2016 Aaron Bishop <erroneous@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -29,6 +30,7 @@
#include "utf16stringdata.h"
#include "utf8stringdata.h"
#include "asciistringdata.h"
+#include "ebcdicstringdata.h"
#include "latin1stringdata.h"
#include "../../script/classes/stringscriptclass.h"
#include "../../script/scripthandlerinfo.h"
@@ -223,6 +225,9 @@ void StringDataInformation::setEncoding(StringDataInformation::StringType encodi
data = new Utf32StringData(this);
data->setLittleEndian(false);
break;
+ case EBCDIC:
+ data = new EbcdicStringData(this);
+ break;
default:
data = new AsciiStringData(this); //TODO add the other classes
break;
diff --git a/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.h b/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.h
index 1f0f07d..64b0072 100644
--- a/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.h
+++ b/kasten/controllers/view/structures/datatypes/strings/stringdatainformation.h
@@ -2,6 +2,7 @@
* This file is part of the Okteta Kasten Framework, made within the KDE community.
*
* Copyright 2011 Alex Richardson <alex.richardson@gmx.de>
+ * Copyright 2016 Aaron Bishop <erroneous@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -34,7 +35,7 @@ class DummyDataInformation;
//TODO QStringLiteral
const QLatin1String stringEncodings[] = {
QLatin1String("ascii"), QLatin1String("latin1"), QLatin1String("utf-8"), QLatin1String("utf-16le"),
- QLatin1String("utf-16-be"), QLatin1String("utf32-le"), QLatin1String("utf32-be")
+ QLatin1String("utf-16-be"), QLatin1String("utf32-le"), QLatin1String("utf32-be"), QLatin1String("ebcdic")
};
class StringDataInformation : public DataInformationWithDummyChildren
@@ -42,7 +43,7 @@ class StringDataInformation : public DataInformationWithDummyChildren
DATAINFORMATION_CLONE_DECL(StringDataInformation, DataInformationWithDummyChildren);
public:
enum StringType {
- InvalidEncoding = -1, ASCII = 0, Latin1, UTF8, UTF16_LE, UTF16_BE, UTF32_LE, UTF32_BE
+ InvalidEncoding = -1, ASCII = 0, Latin1, UTF8, UTF16_LE, UTF16_BE, UTF32_LE, UTF32_BE, EBCDIC
};
StringDataInformation(const QString& name, StringType encoding, DataInformationBase* parent = 0);
diff --git a/kasten/controllers/view/structures/parsers/parserutils.cpp b/kasten/controllers/view/structures/parsers/parserutils.cpp
index 9b8bb1d..94f54af 100644
--- a/kasten/controllers/view/structures/parsers/parserutils.cpp
+++ b/kasten/controllers/view/structures/parsers/parserutils.cpp
@@ -2,6 +2,7 @@
* This file is part of the Okteta Kasten Framework, made within the KDE community.
*
* Copyright 2012 Alex Richardson <alex.richardson@gmx.de>
+ * Copyright 2016 Aaron Bishop <erroneous@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -150,6 +151,8 @@ StringDataInformation::StringType ParserUtils::toStringEncoding(const QString& s
QString enc = str.toLower();
if (enc == QStringLiteral("ascii"))
return StringDataInformation::ASCII;
+ else if (enc == QStringLiteral("ebcdic"))
+ return StringDataInformation::EBCDIC;
else if (enc == QStringLiteral("latin1") || enc == QStringLiteral("latin-1"))
return StringDataInformation::Latin1;
else if (enc.startsWith(QStringLiteral("utf")))