-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompiler.cpp
120 lines (95 loc) · 2.47 KB
/
decompiler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
vector<string> ReadTable()
{
ifstream CharTable("CharTable.fcT");
string falseCharTable;
vector<string> tableContents;
while (getline(CharTable, falseCharTable))
{
tableContents.push_back(falseCharTable);
}
CharTable.close();
return tableContents;
}
int clip(int n, int lower, int upper)
{
return std::max(lower, std::min(n, upper));
}
int main(int argc, char **argv)
{
ifstream CharTable("CharTable.fcT");
if (!CharTable.good())
{
cout << "Error: CharTable cannot be found!" << endl;
return 1;
}
else if (argc < 2)
{
cout << "No input .fc file argument detected!" << endl;
return 1;
}
vector<string> charTable = ReadTable();
cout << argv[1] << endl;
vector<string> finalDecode;
ifstream MyReadFile(argv[1]);
string falseChar;
string argument = "";
while (getline(MyReadFile, falseChar))
{
cout << falseChar << endl;
argument += falseChar;
}
cout << argument << endl;
MyReadFile.close();
int count = 0;
bool inClosure = false;
string currentClosureCount = "";
for (int i = 0; i < argument.size(); i++)
{
falseChar = argument[i];
if (falseChar != "(" && falseChar != ")" && inClosure)
{
currentClosureCount += falseChar;
}
else if (!inClosure && falseChar == ">")
{
finalDecode.push_back(charTable[0]);
}
if (falseChar == "(" && !inClosure)
{
inClosure = true;
}
else if (falseChar == ")" && inClosure)
{
inClosure = false;
int decode = stoi(currentClosureCount);
if (currentClosureCount == "")
{
decode = 0;
}
decode = clip(decode, 1, charTable.size());
finalDecode.push_back(charTable[decode-1]);
currentClosureCount = "";
}
count++;
}
string result = "";
unsigned int vecSize = finalDecode.size();
for (unsigned int i = 0; i < vecSize; i++)
{
result += finalDecode[i];
}
cout << result << endl;
cout << "writing fc-output.txt..." << endl;
ofstream OutputFile("fc-output.txt");
OutputFile << result;
OutputFile.close();
cout << "success!" << endl;
system("pause");
return 0;
}