Revision: 10444 https://osdn.net/projects/ttssh2/scm/svn/commits/10444 Author: zmatsuo Date: 2022-12-31 00:46:12 +0900 (Sat, 31 Dec 2022) Log Message: ----------- ログファイル名プレビュの表示内容を詳しくした - 無効な文字を含んだ時のファイル名も表示するようにした - プレビュ不要時は表示しないようにした - filesys_log.cpp 内でのログファイル名の処理を Unicode化 - 他で使用していないと思われる ConvFName() を無効化した - TODO - tttset.LogDefaultName の Unicode版追加 - ホイールスクロール行数取得に GetDlgItemInt() を使用するようにした - GetDlgItemText() + atoi() だった ticket #45553 Ticket Links: ------------ https://osdn.net/projects/ttssh2/tracker/detail/45553 Modified Paths: -------------- trunk/teraterm/common/ttlib.c trunk/teraterm/common/ttlib.h trunk/teraterm/common/ttlib_static_cpp.cpp trunk/teraterm/teraterm/addsetting.cpp trunk/teraterm/teraterm/filesys_log.cpp trunk/teraterm/teraterm/filesys_log.h -------------- next part -------------- Modified: trunk/teraterm/common/ttlib.c =================================================================== --- trunk/teraterm/common/ttlib.c 2022-12-29 16:43:20 UTC (rev 10443) +++ trunk/teraterm/common/ttlib.c 2022-12-30 15:46:12 UTC (rev 10444) @@ -540,71 +540,14 @@ return (int)r; } - -// strftime \x82ɓn\x82\xB9\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x8D폜\x82\xB7\x82\xE9 (2006.8.28 maya) +// strftime \x82ɓn\x82\xB9\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x8D폜\x82\xB7\x82\xE9 void deleteInvalidStrftimeChar(PCHAR FName) { - size_t i, j=0, len, p; - - len = strlen(FName); - for (i=0; i<len; i++) { - if (FName[i] == '%') { - if (FName[i+1] != 0) { - p = i+1; - if (FName[i+2] != 0 && FName[i+1] == '#') { - p = i+2; - } - switch (FName[p]) { - case 'a': - case 'A': - case 'b': - case 'B': - case 'c': - case 'd': - case 'H': - case 'I': - case 'j': - case 'm': - case 'M': - case 'p': - case 'S': - case 'U': - case 'w': - case 'W': - case 'x': - case 'X': - case 'y': - case 'Y': - case 'z': - case 'Z': - case '%': - FName[j] = FName[i]; // % - j++; - i++; - if (p-i == 2) { - FName[j] = FName[i]; // # - j++; - i++; - } - FName[j] = FName[i]; - j++; - break; - default: - i++; // % - if (p-i == 2) { - i++; // # - } - } - } - // % \x82ŏI\x82\xED\x82\xC1\x82Ă\xA2\x82\xE9\x8Fꍇ\x82̓R\x83s\x81[\x82\xB5\x82Ȃ\xA2 - } - else { - FName[j] = FName[i]; - j++; - } - } - - FName[j] = 0; + const size_t len = strlen(FName); + wchar_t *FNameW = ToWcharA(FName); + deleteInvalidStrftimeCharW(FNameW); + WideCharToACP_t(FNameW, FName, len); + free(FNameW); } // \x83t\x83\x8B\x83p\x83X\x82\xA9\x82\xE7\x81A\x83t\x83@\x83C\x83\x8B\x96\xBC\x95\x94\x95\xAA\x82݂̂\xF0 strftime \x82ŕϊ\xB7\x82\xB7\x82\xE9 (2006.8.28 maya) @@ -647,6 +590,7 @@ } } +#if 0 void ConvFName(const char *HomeDir, PCHAR Temp, int templen, const char *DefExt, PCHAR FName, int destlen) { // destlen = sizeof FName @@ -663,6 +607,7 @@ } strncat_s(FName,destlen,Temp,_TRUNCATE); } +#endif // "\n" \x82\xF0\x89\xFC\x8Ds\x82ɕϊ\xB7\x82\xB7\x82\xE9 (2006.7.29 maya) // "\t" \x82\xF0\x83^\x83u\x82ɕϊ\xB7\x82\xB7\x82\xE9 (2006.11.6 maya) Modified: trunk/teraterm/common/ttlib.h =================================================================== --- trunk/teraterm/common/ttlib.h 2022-12-29 16:43:20 UTC (rev 10443) +++ trunk/teraterm/common/ttlib.h 2022-12-30 15:46:12 UTC (rev 10444) @@ -85,10 +85,13 @@ DllExport void replaceInvalidFileNameChar(PCHAR FName, unsigned char c); BOOL isInvalidStrftimeCharW(const wchar_t *format); int isInvalidStrftimeChar(PCHAR FName); +void deleteInvalidStrftimeCharW(wchar_t *FName); void deleteInvalidStrftimeChar(PCHAR FName); void ParseStrftimeFileName(PCHAR FName, int destlen); +#if 0 void ConvFName(const char *HomeDir, PCHAR Temp, int templen, const char *DefExt, PCHAR FName, int destlen); void ConvFNameW(const wchar_t *HomeDir, wchar_t *Temp, size_t templen, const wchar_t *DefExt, wchar_t *FName, size_t destlen); +#endif void RestoreNewLine(PCHAR Text); size_t RestoreNewLineW(wchar_t *Text); BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest); Modified: trunk/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- trunk/teraterm/common/ttlib_static_cpp.cpp 2022-12-29 16:43:20 UTC (rev 10443) +++ trunk/teraterm/common/ttlib_static_cpp.cpp 2022-12-30 15:46:12 UTC (rev 10444) @@ -1111,6 +1111,7 @@ wcsncpy_s(FileName,destlen,Temp,_TRUNCATE); } +#if 0 void ConvFNameW(const wchar_t *HomeDir, wchar_t *Temp, size_t templen, const wchar_t *DefExt, wchar_t *FName, size_t destlen) { // destlen = sizeof FName @@ -1127,6 +1128,7 @@ } wcsncat_s(FName,destlen,Temp,_TRUNCATE); } +#endif /** * path\x82\xAA\x91\x8A\x91p\x83X\x82\xA9\x82ǂ\xA4\x82\xA9\x82\xF0\x95Ԃ\xB7 @@ -1761,3 +1763,69 @@ return FALSE;; } + +// strftime \x82ɓn\x82\xB9\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x8D폜\x82\xB7\x82\xE9 +void deleteInvalidStrftimeCharW(wchar_t *FName) +{ + size_t i, j=0, len, p; + + len = wcslen(FName); + for (i=0; i<len; i++) { + if (FName[i] == '%') { + if (FName[i+1] != 0) { + p = i+1; + if (FName[i+2] != 0 && FName[i+1] == '#') { + p = i+2; + } + switch (FName[p]) { + case 'a': + case 'A': + case 'b': + case 'B': + case 'c': + case 'd': + case 'H': + case 'I': + case 'j': + case 'm': + case 'M': + case 'p': + case 'S': + case 'U': + case 'w': + case 'W': + case 'x': + case 'X': + case 'y': + case 'Y': + case 'z': + case 'Z': + case '%': + FName[j] = FName[i]; // % + j++; + i++; + if (p-i == 2) { + FName[j] = FName[i]; // # + j++; + i++; + } + FName[j] = FName[i]; + j++; + break; + default: + i++; // % + if (p-i == 2) { + i++; // # + } + } + } + // % \x82ŏI\x82\xED\x82\xC1\x82Ă\xA2\x82\xE9\x8Fꍇ\x82̓R\x83s\x81[\x82\xB5\x82Ȃ\xA2 + } + else { + FName[j] = FName[i]; + j++; + } + } + + FName[j] = 0; +} Modified: trunk/teraterm/teraterm/addsetting.cpp =================================================================== --- trunk/teraterm/teraterm/addsetting.cpp 2022-12-29 16:43:20 UTC (rev 10443) +++ trunk/teraterm/teraterm/addsetting.cpp 2022-12-30 15:46:12 UTC (rev 10444) @@ -57,7 +57,7 @@ #include "themedlg.h" #include "theme.h" #include "ttcmn_notify2.h" -#include "filesys_log.h" // for ConvertLognameW() +#include "filesys_log.h" // for FLogGetLogFilenameBase() const mouse_cursor_t MouseCursor[] = { {"ARROW", IDC_ARROW}, @@ -169,7 +169,6 @@ void CGeneralPropPageDlg::OnOK() { - char buf[64]; int val; // (1) @@ -182,8 +181,7 @@ ts.AcceptBroadcast = GetCheck(IDC_ACCEPT_BROADCAST); // (4)IDC_MOUSEWHEEL_SCROLL_LINE - GetDlgItemText(IDC_SCROLL_LINE, buf, _countof(buf)); - val = atoi(buf); + val = GetDlgItemInt(IDC_SCROLL_LINE); if (val > 0) ts.MouseWheelScrollLine = val; @@ -1366,7 +1364,7 @@ enum { IDD = IDD_TABSHEET_LOG }; BOOL OnCommand(WPARAM wParam, LPARAM lParam); void OnHelp(); - wchar_t *CreateLogFilename(const wchar_t *format); + wchar_t *MakePreviewStr(const wchar_t *format, const wchar_t *UILanguageFile); CTipWin *m_TipWin; }; @@ -1534,35 +1532,34 @@ ::SetFocus(::GetDlgItem(GetSafeHwnd(), IDC_VIEWLOG_EDITOR)); } -wchar_t *CLogPropPageDlg::CreateLogFilename(const wchar_t *format) +wchar_t *CLogPropPageDlg::MakePreviewStr(const wchar_t *format, const wchar_t *UILanguageFile) { - time_t time_local; - struct tm tm_local; - time(&time_local); - localtime_s(&tm_local, &time_local); - wchar_t *str; + wchar_t *str = FLogGetLogFilenameBase(format); + wchar_t *message = NULL; if (isInvalidStrftimeCharW(format)) { - str = _wcsdup(L"Invalid character is included in log file name."); + wchar_t *msg; + GetI18nStrWW("Tera Term", "MSG_LOGFILE_INVALID_CHAR_ERROR", + L"Invalid character is included in log file name.", + UILanguageFile, &msg); + awcscats(&message, L"\r\n", msg, L"(strftime)", NULL); + free(msg); } - else { - size_t len = 128; - str = (wchar_t*)malloc(sizeof(wchar_t) * len); - wcsftime(str, len, format, &tm_local); - wchar_t *replace = replaceInvalidFileNameCharW(str, L'_'); - free(str); - str = replace; - if (isInvalidFileNameCharW(str)) { - free(str); - str = _wcsdup(L"Invalid character is included in log file name."); - } - else { - wchar_t *str2 = ConvertLognameW(&cv, str); - free(str); - str = str2; - } + if (isInvalidFileNameCharW(format)) { + wchar_t *msg; + GetI18nStrWW("Tera Term", "MSG_LOGFILE_INVALID_CHAR_ERROR", + L"Invalid character is included in log file name.", + UILanguageFile, &msg); + awcscats(&message, L"\r\n", msg, L"(char)", NULL); + free(msg); } + + if (message != NULL) { + awcscat(&str, message); + free(message); + } + return str; } @@ -1674,11 +1671,11 @@ if (format == NULL) { hGetDlgItemTextW(m_hWnd, IDC_DEFAULTNAME_EDITOR, &format); } - wchar_t *str = CreateLogFilename(format); - if (wcslen(str) > 0) { + wchar_t *preview = MakePreviewStr(format, ts.UILanguageFileW); + if (preview[0] != 0 && wcscmp(format, preview) != 0) { RECT rc; ::GetWindowRect(::GetDlgItem(m_hWnd, IDC_DEFAULTNAME_EDITOR), &rc); - m_TipWin->SetText(str); + m_TipWin->SetText(preview); m_TipWin->SetPos(rc.left, rc.bottom); m_TipWin->SetHideTimer(5 * 1000); // \x95\\x8E\xA6\x8E\x9E\x8A\xD4 if (!m_TipWin->IsVisible()) { @@ -1688,7 +1685,7 @@ else { m_TipWin->SetVisible(FALSE); } - free(str); + free(preview); free(format); return TRUE; } Modified: trunk/teraterm/teraterm/filesys_log.cpp =================================================================== --- trunk/teraterm/teraterm/filesys_log.cpp 2022-12-29 16:43:20 UTC (rev 10443) +++ trunk/teraterm/teraterm/filesys_log.cpp 2022-12-30 15:46:12 UTC (rev 10444) @@ -162,7 +162,7 @@ * @return \x92u\x82\xAB\x8A\xB7\x82\xA6\x82\xE7\x82ꂽ\x95\xB6\x8E\x9A\x97\xF1 * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7free()\x82\xB7\x82邱\x82\xC6 */ -wchar_t *ConvertLognameW(const TComVar *pcv, const wchar_t *src) +static wchar_t *ConvertLognameW(const TComVar *pcv, const wchar_t *src) { const TTTSet *pts = pcv->ts; size_t dest_len = wcslen(src) + 1; @@ -225,11 +225,12 @@ break; } - if (add_text != 0) { + if (add_text != NULL) { size_t l = wcslen(add_text); dest_len += l; dest = (wchar_t *)realloc(dest, sizeof(wchar_t) * dest_len); wcscpy(&dest[i], add_text); + free(add_text); i += l; } } @@ -242,18 +243,6 @@ return dest; } -/** - * \x83t\x83@\x83C\x83\x8B\x96\xBC\x95\xB6\x8E\x9A\x97\xF1\x82̒u\x82\xAB\x8A\xB7\x82\xA6 ANSI\x94\xC5 - */ -static void ConvertLogname(char *c, int destlen) -{ - wchar_t *cW = ToWcharA(c); - wchar_t *filenameW = ConvertLognameW(&cv, cW); - WideCharToACP_t(cW, c, destlen); - free(filenameW); - free(cW); -} - static void FixLogOption(void) { if (ts.LogBinary) { @@ -1385,6 +1374,54 @@ } /** + * \x83\x8D\x83O\x83t\x83@\x83C\x83\x8B\x96\xBC\x97p\x82̏C\x8F\xFC\x82\xF0\x8Ds\x82\xA4,\x83t\x83@\x83C\x83\x8B\x96\xBC\x95\x94\x95\xAA\x82̂\xDD + * - strftime() \x82Ɠ\xAF\x82\xB6\x93\xFA\x95t\x93W\x8AJ + * - \x90ݒ肳\x82ꂽ\x83\x8D\x83O\x83t\x83@\x83C\x83\x8B\x83t\x83H\x83\x8B\x83_\x82\xF0\x92lj\xC1 + * - \x83z\x83X\x83g\x96\xBC,\x83|\x81[\x83g\x94ԍ\x86\x93W\x8AJ + * + * @param filename \x83t\x83@\x83C\x83\x8B\x96\xBC(\x83p\x83X\x82͊܂܂Ȃ\xA2) + * @return \x8FC\x8F\xFC\x8Dς݃t\x83@\x83C\x83\x8B\x96\xBC + */ +wchar_t *FLogGetLogFilenameBase(const wchar_t *filename) +{ + // \x83t\x83@\x83C\x83\x8B\x96\xBC\x95\x94\x95\xAA\x82𒊏o + wchar_t *format = ExtractFileNameW(filename); + if (format == NULL) { + format = wcsdup(L""); + } + + // strftime \x82Ɏg\x97p\x82ł\xAB\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x8D폜 + deleteInvalidStrftimeCharW(format); + + // \x8C\xBB\x8Dݎ\x9E\x8D\x8F\x82\xF0\x8E擾 + time_t time_local; + time(&time_local); + struct tm tm_local; + localtime_s(&tm_local, &time_local); + + // strftime()\x82ŕϊ\xB7 + size_t len = 128; + wchar_t *formated = (wchar_t*)malloc(sizeof(wchar_t) * len); + size_t r = wcsftime(formated, len, format, &tm_local); + if (r == 0) { + // \x83G\x83\x89\x81[\x82\xAA\x95Ԃ\xC1\x82Ă\xAB\x82\xBD + wcscpy(formated, format); + } + free(format); + + // \x83z\x83X\x83g\x96\xBC\x82Ȃ\xC7 + wchar_t *host = ConvertLognameW(&cv, formated); + free(formated); + + // \x83t\x83@\x83C\x83\x8B\x96\xBC\x82Ɏg\x97p\x82ł\xAB\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x92u\x8A\xB7 + //wchar_t *replaced = replaceInvalidFileNameCharW(host, 0); // \x8D폜 + wchar_t *replaced = replaceInvalidFileNameCharW(host, L'_'); + free(host); + + return replaced; +} + +/** * \x83\x8D\x83O\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x8E擾 * \x83\x8D\x83O\x83t\x83@\x83C\x83\x8B\x96\xBC\x97p\x82̏C\x8F\xFC\x82\xF0\x8Ds\x82\xA4 * - strftime() \x82Ɠ\xAF\x82\xB6\x93\xFA\x95t\x93W\x8AJ @@ -1399,27 +1436,36 @@ */ wchar_t *FLogGetLogFilename(const wchar_t *log_filename) { - const char *logdir = ToCharW(ts.LogDefaultPathW); - - // \x8C\xB3\x82ƂȂ\xE9\x83t\x83@\x83C\x83\x8B\x96\xBC - char base_name[MAX_PATH]; + wchar_t *dir; + wchar_t *fname; if (log_filename == NULL) { - strncpy_s(base_name, _countof(base_name), ts.LogDefaultName, _TRUNCATE); + dir = wcsdup(ts.LogDefaultPathW); + fname = ToWcharA(ts.LogDefaultName); + //fname = wcsdup(ts.LogDefaultNameW); + } else if (!IsRelativePathW(log_filename)) { + // \x90\xE2\x91p\x83X\x82\xAA\x93\xFC\x97͂\xB3\x82ꂽ + dir = ExtractDirNameW(log_filename); + fname = ExtractFileNameW(log_filename); } else { - char *filenameA = ToCharW(log_filename); - strncpy_s(base_name, _countof(base_name), filenameA, _TRUNCATE); - free(filenameA); + dir = wcsdup(ts.LogDefaultPathW); + fname = wcsdup(log_filename); } - // \x83t\x83\x8B\x83p\x83X\x89\xBB - char full_path[MAX_PATH]; - ConvFName(logdir, base_name, sizeof(base_name), "", full_path, sizeof(full_path)); - ParseStrftimeFileName(full_path, sizeof(full_path)); - ConvertLogname(full_path, sizeof(full_path)); + wchar_t *formated = FLogGetLogFilenameBase(fname); + free(fname); - free((void *)logdir); - return ToWcharA(full_path); + // \x98A\x8C\x8B\x82\xB7\x82\xE9 + wchar_t *logfull = NULL; + awcscats(&logfull, dir, L"\\", formated, NULL); + free(dir); + + // \x90\xB3\x8BK\x89\xBB + wchar_t *normal; + hGetFullPathNameW(logfull, &normal, NULL); + free(logfull); + + return normal; } BOOL FLogIsPause() Modified: trunk/teraterm/teraterm/filesys_log.h =================================================================== --- trunk/teraterm/teraterm/filesys_log.h 2022-12-29 16:43:20 UTC (rev 10443) +++ trunk/teraterm/teraterm/filesys_log.h 2022-12-30 15:46:12 UTC (rev 10444) @@ -56,6 +56,7 @@ BOOL FLogOpenDialog(HINSTANCE hInst, HWND hWnd, FLogDlgInfo_t *info); void FLogAddCommentDlg(HINSTANCE hInst, HWND hWnd); wchar_t *FLogGetLogFilename(const wchar_t *log_filename); +wchar_t *FLogGetLogFilenameBase(const wchar_t *filename); void logfile_lock_initialize(void); void FLogPause(BOOL Pause); @@ -79,8 +80,6 @@ void FLogPutUTF32(unsigned int u32); void FLogOutputAllBuffer(void); -wchar_t *ConvertLognameW(const TComVar *pcv, const wchar_t *src); - #ifdef __cplusplus } #endif