-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeld.c
81 lines (70 loc) · 1.73 KB
/
meld.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <process.h>
#include <shellapi.h>
#include <shlwapi.h>
static wchar_t meld_bin[MAX_PATH + 10];
static wchar_t **get_argv()
{
wchar_t **old_argv, **argv;
int argc;
int i;
old_argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if(old_argv == NULL) {
exit(1);
}
if (GetModuleFileNameW(NULL, meld_bin, MAX_PATH) == 0) {
exit(1);
}
PathRemoveFileSpecW(meld_bin);
wcscat(meld_bin, L"\\bin\\meld");
argv = (wchar_t **) malloc(sizeof (*argv) * (argc + 2));
argv[0] = old_argv[0];
argv[1] = meld_bin;
for(i = 1; i < argc; ++i) {
argv[i + 1] = old_argv[i];
}
argv[argc + 1] = NULL;
return argv;
}
static wchar_t **get_envp()
{
int i, n;
wchar_t *env_block, *p;
wchar_t **envp;
env_block = GetEnvironmentStringsW();
if (env_block == NULL) {
exit(1);
}
n = 0;
p = env_block;
while (*p != L'\0') {
++n;
p += wcslen(p) + 1;
}
envp = (wchar_t **) malloc(sizeof (*envp) * n + 1);
envp[0] = env_block;
for (i = 1; i < n; ++i) {
envp[i] = envp[i - 1] + wcslen(envp[i - 1]) + 1;
}
envp[n] = NULL;
return envp;
}
#ifdef USE_WINMAIN
#define PYTHON_EXE L"pythonw.exe"
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#else
#define PYTHON_EXE L"python.exe"
int main(int _argc, char *_argv[])
#endif
{
const wchar_t * const *argv;
const wchar_t * const *envp;
argv = (const wchar_t * const *) get_argv();
_putenv("LANG=en_US");
envp = (const wchar_t * const *) get_envp();
_wspawnvpe(_P_WAIT, PYTHON_EXE, argv, envp);
return 0;
}