-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmlang2cpp.cpp
More file actions
108 lines (95 loc) · 2.61 KB
/
mlang2cpp.cpp
File metadata and controls
108 lines (95 loc) · 2.61 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
/*
$Author = Sargis Ananyan;
$Corp = RedM Inc;
$Web = https://redm.pro/;
$Lincese = BSD 3;
$Name = mLang;
$Description = A programming language for web programming.;
*/
#include "compiler/compiler.h"
#include <pwd.h>
/***
* Kitten compiler for PHP interface
**/
void usage (void) {
printf ("This is for internal usage only! Use mlang.py\n"
"mlang2cpp. Convert php code into C++ code\n"
"-a\tUse safe integer arithmetic\n"
"-b<dir>\tBase directory. Use it when compiling the same code from different directories\n"
"-d<dir>\tDestination directory\n"
"-f<file>\tInternal file with library headers and e.t.c.\n"
"-i<file>\tIndex for faster compilations\n"
"-I<dir>\tDirectory where php files will be searched\n"
"-j<thread_cnt>\tUse multiple threads\n"
"-r\tSplit output into multiple directories\n"
"-v\tVerbosity\n");
}
static void runtime_handler (const int sig) {
fprintf (stderr, "%s caught, terminating program\n", sig == SIGSEGV ? "SIGSEGV" : "SIGABRT");
dl_print_backtrace();
dl_print_backtrace_gdb();
_exit (EXIT_FAILURE);
}
static void set_debug_handlers (void) {
// signal (SIGFPE, dl_runtime_handler);
dl_signal (SIGSEGV, runtime_handler);
dl_signal (SIGABRT, runtime_handler);
}
int main (int argc, char *argv[]) {
set_debug_handlers();
int i;
int verbosity = 0;
struct passwd *user_pwd = getpwuid (getuid());
dl_passert (user_pwd != NULL, "Failed to get user name");
char *user = user_pwd->pw_name;
if (user != NULL && (!strcmp (user, "levlam") || !strcmp (user, "arseny30"))) {
verbosity = 3;
}
CompilerArgs *args = new CompilerArgs();
while ((i = getopt (argc, argv, "arvb:f:d:i:j:I:")) != -1) {
switch (i) {
case 'a':
args->set_use_safe_integer_arithmetic (true);
break;
case 'f':
args->set_functions_txt (optarg);
break;
case 'I':
args->add_include (optarg);
break;
case 'd':
args->set_dest_dir (optarg);
break;
case 'i':
args->set_index_path (optarg);
break;
case 'r':
args->set_use_subdirs (true);
break;
case 'b':
args->set_base_dir (optarg);
break;
case 'v':
verbosity++;
break;
case 'j':
args->set_threads_number (atoi (optarg));
break;
default:
printf ("Unknown option '%c'", (char)i);
usage();
exit (1);
}
}
args->set_verbosity (verbosity);
if (optind >= argc) {
usage();
return 2;
}
while (optind < argc) {
args->add_main_file (argv[optind]);
optind++;
}
compiler_execute (args);
return 0;
}