-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExeFile.cpp
More file actions
129 lines (105 loc) · 3.45 KB
/
ExeFile.cpp
File metadata and controls
129 lines (105 loc) · 3.45 KB
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
121
122
123
124
125
126
127
128
129
#include"ExeFile.h"
#include"File.h"
ExeFile::ExeFile(string text, TreeNode* parent) :File(text, parent)
{
extension_ = "exe";
readCommands(text);
readContent();
}
ExeFile::ExeFile(const string& name, TreeNode* parent, string content):File( name, parent,"", "exe")
{
readCommands(content);
readContent();
}
ExeFile::~ExeFile()
{
for (int i = 0; i < commands_.size(); i++) {
delete commands_[i];
}
}
//Egzekjutuje exe fajl
void ExeFile::execute()
{
bool first = true;
for (int i = 0; i < commands_.size(); i++) {
try {
commands_[i]->Do();
}
catch (NameError& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE "+getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (ExtensionError& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (SearchError& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (InsertError& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (WrongCommand& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (CommandError& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (CommandNotFound& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
catch (DeleteError& e) {
if (first) { first = false; Command::writeErrorInLogFile("EXE " + getNameWithExtension()); }
cout << e.what() << endl;
Command::writeErrorInLogFile(commands_[i]->commandToString());
}
}
}
//Ispis exe fajla na standardni izlaz
void ExeFile::readContent()
{
for (int i = 0; i < commands_.size(); i++) {
content_+=commands_[i]->commandToString();
if (i != commands_.size() - 1)content_+= "\\n";
}
}
void ExeFile::readCommands(string& text)
{
string line,saved_line;
while (!text.empty()) {
try {
saved_line=line = Command::readCodeLine(text);//Cita liniju koda sa ulaza
commands_.push_back(Command::chooseCommand(line, text));//Bira konstruktor komande i ubacuje je u vektor komandi
}//Prijavljivanje greske
catch (CommandError& e) {
cout << e.what() << endl;
cout << saved_line << endl;
}
catch (WrongCommand& e) {
cout << e.what() << endl;
cout << saved_line << endl;
}
catch (CommandNotFound& e) {
cout << e.what() << endl;
cout << saved_line << endl;
}
}
}
void ExeFile::copyCommands(vector<Command*>commands)
{
for (int i = 0; i < commands.size(); i++) {
commands_.push_back(Command::chooseCommand(commands[i]));
}
}