[ttssh2-commit] [9531] $APPDATA/teraterm5/cygterm.cfg も読むようにした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 11月 15日 (月) 00:09:24 JST


Revision: 9531
          https://osdn.net/projects/ttssh2/scm/svn/commits/9531
Author:   zmatsuo
Date:     2021-11-15 00:09:24 +0900 (Mon, 15 Nov 2021)
Log Message:
-----------
$APPDATA/teraterm5/cygterm.cfg も読むようにした

- cygterm.cfg が Unicodeフォルダ名にあっても読めるようにした
  - cygterm.exe が Unicodeフォルダ名にある場合
- ドキュメントを修正 (日本語版のみ)
  - URLが404だったので削除
  - 日付を更新
  - 読み込む cygterm.cfg について追記
  - 動作確認環境を削除

Modified Paths:
--------------
    trunk/cygwin/cygterm/README-j
    trunk/cygwin/cygterm/cygterm.cc

-------------- next part --------------
Modified: trunk/cygwin/cygterm/README-j
===================================================================
--- trunk/cygwin/cygterm/README-j	2021-11-11 15:30:41 UTC (rev 9530)
+++ trunk/cygwin/cygterm/README-j	2021-11-14 15:09:24 UTC (rev 9531)
@@ -3,14 +3,12 @@
 
                 $B%?!<%_%J%k!&%(%_%e%l!<%?$G(B Cygwin $B$r;H$&!#(B
 
-                (C) 2006-2016 TeraTerm Project
+                (C) 2006- TeraTerm Project
                 https://ttssh2.osdn.jp/
 
                 Based on CygTerm by Original developer:
                 Copyright (C) 2000-2006 NSym
                 nsym****@dd*****
-      (English) https://googledrive.com/host/0B1s-dM6d6yC4fmhEZ3c0VTNFWEFtV3daUlRGQmFHVnBmVHRybUNnUVliNWktNDRlZ2NnZTQ/index-e.html
-     (Japanese) https://googledrive.com/host/0B1s-dM6d6yC4fmhEZ3c0VTNFWEFtV3daUlRGQmFHVnBmVHRybUNnUVliNWktNDRlZ2NnZTQ/index.html
 
 
 // $B$O(B $B$8(B $B$a(B $B$K(B //
@@ -97,9 +95,15 @@
 
     cygterm.cfg $B$O @ _Dj%U%!%$%k$G$9!#(B $B;HMQ$9$kC<Kv%(%_%e%l!<%?$N%3%^%s%I%i%$%s(B
     $B$d5/F0$9$k%7%'%k$N%3%^%s%I%i%$%sEy$r @ _Dj$7$^$9!#(B
-    cygterm.cfg $B$O(B cygterm.exe $B$HF1$8%G%#%l%/%H%j$K$J$$$H$$$1$^$;$s!#(B
 
-      cygterm.cfg $B$NNc(B
+    cygterm.cfg $B$O<!$N=g=x$GFI$_9~$^$l$^$9!#(B
+      - $B%3%^%s%I%i%$%s0z?t(B
+      - exe $B$HF1$8%U%)%k%@(B
+      - /etc/cygterm.conf (cygwin$B$N(B/etc/)
+      - $APPDATA/teraterm5/cygterm.cfg
+      - ~/.cygtermrc
+
+    cygterm.cfg $B$NNc(B
       +-----------------------------------------------------------------------
       | TERM = C:\program files\ttermpro\ttermpro.exe %s %d /KR=SJIS /KT=SJIS
       | TERM_TYPE = vt100
@@ -263,22 +267,11 @@
     $B<B9T;~$K@\B3$G$-$:!"92$F$k$3$H$K$J$C$F$7$^$$$^$9!#(B
     TCP/IP Port# $B$K(B 23 $B$r;XDj$7$F @ _DjJ]B8$7D>$;$P85$KLa$j$^$9!#(B
 
-// $BF0(B $B:n(B $B3N(B $BG'(B //
+// $BJQ(B $B99(B $BMz(B $BNr(B //
+v1.07_30(beta) 2021/11/14
+        * $BFI$_9~$`@_Dj%U%!%$%k$rDI2C(B
+          $APPDATA/teraterm5/cygterm.cfg
 
-    2010$BG/(B 10$B7n8=:_!"0J2<$N4D6-$GF0:n$,3NG'$G$-$F$$$^$9!#(B
-
-        WindowsXP SP3 + Cygwin 1.5.25-15
-        WindowsXP SP3 + Cygwin 1.7.7
-
-        $B%?!<%_%J%k%(%_%e%l!<%?(B
-                Tera Term Pro 2.3
-                Tera Term 4.67
-                PuTTY 0.60
-        $B%7%'%k(B
-                bash 3.2.51
-                zsh 4.3.10
-
-// $BJQ(B $B99(B $BMz(B $BNr(B //
 v1.07_29 2016/11/26 (by maya)
         * $B%"%$%3%s$rJQ99$7$?!#(B
 
@@ -302,7 +295,7 @@
 
 v1.07_23 2011/04/18 (by doda)
         * -d $B%*%W%7%g%s$G;XDj$5$l$?%G%#%l%/%H%j$X$N0\F0$,<:GT$7$?;~!"(B
-	  $B%(%i!<%a%C%;!<%8$rI=<($9$k$h$&$K$7$?!#(B
+          $B%(%i!<%a%C%;!<%8$rI=<($9$k$h$&$K$7$?!#(B
 
 v1.07_22 2011/03/03 (by maya)
         * $B%$%s%9%H!<%i$+$i5/F0%A%'%C%/$r$9$k$?$a$N(B mutex $B$r:o=|$7$?!#(B
@@ -312,7 +305,7 @@
 
 v1.07_20 2010/10/20 (by doda)
         * '-d' $B%*%W%7%g%s$G$N%G%#%l%/%H%jJQ99$N%?%$%_%s%0$rCY$i$;$?!#(B
-	  (security fix)
+          (security fix)
 
 v1.07_19 2010/01/28 (by doda)
         * '-s' $B%*%W%7%g%s$N0z?t$K(B 'AUTO' $B$r<u$1IU$1$k$h$&$K$7$?!#(B
@@ -439,7 +432,7 @@
         * $B%?!<%_%J%k!&%(%_%e%l!<%?$,DLCN$7$F$/$k%?!<%_%J%k%?%$%W$K!"BgJ8;z$,(B
           $B4^$^$l$F$$$l$P!"$=$l$r>.J8;z$KJQ49$9$k$h$&$K=$@5!#(B
           $B%?!<%_%J%k!&%(%_%e%l!<%?$K$h$C$F$O4D6-JQ?t(B TERM $B$NCM$,(B 'ANSI' 'VT100'
-          $B$N$h$&$KBgJ8;z$K$j(B terminfo $B$K%^%C%A$7$J$$$?$a!#(B
+          $B$N$h$&$KBgJ8;z$J$j(B terminfo $B$K%^%C%A$7$J$$$?$a!#(B
           (Windows 2000 telnet.exe $BEy(B)
 
 v1.02 2002/07/22

Modified: trunk/cygwin/cygterm/cygterm.cc
===================================================================
--- trunk/cygwin/cygterm/cygterm.cc	2021-11-11 15:30:41 UTC (rev 9530)
+++ trunk/cygwin/cygterm/cygterm.cc	2021-11-14 15:09:24 UTC (rev 9531)
@@ -33,7 +33,7 @@
 //
 
 static char Program[] = "CygTerm+";
-static char Version[] = "version 1.07_28 (2016/02/17)";
+static char Version[] = "version 1.07_30_beta (2021/11/14)";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -52,8 +52,10 @@
 #include <sys/wait.h>
 #include <arpa/inet.h>
 #include <windows.h>
+#include <shlobj.h>
 #include <pwd.h>
 #include <sys/select.h>
+#include <wchar.h>
 
 // pageant support (ssh-agent proxy)
 //----------------------------------
@@ -284,29 +286,107 @@
     return;
 }
 
-//====================//
-// load configuration //
-//--------------------//
-void load_cfg()
+// '\\' -> '/'
+void convert_bs(char *path)
 {
-    // Windows system configuration file (.cfg) path
-    char win_conf[MAX_PATH];
+    char *p = path;
+    while(*p != 0) {
+        if (*p == '\\') {
+            *p = '/';
+        }
+        p++;
+    }
+}
 
+// L'\\' -> L'/'
+void convert_bsW(wchar_t *path)
+{
+    wchar_t *p = path;
+    while(*p != 0) {
+        if (*p == L'\\') {
+            *p = L'/';
+        }
+        p++;
+    }
+}
+
+// wchar -> utf8
+char *convert_utf8_from_wchar(const wchar_t *strW)
+{
+    size_t mb_len = ::WideCharToMultiByte(CP_UTF8, 0, strW, -1, NULL, 0, NULL, NULL);
+    char *u8 = (char *)malloc(sizeof(wchar_t) * mb_len);
+    ::WideCharToMultiByte(CP_UTF8, 0, strW, -1, u8, mb_len, NULL, NULL);
+    return u8;
+}
+
+// $APPDATA
+char *get_appdata_dir()
+{
+#if 0
+	// link error :-(
+    wchar_t *home_pathW;
+    SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &home_pathW);
+    convert_bsW(home_pathW);
+    char *home_pathU8 = convert_utf8_from_wchar(home_pathW);
+    CoTaskMemFree(home_pathW);
+    return home_pathU8;
+#endif
+#if 1
+    char *appdata = strdup(getenv("APPDATA"));
+    convert_bs(appdata);
+    return appdata;
+#endif
+}
+
+void get_cfg_filenames(char **cfg_exe_full, char **cfg_appdata_full, char **cfg)
+{
+    wchar_t win_conf[MAX_PATH];
+
     // get cfg path from exe path
-    if (GetModuleFileName(NULL, win_conf, MAX_PATH) <= 0) {
+    if (GetModuleFileNameW(NULL, win_conf, MAX_PATH) <= 0) {
+        *cfg_exe_full = NULL;
+        *cfg = NULL;
         return;
     }
-    char* bs = strrchr(win_conf, '\\');
-    if (bs == NULL) {
-        return;
+
+    convert_bsW(win_conf);
+
+    wchar_t* bcW = wcsrchr(win_conf, '/');
+    if (bcW != NULL) {
+        wchar_t* dot = wcsrchr(bcW, '.');
+        if (dot == NULL) {
+            wcscat(bcW, L".cfg");
+        } else {
+            wcscpy(dot, L".cfg");
+        }
     }
-    char* dot = strrchr(bs, '.');
-    if (dot == NULL) {
-        strcat(bs, ".cfg");
-    } else {
-        strcpy(dot, ".cfg");
-    }
+    char *u8 = convert_utf8_from_wchar(win_conf);
+    *cfg_exe_full = u8;
 
+    char *bs = strrchr(u8, '/');
+    *cfg = strdup(bs+1);
+
+    char *appdata = get_appdata_dir();
+    const char *teraterm = "/teraterm5/";
+    size_t len = strlen(appdata) + strlen(teraterm) + strlen(*cfg) + 1;
+    *cfg_appdata_full = (char *)malloc(sizeof(wchar_t) * len);
+    strcpy(*cfg_appdata_full, appdata);
+    strcat(*cfg_appdata_full, teraterm);
+    strcat(*cfg_appdata_full, *cfg);
+    free(appdata);
+}
+
+//====================//
+// load configuration //
+//--------------------//
+void load_cfg()
+{
+    // configuration file (.cfg) path
+    char *conf_exe_full;
+    char *conf_appdata_full;
+    char *conf_base;
+    get_cfg_filenames(&conf_exe_full, &conf_appdata_full, &conf_base);
+
     char sys_conf[] = "/etc/cygterm.conf";
 
     // user configuration file (~/.*rc) path
@@ -324,15 +404,15 @@
     if (username != NULL) {
         struct passwd* pw_ent = getpwnam(username);
         if (pw_ent != NULL) {
-	    strncpy(pw_shell, pw_ent->pw_shell, sizeof(pw_shell)-1);
-	    pw_shell[sizeof(pw_shell)-1] = 0;
+            strncpy(pw_shell, pw_ent->pw_shell, sizeof(pw_shell)-1);
+            pw_shell[sizeof(pw_shell)-1] = 0;
 
             strcpy(usr_conf, pw_ent->pw_dir);
             strcat(usr_conf, "/.");
-            strcat(usr_conf, bs + 1);
+            strcat(usr_conf, conf_base);
             char* dot = strrchr(usr_conf, '.');
             if (dot == NULL) {
-                strcat(bs, "rc");
+                strcat(usr_conf, "rc");
             } else {
                 strcpy(dot, "rc");
             }
@@ -356,8 +436,14 @@
         strcpy(tmp_conf, "");
     }
 
-    char *conf_path[] = { tmp_conf, win_conf, sys_conf, usr_conf };
-    for (int i = 0; i < 4; i++) {
+    char const *conf_path[] = {
+        tmp_conf,
+        conf_exe_full,      // [exe directory]/cygterm.cfg
+        sys_conf,           // /etc/cygterm.conf
+        conf_appdata_full,  // $APPDATA/teraterm5/cygterm.cfg
+        usr_conf            // ~/cygtermrc
+    };
+    for (int i = 0; i < sizeof(conf_path)/sizeof(conf_path[0]); i++) {
         // ignore empty configuration file path
         if (strcmp(conf_path[i], "") == 0) {
             continue;
@@ -378,6 +464,10 @@
     if (strcmp(tmp_conf, "") != 0) {
         unlink(tmp_conf);
     }
+
+    free(conf_base);
+    free(conf_exe_full);
+    free(conf_appdata_full);
 }
 
 void quote_cut(char *dst, size_t len, char *src) {


ttssh2-commit メーリングリストの案内
Back to archive index