• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision9520 (tree)
Time2021-11-10 22:02:08
Authorzmatsuo

Log Message

msys2を呼び出せるようにした

Change Summary

Incremental Difference

--- trunk/cygwin/cyglib/cyglib.c (revision 9519)
+++ trunk/cygwin/cyglib/cyglib.c (revision 9520)
@@ -29,7 +29,6 @@
2929 #include <windows.h>
3030 #include <stdio.h>
3131 #include <stdlib.h>
32-#include <direct.h>
3332 #include <locale.h>
3433 #include <string.h>
3534 #include <errno.h>
@@ -39,17 +38,12 @@
3938
4039 #include "cyglib.h"
4140
42-//#define CYGWIN 1
43-//#define MSYS2 1
44-
45-#if !defined(CYGWIN) && !defined(MSYS2)
46-#define CYGWIN 1
47-#endif
48-
4941 /**
50- * cygwin1.dllを探す
42+ * cygwin1.dll / msys-2.0.dllを探す
5143 *
52- * @param[in] cygwin_dir (存在するであろう)フォルダ
44+ * @param[in] dll_base dllファイル名
45+ * @param[in] cygwin_dir (存在するであろう)フォルダ(*1)
46+ * @param[in] search_paths (*1)が見つからなかったときに探すパス
5347 * @param[out] find_dir 見つかったフォルダ free() すること
5448 * @param[out] find_in_path 環境変数 PATH 内に見つかった
5549 *
@@ -56,27 +50,11 @@
5650 * @retval TRUE 見つかった
5751 * @retval FALSE 見つからない
5852 */
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)
6054 {
6155 wchar_t file[MAX_PATH];
6256 wchar_t *filename;
6357 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
8058 wchar_t *dll;
8159 int i;
8260 DWORD r;
@@ -88,7 +66,7 @@
8866 if (cygwin_dir != NULL && cygwin_dir[0] != 0) {
8967 // SearchPathW() で探す
9068 dll = NULL;
91- awcscats(&dll, L"bin\\", dll_base, L".dll", NULL);
69+ awcscats(&dll, L"bin\\", dll_base, NULL);
9270 r = SearchPathW(cygwin_dir, dll, L".dll", _countof(file), file, &filename);
9371 free(dll);
9472 if (r > 0) {
@@ -97,7 +75,7 @@
9775
9876 // SearchPathW() だと "msys-2.0.dll" が見つけることができない (Windows 10)
9977 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);
10179 r = GetFileAttributesW(dll);
10280 if (r != INVALID_FILE_ATTRIBUTES) {
10381 // 見つかった
@@ -211,7 +189,7 @@
211189 * @retval ERROR_NOT_ENOUGH_MEMORY メモリ不足
212190 * @retval ERROR_OPEN_FAILED 実行できない
213191 */
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)
215193 {
216194 BOOL find_cygwin;
217195 wchar_t *find_dir;
@@ -219,14 +197,8 @@
219197 wchar_t *ExeDirW;
220198 wchar_t *cygterm_cmd;
221199 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
228200
229- find_cygwin = CygwinSearchDLL(CygwinDirectory, &find_dir, &find_in_path);
201+ find_cygwin = SearchDLL(dll_base, CygwinDirectory, search_paths, &find_dir, &find_in_path);
230202 if (find_cygwin == FALSE) {
231203 return ERROR_FILE_NOT_FOUND;
232204 }
@@ -257,3 +229,42 @@
257229
258230 return NO_ERROR;
259231 }
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+}
--- trunk/cygwin/cyglib/cyglib.h (revision 9519)
+++ trunk/cygwin/cyglib/cyglib.h (revision 9520)
@@ -35,6 +35,7 @@
3535 #endif
3636
3737 DWORD CygwinConnect(const wchar_t *CygwinDirectory, const wchar_t *cmdline);
38+DWORD Msys2Connect(const wchar_t *Msys2Directory, const wchar_t *cmdline);
3839
3940 #ifdef __cplusplus
4041 }
Show on old repository browser