elonmusk 1.0.72 → 1.0.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,784 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /*
4
-
5
- # BSD 2-Clause License
6
- #
7
- # Copyright (c) 2023, Gregory Cohen
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # 1. Redistributions of source code must retain the above copyright notice, this
14
- # list of conditions and the following disclaimer.
15
- #
16
- # 2. Redistributions in binary form must reproduce the above copyright notice,
17
- # this list of conditions and the following disclaimer in the documentation
18
- # and/or other materials provided with the distribution.
19
- #
20
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- # Get rid of the "ca"s if you want to make it work for the US.
32
- # This program is for personal, non-commerical use.
33
- # Any sites this program downloads from are being used for personal, non-commerical use.
34
- # If any legal problems do arise, feel free to contact me at my
35
- # email and I can modify this program to use some ohter site.
36
-
37
-
38
- */
39
-
40
-
41
- function m() {
42
- main_func = "";
43
- decl = "const";
44
- all_code = "";
45
- VERBOSE_DEBUG = this.global && process.env["DEBUG"] == "true";
46
- function get_all_declarations() {
47
- return ((this.global && process.env["DECLS"]) || "").split(/,,/);
48
- }
49
- g = 0;
50
- const javascript = process["mode"] === "js";
51
- const cpp = process["mode"] === "cpp";
52
- javascript || cpp || alert("Error, no mode selected");
53
- if (cpp) {
54
- decl = "const";
55
- decl_int = "size_t";
56
- array_decl = "Array";
57
- precode = `
58
-
59
- #define function static inline void*
60
- #define var auto
61
- #define let auto
62
- #define const const auto
63
- `;
64
- } else {
65
- array_decl = decl = decl_int = "";
66
- precode = `
67
- function set_globals() {
68
- nesting=0;VERBOSE_DEBUG=${VERBOSE_DEBUG};function puts() { eval("return con" + "sole" + ".warn"); }
69
- } ; set_globals(); `;
70
- } /*
71
- if (javascript)*/
72
- if (cpp) {
73
- len = "array.size()";
74
- } else {
75
- len = "array.length";
76
- }
77
- const m = (func, array, cond, one, i = [0, len]) => {
78
- func = func.split(".").join("_");
79
- c = "";
80
- if (cpp) {
81
- c += `#ifndef ${func}_macro
82
- #define ${func}_macro
83
- #undef ${func}
84
- #undef ${func}_otherwise
85
- #ifndef nop_func_macro
86
- #define nop_func_macro
87
- static double* nop_func(...) { return nullptr; }
88
- #endif
89
- #define ${func}_otherwise nop_func`;
90
- }
91
- var new_one = [];
92
-
93
- one = one.split(/\s*;\s*/);
94
- for (const i of one) {
95
- if (i.length) {
96
- new_one.push(i + ";");
97
- }
98
- }
99
- one = new_one;
100
- c += precode + `function ${func}(${array_decl} array, ${decl_int} i) {`;
101
- c += `${cpp ? "double * " : "var"} rvalue`;
102
- // }}`;
103
- c += `
104
- ${
105
- this.global &&
106
- get_all_declarations().map((i) => {
107
- if (!i.trim()) return "";
108
- return "/* DECL */ const " + i;
109
- })
110
- }
111
- ${VERBOSE_DEBUG ? ++nesting : ""};
112
- const max = ${i[1]};
113
- while (i < max) {
114
- Object element = array[i];
115
- `;
116
- if (javascript) {
117
- c += `const style = element.style`;
118
- }
119
- c += ` ${
120
- VERBOSE_DEBUG
121
- ? 'puts(" ".repeat((nesting - 1) * 4) + `....Iteration ${i} i=` + [i, "/", max, " (", Math.round(i/max*100, 2), "%", ") +", 1.0/max*100, "%", " of loop completed"].join(""))'
122
- : ""
123
- }
124
- const condition = ${cond};
125
- if (condition) {
126
- using namespace std;
127
- ${one.slice(0, one.length - 1).join("\n\t\t\t\t")}
128
- //{one.slice(one.length - 1)
129
- rvalue = ${
130
- cpp ? "*(double**)(size_t)(size_t*)&(" : ""
131
- }${(last = one[one.length - 1]).substr(
132
- 0,
133
- last.length - 1
134
- )}${cpp ? ")" : ""};
135
- } else {`;
136
- if (javascript) {
137
- c += "try { ";
138
- }
139
- c += `
140
- rvalue = ${func}_otherwise(${cpp ? "&(" : "["}element${
141
- cpp ? ")" : "]"
142
- }, 0);
143
- `;
144
- if (javascript)
145
- c += `
146
- } catch (e) {}`;
147
- c;
148
- c += ` } ++i; } `;
149
- if (VERBOSE_DEBUG && javascript)
150
- c += `
151
- puts("Loop comp");
152
- --nesting;`;
153
- c += `
154
- return rvalue;
155
- }
156
- `;
157
- if (cpp) {
158
- c += `#endif` + "\n";
159
- }
160
- {
161
- }
162
- function remove_sides(a, first, last) {
163
- if (a.startsWith(first)) a = a.slice(first.length, a.length);
164
- if (a.endsWith(last)) {
165
- a = a.slice(0, a.length - last.length);
166
- }
167
- return a;
168
- }
169
-
170
- /* String.prototype.gsub = function*/
171
-
172
- if (!func.endsWith("otherwise")) {
173
- d = main_func;
174
- if (cpp) {
175
- try {
176
- array = mod(JSON.parse(array));
177
- } catch (e) {
178
- console.warn(e);
179
- process.exit();
180
- }
181
- d += "return \n";
182
-
183
- d += `${func}(\n${array},\n${i[0]}\n);`;
184
- }
185
- main_func = d;
186
- }
187
- function to_s(e) {
188
- return e;
189
- }
190
- };
191
- args = "";
192
- try {
193
- args = process.argv.slice(2).join(",,");
194
- } catch (_) {
195
- args = [...arguments].join(",,");
196
- }
197
- if (!args) {
198
- puts("Added m function and env function");
199
- return;
200
- }
201
- args = args.split(",,");
202
- for (var i = 0; i < args.length; ) {
203
- s = args.slice(i, i + 4);
204
- if (s[0].match(/otherwise$/)) {
205
- s = [s[0], [true], true, s[1]];
206
- i += 2;
207
- } else {
208
- i += 4;
209
- }
210
- m(...s);
211
- foo(s[0], c);
212
- all_code += c;
213
- }
214
- all_code += `
215
- function ${(prog_name = "e" + Date.now())}_main() {
216
- ${main_func}
217
- }`;
218
- if (cpp)
219
- all_code = cpp_pre_code() + all_code + `\n\n\nint main(int argc, char ** argv , char ** envp) { main_( argc, argv, envp); }`;
220
- else all_code += "\n" + prog_name + "_main();";
221
- foo("all_code", all_code);
222
- if (javascript) {
223
- try {
224
- eval(all_code);
225
- } catch (e) {
226
- console.warn(e);
227
- }
228
- }
229
- function foo(func, code) {
230
- const out = `${func}.${process.mode}`;
231
- try {
232
- require("fs").writeFileSync(out, code);
233
- } catch (_) {
234
- console.log(_);
235
- var saveData = (function () {
236
- var a = document.createElement("a");
237
- document.body.appendChild(a);
238
- a.style = "display: none";
239
- return function (data, fileName) {
240
- var json = data,
241
- blob = new Blob([json], { type: "octet/stream" }),
242
- url = window.URL.createObjectURL(blob);
243
- a.href = url;
244
- a.download = fileName;
245
- a.click();
246
- window.URL.revokeObjectURL(url);
247
- };
248
- })();
249
- saveData(code, out);
250
- }
251
- }
252
- return true;
253
- }
254
-
255
- env("mode", "js", 1) && m() && env("mode", "cpp", 1) && m();
256
- function env(a, b, mode) {
257
- var n = this.global || window;
258
- n.process = n.process || { env: { DEBUG: "true", DECLS: "" } };
259
-
260
- if (!mode) {
261
- process.env.DECLS += `${a}=${b},,`;
262
- } else {
263
- process[a] = b;
264
- }
265
- return true;
266
- }
267
- function help() {
268
- console.table(`m() (Browser console and node) -> generates a list of all arguments (or strings separted by double commas)
269
- Functions are run sequentially. Otherwise functions are not run.
270
- All functions loop over something
271
- All functions have a conditional.
272
- func_name iterable (such as a list or a DOMElement) condition expression
273
- The resultant function returns the last expression in the function
274
- This isn't a DSL, it's extremely broad.
275
- Any algorithm can be expressed this way.
276
- This makes writing algorithms much, much easier.
277
- It works in Node.js and in the browser.
278
- After generating all functions, the resultant code gets downloaded.
279
- `);
280
- }
281
-
282
- //functin cpp
283
-
284
- function cpp_code() {
285
- return (cpp_code =
286
- `
287
- #include <cstddef>
288
- #include <iostream>
289
- #include <vector>
290
- #include <sstream>
291
- #include <cstring>
292
- #include <map>
293
-
294
- //namespace {
295
- enum {
296
- INT,
297
- DOUBLE,
298
- STRING,
299
- VECTOR,
300
- MAP,
301
-
302
- NEEDS_FREEING,
303
- NEEDS_DELETING,
304
- NEEDS_DELETING_ARRAY
305
- };
306
-
307
- //#define c construct
308
-
309
- class Object {
310
- public:
311
- double type;
312
- double value;
313
-
314
-
315
- ~Object() {
316
- union { char* v;
317
- double d;
318
- } un;
319
- un.d = value;
320
-
321
- switch ((size_t)type) {
322
- case NEEDS_FREEING:
323
- std::cout << "Freeing " << (std::string)(*this) << "\\n";
324
- free(*un.v);
325
- delete un.v;
326
- break;
327
- case NEEDS_DELETING_ARRAY:
328
- delete [] un.v;
329
- delete ptr;
330
- break;
331
- case NEEDS_DELETING:
332
- delete *un.v;
333
- delete un.v;
334
- break;
335
- }
336
- };
337
-
338
- operator const std::string() const;
339
-
340
-
341
- const Object& print() const;
342
-
343
-
344
- bool operator < (Object a) const {
345
- return (const std::string)(*this) < (const std::string)(a);
346
- };
347
-
348
- };
349
-
350
-
351
-
352
-
353
-
354
- template <class A>
355
- class Array_sub : public std::vector<A>
356
- {
357
- public:
358
- Array_sub(std::initializer_list<A> a) : std::vector<A>{a}
359
- {}
360
-
361
- inline void push(const A value) {
362
- std::vector<A>::emplace_back(value);
363
- }
364
-
365
-
366
-
367
-
368
- inline Array_sub<A>& operator<< (A v) {
369
- push(v);
370
- return *this;
371
- }
372
-
373
- inline const auto surround(const char* first, const char* second) const {
374
-
375
- typedef Array_sub<A> Array;
376
- Array b{};
377
- std::cout << "Start of loops\\n";
378
- for (size_t i = 0; i < this->size(); ++i) {
379
- std::string s{first};
380
- s+= (std::string)((*this)[i]);
381
- s += second;
382
-
383
- b.emplace_back(construct_needs_freeing(strdup(s.c_str())));
384
- std::cout << "Loop number " << i << std::endl;
385
- }
386
- std::cout << "End of loops\\n";
387
- return b;
388
- }
389
-
390
- inline auto js() {
391
- return surround("<script type='text/javascript'>", "</script>");
392
- }
393
-
394
- inline const auto construct_needs_freeing(const char* const a) const {
395
- union {
396
- const char* c;
397
- double d;
398
- } u;
399
-
400
- u.c = a;
401
-
402
- return *new Object{NEEDS_FREEING, u.d};
403
- }
404
-
405
-
406
-
407
-
408
- operator const std::string() const {
409
- return to_s();
410
- }
411
-
412
- inline auto append(const char* arg1) const {
413
- return surround(nullptr, arg1);
414
- }
415
-
416
-
417
- inline auto prepend(const char* arg1) const {
418
- return surround(nullptr, arg1);
419
- }
420
-
421
- inline auto quote() const {
422
- return surround("'", "'");
423
- }
424
-
425
- inline auto join(const char* delim) const {
426
- std::string result;
427
- const auto length=this->size();
428
- for (size_t i = 0; i < length; ++i) {
429
- result += (*this)[i];
430
- if (i==length-1) {
431
- } else {
432
- result += delim;
433
- }
434
- }
435
-
436
- return result;
437
- }
438
-
439
- inline auto html(const char* title) const {
440
- std::string site_content;
441
- site_content += "Content-type: text/html\\r\\n\\r\\n<!DOCTYPE html><html><head><title>";
442
- site_content += title;
443
- site_content += "</title></head>";
444
- site_content += "<body>";
445
- //this->surround("<p>", "</p>");
446
- site_content += this->surround("<p>", "</p>");
447
- site_content += "</body></html>";
448
- return site_content;
449
- }
450
-
451
- inline auto p() const {
452
- return surround("<p>", "</p>");
453
- }
454
-
455
- inline auto div() const {
456
- return surround("<div>", "</div>");
457
- }
458
-
459
- inline auto nls() const {
460
- return surround(nullptr, "\\n");
461
- }
462
-
463
-
464
-
465
- const std::string to_s() const {
466
- std::ostringstream str;
467
- str << '[';
468
- for (size_t i = 0; i < this->size(); ++i) {
469
- str << (std::string)((*this)[i]);
470
-
471
- if (i == this->size() - 1) {
472
- } else {
473
- str << ", ";
474
- }
475
- }
476
- str << ']';
477
-
478
-
479
-
480
- return str.str();
481
-
482
- }
483
- };
484
- typedef Array_sub<Object> Array;
485
-
486
-
487
- union Object_v {
488
- double d;
489
- const void* v;
490
- long long int long_long;
491
-
492
- const std::map<Object, Object>* map;
493
- //const char* string;
494
- const Array* array; /*/const ch
495
- const cha*/
496
- const char* string;
497
- };
498
-
499
-
500
- Object::operator const std::string() const {
501
- Object_v val_;
502
-
503
- val_.d = this->value;
504
-
505
- switch ((size_t)this->type) {
506
- case STRING:
507
- return val_.string;
508
- case NEEDS_DELETING:
509
- return "[needs_deleting]";
510
- case NEEDS_FREEING:return val_.string;
511
- // return std::string(val_.string) + ";
512
- case NEEDS_DELETING_ARRAY: return "[needs_deleting_array]";
513
- case INT:
514
- return std::to_string((long long int)val_.long_long );
515
- case DOUBLE:
516
- return std::to_string(val_.d);
517
- case VECTOR:
518
- return val_.array->to_s();
519
- case MAP:
520
- std::string map_str = "{";
521
- // std::map<A,
522
-
523
- //auto& map = val_->map;
524
- for (const auto i : *val_.map) {
525
- map_str += (std::string)(i.first);
526
- map_str += ": ";
527
-
528
- map_str += (std::string)(i.second);
529
-
530
- map_str += ", ";
531
- }
532
- // map_str[map_str.size() =
533
- if (map_str.size () ) {
534
- map_str[map_str.size() - 2] = '}';
535
- map_str.resize(map_str.size() - 1);
536
- }
537
-
538
- // std::cout << map_str;
539
-
540
- return map_str;
541
- }
542
-
543
- return "Error string";
544
- };
545
-
546
- const Object& Object::print() const {
547
- std::cout << (std::string)(*this) << "<br/>";
548
- return *this;
549
- }
550
- Object construct(const long long int a) { union Object_v un; un.long_long = a; return Object {0, un.d}; }
551
- Object construct(const std::map<Object, Object> && a) {Object_v un; un.map = &a; return Object{4, un.d}; }
552
-
553
- Object construct(Array && a ) {Object_v q; q.array = &a; return Object{3, q.d}; }
554
- Object operator ""_c(unsigned long long a) {
555
- return construct(a);
556
- }
557
-
558
- Object construct(const double a) {
559
- return Object{1, a};
560
-
561
- }
562
-
563
-
564
- Object construct(const char* a) {
565
- union {
566
- double d;
567
- const void* v; } b;
568
- b.v = a;
569
-
570
- return Object{2, b.d};
571
- }
572
-
573
-
574
-
575
- ` + additional_cpp_code()); //moremore+more_cpp_code();
576
- }
577
- function nums(a) {
578
- if (typeof a != "number") return mod(a);
579
-
580
- //while (1) console.log(a)
581
- if (a.toString().includes(".")) {
582
- return surround(a);
583
- } else {
584
- return surround(a + "ll");
585
- }
586
- }
587
-
588
- function cpp_pre_code() {
589
- return cpp_code();
590
- }
591
- function set_kv(kv) {
592
- for (var i_ of [0, 1]) kv[i_] = nums(kv[i_]);
593
-
594
- //}
595
-
596
- //}
597
- }
598
-
599
- function surround(a) {
600
- return "construct(" + a + ")";
601
- }
602
- function mod(array, a = 0) {
603
- if (typeof array == "string") {
604
- return surround(JSON.stringify(array));
605
- }
606
- a = a + 1;
607
- if (a == 1) {
608
- var str = " Array{";
609
- } else var str = "";
610
- var element = false;
611
-
612
- try {
613
- // let str = "";
614
- if (typeof array == "object" && array.length === undefined) {
615
- str = "construct(" + "\n" + "\t".repeat(a) + " std::map<Object, Object >{";
616
- // var element
617
- var a = 0;
618
- console.log(array);
619
- // fs.writeFileSync("args/" +
620
- const s = JSON.stringify;
621
- for (var i in array) {
622
- var kv = [i, array[i]];
623
- element = true;
624
- set_kv(kv);
625
- const t = " Object ";
626
- const pair = "std::pair<" + t + "," + t + ">";
627
- str += pair + "(" + kv.join(",") + ")";
628
-
629
- str += ", ";
630
- }
631
- str = str.replace(/, $/, "}" + ") , /* end of map */"); //";
632
- } else if (array.length === undefined) {
633
- array = ["", array];
634
- set_kv(array);
635
- return array[1];
636
- } else
637
- for (var i of array) {
638
- // if (a ==
639
- if (typeof i != "number") {
640
- if (typeof i == "object" && i.join === undefined) {
641
- str += mod(i, a);
642
- } else if (typeof i == "string") {
643
- const SEPARATOR = ",";
644
- str +=
645
- "construct(" + JSON.stringify(i) + ") /* string literal */" + SEPARATOR;
646
- } else {
647
- str +=
648
- "\t".repeat(a) +
649
- "construct(" +
650
- "Array" +
651
- "{" +
652
- "\n" +
653
- "\t".repeat(a) +
654
- mod(i, a) +
655
- "\t".repeat(a - 1) +
656
- "}" +
657
- ")" +
658
- ",\n";
659
- }
660
- } else {
661
- const value = ["", i];
662
- set_kv(value);
663
- str += value[1] + ", ";
664
- }
665
- }
666
-
667
- if (a == 1) str += "}";
668
- //str = str.slice(0, s
669
-
670
- return str.replace(/, $/, "");
671
- } catch (e) {
672
- console.warn(e);
673
- process.exit(1);
674
- }
675
- }
676
-
677
- //#include <iostream>
678
-
679
- function additional_cpp_code() {
680
- return `
681
- #include \"fcgio.h\"
682
- using namespace std;
683
- #define endl "<br />"
684
- static inline void* ${prog_name}_main ();
685
- static int mmain();
686
-
687
- int
688
- main_
689
- (
690
- int argc, char** argv, char** envp)
691
- {
692
- (void)envp;
693
- Array args{};
694
- for (int i = 0; i < argc; ++i)
695
- args << construct(argv[i]);
696
- //auto content = (string)args.html("Title"); //cout << c
697
- auto content=std::string{};
698
- cout << Array{construct(1ll)}.html("Hello");
699
- //cout << content;
700
-
701
-
702
- const auto server=0;
703
-
704
- if (server) {
705
- // Backup the stdio streambufs
706
- streambuf * cin_streambuf = cin.rdbuf();
707
- streambuf * cout_streambuf = cout.rdbuf();
708
- streambuf * cerr_streambuf = cerr.rdbuf();
709
-
710
- FCGX_Request request;
711
-
712
- FCGX_Init();
713
- /*
714
- *
715
- *
716
- *
717
- * The above function seems to memory leak 1 block of 768 bytes. It never deletes it at exit.
718
- *
719
- *
720
- *
721
- */
722
- FCGX_InitRequest(&request, 0, 0);
723
-
724
- while (FCGX_Accept_r(&request) == 0) {
725
- fcgi_streambuf cin_fcgi_streambuf(request.in);
726
- fcgi_streambuf cout_fcgi_streambuf(request.out);
727
- fcgi_streambuf cerr_fcgi_streambuf(request.err);
728
-
729
- cin.rdbuf(&cin_fcgi_streambuf);
730
- cout.rdbuf(&cout_fcgi_streambuf);
731
- cerr.rdbuf(&cerr_fcgi_streambuf);
732
-
733
- cout << content;
734
-
735
- // system(\"echo 5 > /root/six\");
736
- mmain();
737
- cout << "Where?";
738
- // system(\"echo 6\");
739
-
740
- // Note: the fcgi_streambuf destructor will auto flush
741
- }
742
-
743
- // restore stdio streambufs
744
- cin.rdbuf(cin_streambuf);
745
- cout.rdbuf(cout_streambuf);
746
- cerr.rdbuf(cerr_streambuf);
747
- }
748
-
749
- ${prog_name}_main();
750
-
751
- return 0;
752
- }
753
-
754
-
755
- static int mmain()
756
- {
757
- std::string command(\"ls * 2>&1\");
758
-
759
- char buffer[4096];
760
- std::string result;
761
-
762
- // std::cout << "Opening reading pipe"
763
- FILE* pipe = popen(command.c_str(), \"r\");
764
- if (!pipe)
765
- {
766
- std::cerr << \"Couldn't start command.\" << endl;
767
- return 0;
768
- }
769
- while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
770
- //std::cout << \"Reading...\" << std::endl;
771
- result += buffer;
772
- }
773
- auto returnCode = pclose(pipe);
774
-
775
- std::cout << result << endl;
776
- std::cout << returnCode << endl;
777
-
778
- // ${prog_name}_main();
779
-
780
- ${prog_name}_main ();
781
- return 0;
782
- }
783
- `;
784
- }