Revision: 8861 https://osdn.net/projects/ttssh2/scm/svn/commits/8861 Author: zmatsuo Date: 2020-07-26 01:00:36 +0900 (Sun, 26 Jul 2020) Log Message: ----------- ログ/マクロ送信を別の文字コードで行えるようにした - マクロ送信は常に UTF-8 Modified Paths: -------------- trunk/teraterm/teraterm/vtterm.c -------------- next part -------------- Modified: trunk/teraterm/teraterm/vtterm.c =================================================================== --- trunk/teraterm/teraterm/vtterm.c 2020-07-25 16:00:24 UTC (rev 8860) +++ trunk/teraterm/teraterm/vtterm.c 2020-07-25 16:00:36 UTC (rev 8861) @@ -452,24 +452,65 @@ MoveCursor(MainX, MainY); // move to main screen } -static void Log1Byte(BYTE b) +/* + * \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) { - LogPut1(b); - DDEPut1(b); + 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; + } } -static void Log1UTF32(vtterm_work_t *vtterm, unsigned int u32) +/** + * 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 + */ +static void OutputLogUTF32WONL(vtterm_work_t *vtterm, 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)) { + 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]; + if (DDELog) + DDEPut1(b); + if (log_available && vtterm->log_code == 0) + LogPut1(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) { - default: case 0: { - // UTF-8 - char u8[4]; - size_t u8_len = UTF32ToUTF8(u32, u8, _countof(u8)); - size_t i; - for (i = 0; i < u8_len; i++) { - Log1Byte(u8[i]); - } + // UTF-8, \x8Fo\x97͍ς\xDD break; } case 1: @@ -481,13 +522,13 @@ for (i = 0; i < u16_len; i++) { if (vtterm->log_code == 1) { // UTF-16LE - Log1Byte(u16[i] & 0xff); - Log1Byte((u16[i] >> 8) & 0xff); + LogPut1(u16[i] & 0xff); + LogPut1((u16[i] >> 8) & 0xff); } else { // UTF-16BE - Log1Byte(u16[i] & 0xff); - Log1Byte((u16[i] >> 8) & 0xff); + LogPut1(u16[i] & 0xff); + LogPut1((u16[i] >> 8) & 0xff); } } } @@ -494,43 +535,56 @@ } } -static void Log1NewLine(vtterm_work_t *vtterm) +/** + * \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 + */ +static void OutputLogNewLine(vtterm_work_t *vtterm) { - switch(vtterm->log_cr_type) { - case 0: - // CR + LF - Log1UTF32(vtterm, CR); - Log1UTF32(vtterm, LF); - break; - case 1: - // CR - Log1UTF32(vtterm, CR); - break; - case 2: - // LF - Log1UTF32(vtterm, LF); - break; + // \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; + } } + + // \x83}\x83N\x83\x8D\x8Fo\x97\xCD + DDEPut1(CR); + DDEPut1(LF); } +/** + * 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 + */ static void OutputLogUTF32(unsigned int u32) { vtterm_work_t *vtterm = &vtterm_work; - if (cv.HLogBuf == 0) { - // \x83\x8D\x83O\x82͎\xE6\x82\xC1\x82Ă\xA2\x82Ȃ\xA2, \x89\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2 - return; - } - - // \x89\xFC\x8Ds\x83R\x81[\x83h\x82\xF0\x83`\x83F\x83b\x83N - // CR hold \x93\xFC\x97\xCD \x89\xFC\x8Ds\x8Fo\x97\xCD CR hold \x95ύX - // ------------+-------+-----------+------------ - // \x82Ȃ\xB5 CR 0 \x83Z\x83b\x83g\x82\xB7\x82\xE9 - // \x82Ȃ\xB5 LF 1 \x95ω\xBB\x82Ȃ\xB5 - // \x82Ȃ\xB5 \x82\xBB\x82̑\xBC 0 \x95ω\xBB\x82Ȃ\xB5 - // \x82\xA0\x82\xE8 CR 1 \x95ω\xBB\x82Ȃ\xB5(\x83z\x81[\x83\x8B\x83h\x82\xB5\x82\xBD\x82܂\xDC) - // \x82\xA0\x82\xE8 LF 1 \x83N\x83\x8A\x83A\x82\xB7\x82\xE9 - // \x82\xA0\x82\xE8 \x82\xBB\x82̑\xBC 1 \x83N\x83\x8A\x83A\x82\xB7\x82\xE9 + // \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; @@ -537,7 +591,7 @@ return; } else if (u32 == LF) { - Log1NewLine(vtterm); + OutputLogNewLine(vtterm); return; } else { @@ -546,30 +600,40 @@ } else { if (u32 == CR) { - Log1NewLine(vtterm); + OutputLogNewLine(vtterm); return; } else if (u32 == LF) { vtterm->log_cr_hold = FALSE; - Log1NewLine(vtterm); + OutputLogNewLine(vtterm); return; } else { vtterm->log_cr_hold = FALSE; - Log1NewLine(vtterm); + OutputLogNewLine(vtterm); } } - Log1UTF32(vtterm, u32); + // \x89\xFC\x8Ds\x88ȊO\x82\xF0\x8Fo\x97\xCD + OutputLogUTF32WONL(vtterm, u32); } +/** + * 1\x83L\x83\x83\x83\x89\x83N\x83^(BYTE)\x82\xF0\x83\x8D\x83O(or/and macro\x91\x97\x90M\x83o\x83b\x83t\x83@)\x82֏o\x97\xCD + */ static void OutputLogByte(BYTE b) { - if (cv.HLogBuf!=0) { - OutputLogUTF32(b); - } + OutputLogUTF32(b); } +/** + * \x83\x8D\x83O(or/and Macro\x91\x97\x90M\x83o\x83b\x83t\x83@)\x8Fo\x97͂̕K\x97v\x82\xAA\x82\xA0\x82邩? + */ +static BOOL NeedsOutputBufs(void) +{ + return cv.HLogBuf != 0 || DDELog; +} + void MoveToStatusLine() { MainX = CursorX; @@ -689,12 +753,12 @@ if (CursorX == CursorLeftM || CursorX == 0) { if (CursorY > 0 && (ts.TermFlag & TF_BACKWRAP)) { MoveCursor(CursorRightM, CursorY-1); - if (cv.HLogBuf!=0 && !ts.LogTypePlainText) OutputLogByte(BS); + if (NeedsOutputBufs() && !ts.LogTypePlainText) OutputLogByte(BS); } } else if (CursorX > 0) { MoveCursor(CursorX-1, CursorY); - if (cv.HLogBuf!=0 && !ts.LogTypePlainText) OutputLogByte(BS); + if (NeedsOutputBufs() && !ts.LogTypePlainText) OutputLogByte(BS); } } @@ -701,7 +765,7 @@ static void CarriageReturn(BOOL logFlag) { if (!ts.EnableContinuedLineCopy || logFlag) - if (cv.HLogBuf!=0) OutputLogByte(CR); + if (NeedsOutputBufs()) OutputLogByte(CR); if (RelativeOrgMode || CursorX > CursorLeftM) MoveCursor(CursorLeftM, CursorY); @@ -719,7 +783,7 @@ BuffDumpCurrentLine(b); if (!ts.EnableContinuedLineCopy || logFlag) - if (cv.HLogBuf!=0) OutputLogByte(LF); + if (NeedsOutputBufs()) OutputLogByte(LF); if (CursorY < CursorBottom) MoveCursor(CursorX,CursorY+1); @@ -745,7 +809,7 @@ Wrap = FALSE; } CursorForwardTab(1, AutoWrapMode); - if (cv.HLogBuf!=0) OutputLogByte(HT); + if (NeedsOutputBufs()) OutputLogByte(HT); } void RepeatChar(BYTE b, int count) @@ -840,7 +904,7 @@ #endif } - if (cv.HLogBuf !=0) { + if (NeedsOutputBufs()) { // (2005.2.20 yutaka) if (ts.LogTypePlainText) { if (__isascii(b) && !isprint(b)) { @@ -942,12 +1006,12 @@ CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0; } - if (cv.HLogBuf!=0) OutputLogByte(b); + if (NeedsOutputBufs()) OutputLogByte(b); /* if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) { // ASCII\x95\xB6\x8E\x9A\x82ŁA\x94\xF1\x95\\x8E\xA6\x82ȕ\xB6\x8E\x9A\x82̓\x8D\x83O\x8D̎悵\x82Ȃ\xA2\x81B } else { - if (cv.HLogBuf!=0) OutputLogByte(b); + if (NeedsOutputBufs()) OutputLogByte(b); } */ @@ -1037,7 +1101,7 @@ Wrap = FALSE; - if (cv.HLogBuf!=0) { + if (NeedsOutputBufs()) { OutputLogByte(HIBYTE(Kanji)); OutputLogByte(LOBYTE(Kanji)); }