Skip to content

Commit

Permalink
v0.0.92
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Jan 9, 2025
1 parent 4b0bbe7 commit c16d276
Show file tree
Hide file tree
Showing 15 changed files with 651 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

============

## 0.0.92

- Implemented:
- Encoding Menu -> Interpret as ... IBM-775, IBM-500, IBM-437, IBM-424, IBM-420

## 0.0.91

- Implemented:
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ set(PROJECT_SOURCES
src/encoding/interpret_as_ibm_852.h
src/encoding/interpret_as_ibm_850.cpp
src/encoding/interpret_as_ibm_850.h
src/encoding/interpret_as_ibm_775.cpp
src/encoding/interpret_as_ibm_775.h
src/encoding/interpret_as_ibm_500.cpp
src/encoding/interpret_as_ibm_500.h
src/encoding/interpret_as_ibm_437.cpp
src/encoding/interpret_as_ibm_437.h
src/encoding/interpret_as_ibm_424.cpp
src/encoding/interpret_as_ibm_424.h
src/encoding/interpret_as_ibm_420.cpp
src/encoding/interpret_as_ibm_420.h
${PROJECT_UI}
)

Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.0, 2025-01-08T21:08:54. -->
<!-- Written by QtCreator 15.0.0, 2025-01-09T14:35:31. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -103,13 +103,13 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_GENERATOR:STRING=Ninja
-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}</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="int" key="EnableQmlDebugging">0</value>
Expand Down
7 changes: 6 additions & 1 deletion src/encoding/interpret_as_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ InterpreteAsDialog::InterpreteAsDialog(QWidget* parent)
"IBM-857",
"IBM-855",
"IBM-852",
"IBM-850"
"IBM-850",
"IBM-775",
"IBM-500",
"IBM-437",
"IBM-424",
"IBM-420"
});

// Create OK and Cancel buttons using QDialogButtonBox
Expand Down
92 changes: 92 additions & 0 deletions src/encoding/interpret_as_ibm_420.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "../codeeditor.h"
#include "interpret_as_ibm_420.h"
#include <QFile>
#include <QDebug>

// Singleton instance
Interpret_As_IBM_420& Interpret_As_IBM_420::instance() {
static Interpret_As_IBM_420 instance;
return instance;
}

// EBCDIC to Unicode mapping for IBM-420 (Arabic EBCDIC)
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_420::ebcdicTable = {
{0x80, QChar(0x0627)}, // ا (Alef)
{0x81, QChar(0x0628)}, // ب (Beh)
{0x82, QChar(0x062A)}, // ت (Teh)
{0x83, QChar(0x062B)}, // ث (Theh)
{0x84, QChar(0x062C)}, // ج (Jeem)
{0x85, QChar(0x062D)}, // ح (Hah)
{0x86, QChar(0x062E)}, // خ (Khah)
{0x87, QChar(0x062F)}, // د (Dal)
{0x88, QChar(0x0630)}, // ذ (Thal)
{0x89, QChar(0x0631)}, // ر (Reh)
{0x8A, QChar(0x0632)}, // ز (Zain)
{0x8B, QChar(0x0633)}, // س (Seen)
{0x8C, QChar(0x0634)}, // ش (Sheen)
{0x8D, QChar(0x0635)}, // ص (Sad)
{0x8E, QChar(0x0636)}, // ض (Dad)
{0x8F, QChar(0x0637)}, // ط (Tah)
{0x90, QChar(0x0638)}, // ظ (Zah)
{0x91, QChar(0x0639)}, // ع (Ain)
{0x92, QChar(0x063A)}, // غ (Ghain)
{0x93, QChar(0x0641)}, // ف (Feh)
{0x94, QChar(0x0642)}, // ق (Qaf)
{0x95, QChar(0x0643)}, // ك (Kaf)
{0x96, QChar(0x0644)}, // ل (Lam)
{0x97, QChar(0x0645)}, // م (Meem)
{0x98, QChar(0x0646)}, // ن (Noon)
{0x99, QChar(0x0647)}, // ه (Heh)
{0x9A, QChar(0x0648)}, // و (Waw)
{0x9B, QChar(0x064A)}, // ي (Yeh)
};

// Constructor
Interpret_As_IBM_420::Interpret_As_IBM_420() {}

// Main execution function
void Interpret_As_IBM_420::execute(QPlainTextEdit* editor) {
if (!editor) {
qWarning() << "[ERROR] No editor instance provided.";
return;
}

CodeEditor* codeEditor = qobject_cast<CodeEditor*>(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 = decodeIBM420(rawData);
editor->setPlainText(decodedText);
qDebug() << "[DEBUG] IBM-420 Decoding applied for file:" << filePath;
}

// Decode raw data from IBM-420 encoding
QString Interpret_As_IBM_420::decodeIBM420(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;
}
22 changes: 22 additions & 0 deletions src/encoding/interpret_as_ibm_420.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <QPlainTextEdit>
#include <QString>
#include <QByteArray>
#include <unordered_map>

class Interpret_As_IBM_420 {
public:
static Interpret_As_IBM_420& instance();
void execute(QPlainTextEdit* editor);

private:
Interpret_As_IBM_420();
~Interpret_As_IBM_420() = default;

Interpret_As_IBM_420(const Interpret_As_IBM_420&) = delete;
Interpret_As_IBM_420& operator=(const Interpret_As_IBM_420&) = delete;

QString decodeIBM420(const QByteArray& rawData);
static const std::unordered_map<unsigned char, QChar> ebcdicTable;
};
91 changes: 91 additions & 0 deletions src/encoding/interpret_as_ibm_424.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "../codeeditor.h"
#include "interpret_as_ibm_424.h"
#include <QFile>
#include <QDebug>

// Singleton instance
Interpret_As_IBM_424& Interpret_As_IBM_424::instance() {
static Interpret_As_IBM_424 instance;
return instance;
}

// EBCDIC to Unicode mapping for IBM-424 (Hebrew EBCDIC)
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_424::ebcdicTable = {
{0x80, QChar(0x05D0)}, // א (Alef)
{0x81, QChar(0x05D1)}, // ב (Bet)
{0x82, QChar(0x05D2)}, // ג (Gimel)
{0x83, QChar(0x05D3)}, // ד (Dalet)
{0x84, QChar(0x05D4)}, // ה (He)
{0x85, QChar(0x05D5)}, // ו (Vav)
{0x86, QChar(0x05D6)}, // ז (Zayin)
{0x87, QChar(0x05D7)}, // ח (Het)
{0x88, QChar(0x05D8)}, // ט (Tet)
{0x89, QChar(0x05D9)}, // י (Yod)
{0x8A, QChar(0x05DA)}, // ך (Final Kaf)
{0x8B, QChar(0x05DB)}, // כ (Kaf)
{0x8C, QChar(0x05DC)}, // ל (Lamed)
{0x8D, QChar(0x05DD)}, // ם (Final Mem)
{0x8E, QChar(0x05DE)}, // מ (Mem)
{0x8F, QChar(0x05DF)}, // ן (Final Nun)
{0x90, QChar(0x05E0)}, // נ (Nun)
{0x91, QChar(0x05E1)}, // ס (Samekh)
{0x92, QChar(0x05E2)}, // ע (Ayin)
{0x93, QChar(0x05E3)}, // ף (Final Pe)
{0x94, QChar(0x05E4)}, // פ (Pe)
{0x95, QChar(0x05E5)}, // ץ (Final Tsadi)
{0x96, QChar(0x05E6)}, // צ (Tsadi)
{0x97, QChar(0x05E7)}, // ק (Qof)
{0x98, QChar(0x05E8)}, // ר (Resh)
{0x99, QChar(0x05E9)}, // ש (Shin)
{0x9A, QChar(0x05EA)}, // ת (Tav)
};

// Constructor
Interpret_As_IBM_424::Interpret_As_IBM_424() {}

// Main execution function
void Interpret_As_IBM_424::execute(QPlainTextEdit* editor) {
if (!editor) {
qWarning() << "[ERROR] No editor instance provided.";
return;
}

CodeEditor* codeEditor = qobject_cast<CodeEditor*>(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 = decodeIBM424(rawData);
editor->setPlainText(decodedText);
qDebug() << "[DEBUG] IBM-424 Decoding applied for file:" << filePath;
}

// Decode raw data from IBM-424 encoding
QString Interpret_As_IBM_424::decodeIBM424(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;
}
22 changes: 22 additions & 0 deletions src/encoding/interpret_as_ibm_424.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <QPlainTextEdit>
#include <QString>
#include <QByteArray>
#include <unordered_map>

class Interpret_As_IBM_424 {
public:
static Interpret_As_IBM_424& instance();
void execute(QPlainTextEdit* editor);

private:
Interpret_As_IBM_424();
~Interpret_As_IBM_424() = default;

Interpret_As_IBM_424(const Interpret_As_IBM_424&) = delete;
Interpret_As_IBM_424& operator=(const Interpret_As_IBM_424&) = delete;

QString decodeIBM424(const QByteArray& rawData);
static const std::unordered_map<unsigned char, QChar> ebcdicTable;
};
Loading

0 comments on commit c16d276

Please sign in to comment.