Revision: 8880 https://osdn.net/projects/ttssh2/scm/svn/commits/8880 Author: zmatsuo Date: 2020-08-06 00:06:37 +0900 (Thu, 06 Aug 2020) Log Message: ----------- ログファイルへの文字コードの変換を filesys_log で行うようにした - filesys_log へ追加 (vtterm.c から移動) - FLogPutUTF32() - FLogSetCode() - FLogOutputBOM() Modified Paths: -------------- branches/filesys_log/teraterm/teraterm/filesys_log.cpp branches/filesys_log/teraterm/teraterm/filesys_log.h branches/filesys_log/teraterm/teraterm/vtterm.c branches/filesys_log/teraterm/teraterm/vtterm.h branches/filesys_log/teraterm/teraterm/vtwin.cpp -------------- next part -------------- Modified: branches/filesys_log/teraterm/teraterm/filesys_log.cpp =================================================================== --- branches/filesys_log/teraterm/teraterm/filesys_log.cpp 2020-08-05 15:06:29 UTC (rev 8879) +++ branches/filesys_log/teraterm/teraterm/filesys_log.cpp 2020-08-05 15:06:37 UTC (rev 8880) @@ -92,6 +92,9 @@ BOOL IsPause; PFileTransDlg FLogDlg; + + int log_code; + } TFileVar_; typedef TFileVar_ *PFileVar_; @@ -1308,6 +1311,7 @@ fv->FileHandle = INVALID_HANDLE_VALUE; fv->LogThread = INVALID_HANDLE_VALUE; fv->eLineEnd = Line_LineHead; + fv->log_code = 0; // UTF-8 ret = LogStart(fname); if (ret == FALSE) { @@ -1322,6 +1326,16 @@ return LogVar != NULL; } +BOOL FLogIsOpendText(void) +{ + return LogVar != NULL && FileLog; +} + +BOOL FLogIsOpendBin(void) +{ + return LogVar != NULL && BinLog; +} + void FLogWriteStr(const char *str) { if (LogVar != NULL) @@ -1540,3 +1554,90 @@ cv.BinBuf = NULL; } } + +void FLogPutUTF32(unsigned int u32) +{ + PFileVar fv = LogVar; + size_t i; + BOOL log_available = (cv.HLogBuf != 0); + + if (!log_available) { + // \x83\x8D\x83O\x82ɂ͏o\x97͂\xB5\x82Ȃ\xA2(macro\x8Fo\x97͂\xBE\x82\xAF\x82\xBE\x82\xC1\x82\xBD) + return; + } + + switch(fv->log_code) { + case 0: { + // UTF-8 + char u8_buf[4]; + size_t u8_len = UTF32ToUTF8(u32, u8_buf, _countof(u8_buf)); + for (i = 0; i < u8_len; i++) { + BYTE b = u8_buf[i]; + LogPut1(b); + } + break; + } + case 1: + case 2: { + // UTF-16 + wchar_t u16[2]; + size_t u16_len = UTF32ToUTF16(u32, u16, _countof(u16)); + size_t i; + for (i = 0; i < u16_len; i++) { + if (fv->log_code == 1) { + // UTF-16LE + LogPut1(u16[i] & 0xff); + LogPut1((u16[i] >> 8) & 0xff); + } + else { + // UTF-16BE + LogPut1((u16[i] >> 8) & 0xff); + LogPut1(u16[i] & 0xff); + } + } + } + } +} + +void FLogOutputBOM(void) +{ + PFileVar fv = LogVar; + BOOL needs_unlock = FALSE; + + if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL)) { + cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf); + needs_unlock = TRUE; + } + + switch(fv->log_code) { + case 0: + // UTF-8 + LogPut1(0xef); + LogPut1(0xbb); + LogPut1(0xbf); + break; + case 1: + // UTF-16LE + LogPut1(0xfe); + LogPut1(0xff); + break; + case 2: + // UTF-16BE + LogPut1(0xff); + LogPut1(0xfe); + break; + default: + break; + } + + if (needs_unlock) { + GlobalUnlock(cv.HLogBuf); + cv.LogBuf = NULL; + } +} + +void FLogSetCode(int code) +{ + PFileVar fv = LogVar; + fv->log_code = code; +} Modified: branches/filesys_log/teraterm/teraterm/filesys_log.h =================================================================== --- branches/filesys_log/teraterm/teraterm/filesys_log.h 2020-08-05 15:06:29 UTC (rev 8879) +++ branches/filesys_log/teraterm/teraterm/filesys_log.h 2020-08-05 15:06:37 UTC (rev 8880) @@ -33,8 +33,6 @@ extern "C" { #endif -//extern BOOL FileLog, BinLog; - // log typedef struct { wchar_t *filename; // [in] \x83t\x83@\x83C\x83\x8B\x96\xBC\x8F\x89\x8A\xFA\x92l(NULL=default) [out] \x93\xFC\x97̓t\x83@\x83C\x83\x8B\x96\xBC\x81Afree()\x82\xB7\x82邱\x82\xC6 @@ -43,7 +41,6 @@ int code; // 0/1/2 = UTF-8/UTF-16LE/UTF-16BE } FLogDlgInfo_t; void logfile_lock_initialize(void); -void LogPut1(BYTE b); void FLogPause(BOOL Pause); void FLogRotateSize(size_t size); void FLogRotateRotate(int step); @@ -52,6 +49,8 @@ void FLogClose(void); BOOL FLogOpen(const wchar_t *fname); BOOL FLogIsOpend(void); +BOOL FLogIsOpendText(void); +BOOL FLogIsOpendBin(void); void FLogWriteStr(const char *str); void FLogInfo(char *param_ptr, size_t param_len); const wchar_t *FLogGetFilename(void); @@ -62,6 +61,10 @@ void FLogShowDlg(void); int FLogGetCount(void); void FLogWriteFile(void); +void FLogPutUTF32(unsigned int u32); +void FLogSetCode(int code); +void FLogOutputBOM(void); +//void LogPut1(BYTE b); #ifdef __cplusplus } Modified: branches/filesys_log/teraterm/teraterm/vtterm.c =================================================================== --- branches/filesys_log/teraterm/teraterm/vtterm.c 2020-08-05 15:06:29 UTC (rev 8879) +++ branches/filesys_log/teraterm/teraterm/vtterm.c 2020-08-05 15:06:37 UTC (rev 8880) @@ -58,6 +58,7 @@ #include "codeconv.h" #include "unicode.h" #include "ttdde.h" +#include "checkeol.h" #include "vtterm.h" @@ -215,8 +216,7 @@ static _locale_t CLocale = NULL; typedef struct { - BOOL log_cr_hold; - int log_code; + CheckEOLData_t *eol; int log_cr_type; } vtterm_work_t; @@ -362,8 +362,7 @@ { vtterm_work_t *vtterm = &vtterm_work; - vtterm->log_cr_hold = FALSE; - vtterm->log_code = 0; + vtterm->eol = CheckEOLCreate(); vtterm->log_cr_type = 0; } } @@ -452,119 +451,43 @@ MoveCursor(MainX, MainY); // move to main screen } -/* - * \x83\x8D\x83O\x82\xC91\x83L\x83\x83\x83\x89\x83N\x83^(BYTE)\x8Fo\x97\xCD - */ -static void Log1Char(vtterm_work_t *vtterm, char c) -{ - switch (vtterm->log_code) { - case 0: - default: - // UTF-8 - LogPut1(c); - break; - case 1: - // UTF-16LE - LogPut1(c); - LogPut1(0); - break; - case 2: - // UTF-16LE - LogPut1(0); - LogPut1(c); - break; - } -} - /** - * 1\x83L\x83\x83\x83\x89\x83N\x83^(unsigned int, char32_t)\x82\xF0\x83\x8D\x83O(or/and macro\x91\x97\x90M\x83o\x83b\x83t\x83@)\x82֏o\x97\xCD - * New Line \x88ȊO + * 1\x83L\x83\x83\x83\x89\x83N\x83^(unsigned int, char32_t)\x82\xF0macro\x82֏o\x97\xCD */ -static void OutputLogUTF32WONL(vtterm_work_t *vtterm, unsigned int u32) +static void DDEPut1U32(unsigned int u32) { - size_t i; - BOOL log_available = (cv.HLogBuf != 0); - - if (!DDELog && !log_available) { - // \x83\x8D\x83O\x82ɂ\xE0 macro \x82ɂ\xE0\x8Fo\x97͕s\x97v - return; - } - - // UTF-8 \x82ŏo\x97͂\xB7\x82\xE9 Log or/and macro - if (DDELog || (log_available && vtterm->log_code == 0)) { + if (DDELog) { + // UTF-8 \x82ŏo\x97͂\xB7\x82\xE9 char u8_buf[4]; size_t u8_len = UTF32ToUTF8(u32, u8_buf, _countof(u8_buf)); + size_t i; for (i = 0; i < u8_len; i++) { BYTE b = u8_buf[i]; - if (DDELog) - DDEPut1(b); - if (log_available && vtterm->log_code == 0) - LogPut1(b); + DDEPut1(b); } } - - if (!log_available) { - // \x83\x8D\x83O\x82ɂ͏o\x97͂\xB5\x82Ȃ\xA2(macro\x8Fo\x97͂\xBE\x82\xAF\x82\xBE\x82\xC1\x82\xBD) - return; - } - - switch(vtterm->log_code) { - case 0: { - // UTF-8, \x8Fo\x97͍ς\xDD - break; - } - case 1: - case 2: { - // UTF-16 - wchar_t u16[2]; - size_t u16_len = UTF32ToUTF16(u32, u16, _countof(u16)); - size_t i; - for (i = 0; i < u16_len; i++) { - if (vtterm->log_code == 1) { - // UTF-16LE - LogPut1(u16[i] & 0xff); - LogPut1((u16[i] >> 8) & 0xff); - } - else { - // UTF-16BE - LogPut1(u16[i] & 0xff); - LogPut1((u16[i] >> 8) & 0xff); - } - } - } - } } /** - * \x89\xFC\x8Ds\x82\xF0\x83\x8D\x83O(or/and macro\x91\x97\x90M\x83o\x83b\x83t\x83@)\x82֏o\x97\xCD - * \x83\x8D\x83O\x82ɂ͐ݒ肳\x82ꂽ\x89\xFC\x8Ds\x83R\x81[\x83h\x82\xF0\x8Fo\x97\xCD - * macro\x97p\x82ɂ\xCD CR+LF \x82\xF0\x8Fo\x97\xCD + * \x83\x8D\x83O\x82ݒ肳\x82ꂽ\x89\xFC\x8Ds\x83R\x81[\x83h\x82\xF0\x8Fo\x97\xCD */ static void OutputLogNewLine(vtterm_work_t *vtterm) { - // \x83\x8D\x83O\x8Fo\x97\xCD - if (cv.HLogBuf != 0) { - // \x83\x8D\x83O\x82͎\xE6\x82\xC1\x82Ă\xA2\x82\xE9 - switch(vtterm->log_cr_type) { - case 0: - // CR + LF - Log1Char(vtterm, CR); - Log1Char(vtterm, LF); - break; - case 1: - // CR - Log1Char(vtterm, CR); - break; - case 2: - // LF - Log1Char(vtterm, LF); - break; - } + switch(vtterm->log_cr_type) { + case 0: + // CR + LF + FLogPutUTF32(CR); + FLogPutUTF32(LF); + break; + case 1: + // CR + FLogPutUTF32(CR); + break; + case 2: + // LF + FLogPutUTF32(LF); + break; } - - // \x83}\x83N\x83\x8D\x8Fo\x97\xCD - DDEPut1(CR); - DDEPut1(LF); } /** @@ -572,50 +495,35 @@ */ static void OutputLogUTF32(unsigned int u32) { + if (!FLogIsOpend() && !DDELog) { + return; + } vtterm_work_t *vtterm = &vtterm_work; - // \x93\xFC\x97͂\xAA\x89\xFC\x8Ds(CR or LF)\x82̏ꍇ\x81A - // \x89\xFC\x8Ds\x82̎\xED\x97\xDE(CR or LF or CR+LF)\x82\xF0\x8E\xA9\x93\xAE\x82Ŕ\xBB\x92肵\x82\xC4 - // OutputLogNewLine() \x82ʼn\xFC\x8Ds\x82\xF0\x8Fo\x97͂\xB7\x82\xE9 - // \x93\xFC\x97\xCD CR hold \x89\xFC\x8Ds\x8Fo\x97\xCD CR hold \x95ύX - // +-------+-----------+-----------+------------ - // CR \x82Ȃ\xB5 \x82\xB5\x82Ȃ\xA2 \x83Z\x83b\x83g\x82\xB7\x82\xE9 - // LF \x82Ȃ\xB5 \x82\xB7\x82\xE9 \x95ω\xBB\x82Ȃ\xB5 - // \x82\xBB\x82̑\xBC \x82Ȃ\xB5 \x82\xB5\x82Ȃ\xA2 \x95ω\xBB\x82Ȃ\xB5 - // CR \x82\xA0\x82\xE8 \x82\xB7\x82\xE9 \x95ω\xBB\x82Ȃ\xB5(\x83z\x81[\x83\x8B\x83h\x82\xB5\x82\xBD\x82܂\xDC) - // LF \x82\xA0\x82\xE8 \x82\xB7\x82\xE9 \x83N\x83\x8A\x83A\x82\xB7\x82\xE9 - // \x82\xBB\x82̑\xBC \x82\xA0\x82\xE8 \x82\xB7\x82\xE9 \x83N\x83\x8A\x83A\x82\xB7\x82\xE9 - if (vtterm->log_cr_hold == FALSE) { - if (u32 == CR) { - vtterm->log_cr_hold = TRUE; - return; - } - else if (u32 == LF) { + CheckEOLRet r = CheckEOLCheck(vtterm->eol, u32); + if ((r & CheckEOLOutputEOL) != 0) { + // \x83\x8D\x83O\x81A\x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD + if (FLogIsOpend()) { OutputLogNewLine(vtterm); - return; } - else { - // \x89\xFC\x8Ds\x93\xC1\x82ɂȂ\xB5 + + // \x83}\x83N\x83\x8D\x81A\x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD + if (DDELog) { + DDEPut1(CR); + DDEPut1(LF); } } - else { - if (u32 == CR) { - OutputLogNewLine(vtterm); - return; + if ((r & CheckEOLOutputChar) != 0) { + // \x83\x8D\x83O\x81Au32\x82\xF0\x8Fo\x97\xCD + if (FLogIsOpend()) { + FLogPutUTF32(u32); } - else if (u32 == LF) { - vtterm->log_cr_hold = FALSE; - OutputLogNewLine(vtterm); - return; + + // \x83}\x83N\x83\x8D\x81Au32\x82\xF0\x8Fo\x97\xCD + if (DDELog) { + DDEPut1U32(u32); } - else { - vtterm->log_cr_hold = FALSE; - OutputLogNewLine(vtterm); - } } - - // \x89\xFC\x8Ds\x88ȊO\x82\xF0\x8Fo\x97\xCD - OutputLogUTF32WONL(vtterm, u32); } /** @@ -634,49 +542,6 @@ return cv.HLogBuf != 0 || DDELog; } -void TermLogSetCode(int code) -{ - vtterm_work_t *vtterm = &vtterm_work; - vtterm->log_code = code; -} - -void TermLogOutputBOM(void) -{ - vtterm_work_t *vtterm = &vtterm_work; - BOOL needs_unlock = FALSE; - - if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL)) { - cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf); - needs_unlock = TRUE; - } - - switch (vtterm->log_code) { - case 0: - // UTF-8 - LogPut1(0xef); - LogPut1(0xbb); - LogPut1(0xbf); - break; - case 1: - // UTF-16LE - LogPut1(0xfe); - LogPut1(0xff); - break; - case 2: - // UTF-16BE - LogPut1(0xff); - LogPut1(0xfe); - break; - default: - break; - } - - if (needs_unlock) { - GlobalUnlock(cv.HLogBuf); - cv.LogBuf = NULL; - } -} - void MoveToStatusLine() { MainX = CursorX; Modified: branches/filesys_log/teraterm/teraterm/vtterm.h =================================================================== --- branches/filesys_log/teraterm/teraterm/vtterm.h 2020-08-05 15:06:29 UTC (rev 8879) +++ branches/filesys_log/teraterm/teraterm/vtterm.h 2020-08-05 15:06:37 UTC (rev 8880) @@ -49,8 +49,6 @@ void TermPasteString(char *str, int len); void TermSendStartBracket(void); void TermSendEndBracket(void); -void TermLogSetCode(int code); -void TermLogOutputBOM(void); #ifdef __cplusplus } Modified: branches/filesys_log/teraterm/teraterm/vtwin.cpp =================================================================== --- branches/filesys_log/teraterm/teraterm/vtwin.cpp 2020-08-05 15:06:29 UTC (rev 8879) +++ branches/filesys_log/teraterm/teraterm/vtwin.cpp 2020-08-05 15:06:37 UTC (rev 8880) @@ -4135,11 +4135,13 @@ // \x83t\x83@\x83C\x83\x8B\x8D폜 _DeleteFileW(filename); } - TermLogSetCode(info.code); BOOL r = FLogOpen(filename); if (r != FALSE) { - if (info.bom) { - TermLogOutputBOM(); + if (FLogIsOpendText()) { + FLogSetCode(info.code); + if (info.bom) { + FLogOutputBOM(); + } } } else {