-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
344 lines (340 loc) · 16 KB
/
Copy pathmain.cpp
File metadata and controls
344 lines (340 loc) · 16 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include <QtCore/QCoreApplication>
#include <QtCore>
#include <string_view>
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
QFile file(argv[2]);
QTextStream stream(stdout);
stream << "File: " << argv[2] << "\n";
stream.flush();
file.open(QIODevice::ReadOnly);
QFile optfl(argv[3]);
optfl.open(QIODevice::WriteOnly);
optfl.setPermissions(QFileDevice::WriteUser);
optfl.setPermissions(QFileDevice::ReadOwner);
QString optdata="";
QString arg1 = QString(argv[1]);
//stream << "s"<<argv[1]<<"e";
//stream << (arg1 == "-py ");
//stream << (arg1 == "-py");
stream.flush();
if (arg1 == "-py"){
while (true) {
QString str = QString(file.readLine(1024));
//stream << str;;
str = str.trimmed();
stream.flush();
QStringList list = str.split(" ");
if (list[0]=="end"){
break;
}
if (list[0] == "strcls") {
optdata=optdata.append("class " + list[1] + ":\n");
}
else if (list[0] == "strdef") {
optdata=optdata.append(" def " + list[1] + ":\n");
}
else if (list[0] == "strret") {
optdata=optdata.append(" return " + list[1] + "\n");
}
else if (list[0] == "strmetif") {
optdata=optdata.append(" if " + list[1] + ":\n");
}
else if (list[0] == "strmetelse") {
optdata=optdata.append(" else:\n");
}
else if (list[0] == "strmetwh") {
optdata=optdata.append(" while " + list[1] + ":\n");
}
else if (list[0] == "strmetinfor") {
optdata=optdata.append(" for " + list[1] + " in " + list[2] + ":\n");
}
else if (list[0] == "strclsdef") {
optdata=optdata.append(" def " + list[1] + "(self):\n");
}
else if (list[0] == "strif") {
optdata=optdata.append("if " + list[1] + ":\n");
}
else if (list[0] == "strelse") {
optdata=optdata.append("else:\n");
}
else if (list[0] == "strwh") {
optdata=optdata.append("while " + list[1] + ":\n");
}
else if (list[0] == "strinfor") {
optdata=optdata.append("for " + list[1] + " in " + list[2] + ":\n");
}
else if (list[0] == "str__init__") {
optdata=optdata.append(" def __init__(self):\n");
}
else if (list[0] == "strfor"){
optdata=optdata.append("for():");
}
else if (list[0] == "imp") {
optdata=optdata.append("import " + list[1] + "\n");
}stream << file.error();
stream << optfl.error();
stream << file.errorString();
stream << optfl.errorString();
//stream << "//error below if found";
stream.flush();
}
}
else if (arg1 == "-cpp") {
optdata = optdata.append("#include <iostream>\n#include <string>\n");
while (true) {
QString str = QString(file.readLine(1024));
str = str.trimmed();
QStringList list = str.split(" ");
if (list[0] == "end") {
break;
}
if (list[0] == "strcls") {
if (list[2] == "n")
optdata = optdata.append("class " + list[1] + " {\npublic:\n\t\nprivate:\n\t\nprotected:\n\t\n}");
else if (list[2] == "c")
optdata = optdata.append("class " + list[1] + " {\npublic:\n\t" + list[1] + "()\n\t\nprivate:\n\t\nprotected:\n\t\n}");
else if (list[2] == "d")
optdata = optdata.append("class " + list[1] + " {\npublic:\n\t~" + list[1] + "()\n\t\nprivate:\n\t\nprotected:\n\t\n}");
else if (list[2] == "cd")
optdata = optdata.append("class " + list[1] + " {\npublic:\n\t" + list[1] + "()\n\t~" + list[1] + "()\n\t\nprivate:\n\t\nprotected:\n\t\n}");
}
else if (list[0] == "strfunc") {
if (list[2] == "int") {
if (list[4] == "n") {
if (list[3] == "n")
optdata = optdata.append("int " + list[1] + "(){\n");
else if (list[3] == "16")
optdata = optdata.append("int_16_t " + list[1] + "(){\n");
else if (list[3] == "32")
optdata = optdata.append("int_32_t " + list[1] + "(){\n");
else if (list[3] == "64")
optdata = optdata.append("int_64_t " + list[1] + "(){\n");
}
else if (list[4] == "f") {
if (list[3] == "16")
optdata = optdata.append("int_fast16_t " + list[1] + "(){\n");
else if (list[3] == "32")
optdata = optdata.append("int_fast32_t " + list[1] + "(){\n");
else if (list[3] == "64")
optdata = optdata.append("int_fast64_t " + list[1] + "(){\n");
}
}
else if (list[2] == "void") {
optdata = optdata.append("void " + list[1] + "(){\n");
}
else if (list[2] == "char")
optdata = optdata.append("char " + list[1] + "(){\n");
else if (list[2] == "float") {
optdata = optdata.append("float " + list[1] + "(){\n");
}
else if (list[2] == "double") {
optdata = optdata.append("double " + list[1] + "(){\n");
}
else if (list[2] == "bool")
optdata = optdata.append("bool " + list[1] + "(){\n");
else if (list[2] == "string")
optdata = optdata.append("std::string " + list[1] + "(){\n");
else if (list[2] == "long")
optdata = optdata.append("long " + list[1] + "(){\n");
else if (list[2] == "szt")
optdata = optdata.append("size_t " + list[1] + "(){\n");
}
else if (list[0] == "for")
optdata = optdata.append("\tfor(){\n\t\t\n}");
else if (list[0] == "if")
optdata = optdata.append("\tif(){\n\t\t\n}");
else if (list[0] == "elf")
optdata = optdata.append("\telse if(){\n\t\t\n}");
else if (list[0] == "els")
optdata = optdata.append("\telse{\n\t\t\n}");
else if (list[0] == "whl")
optdata = optdata.append("\twhile(){\n\t\t\n}");
else if (list[0] == "strswc")
optdata = optdata.append("\tswitch(){\n");
else if (list[0] == "case")
optdata = optdata.append("\t\tcase " + list[1] + ":\n\t\t\t\n\t\t\tbreak;\n");
else if (list[0] == "dflt")
optdata = optdata.append("\t\tdefault:\n\t\t\t\n\t\t\tbreak;\n");
else if (list[0] == "endswc")
optdata = optdata.append("\t}\n");
else if (list[0] == "endfunc_nms")
optdata = optdata.append("}\n");
else if (list[0]=="ret")
optdata = optdata.append("\treturn " + list[1] + ";\n");
else if (list[0] == "inc")
optdata = optdata.append("#include <" + list[1] + ">\n");
else if (list[0]=="strnms")
optdata = optdata.append("namespace " + list[1] + " {\n");
stream << file.error();
stream << optfl.error();
stream << file.errorString();
stream << optfl.errorString();
//stream << "//error below if found";
stream.flush();
}
}
else if (arg1 == "-jv") {
while (true) {
QString str = QString(file.readLine(1024));
str = str.trimmed();
QStringList list = str.split(" ");
if (list[0] == "end") {
break;
}
if (list[0] == "strcls") {
if (list[2]=="n")
optdata = optdata.append("class " + list[1] + " {\n");
else if (list[2]=="c")
optdata = optdata.append("class " + list[1] + " {\n\tpublic " + list[1] + "(){\n\t}\n");
}
else if (list[0] == "strfunc") {
if (list[2] == "int") {
if (list[3]=="pus")
optdata = optdata.append("\tpublic static int "+ list[1]+"(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static int " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static int " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic int " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate int " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected int " + list[1] + "(){\n");
}
else if (list[2] == "void") {
if (list[3] == "pus")
optdata = optdata.append("\tpublic static void " + list[1] + "(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static void " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static void " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic void " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate void " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected void " + list[1] + "(){\n");
}
else if (list[2] == "float") {
if (list[3] == "pus")
optdata = optdata.append("\tpublic static float " + list[1] + "(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static float " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static float " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic float " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate float " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected float " + list[1] + "(){\n");
}
else if (list[2] == "double") {
if (list[3] == "pus")
optdata = optdata.append("\tpublic static double " + list[1] + "(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static double " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static double " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic double " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate double " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected double " + list[1] + "(){\n");
}
else if (list[2] == "bool") {
if (list[3] == "pus")
optdata = optdata.append("\tpublic static boolean " + list[1] + "(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static boolean " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static boolean " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic boolean " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate boolean " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected boolean " + list[1] + "(){\n");
}
else if (list[2] == "string") {
if (list[3] == "pus")
optdata = optdata.append("\tpublic static String " + list[1] + "(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static String " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static String " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic String " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate String " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected String " + list[1] + "(){\n");
}
else if (list[2] == "char") {
if (list[3] == "pus")
optdata = optdata.append("\tpublic static char " + list[1] + "(){\n");
else if (list[3] == "prvs")
optdata = optdata.append("\tprivate static char " + list[1] + "(){\n");
else if (list[3] == "prots")
optdata = optdata.append("\tprotected static char " + list[1] + "(){\n");
if (list[3] == "pu")
optdata = optdata.append("\tpublic char " + list[1] + "(){\n");
else if (list[3] == "prv")
optdata = optdata.append("\tprivate char " + list[1] + "(){\n");
else if (list[3] == "prot")
optdata = optdata.append("\tprotected char " + list[1] + "(){\n");
}
}
else if (list[0] == "for")
optdata = optdata.append("\t\tfor(){\n\t\t\n}");
else if (list[0] == "if")
optdata = optdata.append("\t\tif(){\n\t\t\n}");
else if (list[0] == "elf")
optdata = optdata.append("\t\telse if(){\n\t\t\n}");
else if (list[0] == "els")
optdata = optdata.append("\t\telse{\n\t\t\n}");
else if (list[0] == "whl")
optdata = optdata.append("\t\twhile(){\n\t\t\n}");
else if (list[0] == "strswc")
optdata = optdata.append("\t\tswitch(){\n");
else if (list[0] == "case")
optdata = optdata.append("\t\t\tcase " + list[1] + ":\n\t\t\t\t\n\t\t\t\tbreak;\n");
else if (list[0] == "dflt")
optdata = optdata.append("\t\t\tdefault:\n\t\t\t\t\n\t\t\t\tbreak;\n");
else if (list[0] == "endswc")
optdata = optdata.append("\t\t}\n");
else if (list[0] == "endfunc")
optdata = optdata.append("\t}\n");
else if (list[0] == "ret")
optdata = optdata.append("\t\treturn " + list[1] + ";\n");
else if (list[0] == "imp")
optdata = optdata.append("import " + list[1] + ";\n");
else if (list[0]=="endcls")
optdata = optdata.append("}\n");
else if (list[0]=="pkg")
optdata = optdata.append("package " + list[1] + ";\n");
stream << file.error();
stream << optfl.error();
stream << file.errorString();
stream << optfl.errorString();
//stream << "//error below if found";
stream.flush();
}
}
optfl.write(optdata.toUtf8());
stream << file.error();
stream << optfl.error();
stream << file.errorString();
stream << optfl.errorString();
//stream << "//error below if found";
stream.flush();
file.close();
optfl.close();
QCoreApplication::exit();
exit(0);
return a.exec();
}