summaryrefslogtreecommitdiffhomepage
path: root/dev/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc
blob: ed5378244c75662df0062fa96429eb1f2baf3934 (plain)
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
/*
 *	========================================================
 *
 *	C++ Preprocessor Driver
 * 	Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license.
 *
 * 	========================================================
 */

/// BUGS: 0

#include <CompilerKit/ErrorID.h>
#include <CompilerKit/Frontend.h>
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <vector>

#define kMacroPrefix '#'

/// @author Amlal El Mahrouss (amlal@nekernel.org)
/// @file CPlusPlusPreprocessor.cc
/// @brief Preprocessor.

typedef Int32 (*bpp_parser_fn_t)(CompilerKit::STLString& line, std::ifstream& hdr_file,
                                 std::ofstream& pp_out);

/////////////////////////////////////////////////////////////////////////////////////////

// @brief Preprocessor internal types.

/////////////////////////////////////////////////////////////////////////////////////////

namespace Detail {
enum {
  kInvalid = 0,
  kEqual   = 100,
  kGreaterEqThan,
  kLesserEqThan,
  kGreaterThan,
  kLesserThan,
  kNotEqual,
  kCount = 6,
};

struct bpp_macro_condition final {
  int32_t                fType;
  CompilerKit::STLString fTypeName;

  void Print() {
    std::cout << "type: " << fType << "\n";
    std::cout << "type_name: " << fTypeName << "\n";
  }
};

struct bpp_macro final {
  std::vector<CompilerKit::STLString> fArgs;
  CompilerKit::STLString              fName;
  CompilerKit::STLString              fValue;

  void Print() {
    std::cout << "name: " << fName << "\n";
    std::cout << "value: " << fValue << "\n";

    for (auto& arg : fArgs) {
      std::cout << "arg: " << arg << "\n";
    }
  }
};
}  // namespace Detail

static std::vector<CompilerKit::STLString> kFiles;
static std::vector<Detail::bpp_macro>      kMacros;
static std::vector<CompilerKit::STLString> kIncludes;

static CompilerKit::STLString kWorkingDir = "";

/////////////////////////////////////////////////////////////////////////////////////////

// @name bpp_parse_if_condition
// @brief parse #if condition

/////////////////////////////////////////////////////////////////////////////////////////

int32_t bpp_parse_if_condition(Detail::bpp_macro_condition& cond, Detail::bpp_macro& macro,
                               bool& inactive_code, bool& defined,
                               CompilerKit::STLString& macro_str) {
  if (cond.fType == Detail::kEqual) {
    auto substr_macro = macro_str.substr(macro_str.find(macro.fName) + macro.fName.size());

    if (substr_macro.find(macro.fValue) != CompilerKit::STLString::npos) {
      if (macro.fValue == "0") {
        defined       = false;
        inactive_code = true;

        return 1;
      }

      defined       = true;
      inactive_code = false;

      return 1;
    }
  } else if (cond.fType == Detail::kNotEqual) {
    auto substr_macro = macro_str.substr(macro_str.find(macro.fName) + macro.fName.size());

    if (substr_macro.find(macro.fName) != CompilerKit::STLString::npos) {
      if (substr_macro.find(macro.fValue) != CompilerKit::STLString::npos) {
        defined       = false;
        inactive_code = true;

        return 1;
      }

      defined       = true;
      inactive_code = false;

      return 1;
    }

    return 0;
  }

  auto substr_macro = macro_str.substr(macro_str.find(macro.fName) + macro.fName.size());

  CompilerKit::STLString number;

  for (auto& macro_num : kMacros) {
    if (substr_macro.find(macro_num.fName) != CompilerKit::STLString::npos) {
      for (size_t i = 0; i < macro_num.fName.size(); ++i) {
        if (isdigit(macro_num.fValue[i])) {
          number += macro_num.fValue[i];
        } else {
          number.clear();
          break;
        }
      }

      break;
    }
  }

  size_t y = 2;

  /* last try */
  for (; y < macro_str.size(); y++) {
    if (isdigit(macro_str[y])) {
      for (size_t x = y; x < macro_str.size(); x++) {
        if (macro_str[x] == ' ') break;

        number += macro_str[x];
      }

      break;
    }
  }

  size_t rhs = atol(macro.fValue.c_str());
  size_t lhs = atol(number.c_str());

  if (lhs == 0) {
    number.clear();
    ++y;

    for (; y < macro_str.size(); y++) {
      if (isdigit(macro_str[y])) {
        for (size_t x = y; x < macro_str.size(); x++) {
          if (macro_str[x] == ' ') break;

          number += macro_str[x];
        }

        break;
      }
    }

    lhs = atol(number.c_str());
  }

  if (cond.fType == Detail::kGreaterThan) {
    if (lhs < rhs) {
      defined       = true;
      inactive_code = false;

      return 1;
    }

    return 0;
  }

  if (cond.fType == Detail::kGreaterEqThan) {
    if (lhs <= rhs) {
      defined       = true;
      inactive_code = false;

      return 1;
    }

    return 0;
  }

  if (cond.fType == Detail::kLesserEqThan) {
    if (lhs >= rhs) {
      defined       = true;
      inactive_code = false;

      return 1;
    }

    return 0;
  }

  if (cond.fType == Detail::kLesserThan) {
    if (lhs > rhs) {
      defined       = true;
      inactive_code = false;

      return 1;
    }

    return 0;
  }

  return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////

// @brief stores every included file here.

/////////////////////////////////////////////////////////////////////////////////////////

std::vector<CompilerKit::STLString> kAllIncludes;

/////////////////////////////////////////////////////////////////////////////////////////

// @name bpp_parse_file
// @brief parse file to preprocess it.

/////////////////////////////////////////////////////////////////////////////////////////

void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) {
  CompilerKit::STLString hdr_line;
  CompilerKit::STLString line_after_include;

  bool inactive_code = false;
  bool defined       = false;

  try {
    while (std::getline(hdr_file, hdr_line)) {
      if (inactive_code) {
        if (hdr_line.find("#endif") == CompilerKit::STLString::npos) {
          continue;
        } else if (hdr_line[0] == kMacroPrefix &&
                   hdr_line.find("#endif") != CompilerKit::STLString::npos) {
          inactive_code = false;
        }
      }

      if (hdr_line.find("*/") != CompilerKit::STLString::npos) {
        hdr_line.erase(hdr_line.find("*/"), strlen("*/"));
      }

      if (hdr_line.find("/*") != CompilerKit::STLString::npos) {
        inactive_code = true;

        // get rid of comment.
        hdr_line.erase(hdr_line.find("/*"));
      }

      if (hdr_line[0] == kMacroPrefix && hdr_line.find("endif") != CompilerKit::STLString::npos) {
        if (!defined && inactive_code) {
          inactive_code = false;
          defined       = false;

          continue;
        }

        continue;
      }

      if (!defined && inactive_code) {
        continue;
      }

      if (defined && inactive_code) {
        continue;
      }

      for (auto macro : kMacros) {
        if (CompilerKit::find_word(hdr_line, macro.fName)) {
          if (hdr_line.substr(hdr_line.find(macro.fName)).find(macro.fName + '(') !=
              CompilerKit::STLString::npos) {
            if (!macro.fArgs.empty()) {
              CompilerKit::STLString              symbol_val = macro.fValue;
              std::vector<CompilerKit::STLString> args;

              size_t x_arg_indx = 0;

              CompilerKit::STLString line_after_define = hdr_line;
              CompilerKit::STLString str_arg;

              if (line_after_define.find("(") != CompilerKit::STLString::npos) {
                line_after_define.erase(0, line_after_define.find("(") + 1);

                for (auto& subc : line_after_define) {
                  if (subc == ' ' || subc == '\t') continue;

                  if (subc == ',' || subc == ')') {
                    if (str_arg.empty()) continue;

                    args.push_back(str_arg);

                    str_arg.clear();

                    continue;
                  }

                  str_arg.push_back(subc);
                }
              }

              for (auto arg : macro.fArgs) {
                if (symbol_val.find(macro.fArgs[x_arg_indx]) != CompilerKit::STLString::npos) {
                  symbol_val.replace(symbol_val.find(macro.fArgs[x_arg_indx]),
                                     macro.fArgs[x_arg_indx].size(), args[x_arg_indx]);
                  ++x_arg_indx;
                } else {
                  throw std::runtime_error("cppdrv: Internal error.");
                }
              }

              auto len = macro.fName.size();
              len += symbol_val.size();
              len += 2;  // ( and )

              hdr_line.erase(hdr_line.find(")"), 1);

              hdr_line.replace(hdr_line.find(hdr_line.substr(hdr_line.find(macro.fName + '('))),
                               len, symbol_val);
            } else {
              auto value = macro.fValue;

              hdr_line.replace(hdr_line.find(macro.fName), macro.fName.size(), value);
            }
          }
        }
      }

      if (hdr_line[0] == kMacroPrefix && hdr_line.find("define ") != CompilerKit::STLString::npos) {
        auto line_after_define = hdr_line.substr(hdr_line.find("define ") + strlen("define "));

        CompilerKit::STLString macro_value;
        CompilerKit::STLString macro_key;

        std::size_t pos = 0UL;

        std::vector<CompilerKit::STLString> args;
        bool                                on_args = false;

        for (auto& ch : line_after_define) {
          ++pos;

          if (ch == '(') {
            on_args = true;
            continue;
          }

          if (ch == ')') {
            on_args = false;
            continue;
          }

          if (ch == '\\') continue;

          if (on_args) continue;

          if (ch == ' ') {
            for (size_t i = pos; i < line_after_define.size(); i++) {
              macro_value += line_after_define[i];
            }

            break;
          }

          macro_key += ch;
        }

        CompilerKit::STLString str;

        if (line_after_define.find("(") != CompilerKit::STLString::npos) {
          line_after_define.erase(0, line_after_define.find("(") + 1);

          for (auto& subc : line_after_define) {
            if (subc == ',' || subc == ')') {
              if (str.empty()) continue;

              args.push_back(str);

              str.clear();

              continue;
            }

            str.push_back(subc);
          }
        }

        Detail::bpp_macro macro;

        macro.fArgs  = args;
        macro.fName  = macro_key;
        macro.fValue = macro_value;

        kMacros.emplace_back(macro);

        continue;
      }

      if (hdr_line[0] != kMacroPrefix) {
        if (inactive_code) {
          continue;
        }

        pp_out << hdr_line << std::endl;

        continue;
      }

      if (hdr_line[0] == kMacroPrefix && hdr_line.find("ifndef") != CompilerKit::STLString::npos) {
        auto line_after_ifndef = hdr_line.substr(hdr_line.find("ifndef") + strlen("ifndef") + 1);
        CompilerKit::STLString macro;

        for (auto& ch : line_after_ifndef) {
          if (ch == ' ') {
            break;
          }

          macro += ch;
        }

        if (macro == "0") {
          defined       = true;
          inactive_code = false;
          continue;
        }

        if (macro == "1") {
          defined       = false;
          inactive_code = true;

          continue;
        }

        bool found = false;

        defined       = true;
        inactive_code = false;

        for (auto& macro_ref : kMacros) {
          if (hdr_line.find(macro_ref.fName) != CompilerKit::STLString::npos) {
            found = true;
            break;
          }
        }

        if (found) {
          defined       = false;
          inactive_code = true;

          continue;
        }
      } else if (hdr_line[0] == kMacroPrefix &&
                 hdr_line.find("else") != CompilerKit::STLString::npos) {
        if (!defined && inactive_code) {
          inactive_code = false;
          defined       = true;

          continue;
        } else {
          defined       = false;
          inactive_code = true;

          continue;
        }
      } else if (hdr_line[0] == kMacroPrefix &&
                 hdr_line.find("ifdef") != CompilerKit::STLString::npos) {
        auto line_after_ifdef = hdr_line.substr(hdr_line.find("ifdef") + strlen("ifdef") + 1);
        CompilerKit::STLString macro;

        for (auto& ch : line_after_ifdef) {
          if (ch == ' ') {
            break;
          }

          macro += ch;
        }

        if (macro == "0") {
          defined       = false;
          inactive_code = true;

          continue;
        }

        if (macro == "1") {
          defined       = true;
          inactive_code = false;

          continue;
        }

        defined       = false;
        inactive_code = true;

        for (auto& macro_ref : kMacros) {
          if (hdr_line.find(macro_ref.fName) != CompilerKit::STLString::npos) {
            defined       = true;
            inactive_code = false;

            break;
          }
        }
      } else if (hdr_line[0] == kMacroPrefix &&
                 hdr_line.find("if") != CompilerKit::STLString::npos) {
        inactive_code = true;

        std::vector<Detail::bpp_macro_condition> bpp_macro_condition_list = {
            {
                .fType     = Detail::kEqual,
                .fTypeName = "==",
            },
            {
                .fType     = Detail::kNotEqual,
                .fTypeName = "!=",
            },
            {
                .fType     = Detail::kLesserThan,
                .fTypeName = "<",
            },
            {
                .fType     = Detail::kGreaterThan,
                .fTypeName = ">",
            },
            {
                .fType     = Detail::kLesserEqThan,
                .fTypeName = "<=",
            },
            {
                .fType     = Detail::kGreaterEqThan,
                .fTypeName = ">=",
            },
        };

        int32_t good_to_go = 0;

        for (auto& macro_condition : bpp_macro_condition_list) {
          if (hdr_line.find(macro_condition.fTypeName) != CompilerKit::STLString::npos) {
            for (auto& found_macro : kMacros) {
              if (hdr_line.find(found_macro.fName) != CompilerKit::STLString::npos) {
                good_to_go = bpp_parse_if_condition(macro_condition, found_macro, inactive_code,
                                                    defined, hdr_line);

                break;
              }
            }
          }
        }

        if (good_to_go) continue;

        auto line_after_if = hdr_line.substr(hdr_line.find("if") + strlen("if") + 1);
        CompilerKit::STLString macro;

        for (auto& ch : line_after_if) {
          if (ch == ' ') {
            break;
          }

          macro += ch;
        }

        if (macro == "0") {
          defined       = false;
          inactive_code = true;
          continue;
        }

        if (macro == "1") {
          defined       = true;
          inactive_code = false;

          continue;
        }

        // last try, is it defined to be one?
        for (auto& macro_ref : kMacros) {
          if (macro_ref.fName.find(macro) != CompilerKit::STLString::npos &&
              macro_ref.fValue == "1") {
            inactive_code = false;
            defined       = true;

            break;
          }
        }
      } else if (hdr_line[0] == kMacroPrefix &&
                 hdr_line.find("warning") != CompilerKit::STLString::npos) {
        auto line_after_warning = hdr_line.substr(hdr_line.find("warning") + strlen("warning") + 1);
        CompilerKit::STLString message;

        for (auto& ch : line_after_warning) {
          if (ch == '\r' || ch == '\n') {
            break;
          }

          message += ch;
        }

        std::cout << "warn: " << message << std::endl;
      } else if (hdr_line[0] == kMacroPrefix &&
                 hdr_line.find("error") != CompilerKit::STLString::npos) {
        auto line_after_warning = hdr_line.substr(hdr_line.find("error") + strlen("error") + 1);
        CompilerKit::STLString message;

        for (auto& ch : line_after_warning) {
          if (ch == '\r' || ch == '\n') {
            break;
          }

          message += ch;
        }

        throw std::runtime_error("error: " + message);
      } else if (hdr_line[0] == kMacroPrefix &&
                 hdr_line.find("include ") != CompilerKit::STLString::npos) {
        line_after_include = hdr_line.substr(hdr_line.find("include ") + strlen("include "));

      kIncludeFile:
        auto it = std::find(kAllIncludes.cbegin(), kAllIncludes.cend(), line_after_include);

        if (it != kAllIncludes.cend()) {
          continue;
        }

        CompilerKit::STLString path;

        kAllIncludes.push_back(line_after_include);

        bool enable    = false;
        bool not_local = false;

        for (auto& ch : line_after_include) {
          if (ch == ' ') continue;

          if (ch == '<') {
            not_local = true;
            enable    = true;

            continue;
          }

          if (ch == '\"') {
            not_local = false;
            enable    = true;
            continue;
          }

          if (enable) {
            path += ch;
          }
        }

        if (not_local) {
          bool open = false;

          if (path.ends_with('>')) {
            path.erase(path.find('>'));
          }

          if (path.ends_with('"')) {
            path.erase(path.find('"'));
          }

          for (auto& include : kIncludes) {
            CompilerKit::STLString header_path = include;
            header_path.push_back('/');
            header_path += path;

            std::ifstream header(header_path);

            if (!header.is_open()) continue;

            open = true;

            bpp_parse_file(header, pp_out);

            break;
          }

          if (!open) {
            throw std::runtime_error("cppdrv: no such include file: " + path);
          }
        } else {
          std::ifstream header(path);

          if (!header.is_open()) throw std::runtime_error("cppdrv: no such include file: " + path);

          bpp_parse_file(header, pp_out);
        }
      } else {
        std::cerr << ("cppdrv: unknown pre-processor directive, " + hdr_line) << "\n";
        continue;
      }
    }
  } catch (std::out_of_range& oor) {
    return;
  }
}

/////////////////////////////////////////////////////////////////////////////////////////

// @brief main entrypoint of app.

/////////////////////////////////////////////////////////////////////////////////////////

NECTI_MODULE(CPlusPlusPreprocessorMain) {
  try {
    bool skip        = false;
    bool double_skip = false;

    Detail::bpp_macro macro_1;

    macro_1.fName  = "__true";
    macro_1.fValue = "1";

    kMacros.push_back(macro_1);

    Detail::bpp_macro macro_unreachable;

    macro_unreachable.fName  = "__unreachable";
    macro_unreachable.fValue = "__compilerkit_unreachable";

    kMacros.push_back(macro_unreachable);

    Detail::bpp_macro macro_unused;

    macro_unreachable.fName  = "__unused";
    macro_unreachable.fValue = "__compilerkit_unused";

    kMacros.push_back(macro_unused);

    Detail::bpp_macro macro_0;

    macro_0.fName  = "__false";
    macro_0.fValue = "0";

    kMacros.push_back(macro_0);

    Detail::bpp_macro macro_zka;

    macro_zka.fName  = "__NECTI__";
    macro_zka.fValue = "1";

    kMacros.push_back(macro_zka);

    Detail::bpp_macro macro_cxx;

    macro_cxx.fName  = "__cplusplus";
    macro_cxx.fValue = "202302L";

    kMacros.push_back(macro_cxx);

    Detail::bpp_macro macro_size_t;
    macro_size_t.fName  = "__SIZE_TYPE__";
    macro_size_t.fValue = "unsigned long long int";

    kMacros.push_back(macro_size_t);

    macro_size_t.fName  = "__UINT32_TYPE__";
    macro_size_t.fValue = "unsigned int";

    kMacros.push_back(macro_size_t);

    macro_size_t.fName  = "__UINTPTR_TYPE__";
    macro_size_t.fValue = "unsigned long long int";

    kMacros.push_back(macro_size_t);

    for (auto index = 1UL; index < argc; ++index) {
      if (skip) {
        skip = false;
        continue;
      }

      if (double_skip) {
        ++index;
        double_skip = false;
        continue;
      }

      if (argv[index][0] == '-') {
        if (strcmp(argv[index], "-cpp-ver") == 0) {
          printf("%s\n",
                 "NeKernel Preprocessor Driver v1.11, (c) Amlal El Mahrouss 2024-2025 all rights "
                 "reserved.");

          return NECTI_SUCCESS;
        }

        if (strcmp(argv[index], "-cpp-help") == 0) {
          printf("%s\n",
                 "NeKernel Preprocessor Driver v1.11, (c) Amlal El Mahrouss 2024-2025 all rights "
                 "reserved.");
          printf("%s\n", "-cpp-working-dir <path>: set directory to working path.");
          printf("%s\n", "-cpp-include-dir <path>: add directory to include path.");
          printf("%s\n", "-cpp-def <name> <value>: define a macro.");
          printf("%s\n", "-cpp-ver: print the version.");
          printf("%s\n", "-cpp-help: show help (this current command).");

          return NECTI_SUCCESS;
        }

        if (strcmp(argv[index], "-cpp-include-dir") == 0) {
          CompilerKit::STLString inc = argv[index + 1];

          skip = true;

          kIncludes.push_back(inc);
        }

        if (strcmp(argv[index], "-cpp-working-dir") == 0) {
          CompilerKit::STLString inc = argv[index + 1];
          skip                       = true;
          kWorkingDir                = inc;
        }

        if (strcmp(argv[index], "-cpp-def") == 0 && argv[index + 1] != nullptr &&
            argv[index + 2] != nullptr) {
          CompilerKit::STLString macro_key = argv[index + 1];

          CompilerKit::STLString macro_value;
          bool                   is_string = false;

          for (int argv_find_len = 0; argv_find_len < strlen(argv[index]); ++argv_find_len) {
            if (!isdigit(argv[index][argv_find_len])) {
              is_string = true;
              macro_value += "\"";

              break;
            }
          }

          macro_value += argv[index + 2];

          if (is_string) macro_value += "\"";

          Detail::bpp_macro macro;
          macro.fName  = macro_key;
          macro.fValue = macro_value;

          kMacros.push_back(macro);

          double_skip = true;
        }

        continue;
      }

      kFiles.emplace_back(argv[index]);
    }

    if (kFiles.empty()) return NECTI_EXEC_ERROR;

    for (auto& file : kFiles) {
      if (!std::filesystem::exists(file)) continue;

      std::ifstream file_descriptor(file);
      std::ofstream file_descriptor_pp(file + ".pp");

      bpp_parse_file(file_descriptor, file_descriptor_pp);
    }

    return NECTI_SUCCESS;
  } catch (const std::runtime_error& e) {
    std::cout << e.what() << '\n';
  }

  return NECTI_EXEC_ERROR;
}

// Last rev 8-1-24