• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision9531 (tree)
Time2021-11-15 00:09:24
Authorzmatsuo

Log Message

$APPDATA/teraterm5/cygterm.cfg も読むようにした

- cygterm.cfg が Unicodeフォルダ名にあっても読めるようにした

- cygterm.exe が Unicodeフォルダ名にある場合

- ドキュメントを修正 (日本語版のみ)

- URLが404だったので削除
- 日付を更新
- 読み込む cygterm.cfg について追記
- 動作確認環境を削除

Change Summary

Incremental Difference

--- trunk/cygwin/cygterm/cygterm.cc (revision 9530)
+++ trunk/cygwin/cygterm/cygterm.cc (revision 9531)
@@ -33,7 +33,7 @@
3333 //
3434
3535 static char Program[] = "CygTerm+";
36-static char Version[] = "version 1.07_28 (2016/02/17)";
36+static char Version[] = "version 1.07_30_beta (2021/11/14)";
3737
3838 #include <stdio.h>
3939 #include <stdlib.h>
@@ -52,8 +52,10 @@
5252 #include <sys/wait.h>
5353 #include <arpa/inet.h>
5454 #include <windows.h>
55+#include <shlobj.h>
5556 #include <pwd.h>
5657 #include <sys/select.h>
58+#include <wchar.h>
5759
5860 // pageant support (ssh-agent proxy)
5961 //----------------------------------
@@ -284,29 +286,107 @@
284286 return;
285287 }
286288
287-//====================//
288-// load configuration //
289-//--------------------//
290-void load_cfg()
289+// '\\' -> '/'
290+void convert_bs(char *path)
291291 {
292- // Windows system configuration file (.cfg) path
293- char win_conf[MAX_PATH];
292+ char *p = path;
293+ while(*p != 0) {
294+ if (*p == '\\') {
295+ *p = '/';
296+ }
297+ p++;
298+ }
299+}
294300
301+// L'\\' -> L'/'
302+void convert_bsW(wchar_t *path)
303+{
304+ wchar_t *p = path;
305+ while(*p != 0) {
306+ if (*p == L'\\') {
307+ *p = L'/';
308+ }
309+ p++;
310+ }
311+}
312+
313+// wchar -> utf8
314+char *convert_utf8_from_wchar(const wchar_t *strW)
315+{
316+ size_t mb_len = ::WideCharToMultiByte(CP_UTF8, 0, strW, -1, NULL, 0, NULL, NULL);
317+ char *u8 = (char *)malloc(sizeof(wchar_t) * mb_len);
318+ ::WideCharToMultiByte(CP_UTF8, 0, strW, -1, u8, mb_len, NULL, NULL);
319+ return u8;
320+}
321+
322+// $APPDATA
323+char *get_appdata_dir()
324+{
325+#if 0
326+ // link error :-(
327+ wchar_t *home_pathW;
328+ SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &home_pathW);
329+ convert_bsW(home_pathW);
330+ char *home_pathU8 = convert_utf8_from_wchar(home_pathW);
331+ CoTaskMemFree(home_pathW);
332+ return home_pathU8;
333+#endif
334+#if 1
335+ char *appdata = strdup(getenv("APPDATA"));
336+ convert_bs(appdata);
337+ return appdata;
338+#endif
339+}
340+
341+void get_cfg_filenames(char **cfg_exe_full, char **cfg_appdata_full, char **cfg)
342+{
343+ wchar_t win_conf[MAX_PATH];
344+
295345 // get cfg path from exe path
296- if (GetModuleFileName(NULL, win_conf, MAX_PATH) <= 0) {
346+ if (GetModuleFileNameW(NULL, win_conf, MAX_PATH) <= 0) {
347+ *cfg_exe_full = NULL;
348+ *cfg = NULL;
297349 return;
298350 }
299- char* bs = strrchr(win_conf, '\\');
300- if (bs == NULL) {
301- return;
351+
352+ convert_bsW(win_conf);
353+
354+ wchar_t* bcW = wcsrchr(win_conf, '/');
355+ if (bcW != NULL) {
356+ wchar_t* dot = wcsrchr(bcW, '.');
357+ if (dot == NULL) {
358+ wcscat(bcW, L".cfg");
359+ } else {
360+ wcscpy(dot, L".cfg");
361+ }
302362 }
303- char* dot = strrchr(bs, '.');
304- if (dot == NULL) {
305- strcat(bs, ".cfg");
306- } else {
307- strcpy(dot, ".cfg");
308- }
363+ char *u8 = convert_utf8_from_wchar(win_conf);
364+ *cfg_exe_full = u8;
309365
366+ char *bs = strrchr(u8, '/');
367+ *cfg = strdup(bs+1);
368+
369+ char *appdata = get_appdata_dir();
370+ const char *teraterm = "/teraterm5/";
371+ size_t len = strlen(appdata) + strlen(teraterm) + strlen(*cfg) + 1;
372+ *cfg_appdata_full = (char *)malloc(sizeof(wchar_t) * len);
373+ strcpy(*cfg_appdata_full, appdata);
374+ strcat(*cfg_appdata_full, teraterm);
375+ strcat(*cfg_appdata_full, *cfg);
376+ free(appdata);
377+}
378+
379+//====================//
380+// load configuration //
381+//--------------------//
382+void load_cfg()
383+{
384+ // configuration file (.cfg) path
385+ char *conf_exe_full;
386+ char *conf_appdata_full;
387+ char *conf_base;
388+ get_cfg_filenames(&conf_exe_full, &conf_appdata_full, &conf_base);
389+
310390 char sys_conf[] = "/etc/cygterm.conf";
311391
312392 // user configuration file (~/.*rc) path
@@ -324,15 +404,15 @@
324404 if (username != NULL) {
325405 struct passwd* pw_ent = getpwnam(username);
326406 if (pw_ent != NULL) {
327- strncpy(pw_shell, pw_ent->pw_shell, sizeof(pw_shell)-1);
328- pw_shell[sizeof(pw_shell)-1] = 0;
407+ strncpy(pw_shell, pw_ent->pw_shell, sizeof(pw_shell)-1);
408+ pw_shell[sizeof(pw_shell)-1] = 0;
329409
330410 strcpy(usr_conf, pw_ent->pw_dir);
331411 strcat(usr_conf, "/.");
332- strcat(usr_conf, bs + 1);
412+ strcat(usr_conf, conf_base);
333413 char* dot = strrchr(usr_conf, '.');
334414 if (dot == NULL) {
335- strcat(bs, "rc");
415+ strcat(usr_conf, "rc");
336416 } else {
337417 strcpy(dot, "rc");
338418 }
@@ -356,8 +436,14 @@
356436 strcpy(tmp_conf, "");
357437 }
358438
359- char *conf_path[] = { tmp_conf, win_conf, sys_conf, usr_conf };
360- for (int i = 0; i < 4; i++) {
439+ char const *conf_path[] = {
440+ tmp_conf,
441+ conf_exe_full, // [exe directory]/cygterm.cfg
442+ sys_conf, // /etc/cygterm.conf
443+ conf_appdata_full, // $APPDATA/teraterm5/cygterm.cfg
444+ usr_conf // ~/cygtermrc
445+ };
446+ for (int i = 0; i < sizeof(conf_path)/sizeof(conf_path[0]); i++) {
361447 // ignore empty configuration file path
362448 if (strcmp(conf_path[i], "") == 0) {
363449 continue;
@@ -378,6 +464,10 @@
378464 if (strcmp(tmp_conf, "") != 0) {
379465 unlink(tmp_conf);
380466 }
467+
468+ free(conf_base);
469+ free(conf_exe_full);
470+ free(conf_appdata_full);
381471 }
382472
383473 void quote_cut(char *dst, size_t len, char *src) {
Show on old repository browser