-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRepeater_Nesting_Utility_4.0.cpp
326 lines (270 loc) · 8.88 KB
/
Repeater_Nesting_Utility_4.0.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
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
/*
Intention Repeater Nesting Utility created by Anthro Teacher aka Thomas
Sweet. May 23, 2021. Version 4.0
Format code with: clang-format-9
Style = Mozilla format.
Compile code with: clang++-9 -O3 -Wall -static
./Repeater_Nesting_Utility_4.0.cpp -o ./Repeater_Nesting_Utility_4.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
const std::string WHITESPACE = " \n\r\t\f\v";
std::string
ltrim(const std::string& s)
{
size_t start = s.find_first_not_of(WHITESPACE);
return (start == std::string::npos) ? "" : s.substr(start);
}
std::string
rtrim(const std::string& s)
{
size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
}
std::string
trim(const std::string& s)
{
return rtrim(ltrim(s));
}
void
RestoreKeyboardBlocking(struct termios* initial_settings)
{
tcsetattr(0, TCSANOW, initial_settings);
}
void
SetKeyboardNonBlock(struct termios* initial_settings)
{
struct termios new_settings;
tcgetattr(0, initial_settings);
new_settings = *initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 0;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
}
void
print_help()
{
cout << "Intention Repeater Nesting File Creation Utility v4.0." << endl;
cout << "Created by Anthro Teacher aka Thomas Sweet (5/23/2021)." << endl
<< endl;
cout << "https://www.intentionrepeater.com" << endl;
cout << "https://forums.intentionrepeater.com" << endl << endl;
cout << "Optional Flags:" << endl;
cout << " a) -z or --zip, example: --zip" << endl;
cout << " b) -n or --numfiles, example: --numfiles 10" << endl;
cout << " c) -r or --numreps, example: --numreps 100" << endl;
cout << " d) -h or --help, example: --help" << endl << endl;
cout << "--zip = When provided, will create a NESTFILES.ZIP archive on the "
"fly, and remove temporary N# files."
<< endl;
cout << "--numfiles = Specify how many Nesting Files (N#) to create." << endl;
cout << "--numreps = Specify how many times to reference each Nesting File "
<< endl;
cout << "--help = Print this help." << endl << endl << std::flush;
}
int
main(int argc, char** argv)
{
std::string num_files, num_repetitions, archive_7zip, build_string,
create_filename, create_filename_1, command;
std::string param_archive_7zip, param_num_files, param_num_repetitions;
struct termios term_settings;
long long int CHUNK_SIZE = 10;
char c = 0;
std::string prefix_7zip = "7z a -mmt2 -mx=9 NESTFILES.ZIP";
std::fstream myfile;
param_archive_7zip = "";
param_num_files = "";
param_num_repetitions = "";
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-z") || !strcmp(argv[i], "--zip")) {
param_archive_7zip = "Y";
} else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--numfiles")) {
param_num_files = argv[i + 1];
} else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--numreps")) {
param_num_repetitions = argv[i + 1];
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
print_help();
exit(EXIT_SUCCESS);
}
}
cout << "Intention Repeater Nesting File Creation Utility v4.0." << endl;
cout << "Created by Anthro Teacher (5/23/2021)." << endl;
cout << "Note: 10 reps per file X 100 files = 1 Googol Repetitions per "
"iteration!"
<< endl;
cout << "Number of total Reps = (# reps per file) ^ (# files)." << endl
<< endl;
cout << "Press 'q' key to quit when running." << endl << endl << std::flush;
if (param_archive_7zip == "") {
cout << "Archive into Zip? (y/N): ";
std::getline(std::cin, archive_7zip);
cout << endl;
} else {
archive_7zip = param_archive_7zip;
}
std::transform(
archive_7zip.begin(), archive_7zip.end(), archive_7zip.begin(), ::toupper);
if (param_num_files == "") {
cout << "# of Nesting Files to create: ";
std::getline(std::cin, num_files);
cout << endl;
} else {
num_files = param_num_files;
}
if (param_num_repetitions == "") {
cout << "# of Repetitions in each Nesting File: ";
std::getline(std::cin, num_repetitions);
cout << endl;
} else {
num_repetitions = param_num_repetitions;
}
SetKeyboardNonBlock(&term_settings);
myfile.open("P0", ios::out);
if (myfile.is_open()) {
for (long long int repnum = 1; repnum <= stoll(num_repetitions); repnum++) {
build_string = build_string + "INTENTIONS.TXT ";
}
try {
myfile << build_string;
} catch (...) {
cout << "Error Writing to " << "P0" << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
myfile.close();
}
for (long long int filenum = 0; filenum <= stoll(num_files); filenum++) {
if (archive_7zip == "Y") {
c = getchar();
cout << "Adding File # " << trim(std::to_string(filenum)) << " / "
<< num_files << endl;
if (c == 'q' || c == 'Q') {
cout << "Program Terminated by Keypress." << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_SUCCESS);
}
create_filename = "P" + trim(std::to_string(filenum));
create_filename_1 = "P" + trim(std::to_string(filenum - 1));
try {
myfile.open(create_filename, ios::out);
} catch (...) {
cout << "Error creating " << create_filename << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
build_string = "";
for (long long int repnum = 1; repnum <= stoll(num_repetitions);
repnum++) {
build_string += create_filename_1 + " ";
}
try {
myfile << build_string;
} catch (...) {
cout << "Error Writing to " << create_filename << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
myfile.close();
if (filenum % CHUNK_SIZE == 0) {
try {
command = prefix_7zip + " P* >> logfile.txt";
system(command.c_str());
} catch (...) {
cout << "Error updating NESTFILES.ZIP" << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
#ifdef _WIN32
command = "del P* >nul 2>&1";
#else
command = "rm -f P* >> logfile.txt";
#endif
try {
system(command.c_str());
} catch (...) {
cout << "Error removing temporary N# files" << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
command = prefix_7zip + " P* >> logfile.txt";
cout << "Updating NESTFILES.ZIP Archive" << endl;
try {
system(command.c_str());
} catch (...) {
cout << "Error adding files to NESTFILES.ZIP" << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
#ifdef _WIN32
command = "del P* >nul 2>&1";
#else
command = "rm -f P* >> logfile.txt";
#endif
try {
system(command.c_str());
} catch (...) {
cout << "Error removing N# files: " << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
}
} else {
create_filename = "P" + trim(std::to_string(filenum));
create_filename_1 = "P" + trim(std::to_string(filenum - 1));
build_string = "";
for (long long int repnum = 1; repnum <= stoll(num_repetitions);
repnum++) {
build_string += create_filename_1;
}
command = prefix_7zip + " P* >> logfile.txt";
try {
system(command.c_str());
} catch (...) {
cout << "Error adding files to NESTFILES.ZIP" << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
#ifdef _WIN32
command = "del P* >nul 2>&1";
#else
command = "rm -f P* >> logfile.txt";
#endif
try {
system(command.c_str());
} catch (...) {
cout << "Error removing P# files: " << endl << std::flush;
RestoreKeyboardBlocking(&term_settings);
exit(EXIT_FAILURE);
}
}
}
cout << "Intention Repeater Nesting Files Written." << endl << endl;
cout << "Be sure to have your intentions in the INTENTIONS.TXT file." << endl
<< endl;
if (archive_7zip == "N") {
cout << "And use " << create_filename
<< " whatever nesting level you prefer, i.e. P25 for "
"25 levels deep."
<< endl
<< endl;
} else {
cout << "And use NESTFILES.ZIP"
<< " in the Intention Repeater to utilize the full NEST stack." << endl
<< endl;
}
cout << std::flush;
RestoreKeyboardBlocking(&term_settings);
return 0;
}