-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
73 lines (64 loc) · 1.5 KB
/
main.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
#include <iostream>
#include "mewlib.h"
#include "virtual.hpp"
#if defined(_WIN32)
#include <windows.h>
#include <libloaderapi.h>
#endif
const char* executable_name() {
#if defined(PLATFORM_POSIX) || defined(__linux__) //check defines for your setup
std::string sp;
std::ifstream("/proc/self/comm") >> sp;
return sp.c_str();
#elif defined(_WIN32)
char* buf = new char[MAX_PATH];
GetModuleFileNameA(NULL, buf, MAX_PATH);
return buf;
#else
MewUserAssert(false, "unrecognized platform");
#endif
}
char** SkipToExec(int argc, char** args) {
const char* exec_name = executable_name();
char** begin = args;
char** end = args+(argc*sizeof(*args));
while (begin != end) {
char* arg = *(begin++);
// printf("\n{[%s][%s]}", exec_name, arg);
if (strcmp(arg, exec_name) == 0) {
return begin;
}
}
return nullptr;
}
// #include <stdafx.h>
#include <iostream>
using namespace std;
#if _WIN32_WINNT < 0x0500
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#ifdef _WIN32
#include <windows.h>
#include "Wincon.h"
#endif
int main(int argc, char** argv) {
if (argc < 2) {
printf("Usage:\n");
printf("> ./nanvm <path/to/file>");
exit(1);
}
const char** real_args = (const char**)SkipToExec(argc, argv);
const char* path = real_args[0];
Virtual::Execute(path);
#ifdef _WIN32
HWND consoleWnd = GetConsoleWindow();
DWORD dwProcessId;
GetWindowThreadProcessId(consoleWnd, &dwProcessId);
if (GetCurrentProcessId()==dwProcessId) {
printf("\n");
system("pause");
}
#endif
return 0;
}