diff --git a/CHANGELOG.md b/CHANGELOG.md index 82aa6fd..f309fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ============ +## 0.0.93 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-297, IBM-290, IBM-285, IBM-284, IBM-280, IBM-278, IBM-277 + ## 0.0.92 - Implemented: diff --git a/CMakeLists.txt b/CMakeLists.txt index cf84e5a..87f3d54 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,20 @@ set(PROJECT_SOURCES src/encoding/interpret_as_ibm_424.h src/encoding/interpret_as_ibm_420.cpp src/encoding/interpret_as_ibm_420.h + src/encoding/interpret_as_ibm_297.cpp + src/encoding/interpret_as_ibm_297.h + src/encoding/interpret_as_ibm_290.cpp + src/encoding/interpret_as_ibm_290.h + src/encoding/interpret_as_ibm_285.cpp + src/encoding/interpret_as_ibm_285.h + src/encoding/interpret_as_ibm_284.cpp + src/encoding/interpret_as_ibm_284.h + src/encoding/interpret_as_ibm_280.cpp + src/encoding/interpret_as_ibm_280.h + src/encoding/interpret_as_ibm_278.cpp + src/encoding/interpret_as_ibm_278.h + src/encoding/interpret_as_ibm_277.cpp + src/encoding/interpret_as_ibm_277.h ${PROJECT_UI} ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index fe6fd12..054c700 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -103,12 +103,12 @@ 2 false - -DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DCMAKE_BUILD_TYPE:STRING=Debug + -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} /data/Code/Qt/Notepad-- diff --git a/src/encoding/interpret_as_dialog.cpp b/src/encoding/interpret_as_dialog.cpp index 9c7339b..1c4b447 100644 --- a/src/encoding/interpret_as_dialog.cpp +++ b/src/encoding/interpret_as_dialog.cpp @@ -65,7 +65,13 @@ InterpreteAsDialog::InterpreteAsDialog(QWidget* parent) "IBM-500", "IBM-437", "IBM-424", - "IBM-420" + "IBM-420", + "IBM-297", + "IBM-290", + "IBM-285", + "IBM-284", + "IBM-278", + "IBM-277" }); // Create OK and Cancel buttons using QDialogButtonBox diff --git a/src/encoding/interpret_as_ibm_277.cpp b/src/encoding/interpret_as_ibm_277.cpp new file mode 100644 index 0000000..a84944e --- /dev/null +++ b/src/encoding/interpret_as_ibm_277.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_277.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_277& Interpret_As_IBM_277::instance() { + static Interpret_As_IBM_277 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-277 (Danish/Norwegian EBCDIC) +const std::unordered_map Interpret_As_IBM_277::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E6)}, // æ + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F8)}, // ø + {0x90, QChar(0x00E5)}, // å + {0xA4, QChar(0x00E9)}, // é + {0xA7, QChar(0x00FC)}, // ü +}; + +// Constructor +Interpret_As_IBM_277::Interpret_As_IBM_277() {} + +// Main execution function +void Interpret_As_IBM_277::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM277(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-277 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-277 encoding +QString Interpret_As_IBM_277::decodeIBM277(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_277.h b/src/encoding/interpret_as_ibm_277.h new file mode 100644 index 0000000..595adac --- /dev/null +++ b/src/encoding/interpret_as_ibm_277.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_277 { +public: + static Interpret_As_IBM_277& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_277(); + ~Interpret_As_IBM_277() = default; + + Interpret_As_IBM_277(const Interpret_As_IBM_277&) = delete; + Interpret_As_IBM_277& operator=(const Interpret_As_IBM_277&) = delete; + + QString decodeIBM277(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_278.cpp b/src/encoding/interpret_as_ibm_278.cpp new file mode 100644 index 0000000..d1e2c4c --- /dev/null +++ b/src/encoding/interpret_as_ibm_278.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_278.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_278& Interpret_As_IBM_278::instance() { + static Interpret_As_IBM_278 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-278 (Nordic EBCDIC) +const std::unordered_map Interpret_As_IBM_278::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00E5)}, // å + {0xA4, QChar(0x00E9)}, // é + {0xA7, QChar(0x00FC)}, // ü +}; + +// Constructor +Interpret_As_IBM_278::Interpret_As_IBM_278() {} + +// Main execution function +void Interpret_As_IBM_278::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM278(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-278 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-278 encoding +QString Interpret_As_IBM_278::decodeIBM278(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_278.h b/src/encoding/interpret_as_ibm_278.h new file mode 100644 index 0000000..c474c86 --- /dev/null +++ b/src/encoding/interpret_as_ibm_278.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_278 { +public: + static Interpret_As_IBM_278& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_278(); + ~Interpret_As_IBM_278() = default; + + Interpret_As_IBM_278(const Interpret_As_IBM_278&) = delete; + Interpret_As_IBM_278& operator=(const Interpret_As_IBM_278&) = delete; + + QString decodeIBM278(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_280.cpp b/src/encoding/interpret_as_ibm_280.cpp new file mode 100644 index 0000000..9df6e1f --- /dev/null +++ b/src/encoding/interpret_as_ibm_280.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_280.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_280& Interpret_As_IBM_280::instance() { + static Interpret_As_IBM_280 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-280 (Italian EBCDIC) +const std::unordered_map Interpret_As_IBM_280::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E0)}, // à + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00E9)}, // é + {0x90, QChar(0x00EC)}, // ì + {0xA4, QChar(0x00F2)}, // ò + {0xA7, QChar(0x00F9)}, // ù +}; + +// Constructor +Interpret_As_IBM_280::Interpret_As_IBM_280() {} + +// Main execution function +void Interpret_As_IBM_280::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM280(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-280 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-280 encoding +QString Interpret_As_IBM_280::decodeIBM280(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_280.h b/src/encoding/interpret_as_ibm_280.h new file mode 100644 index 0000000..b231220 --- /dev/null +++ b/src/encoding/interpret_as_ibm_280.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_280 { +public: + static Interpret_As_IBM_280& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_280(); + ~Interpret_As_IBM_280() = default; + + Interpret_As_IBM_280(const Interpret_As_IBM_280&) = delete; + Interpret_As_IBM_280& operator=(const Interpret_As_IBM_280&) = delete; + + QString decodeIBM280(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_284.cpp b/src/encoding/interpret_as_ibm_284.cpp new file mode 100644 index 0000000..c0cfe8d --- /dev/null +++ b/src/encoding/interpret_as_ibm_284.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_284.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_284& Interpret_As_IBM_284::instance() { + static Interpret_As_IBM_284 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-284 (Spanish EBCDIC) +const std::unordered_map Interpret_As_IBM_284::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E1)}, // á + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00E9)}, // é + {0x90, QChar(0x00ED)}, // í + {0xA4, QChar(0x00F1)}, // ñ + {0xA7, QChar(0x00FA)}, // ú +}; + +// Constructor +Interpret_As_IBM_284::Interpret_As_IBM_284() {} + +// Main execution function +void Interpret_As_IBM_284::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM284(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-284 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-284 encoding +QString Interpret_As_IBM_284::decodeIBM284(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_284.h b/src/encoding/interpret_as_ibm_284.h new file mode 100644 index 0000000..abe3b49 --- /dev/null +++ b/src/encoding/interpret_as_ibm_284.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_284 { +public: + static Interpret_As_IBM_284& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_284(); + ~Interpret_As_IBM_284() = default; + + Interpret_As_IBM_284(const Interpret_As_IBM_284&) = delete; + Interpret_As_IBM_284& operator=(const Interpret_As_IBM_284&) = delete; + + QString decodeIBM284(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_285.cpp b/src/encoding/interpret_as_ibm_285.cpp new file mode 100644 index 0000000..47df699 --- /dev/null +++ b/src/encoding/interpret_as_ibm_285.cpp @@ -0,0 +1,117 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_285.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_285& Interpret_As_IBM_285::instance() { + static Interpret_As_IBM_285 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-285 (UK EBCDIC) +const std::unordered_map Interpret_As_IBM_285::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00A3)}, // £ + {0x81, QChar(0x0061)}, // a + {0x82, QChar(0x0062)}, // b + {0x83, QChar(0x0063)}, // c + {0x84, QChar(0x0064)}, // d + {0x85, QChar(0x0065)}, // e + {0x86, QChar(0x0066)}, // f + {0x87, QChar(0x0067)}, // g + {0x88, QChar(0x0068)}, // h + {0x89, QChar(0x0069)}, // i + {0x8A, QChar(0x006A)}, // j + {0x8B, QChar(0x006B)}, // k + {0x8C, QChar(0x006C)}, // l + {0x8D, QChar(0x006D)}, // m + {0x8E, QChar(0x006E)}, // n + {0x8F, QChar(0x006F)}, // o + {0x90, QChar(0x0070)}, // p + {0x91, QChar(0x0071)}, // q + {0x92, QChar(0x0072)}, // r + {0x93, QChar(0x0073)}, // s + {0x94, QChar(0x0074)}, // t + {0x95, QChar(0x0075)}, // u + {0x96, QChar(0x0076)}, // v + {0x97, QChar(0x0077)}, // w + {0x98, QChar(0x0078)}, // x + {0x99, QChar(0x0079)}, // y + {0x9A, QChar(0x007A)}, // z +}; + +// Constructor +Interpret_As_IBM_285::Interpret_As_IBM_285() {} + +// Main execution function +void Interpret_As_IBM_285::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM285(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-285 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-285 encoding +QString Interpret_As_IBM_285::decodeIBM285(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_285.h b/src/encoding/interpret_as_ibm_285.h new file mode 100644 index 0000000..95bfbc6 --- /dev/null +++ b/src/encoding/interpret_as_ibm_285.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_285 { +public: + static Interpret_As_IBM_285& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_285(); + ~Interpret_As_IBM_285() = default; + + Interpret_As_IBM_285(const Interpret_As_IBM_285&) = delete; + Interpret_As_IBM_285& operator=(const Interpret_As_IBM_285&) = delete; + + QString decodeIBM285(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_290.cpp b/src/encoding/interpret_as_ibm_290.cpp new file mode 100644 index 0000000..7af4fc1 --- /dev/null +++ b/src/encoding/interpret_as_ibm_290.cpp @@ -0,0 +1,90 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_290.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_290& Interpret_As_IBM_290::instance() { + static Interpret_As_IBM_290 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-290 (Japanese Katakana Extended) +const std::unordered_map Interpret_As_IBM_290::ebcdicTable = { + {0x41, QChar(0x30A1)}, // ァ (small a) + {0x42, QChar(0x30A2)}, // ア (a) + {0x43, QChar(0x30A3)}, // ィ (small i) + {0x44, QChar(0x30A4)}, // イ (i) + {0x45, QChar(0x30A5)}, // ゥ (small u) + {0x46, QChar(0x30A6)}, // ウ (u) + {0x47, QChar(0x30A7)}, // ェ (small e) + {0x48, QChar(0x30A8)}, // エ (e) + {0x49, QChar(0x30A9)}, // ォ (small o) + {0x4A, QChar(0x30AA)}, // オ (o) + {0x4B, QChar(0x30AB)}, // カ (ka) + {0x4C, QChar(0x30AC)}, // ガ (ga) + {0x4D, QChar(0x30AD)}, // キ (ki) + {0x4E, QChar(0x30AE)}, // ギ (gi) + {0x4F, QChar(0x30AF)}, // ク (ku) + {0x50, QChar(0x30B0)}, // グ (gu) + {0x51, QChar(0x30B1)}, // ケ (ke) + {0x52, QChar(0x30B2)}, // ゲ (ge) + {0x53, QChar(0x30B3)}, // コ (ko) + {0x54, QChar(0x30B4)}, // ゴ (go) + {0x55, QChar(0x30B5)}, // サ (sa) + {0x56, QChar(0x30B6)}, // ザ (za) + {0x57, QChar(0x30B7)}, // シ (shi) + {0x58, QChar(0x30B8)}, // ジ (ji) + {0x59, QChar(0x30B9)}, // ス (su) + {0x5A, QChar(0x30BA)}, // ズ (zu) +}; + +// Constructor +Interpret_As_IBM_290::Interpret_As_IBM_290() {} + +// Main execution function +void Interpret_As_IBM_290::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM290(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-290 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-290 encoding +QString Interpret_As_IBM_290::decodeIBM290(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_290.h b/src/encoding/interpret_as_ibm_290.h new file mode 100644 index 0000000..fc76dcf --- /dev/null +++ b/src/encoding/interpret_as_ibm_290.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_290 { +public: + static Interpret_As_IBM_290& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_290(); + ~Interpret_As_IBM_290() = default; + + Interpret_As_IBM_290(const Interpret_As_IBM_290&) = delete; + Interpret_As_IBM_290& operator=(const Interpret_As_IBM_290&) = delete; + + QString decodeIBM290(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_297.cpp b/src/encoding/interpret_as_ibm_297.cpp new file mode 100644 index 0000000..76d0a2a --- /dev/null +++ b/src/encoding/interpret_as_ibm_297.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_297.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_297& Interpret_As_IBM_297::instance() { + static Interpret_As_IBM_297 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-297 (French EBCDIC) +const std::unordered_map Interpret_As_IBM_297::ebcdicTable = { + {0x80, QChar(0x00C7)}, // Ç + {0x81, QChar(0x00FC)}, // ü + {0x82, QChar(0x00E9)}, // é + {0x83, QChar(0x00E2)}, // â + {0x84, QChar(0x00E4)}, // ä + {0x85, QChar(0x00E0)}, // à + {0x86, QChar(0x00E5)}, // å + {0x87, QChar(0x00E7)}, // ç + {0x88, QChar(0x00EA)}, // ê + {0x89, QChar(0x00EB)}, // ë + {0x8A, QChar(0x00E8)}, // è + {0x8B, QChar(0x00EF)}, // ï + {0x8C, QChar(0x00EE)}, // î + {0x8D, QChar(0x00EC)}, // ì + {0x8E, QChar(0x00C4)}, // Ä + {0x8F, QChar(0x00C5)}, // Å + {0x90, QChar(0x00C9)}, // É + {0x91, QChar(0x00E6)}, // æ + {0x92, QChar(0x00C6)}, // Æ + {0x93, QChar(0x00F4)}, // ô + {0x94, QChar(0x00F6)}, // ö + {0x95, QChar(0x00F2)}, // ò + {0x96, QChar(0x00FB)}, // û + {0x97, QChar(0x00F9)}, // ù + {0x98, QChar(0x00FF)}, // ÿ + {0x99, QChar(0x00D6)}, // Ö + {0x9A, QChar(0x00DC)}, // Ü + {0x9B, QChar(0x00A2)}, // ¢ + {0x9C, QChar(0x00A3)}, // £ + {0x9D, QChar(0x00A5)}, // ¥ + {0x9E, QChar(0x20A7)}, // ₧ + {0x9F, QChar(0x0192)}, // ƒ + {0xA0, QChar(0x00E1)}, // á + {0xA1, QChar(0x00ED)}, // í + {0xA2, QChar(0x00F3)}, // ó + {0xA3, QChar(0x00FA)}, // ú + {0xA4, QChar(0x00F1)}, // ñ + {0xA5, QChar(0x00D1)}, // Ñ + {0xA6, QChar(0x00AA)}, // ª + {0xA7, QChar(0x00BA)}, // º +}; + +// Constructor +Interpret_As_IBM_297::Interpret_As_IBM_297() {} + +// Main execution function +void Interpret_As_IBM_297::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Invalid CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file:" << filePath; + return; + } + + QByteArray rawData = file.readAll(); + file.close(); + + QString decodedText = decodeIBM297(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-297 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-297 encoding +QString Interpret_As_IBM_297::decodeIBM297(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (ebcdicTable.contains(byte)) { + result.append(ebcdicTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/encoding/interpret_as_ibm_297.h b/src/encoding/interpret_as_ibm_297.h new file mode 100644 index 0000000..402bd67 --- /dev/null +++ b/src/encoding/interpret_as_ibm_297.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_297 { +public: + static Interpret_As_IBM_297& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_297(); + ~Interpret_As_IBM_297() = default; + + Interpret_As_IBM_297(const Interpret_As_IBM_297&) = delete; + Interpret_As_IBM_297& operator=(const Interpret_As_IBM_297&) = delete; + + QString decodeIBM297(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3e17179..ea1d4fb 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -82,6 +82,13 @@ #include "encoding/interpret_as_ibm_437.h" #include "encoding/interpret_as_ibm_424.h" #include "encoding/interpret_as_ibm_420.h" +#include "encoding/interpret_as_ibm_297.h" +#include "encoding/interpret_as_ibm_290.h" +#include "encoding/interpret_as_ibm_285.h" +#include "encoding/interpret_as_ibm_284.h" +#include "encoding/interpret_as_ibm_280.h" +#include "encoding/interpret_as_ibm_278.h" +#include "encoding/interpret_as_ibm_277.h" MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), @@ -1016,6 +1023,27 @@ void MainWindow::on_actionInterpret_As_triggered() if (selectedItem == "IBM-420") { Interpret_As_IBM_420::instance().execute(editor); } + if (selectedItem == "IBM-297") { + Interpret_As_IBM_297::instance().execute(editor); + } + if (selectedItem == "IBM-290") { + Interpret_As_IBM_290::instance().execute(editor); + } + if (selectedItem == "IBM-285") { + Interpret_As_IBM_285::instance().execute(editor); + } + if (selectedItem == "IBM-284") { + Interpret_As_IBM_284::instance().execute(editor); + } + if (selectedItem == "IBM-280") { + Interpret_As_IBM_280::instance().execute(editor); + } + if (selectedItem == "IBM-278") { + Interpret_As_IBM_278::instance().execute(editor); + } + if (selectedItem == "IBM-277") { + Interpret_As_IBM_277::instance().execute(editor); + } } }