6
6
#include < sstream>
7
7
#include < condition_variable>
8
8
using namespace std ;
9
- #define _VERSION_ " v1.13"
9
+ #define _VERSION_ " v1.13.2 "
10
10
#define _DEFAULT_BUFFER_SIZE_ 1024
11
11
string identifiers[] = {
12
12
" output" ,
@@ -46,21 +46,22 @@ bool isInteger(string x) {
46
46
return integer;
47
47
}
48
48
int main (int argc, char * argv[]) {
49
- try {
49
+ if (argc >= 2 ) {
50
50
string fileName = string (argv[1 ]);
51
51
int bufferSize;
52
- try {
52
+ if (argc == 3 ) {
53
53
bufferSize = atoi (string (argv[2 ]).c_str ());
54
54
}
55
- catch (logic_error) {
55
+ else {
56
56
bufferSize = _DEFAULT_BUFFER_SIZE_;
57
57
}
58
58
char buffer[bufferSize];
59
59
Variable variables[bufferSize];
60
60
int variableCount = 0 ;
61
61
ifstream file (fileName);
62
62
if (!file.is_open ()) {
63
- cerr << " [ERROR] File cannot open." ;
63
+ cerr << " [ERROR] File cannot open.\n " ;
64
+ exit (0 );
64
65
}
65
66
while (file.good ()) {
66
67
file.getline (buffer, sizeof (buffer));
@@ -91,10 +92,10 @@ int main(int argc, char* argv[]) {
91
92
cout << string (*(it + 1 )).substr (1 , strlen ((*(it + 1 )).c_str ()) - 2 );
92
93
break ;
93
94
}
94
- if (*it == identifiers[1 ]) {
95
+ else if (*it == identifiers[1 ]) {
95
96
cout << endl;
96
97
}
97
- if (*it == identifiers[2 ]) {
98
+ else if (*it == identifiers[2 ]) {
98
99
bool duplicate = false ;
99
100
for (int i = 0 ; i <= variableCount; i++) {
100
101
if (variables[i].name == *(it + 1 )) {
@@ -108,7 +109,7 @@ int main(int argc, char* argv[]) {
108
109
variables[variableCount++].name = *(it + 1 );
109
110
break ;
110
111
}
111
- if (*it == identifiers[3 ]) {
112
+ else if (*it == identifiers[3 ]) {
112
113
bool undeclared = true ;
113
114
for (int i = 0 ; i <= variableCount; i++) {
114
115
if (variables[i].name == *(it + 1 )) {
@@ -122,7 +123,7 @@ int main(int argc, char* argv[]) {
122
123
}
123
124
break ;
124
125
}
125
- if (*it == identifiers[4 ]) {
126
+ else if (*it == identifiers[4 ]) {
126
127
bool undeclared = true ;
127
128
for (int i = 0 ; i <= variableCount; i++) {
128
129
if (variables[i].name == *(it + 1 )) {
@@ -148,7 +149,7 @@ int main(int argc, char* argv[]) {
148
149
}
149
150
break ;
150
151
}
151
- if (*it == identifiers[4 ]) {
152
+ else if (*it == identifiers[4 ]) {
152
153
bool undeclared = true ;
153
154
for (int i = 0 ; i <= variableCount; i++) {
154
155
if (variables[i].name == *(it + 1 )) {
@@ -164,7 +165,7 @@ int main(int argc, char* argv[]) {
164
165
}
165
166
break ;
166
167
}
167
- if (*it == identifiers[5 ]) {
168
+ else if (*it == identifiers[5 ]) {
168
169
bool undeclared = true ;
169
170
for (int i = 0 ; i <= variableCount; i++) {
170
171
if (variables[i].name == *(it + 1 )) {
@@ -190,7 +191,7 @@ int main(int argc, char* argv[]) {
190
191
}
191
192
break ;
192
193
}
193
- if (*it == identifiers[6 ]) {
194
+ else if (*it == identifiers[6 ]) {
194
195
bool undeclared = true ;
195
196
for (int i = 0 ; i <= variableCount; i++) {
196
197
if (variables[i].name == *(it + 1 )) {
@@ -216,7 +217,7 @@ int main(int argc, char* argv[]) {
216
217
}
217
218
break ;
218
219
}
219
- if (*it == identifiers[7 ]) {
220
+ else if (*it == identifiers[7 ]) {
220
221
bool undeclared = true ;
221
222
for (int i = 0 ; i <= variableCount; i++) {
222
223
if (variables[i].name == *(it + 1 )) {
@@ -242,7 +243,7 @@ int main(int argc, char* argv[]) {
242
243
}
243
244
break ;
244
245
}
245
- if (*it == identifiers[8 ]) {
246
+ else if (*it == identifiers[8 ]) {
246
247
bool undeclared = true ;
247
248
for (int i = 0 ; i <= variableCount; i++) {
248
249
if (variables[i].name == *(it + 1 )) {
@@ -275,7 +276,7 @@ int main(int argc, char* argv[]) {
275
276
}
276
277
}
277
278
}
278
- catch (logic_error) {
279
+ else {
279
280
cout << " JunLang " << _VERSION_ << endl;
280
281
cout << " Usage: " << argv[0 ] << " [filename] <bufferSize>" << endl;
281
282
}
0 commit comments