Revision: 9518 https://osdn.net/projects/ttssh2/scm/svn/commits/9518 Author: zmatsuo Date: 2021-11-10 22:01:44 +0900 (Wed, 10 Nov 2021) Log Message: ----------- cygwin/cyglib に複数個所に重複したコードを移動 - cyglaunch,ttermpro から利用 - パス、ファイル名をUnicode化 - cyglaunch の main() を wmain() へ変更 Modified Paths: -------------- trunk/cygwin/CMakeLists.txt trunk/cygwin/cyglaunch/CMakeLists.txt trunk/cygwin/cyglaunch/cyglaunch.c trunk/cygwin/cyglaunch/cyglaunch.v16.vcxproj trunk/cygwin/cyglaunch/cyglaunch.v8.vcproj trunk/cygwin/cygwin.v16.sln trunk/cygwin/cygwin.v8.sln trunk/teraterm/teraterm/CMakeLists.txt trunk/teraterm/teraterm/ttermpro.v16.vcxproj trunk/teraterm/teraterm/ttermpro.v8.vcproj trunk/teraterm/teraterm/vtwin.cpp trunk/teraterm/ttermpro.v16.sln trunk/teraterm/ttermpro.v8.sln Added Paths: ----------- trunk/cygwin/cyglib/ trunk/cygwin/cyglib/CMakeLists.txt trunk/cygwin/cyglib/cyglib.c trunk/cygwin/cyglib/cyglib.h trunk/cygwin/cyglib/cyglib.v16.vcxproj trunk/cygwin/cyglib/cyglib.v8.vcproj -------------- next part -------------- Modified: trunk/cygwin/CMakeLists.txt =================================================================== --- trunk/cygwin/CMakeLists.txt 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/CMakeLists.txt 2021-11-10 13:01:44 UTC (rev 9518) @@ -3,7 +3,20 @@ cyglaunch PROPERTIES FOLDER cygwin) +add_subdirectory(cyglib) +set_target_properties( + cyglib + PROPERTIES FOLDER cygwin) + add_subdirectory(cygtool) set_target_properties( cygtool_dll PROPERTIES FOLDER cygwin) + +if(false) + add_subdirectory(cygterm) + set_target_properties( + cygterm + PROPERTIES FOLDER cygwin) +endif() + Modified: trunk/cygwin/cyglaunch/CMakeLists.txt =================================================================== --- trunk/cygwin/cyglaunch/CMakeLists.txt 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/cyglaunch/CMakeLists.txt 2021-11-10 13:01:44 UTC (rev 9518) @@ -6,6 +6,7 @@ ${PACKAGE_NAME} WIN32 cyglaunch.c cyglaunch.rc + ../cyglib/cyglib.h ) target_include_directories( @@ -14,6 +15,13 @@ . ) +target_link_libraries( + ${PACKAGE_NAME} + PRIVATE + common_static + cyglib + ) + install( TARGETS ${PACKAGE_NAME} DESTINATION . @@ -20,9 +28,9 @@ ) if(MSVC) - # subsystem:windows, but start form main() + # subsystem:windows, but start form wmain() if(${CMAKE_VERSION} VERSION_LESS "3.12.0") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:mainCRTStartup") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") else() target_link_options( ${PACKAGE_NAME} @@ -31,3 +39,11 @@ ) endif() endif(MSVC) + +if(MINGW) + target_link_options( + ${PACKAGE_NAME} + PRIVATE + -municode + ) +endif(MINGW) Modified: trunk/cygwin/cyglaunch/cyglaunch.c =================================================================== --- trunk/cygwin/cyglaunch/cyglaunch.c 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/cyglaunch/cyglaunch.c 2021-11-10 13:01:44 UTC (rev 9518) @@ -1,145 +1,119 @@ -// -// Cygterm launcher -// -// (C) 2007- TeraTerm Project -// https://ttssh2.osdn.jp/ -// -// [How to compile] -// Cygwin: -// # cc -mno-cygwin -mwindows -o cyglaunch cyglaunch.c -// - -#include <windows.h> -#include <stdio.h> -#include <stdlib.h> -#include <direct.h> - -#define Section "Tera Term" -char *FName = "TERATERM.INI"; - - -// -// Connect to local cygwin -// -void OnCygwinConnection(char *CygwinDirectory, char *cmdline) -{ - char file[MAX_PATH], *filename; - char c, *envptr, *envbuff; - int envbufflen; - char *exename = "cygterm.exe"; - char cmd[1024]; - STARTUPINFO si; - PROCESS_INFORMATION pi; - - if (strlen(CygwinDirectory) > 0) { - if (SearchPath(CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) { - goto found_dll; - } - } - - if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { - goto found_path; - } - - for (c = 'C' ; c <= 'Z' ; c++) { - char tmp[MAX_PATH]; - sprintf(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c); - if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { - goto found_dll; - } - } - - MessageBox(NULL, "Can't find Cygwin directory.", "ERROR", MB_OK | MB_ICONWARNING); - return; - -found_dll:; - envptr = getenv("PATH"); - file[strlen(file)-12] = '\0'; // delete "\\cygwin1.dll" - if (envptr != NULL) { - envbufflen = strlen(file) + strlen(envptr) + 7; // "PATH="(5) + ";"(1) + NUL(1) - if ((envbuff=malloc(envbufflen)) == NULL) { - MessageBox(NULL, "Can't allocate memory.", "ERROR", MB_OK | MB_ICONWARNING); - return; - } - _snprintf(envbuff, envbufflen, "PATH=%s;%s", file, envptr); - } else { - envbufflen = strlen(file) + strlen(envptr) + 6; // "PATH="(5) + NUL(1) - if ((envbuff=malloc(envbufflen)) == NULL) { - MessageBox(NULL, "Can't allocate memory.", "ERROR", MB_OK | MB_ICONWARNING); - return; - } - _snprintf(envbuff, envbufflen, "PATH=%s", file); - } - _putenv(envbuff); - if (envbuff) { - free(envbuff); - envbuff = NULL; - } - -found_path:; - memset(&si, 0, sizeof(si)); - GetStartupInfo(&si); - memset(&pi, 0, sizeof(pi)); - - strcpy(cmd, exename); - strcat(cmd, " "); - strncat(cmd, cmdline, sizeof(cmd)-strlen(cmd)-1); -//printf("%s", cmd); -//MessageBox(NULL, cmd, "", MB_OK); - if (CreateProcess( - NULL, - cmd, - NULL, NULL, FALSE, 0, - NULL, NULL, - &si, &pi) == 0) { - MessageBox(NULL, "Can't execute Cygterm.", "ERROR", MB_OK | MB_ICONWARNING); - } -} - - -int main(int argc, char** argv) -{ - char Temp[256], CygwinDir[256], Cmdline[256]; - char *bs; - int i; - BOOL d_opt=FALSE; - - if (GetModuleFileName(NULL, Temp, sizeof(Temp)) > 0 && - (bs = strrchr(Temp, '\\')) != NULL) { - *bs = 0; - _chdir(Temp); - _snprintf(bs, sizeof(Temp) + Temp - bs, "\\%s", FName); - } - else { - _snprintf(Temp, sizeof(Temp), ".\\", FName); - } - - // Cygwin install path - GetPrivateProfileString(Section, "CygwinDirectory", "c:\\cygwin", - CygwinDir, sizeof(CygwinDir), Temp); - - //printf("%s %d\n", CygwinDir, GetLastError()); - - Cmdline[0] = 0; - for (i=1; i<argc; i++) { - if (i != 1) { - strncat(Cmdline, " ", sizeof(Cmdline)-strlen(Cmdline)-1); - } - if (d_opt && strncmp("\"\\\\", argv[i], 3) == 0) { - argv[i][1] = '/'; - argv[i][2] = '/'; - } - strncat(Cmdline, argv[i], sizeof(Cmdline)-strlen(Cmdline)-1); - if (strcmp(argv[i], "-d") == 0) { - d_opt = TRUE; - } - else { - d_opt = FALSE; - } - } - //printf("%s\n", Cmdline); - - OnCygwinConnection(CygwinDir, Cmdline); - - return 0; -} +/* + * Copyright (C) 2007- TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// +// Cygterm launcher +// + +#include <windows.h> +#include <stdio.h> +#include <stdlib.h> +#include <locale.h> + +#include "ttlib.h" +#include "asprintf.h" +#include "cyglib.h" + +#define Section L"Tera Term" + +/** + * TERATERM.INI \x82\xA9\x82\xE7 CygwinDirectory \x82\xF0\x93ǂݍ\x9E\x82\xDE + */ +static wchar_t *GetCygwinDir(void) +{ + wchar_t *HomeDir; + wchar_t *teraterm_ini; + wchar_t CygwinDir[256]; + + HomeDir = GetHomeDirW(NULL); + teraterm_ini = NULL; + awcscats(&teraterm_ini, HomeDir, L"\\TERATERM.INI", NULL); + free(HomeDir); + + // Cygwin install path + GetPrivateProfileStringW(Section, L"CygwinDirectory", L"", + CygwinDir, _countof(CygwinDir), teraterm_ini); + free(teraterm_ini); + + if (CygwinDir[0] == 0) { + return NULL; + } + return _wcsdup(CygwinDir); +} + +int wmain(int argc, wchar_t *argv[]) +{ + wchar_t *CygwinDir; + wchar_t *Cmdline; + int i; + BOOL d_opt=FALSE; + DWORD e; + + setlocale(LC_ALL, ""); + + // \x88\xF8\x90\x94\x82\xF0\x8C\x8B\x8D\x87\x82\xB5\x82ăR\x83}\x83\x93\x83h\x83\x89\x83C\x83\x93\x82\xF0\x8D쐬 + Cmdline = NULL; + for (i=1; i<argc; i++) { + if (i != 1) { + awcscat(&Cmdline, L" "); + } + if (d_opt && wcsncmp(L"\"\\\\", argv[i], 3) == 0) { + argv[i][1] = '/'; + argv[i][2] = '/'; + } + awcscat(&Cmdline, argv[i]); + if (wcscmp(argv[i], L"-d") == 0) { + d_opt = TRUE; + } + else { + d_opt = FALSE; + } + } + + // cygwin\x82\xAA\x83C\x83\x93\x83X\x83g\x81[\x83\x8B\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83t\x83H\x83\x8B\x83_ + CygwinDir = GetCygwinDir(); + + // cygterm\x82\xF0\x8E\xC0\x8Ds\x82\xB7\x82\xE9 + e = CygwinConnect(CygwinDir, Cmdline); + switch(e) { + case NO_ERROR: + break; + case ERROR_FILE_NOT_FOUND: + MessageBox(NULL, "Can't find Cygwin directory.", "ERROR", MB_OK | MB_ICONWARNING); + break; + case ERROR_NOT_ENOUGH_MEMORY: + MessageBox(NULL, "Can't allocate memory.", "ERROR", MB_OK | MB_ICONWARNING); + break; + case ERROR_OPEN_FAILED: + default: + MessageBox(NULL, "Can't execute Cygterm.", "ERROR", MB_OK | MB_ICONWARNING); + break; + } + + return 0; +} Modified: trunk/cygwin/cyglaunch/cyglaunch.v16.vcxproj =================================================================== --- trunk/cygwin/cyglaunch/cyglaunch.v16.vcxproj 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/cyglaunch/cyglaunch.v16.vcxproj 2021-11-10 13:01:44 UTC (rev 9518) @@ -53,9 +53,10 @@ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> <WarningLevel>Level4</WarningLevel> - <SDLCheck>false</SDLCheck> + <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>..\..\teraterm\common;..\cyglib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <MultiProcessorCompilation>true</MultiProcessorCompilation> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> </ClCompile> @@ -62,7 +63,8 @@ <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> - <EntryPointSymbol>mainCRTStartup</EntryPointSymbol> + <AdditionalDependencies>$(SolutionDir)..\teraterm\$(Configuration)\common_static.lib;%(AdditionalDependencies)</AdditionalDependencies> + <EntryPointSymbol>wmainCRTStartup</EntryPointSymbol> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -70,9 +72,10 @@ <WarningLevel>Level4</WarningLevel> <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> - <SDLCheck>false</SDLCheck> + <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>..\..\teraterm\common;..\cyglib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <MultiProcessorCompilation>true</MultiProcessorCompilation> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> </ClCompile> @@ -81,7 +84,8 @@ <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> <GenerateDebugInformation>true</GenerateDebugInformation> - <EntryPointSymbol>mainCRTStartup</EntryPointSymbol> + <AdditionalDependencies>$(SolutionDir)..\teraterm\$(Configuration)\common_static.lib;%(AdditionalDependencies)</AdditionalDependencies> + <EntryPointSymbol>wmainCRTStartup</EntryPointSymbol> </Link> </ItemDefinitionGroup> <ItemGroup> @@ -90,6 +94,11 @@ <ItemGroup> <ClCompile Include="cyglaunch.c" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\cyglib\cyglib.v16.vcxproj"> + <Project>{a171f48c-bfb2-4766-97c3-9b8b7be9d548}</Project> + </ProjectReference> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> Modified: trunk/cygwin/cyglaunch/cyglaunch.v8.vcproj =================================================================== --- trunk/cygwin/cyglaunch/cyglaunch.v8.vcproj 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/cyglaunch/cyglaunch.v8.vcproj 2021-11-10 13:01:44 UTC (rev 9518) @@ -40,6 +40,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" + AdditionalIncludeDirectories="../../teraterm/common;../cyglib" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" MinimalRebuild="true" BasicRuntimeChecks="3" @@ -60,11 +61,11 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="ole32.lib shell32.lib user32.lib kernel32.lib $(NOINHERIT)" + AdditionalDependencies="$(SolutionDir)..\teraterm\$(ConfigurationName)\common_static.lib ole32.lib shell32.lib user32.lib kernel32.lib $(NOINHERIT)" LinkIncremental="2" GenerateDebugInformation="true" SubSystem="2" - EntryPointSymbol="mainCRTStartup" + EntryPointSymbol="wmainCRTStartup" TargetMachine="1" /> <Tool @@ -117,6 +118,7 @@ /> <Tool Name="VCCLCompilerTool" + AdditionalIncludeDirectories="../../teraterm/common;../cyglib" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="0" UsePrecompiledHeader="0" @@ -135,13 +137,13 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="ole32.lib shell32.lib user32.lib kernel32.lib $(NOINHERIT)" + AdditionalDependencies="$(SolutionDir)..\teraterm\$(ConfigurationName)\common_static.lib ole32.lib shell32.lib user32.lib kernel32.lib $(NOINHERIT)" LinkIncremental="1" GenerateDebugInformation="true" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" - EntryPointSymbol="mainCRTStartup" + EntryPointSymbol="wmainCRTStartup" TargetMachine="1" /> <Tool Added: trunk/cygwin/cyglib/CMakeLists.txt =================================================================== --- trunk/cygwin/cyglib/CMakeLists.txt (rev 0) +++ trunk/cygwin/cyglib/CMakeLists.txt 2021-11-10 13:01:44 UTC (rev 9518) @@ -0,0 +1,21 @@ +set(PACKAGE_NAME "cyglib") + +project(${PACKAGE_NAME}) + +add_library( + ${PACKAGE_NAME} + cyglib.c + cyglib.h + ) + +target_include_directories( + ${PACKAGE_NAME} + PUBLIC + . + ) + +target_link_libraries( + ${PACKAGE_NAME} + PUBLIC + common_static + ) Added: trunk/cygwin/cyglib/cyglib.c =================================================================== --- trunk/cygwin/cyglib/cyglib.c (rev 0) +++ trunk/cygwin/cyglib/cyglib.c 2021-11-10 13:01:44 UTC (rev 9518) @@ -0,0 +1,249 @@ +/* + * Copyright (C) 2021- TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <windows.h> +#include <stdio.h> +#include <stdlib.h> +#include <direct.h> +#include <locale.h> +#include <string.h> +#include <errno.h> + +#include "ttlib.h" +#include "asprintf.h" + +#include "cyglib.h" + +/** + * cygwin1.dll\x82\xF0\x92T\x82\xB7 + * + * @param[in] cygwin_dir (\x91\xB6\x8D݂\xB7\x82\xE9\x82ł\xA0\x82낤)\x83t\x83H\x83\x8B\x83_ + * @param[out] find_dir \x8C\xA9\x82\xA9\x82\xC1\x82\xBD\x83t\x83H\x83\x8B\x83_ free() \x82\xB7\x82邱\x82\xC6 + * @param[out] find_in_path \x8A\xAB\x95ϐ\x94 PATH \x93\xE0\x82Ɍ\xA9\x82\xA9\x82\xC1\x82\xBD + * + * @retval TRUE \x8C\xA9\x82\xA9\x82\xC1\x82\xBD + * @retval FALSE \x8C\xA9\x82\xA9\x82\xE7\x82Ȃ\xA2 + */ +static BOOL CygwinSearchDLL(const wchar_t *cygwin_dir, wchar_t **find_dir, BOOL *find_in_path) +{ + wchar_t file[MAX_PATH]; + wchar_t *filename; + wchar_t c; +#if 1 + const wchar_t *dll_base = L"cygwin1"; + const wchar_t *search_paths[] = { + L"%c:\\cygwin\\bin", + L"%c:\\cygwin64\\bin", + NULL, + }; +#endif +#if 0 + const wchar_t *dll_base = L"msys-2.0"; + const wchar_t *search_paths[] = { + L"%c:\\msys\\usr\\bin", + L"%c:\\msys64\\usr\\bin", + NULL, + }; +#endif + wchar_t *dll; + int i; + DWORD r; + + *find_in_path = FALSE; + *find_dir = NULL; + + // \x8Ew\x92肳\x82ꂽ\x83t\x83H\x83\x8B\x83_\x82ɑ\xB6\x8D݂\xB7\x82邩? + if (cygwin_dir != NULL && cygwin_dir[0] != 0) { + // SearchPathW() \x82ŒT\x82\xB7 + dll = NULL; + awcscats(&dll, L"bin\\", dll_base, L".dll", NULL); + r = SearchPathW(cygwin_dir, dll, L".dll", _countof(file), file, &filename); + free(dll); + if (r > 0) { + goto found_dll; + } + + // SearchPathW() \x82\xBE\x82\xC6 "msys-2.0.dll" \x82\xAA\x8C\xA9\x82\xAF\x82邱\x82Ƃ\xAA\x82ł\xAB\x82Ȃ\xA2 (Windows 10) + dll = NULL; + awcscats(&dll, cygwin_dir, L"\\", dll_base, L".dll", NULL); + r = GetFileAttributesW(dll); + if (r != INVALID_FILE_ATTRIBUTES) { + // \x8C\xA9\x82\xA9\x82\xC1\x82\xBD + wcscpy_s(file, _countof(file), dll); + free(dll); + goto found_dll; + } + free(dll); + } + + // PATH \x82\xA9\x82\xE7\x92T\x82\xB7 + if (SearchPathW(NULL, dll_base, L".dll", _countof(file), file, &filename) > 0) { + *find_in_path = TRUE; + goto found_dll; + } + + // \x82\xA0\x82肻\x82\xA4\x82ȏꏊ\x82\xF0\x92T\x82\xB7 + for (c = 'C' ; c <= 'Z' ; c++) { + for (i = 0; search_paths[i] != NULL; i++) { + // SearchPathW() \x82ŒT\x82\xB7 + const wchar_t *search_path_base = search_paths[i]; + wchar_t *search_path; + aswprintf(&search_path, search_path_base, c); + r = SearchPathW(search_path, dll_base, L".dll", _countof(file), file, &filename); + if (r > 0) { + free(search_path); + goto found_dll; + } + + // \x83t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82邩\x92\xB2\x82ׂ\xE9 + dll = NULL; + awcscats(&dll, search_path, L"\\", dll_base, L".dll", NULL); + r = GetFileAttributesW(dll); + free(search_path); + if (r != INVALID_FILE_ATTRIBUTES) { + wcscpy_s(file, _countof(file), dll); + free(dll); + goto found_dll; + } + free(dll); + } + } + + // \x8C\xA9\x82\xA9\x82\xE7\x82Ȃ\xA9\x82\xC1\x82\xBD + return FALSE; + +found_dll: + { + // cut "cygwin1.dll", \x83t\x83H\x83\x8B\x83_\x82݂̂\xF0\x95Ԃ\xB7 + wchar_t *p = wcsrchr(file, L'\\'); + *p = 0; + } + + *find_dir = _wcsdup(file); + return TRUE; +} + +static errno_t __wdupenv_s(wchar_t** envptr, size_t* buf_size, const wchar_t* name) +{ +#if defined(_MSC_VER) + return _wdupenv_s(envptr, buf_size, name); +#else + const wchar_t* s = _wgetenv(name); + if (s == NULL) { + // \x91\xB6\x8D݂\xB5\x82Ȃ\xA2 + *envptr = NULL; + return EINVAL; + } + *envptr = _wcsdup(s); + if (buf_size != NULL) { + *buf_size = wcslen(*envptr); + } + return 0; +#endif +} + +/** + * \x8A\xAB\x95ϐ\x94 PATH \x82\xC9 add_path \x82\xF0\x92lj\xC1 + */ +static BOOL AddPath(const wchar_t *add_path) +{ + wchar_t *envptr; + wchar_t *new_env; + int r; + errno_t e; + + e = __wdupenv_s(&envptr, NULL, L"PATH"); + if (e == 0) { + aswprintf(&new_env, L"PATH=%s;%s", add_path, envptr); + free(envptr); + } + else { + // \x8A\xAB\x95ϐ\x94 PATH \x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2 + aswprintf(&new_env, L"PATH=%s", add_path); + } + r = _wputenv(new_env); + free(new_env); + return r == 0 ? TRUE : FALSE; +} + +/** + * Connect to local cygwin + * cygterm\x82\xF0\x8E\xC0\x8Ds + * + * @param[in] CygwinDirectory Cygwin\x82\xAA\x83C\x83\x93\x83X\x83g\x81[\x83\x8B\x82\xB5\x82Ă\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_ + * \x8C\xA9\x82\xA9\x82\xE7\x82Ȃ\xAF\x82\xEA\x82f\x83t\x83H\x83\x8B\x83g\x83t\x83H\x83\x8B\x83_\x82Ȃǂ\xF0\x92T\x82\xB7 + * @param[in] cmdline cygterm\x82ɓn\x82\xB7\x83R\x83}\x83\x93\x83h\x83\x89\x83C\x83\x93\x88\xF8\x90\x94 + * NULL\x82̂Ƃ\xAB\x88\xF8\x90\x94\x82Ȃ\xB5 + * @retval NO_ERROR \x8E\xC0\x8Ds\x82ł\xAB\x82\xBD + * @retval ERROR_FILE_NOT_FOUND cygwin\x82\xAA\x8C\xA9\x82\xA9\x82\xE7\x82Ȃ\xA2(cygwin1.dll\x82\xAA\x8C\xA9\x82\xA9\x82\xE7\x82Ȃ\xA2) + * @retval ERROR_NOT_ENOUGH_MEMORY \x83\x81\x83\x82\x83\x8A\x95s\x91\xAB + * @retval ERROR_OPEN_FAILED \x8E\xC0\x8Ds\x82ł\xAB\x82Ȃ\xA2 + */ +DWORD CygwinConnect(const wchar_t *CygwinDirectory, const wchar_t *cmdline) +{ + BOOL find_cygwin; + wchar_t *find_dir; + BOOL find_in_path; + wchar_t *ExeDirW; + wchar_t *cygterm_cmd; + DWORD e; + const wchar_t *cygterm_exe = L"cygterm.exe"; +// const wchar_t *cygterm_exe = L"msys2term.exe"; + +// CygwinDirectory = NULL; + find_cygwin = CygwinSearchDLL(CygwinDirectory, &find_dir, &find_in_path); + if (find_cygwin == FALSE) { + return ERROR_FILE_NOT_FOUND; + } + + if (!find_in_path) { + // \x8A\xAB\x95ϐ\x94 PATH \x82ɒlj\xC1 + // cygterm.exe \x82\xF0\x8E\xC0\x8Ds\x82\xB7\x82\xE9\x82Ƃ\xAB\x82\xC9 cygwin1.dll \x82\xF0\x83\x8D\x81[\x83h\x82ł\xAB\x82\xE9\x82悤\x82ɂ\xB7\x82\xE9 + BOOL r = AddPath(find_dir); + if (r == FALSE) { + free(find_dir); + return ERROR_NOT_ENOUGH_MEMORY; + } + } + free(find_dir); + + ExeDirW = GetExeDirW(NULL); + cygterm_cmd = NULL; + awcscats(&cygterm_cmd, ExeDirW, L"\\", cygterm_exe, NULL); + if (cmdline != NULL && cmdline[0] != 0) { + awcscats(&cygterm_cmd, L" ", cmdline, NULL); + } + + e = TTWinExec(cygterm_cmd); + free(cygterm_cmd); + if (e != NO_ERROR) { + return ERROR_OPEN_FAILED; + } + + return NO_ERROR; +} Added: trunk/cygwin/cyglib/cyglib.h =================================================================== --- trunk/cygwin/cyglib/cyglib.h (rev 0) +++ trunk/cygwin/cyglib/cyglib.h 2021-11-10 13:01:44 UTC (rev 9518) @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021- TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include <windows.h> + +#ifdef __cplusplus +extern "C" { +#endif + +DWORD CygwinConnect(const wchar_t *CygwinDirectory, const wchar_t *cmdline); + +#ifdef __cplusplus +} +#endif Copied: trunk/cygwin/cyglib/cyglib.v16.vcxproj (from rev 9517, trunk/cygwin/cyglaunch/cyglaunch.v16.vcxproj) =================================================================== --- trunk/cygwin/cyglib/cyglib.v16.vcxproj (rev 0) +++ trunk/cygwin/cyglib/cyglib.v16.vcxproj 2021-11-10 13:01:44 UTC (rev 9518) @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + </ItemGroup> + <ItemGroup> + <ClCompile Include="cyglib.c" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="cyglib.h" /> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>16.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{a171f48c-bfb2-4766-97c3-9b8b7be9d548}</ProjectGuid> + <RootNamespace>cyglib</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <ProjectName>cyglib</ProjectName> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level4</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <AdditionalIncludeDirectories>..\..\teraterm\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem> + </SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level4</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <AdditionalIncludeDirectories>..\..\teraterm\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <WholeProgramOptimization>false</WholeProgramOptimization> + </ClCompile> + <Link> + <SubSystem> + </SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file Copied: trunk/cygwin/cyglib/cyglib.v8.vcproj (from rev 9517, trunk/cygwin/cyglaunch/cyglaunch.v8.vcproj) =================================================================== --- trunk/cygwin/cyglib/cyglib.v8.vcproj (rev 0) +++ trunk/cygwin/cyglib/cyglib.v8.vcproj 2021-11-10 13:01:44 UTC (rev 9518) @@ -0,0 +1,158 @@ +<?xml version="1.0" encoding="shift_jis"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="cyglib" + ProjectGUID="{0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}" + RootNamespace="cyglib" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../../teraterm/common" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="4" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="4" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + WholeProgramOptimization="false" + AdditionalIncludeDirectories="../../teraterm/common" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="4" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath=".\cyglib.c" + > + </File> + <File + RelativePath=".\cyglib.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Modified: trunk/cygwin/cygwin.v16.sln =================================================================== --- trunk/cygwin/cygwin.v16.sln 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/cygwin.v16.sln 2021-11-10 13:01:44 UTC (rev 9518) @@ -3,6 +3,8 @@ # Visual Studio Version 16 VisualStudioVersion = 16.0.31729.503 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cyglib", "cyglib\cyglib.v16.vcxproj", "{A171F48C-BFB2-4766-97C3-9B8B7BE9D548}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cyglaunch", "cyglaunch\cyglaunch.v16.vcxproj", "{11B49891-80F0-4DD3-B6E9-70BBE64A4BBF}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cygtool", "cygtool\cygtool.v16.vcxproj", "{E8955970-1031-42B4-9419-F82D9DD80C66}" @@ -13,6 +15,10 @@ Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Debug|x86.ActiveCfg = Debug|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Debug|x86.Build.0 = Debug|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Release|x86.ActiveCfg = Release|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Release|x86.Build.0 = Release|Win32 {11B49891-80F0-4DD3-B6E9-70BBE64A4BBF}.Debug|x86.ActiveCfg = Debug|Win32 {11B49891-80F0-4DD3-B6E9-70BBE64A4BBF}.Debug|x86.Build.0 = Debug|Win32 {11B49891-80F0-4DD3-B6E9-70BBE64A4BBF}.Release|x86.ActiveCfg = Release|Win32 Modified: trunk/cygwin/cygwin.v8.sln =================================================================== --- trunk/cygwin/cygwin.v8.sln 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/cygwin/cygwin.v8.sln 2021-11-10 13:01:44 UTC (rev 9518) @@ -1,7 +1,12 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cyglib", "cyglib\cyglib.v8.vcproj", "{0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cyglaunch", "cyglaunch\cyglaunch.v8.vcproj", "{1A41E0B4-7FBC-44C6-83A4-7881F60CE8C8}" + ProjectSection(ProjectDependencies) = postProject + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5} = {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cygtool", "cygtool\cygtool.v8.vcproj", "{4F0887EE-225F-407A-A403-5A723A4C7B2B}" EndProject @@ -11,6 +16,10 @@ Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Debug|Win32.ActiveCfg = Debug|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Debug|Win32.Build.0 = Debug|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Release|Win32.ActiveCfg = Release|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Release|Win32.Build.0 = Release|Win32 {1A41E0B4-7FBC-44C6-83A4-7881F60CE8C8}.Debug|Win32.ActiveCfg = Debug|Win32 {1A41E0B4-7FBC-44C6-83A4-7881F60CE8C8}.Debug|Win32.Build.0 = Debug|Win32 {1A41E0B4-7FBC-44C6-83A4-7881F60CE8C8}.Release|Win32.ActiveCfg = Release|Win32 Modified: trunk/teraterm/teraterm/CMakeLists.txt =================================================================== --- trunk/teraterm/teraterm/CMakeLists.txt 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/teraterm/teraterm/CMakeLists.txt 2021-11-10 13:01:44 UTC (rev 9518) @@ -303,6 +303,7 @@ ttpcmn ttpset ttptek + cyglib ${ONIGURUMA_LIB} ${SFMT_LIB} ) Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.v16.vcxproj 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj 2021-11-10 13:01:44 UTC (rev 9518) @@ -65,7 +65,7 @@ <ClCompile> <AdditionalOptions>/D"_CRT_SECURE_NO_DEPRECATE" %(AdditionalOptions)</AdditionalOptions> <Optimization>Disabled</Optimization> - <AdditionalIncludeDirectories>$(SolutionDir)..\libs\SFMT;$(SolutionDir)..\libs\oniguruma\src;$(SolutionDir)teraterm;$(SolutionDir)common;$(SolutionDir)ttpfile;$(SolutionDir)ttpdlg;$(SolutionDir)ttpcmn;$(SolutionDir)susie_plugin;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>$(SolutionDir)..\libs\SFMT;$(SolutionDir)..\libs\oniguruma\src;$(SolutionDir)teraterm;$(SolutionDir)common;$(SolutionDir)ttpfile;$(SolutionDir)ttpdlg;$(SolutionDir)ttpcmn;$(SolutionDir)susie_plugin;$(SolutionDir)..\cygwin\cyglib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <BrowseInformation /> @@ -106,7 +106,7 @@ <AdditionalOptions>/D"_CRT_SECURE_NO_DEPRECATE" %(AdditionalOptions)</AdditionalOptions> <Optimization>MaxSpeed</Optimization> <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion> - <AdditionalIncludeDirectories>$(SolutionDir)..\libs\SFMT;$(SolutionDir)..\libs\oniguruma\src;$(SolutionDir)teraterm;$(SolutionDir)common;$(SolutionDir)ttpfile;$(SolutionDir)ttpdlg;$(SolutionDir)ttpcmn;$(SolutionDir)susie_plugin;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>$(SolutionDir)..\libs\SFMT;$(SolutionDir)..\libs\oniguruma\src;$(SolutionDir)teraterm;$(SolutionDir)common;$(SolutionDir)ttpfile;$(SolutionDir)ttpdlg;$(SolutionDir)ttpcmn;$(SolutionDir)susie_plugin;$(SolutionDir)..\cygwin\cyglib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <StringPooling>true</StringPooling> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> @@ -283,6 +283,9 @@ <ClInclude Include="unicode.h" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\cygwin\cyglib\cyglib.v16.vcxproj"> + <Project>{a171f48c-bfb2-4766-97c3-9b8b7be9d548}</Project> + </ProjectReference> <ProjectReference Include="..\..\svnrev_perl\svnrev_perl.v16.vcxproj"> <Project>{53db5f02-7f9e-4e29-9751-b0dac6a8eeba}</Project> </ProjectReference> Modified: trunk/teraterm/teraterm/ttermpro.v8.vcproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.v8.vcproj 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/teraterm/teraterm/ttermpro.v8.vcproj 2021-11-10 13:01:44 UTC (rev 9518) @@ -48,7 +48,7 @@ Name="VCCLCompilerTool" AdditionalOptions="/D"_CRT_SECURE_NO_DEPRECATE"" Optimization="0" - AdditionalIncludeDirectories=""$(SolutionDir)..\libs\SFMT";"$(SolutionDir)..\libs\oniguruma\src";"$(SolutionDir)teraterm";"$(SolutionDir)common";"$(SolutionDir)ttpfile";"$(SolutionDir)ttpdlg";"$(SolutionDir)ttpcmn";"$(SolutionDir)susie_plugin"" + AdditionalIncludeDirectories=""$(SolutionDir)..\libs\SFMT";"$(SolutionDir)..\libs\oniguruma\src";"$(SolutionDir)teraterm";"$(SolutionDir)common";"$(SolutionDir)ttpfile";"$(SolutionDir)ttpdlg";"$(SolutionDir)ttpcmn";"$(SolutionDir)susie_plugin";"$(SolutionDir)..\cygwin\cyglib"" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_WIN32_WINNT=0x0501" RuntimeLibrary="1" BrowseInformation="0" @@ -142,7 +142,7 @@ AdditionalOptions="/D"_CRT_SECURE_NO_DEPRECATE"" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories=""$(SolutionDir)..\libs\SFMT";"$(SolutionDir)..\libs\oniguruma\src";"$(SolutionDir)teraterm";"$(SolutionDir)common";"$(SolutionDir)ttpfile";"$(SolutionDir)ttpdlg";"$(SolutionDir)ttpcmn";"$(SolutionDir)susie_plugin"" + AdditionalIncludeDirectories=""$(SolutionDir)..\libs\SFMT";"$(SolutionDir)..\libs\oniguruma\src";"$(SolutionDir)teraterm";"$(SolutionDir)common";"$(SolutionDir)ttpfile";"$(SolutionDir)ttpdlg";"$(SolutionDir)ttpcmn";"$(SolutionDir)susie_plugin";"$(SolutionDir)..\cygwin\cyglib"" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_WIN32_WINNT=0x0501" StringPooling="true" RuntimeLibrary="0" Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/teraterm/teraterm/vtwin.cpp 2021-11-10 13:01:44 UTC (rev 9518) @@ -65,6 +65,7 @@ #include "ttplug.h" /* TTPLUG */ #include "teraterml.h" #include "buffer.h" +#include "cyglib.h" #include <stdio.h> #define _CRTDBG_MAP_ALLOC @@ -3690,50 +3691,18 @@ } } -static void __dupenv_s(char **envptr, size_t, const char* name) -{ -#if defined(_MSC_VER) - _dupenv_s(envptr, NULL, name); -#else - const char* s = getenv(name); - if (s == NULL) { - *envptr = NULL; - return; - } - *envptr = strdup(s); -#endif -} - // // Connect to local cygwin // void CVTWindow::OnCygwinConnection() { - char file[MAX_PATH], *filename; - char c, *envptr, *envbuff=NULL; - size_t envbufflen; - const char *exename = "cygterm.exe"; - char cygterm[MAX_PATH]; - - if (strlen(ts.CygwinDirectory) > 0) { - if (SearchPath(ts.CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) { - goto found_dll; - } - } - - if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { - goto found_path; - } - - for (c = 'C' ; c <= 'Z' ; c++) { - char tmp[MAX_PATH]; - sprintf_s(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c); - if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) { - goto found_dll; - } - } - - { + wchar_t *CygwinDirectory = ToWcharA(ts.CygwinDirectory); + DWORD e = CygwinConnect(CygwinDirectory, NULL); + free(CygwinDirectory); + switch(e) { + case NO_ERROR: + break; + case ERROR_FILE_NOT_FOUND: { static const TTMessageBoxInfoW info = { "Tera Term", "MSG_ERROR", L"ERROR", @@ -3741,54 +3710,20 @@ MB_OK | MB_ICONWARNING }; TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); + break; } - return; - -found_dll:; - __dupenv_s(&envptr, NULL, "PATH"); - file[strlen(file)-12] = '\0'; // delete "\\cygwin1.dll" - if (envptr != NULL) { - envbufflen = strlen(file) + strlen(envptr) + 7; // "PATH="(5) + ";"(1) + NUL(1) - if ((envbuff = (char *)malloc(envbufflen)) == NULL) { - static const TTMessageBoxInfoW info = { - "Tera Term", - "MSG_ERROR", L"ERROR", - "MSG_CYGTERM_ENV_ALLOC_ERROR", L"Can't allocate memory for environment variable.", - MB_OK | MB_ICONWARNING - }; - TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); - free(envptr); - return; - } - _snprintf_s(envbuff, envbufflen, _TRUNCATE, "PATH=%s;%s", file, envptr); - free(envptr); - } else { - envbufflen = strlen(file) + 6; // "PATH="(5) + NUL(1) - if ((envbuff = (char *)malloc(envbufflen)) == NULL) { - static const TTMessageBoxInfoW info = { - "Tera Term", - "MSG_ERROR", L"ERROR", - "MSG_CYGTERM_ENV_ALLOC_ERROR", L"Can't allocate memory for environment variable.", - MB_OK | MB_ICONWARNING - }; - TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); - return; - } - _snprintf_s(envbuff, envbufflen, _TRUNCATE, "PATH=%s", file); + case ERROR_NOT_ENOUGH_MEMORY: { + static const TTMessageBoxInfoW info = { + "Tera Term", + "MSG_ERROR", L"ERROR", + "MSG_CYGTERM_ENV_ALLOC_ERROR", L"Can't allocate memory for environment variable.", + MB_OK | MB_ICONWARNING + }; + TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); + break; } - _putenv(envbuff); - if (envbuff) { - free(envbuff); - envbuff = NULL; - } - -found_path:; - strncpy_s(cygterm, sizeof(cygterm), ts.HomeDir, _TRUNCATE); - AppendSlash(cygterm, sizeof(cygterm)); - strncat_s(cygterm, sizeof(cygterm), exename, _TRUNCATE); - - DWORD e = TTWinExecA(cygterm); - if (e != NO_ERROR) { + case ERROR_OPEN_FAILED: + default: { static const TTMessageBoxInfoW info = { "Tera Term", "MSG_ERROR", L"ERROR", @@ -3796,10 +3731,11 @@ MB_OK | MB_ICONWARNING }; TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW); + break; } + } } - // // TeraTerm Menu\x82̋N\x93\xAE // Modified: trunk/teraterm/ttermpro.v16.sln =================================================================== --- trunk/teraterm/ttermpro.v16.sln 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/teraterm/ttermpro.v16.sln 2021-11-10 13:01:44 UTC (rev 9518) @@ -18,6 +18,8 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "svnrev_perl", "..\svnrev_perl\svnrev_perl.v16.vcxproj", "{53DB5F02-7F9E-4E29-9751-B0DAC6A8EEBA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cyglib", "..\cygwin\cyglib\cyglib.v16.vcxproj", "{A171F48C-BFB2-4766-97C3-9B8B7BE9D548}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -76,6 +78,12 @@ {53DB5F02-7F9E-4E29-9751-B0DAC6A8EEBA}.Release|Win32.Build.0 = Release|Win32 {53DB5F02-7F9E-4E29-9751-B0DAC6A8EEBA}.Release|x64.ActiveCfg = Release|x64 {53DB5F02-7F9E-4E29-9751-B0DAC6A8EEBA}.Release|x64.Build.0 = Release|x64 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Debug|Win32.ActiveCfg = Debug|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Debug|Win32.Build.0 = Debug|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Debug|x64.ActiveCfg = Debug|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Release|Win32.ActiveCfg = Release|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Release|Win32.Build.0 = Release|Win32 + {A171F48C-BFB2-4766-97C3-9B8B7BE9D548}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Modified: trunk/teraterm/ttermpro.v8.sln =================================================================== --- trunk/teraterm/ttermpro.v8.sln 2021-11-10 13:01:33 UTC (rev 9517) +++ trunk/teraterm/ttermpro.v8.sln 2021-11-10 13:01:44 UTC (rev 9518) @@ -1,13 +1,14 @@ Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C++ Express 2005 +# Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ttermpro", "teraterm\ttermpro.v8.vcproj", "{BC4CDBE3-6269-47A8-BD74-EEB3A6160E06}" ProjectSection(ProjectDependencies) = postProject {118E0D32-5553-4F73-9927-E873C1C500E4} = {118E0D32-5553-4F73-9927-E873C1C500E4} + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5} = {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5} + {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} = {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} + {08C4EEED-92F9-4CA2-A52E-97089A889930} = {08C4EEED-92F9-4CA2-A52E-97089A889930} + {1D9096FC-EC94-4913-B14A-9D97AAB88E7F} = {1D9096FC-EC94-4913-B14A-9D97AAB88E7F} + {5CF58947-E861-4A5C-B0B1-E85486F149CD} = {5CF58947-E861-4A5C-B0B1-E85486F149CD} {6D08053B-1C68-4A7E-8766-3553F5AF010B} = {6D08053B-1C68-4A7E-8766-3553F5AF010B} - {5CF58947-E861-4A5C-B0B1-E85486F149CD} = {5CF58947-E861-4A5C-B0B1-E85486F149CD} - {1D9096FC-EC94-4913-B14A-9D97AAB88E7F} = {1D9096FC-EC94-4913-B14A-9D97AAB88E7F} - {08C4EEED-92F9-4CA2-A52E-97089A889930} = {08C4EEED-92F9-4CA2-A52E-97089A889930} - {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} = {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "keycode", "keycode\keycode.v8.vcproj", "{B31BF2E8-79E6-4735-BEA2-C1B4041C2D2E}" @@ -24,14 +25,14 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ttpset", "ttpset\ttpset.v8.vcproj", "{5CF58947-E861-4A5C-B0B1-E85486F149CD}" ProjectSection(ProjectDependencies) = postProject + {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} = {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} {118E0D32-5553-4F73-9927-E873C1C500E4} = {118E0D32-5553-4F73-9927-E873C1C500E4} - {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} = {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ttptek", "ttptek\ttptek.v8.vcproj", "{6D08053B-1C68-4A7E-8766-3553F5AF010B}" ProjectSection(ProjectDependencies) = postProject + {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} = {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} {118E0D32-5553-4F73-9927-E873C1C500E4} = {118E0D32-5553-4F73-9927-E873C1C500E4} - {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} = {DF4E3C36-A743-4FB4-8EE9-49899E69ED32} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common_static", "common\common_static.v8.vcproj", "{DF4E3C36-A743-4FB4-8EE9-49899E69ED32}" @@ -40,6 +41,8 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "layer_for_unicode", "layer_for_unicode\layer_for_unicode.v8.vcproj", "{08C4EEED-92F9-4CA2-A52E-97089A889930}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cyglib", "..\cygwin\cyglib\cyglib.v8.vcproj", "{0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -82,6 +85,10 @@ {08C4EEED-92F9-4CA2-A52E-97089A889930}.Debug|Win32.Build.0 = Debug|Win32 {08C4EEED-92F9-4CA2-A52E-97089A889930}.Release|Win32.ActiveCfg = Release|Win32 {08C4EEED-92F9-4CA2-A52E-97089A889930}.Release|Win32.Build.0 = Release|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Debug|Win32.ActiveCfg = Debug|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Debug|Win32.Build.0 = Debug|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Release|Win32.ActiveCfg = Release|Win32 + {0C5959D7-A1AB-42ED-BAC2-B158B64CC4D5}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE