msys2を呼び出せるようにした
@@ -29,7 +29,6 @@ | ||
29 | 29 | #include <windows.h> |
30 | 30 | #include <stdio.h> |
31 | 31 | #include <stdlib.h> |
32 | -#include <direct.h> | |
33 | 32 | #include <locale.h> |
34 | 33 | #include <string.h> |
35 | 34 | #include <errno.h> |
@@ -39,17 +38,12 @@ | ||
39 | 38 | |
40 | 39 | #include "cyglib.h" |
41 | 40 | |
42 | -//#define CYGWIN 1 | |
43 | -//#define MSYS2 1 | |
44 | - | |
45 | -#if !defined(CYGWIN) && !defined(MSYS2) | |
46 | -#define CYGWIN 1 | |
47 | -#endif | |
48 | - | |
49 | 41 | /** |
50 | - * cygwin1.dllを探す | |
42 | + * cygwin1.dll / msys-2.0.dllを探す | |
51 | 43 | * |
52 | - * @param[in] cygwin_dir (存在するであろう)フォルダ | |
44 | + * @param[in] dll_base dllファイル名 | |
45 | + * @param[in] cygwin_dir (存在するであろう)フォルダ(*1) | |
46 | + * @param[in] search_paths (*1)が見つからなかったときに探すパス | |
53 | 47 | * @param[out] find_dir 見つかったフォルダ free() すること |
54 | 48 | * @param[out] find_in_path 環境変数 PATH 内に見つかった |
55 | 49 | * |
@@ -56,27 +50,11 @@ | ||
56 | 50 | * @retval TRUE 見つかった |
57 | 51 | * @retval FALSE 見つからない |
58 | 52 | */ |
59 | -static BOOL CygwinSearchDLL(const wchar_t *cygwin_dir, wchar_t **find_dir, BOOL *find_in_path) | |
53 | +static BOOL SearchDLL(const wchar_t *dll_base, const wchar_t *cygwin_dir, const wchar_t **search_paths, wchar_t **find_dir, BOOL *find_in_path) | |
60 | 54 | { |
61 | 55 | wchar_t file[MAX_PATH]; |
62 | 56 | wchar_t *filename; |
63 | 57 | wchar_t c; |
64 | -#if CYGWIN | |
65 | - const wchar_t *dll_base = L"cygwin1"; | |
66 | - const wchar_t *search_paths[] = { | |
67 | - L"%c:\\cygwin\\bin", | |
68 | - L"%c:\\cygwin64\\bin", | |
69 | - NULL, | |
70 | - }; | |
71 | -#endif | |
72 | -#if MSYS2 | |
73 | - const wchar_t *dll_base = L"msys-2.0"; | |
74 | - const wchar_t *search_paths[] = { | |
75 | - L"%c:\\msys\\usr\\bin", | |
76 | - L"%c:\\msys64\\usr\\bin", | |
77 | - NULL, | |
78 | - }; | |
79 | -#endif | |
80 | 58 | wchar_t *dll; |
81 | 59 | int i; |
82 | 60 | DWORD r; |
@@ -88,7 +66,7 @@ | ||
88 | 66 | if (cygwin_dir != NULL && cygwin_dir[0] != 0) { |
89 | 67 | // SearchPathW() で探す |
90 | 68 | dll = NULL; |
91 | - awcscats(&dll, L"bin\\", dll_base, L".dll", NULL); | |
69 | + awcscats(&dll, L"bin\\", dll_base, NULL); | |
92 | 70 | r = SearchPathW(cygwin_dir, dll, L".dll", _countof(file), file, &filename); |
93 | 71 | free(dll); |
94 | 72 | if (r > 0) { |
@@ -97,7 +75,7 @@ | ||
97 | 75 | |
98 | 76 | // SearchPathW() だと "msys-2.0.dll" が見つけることができない (Windows 10) |
99 | 77 | dll = NULL; |
100 | - awcscats(&dll, cygwin_dir, L"\\", dll_base, L".dll", NULL); | |
78 | + awcscats(&dll, cygwin_dir, L"\\bin\\", dll_base, L".dll", NULL); | |
101 | 79 | r = GetFileAttributesW(dll); |
102 | 80 | if (r != INVALID_FILE_ATTRIBUTES) { |
103 | 81 | // 見つかった |
@@ -211,7 +189,7 @@ | ||
211 | 189 | * @retval ERROR_NOT_ENOUGH_MEMORY メモリ不足 |
212 | 190 | * @retval ERROR_OPEN_FAILED 実行できない |
213 | 191 | */ |
214 | -DWORD CygwinConnect(const wchar_t *CygwinDirectory, const wchar_t *cmdline) | |
192 | +static DWORD Connect(const wchar_t *cygterm_exe, const wchar_t *dll_base, const wchar_t *CygwinDirectory, const wchar_t **search_paths, const wchar_t *cmdline) | |
215 | 193 | { |
216 | 194 | BOOL find_cygwin; |
217 | 195 | wchar_t *find_dir; |
@@ -219,14 +197,8 @@ | ||
219 | 197 | wchar_t *ExeDirW; |
220 | 198 | wchar_t *cygterm_cmd; |
221 | 199 | DWORD e; |
222 | -#if CYGWIN | |
223 | - const wchar_t *cygterm_exe = L"cygterm.exe"; | |
224 | -#endif | |
225 | -#if MSYS2 | |
226 | - const wchar_t *cygterm_exe = L"msys2term.exe"; | |
227 | -#endif | |
228 | 200 | |
229 | - find_cygwin = CygwinSearchDLL(CygwinDirectory, &find_dir, &find_in_path); | |
201 | + find_cygwin = SearchDLL(dll_base, CygwinDirectory, search_paths, &find_dir, &find_in_path); | |
230 | 202 | if (find_cygwin == FALSE) { |
231 | 203 | return ERROR_FILE_NOT_FOUND; |
232 | 204 | } |
@@ -257,3 +229,42 @@ | ||
257 | 229 | |
258 | 230 | return NO_ERROR; |
259 | 231 | } |
232 | + | |
233 | +/** | |
234 | + * Connect to local cygwin | |
235 | + * cygtermを実行 | |
236 | + * | |
237 | + * @param[in] CygwinDirectory Cygwinがインストールしてあるフォルダ | |
238 | + * 見つからなければデフォルトフォルダなどを探す | |
239 | + * @param[in] cmdline cygtermに渡すコマンドライン引数 | |
240 | + * NULLのとき引数なし | |
241 | + * @retval NO_ERROR 実行できた | |
242 | + * @retval ERROR_FILE_NOT_FOUND cygwinが見つからない(cygwin1.dllが見つからない) | |
243 | + * @retval ERROR_NOT_ENOUGH_MEMORY メモリ不足 | |
244 | + * @retval ERROR_OPEN_FAILED 実行できない | |
245 | + */ | |
246 | +DWORD CygwinConnect(const wchar_t *CygwinDirectory, const wchar_t *cmdline) | |
247 | +{ | |
248 | + static const wchar_t *cygterm_exe = L"cygterm.exe"; | |
249 | + static const wchar_t *dll_base = L"cygwin1"; | |
250 | + static const wchar_t *search_paths[] = { | |
251 | + L"%c:\\cygwin\\bin", | |
252 | + L"%c:\\cygwin64\\bin", | |
253 | + NULL, | |
254 | + }; | |
255 | + | |
256 | + return Connect(cygterm_exe, dll_base, CygwinDirectory, search_paths, cmdline); | |
257 | +} | |
258 | + | |
259 | +DWORD Msys2Connect(const wchar_t *Msys2Directory, const wchar_t *cmdline) | |
260 | +{ | |
261 | + static const wchar_t *cygterm_exe = L"msys2term.exe"; | |
262 | + static const wchar_t *dll_base = L"msys-2.0"; | |
263 | + static const wchar_t *search_paths[] = { | |
264 | + L"%c:\\msys\\usr\\bin", | |
265 | + L"%c:\\msys64\\usr\\bin", | |
266 | + NULL, | |
267 | + }; | |
268 | + | |
269 | + return Connect(cygterm_exe, dll_base, Msys2Directory, search_paths, cmdline); | |
270 | +} |
@@ -35,6 +35,7 @@ | ||
35 | 35 | #endif |
36 | 36 | |
37 | 37 | DWORD CygwinConnect(const wchar_t *CygwinDirectory, const wchar_t *cmdline); |
38 | +DWORD Msys2Connect(const wchar_t *Msys2Directory, const wchar_t *cmdline); | |
38 | 39 | |
39 | 40 | #ifdef __cplusplus |
40 | 41 | } |