Revision: 9115 https://osdn.net/projects/ttssh2/scm/svn/commits/9115 Author: zmatsuo Date: 2020-12-28 23:29:48 +0900 (Mon, 28 Dec 2020) Log Message: ----------- エスケープシーケンスからの印字を修正 - 内部は Unicode に対応した - CP_ACP に変換して出力 Modified Paths: -------------- trunk/teraterm/common/codeconv.cpp trunk/teraterm/teraterm/buffer.c trunk/teraterm/teraterm/buffer.h trunk/teraterm/teraterm/teraprn.cpp trunk/teraterm/teraterm/teraprn.h trunk/teraterm/teraterm/vtterm.c trunk/teraterm/teraterm/vtwin.cpp Added Paths: ----------- trunk/teraterm/teraterm/teraprnfile.h -------------- next part -------------- Modified: trunk/teraterm/common/codeconv.cpp =================================================================== --- trunk/teraterm/common/codeconv.cpp 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/common/codeconv.cpp 2020-12-28 14:29:48 UTC (rev 9115) @@ -589,7 +589,7 @@ * @param[in] u32 \x95ϊ\xB7\x8C\xB3UTF-32 * @param[in] code_page \x95ϊ\xB7\x90\xE6codepage * @param[in,out] mb_ptr \x95ϊ\xB7\x90敶\x8E\x9A\x97\xF1\x8Fo\x97͐\xE6(NULL\x82̂Ƃ\xAB\x8Fo\x97͂\xB5\x82Ȃ\xA2) - * @param[in] mb_len CP932\x8Fo\x97͐敶\x8E\x9A\x90\x94(\x95\xB6\x8E\x9A\x90\x94,sizeof(wchar_t)*wstr_len bytes) + * @param[in] mb_len \x95ϊ\xB7\x90\xE6\x8Fo\x97͐敶\x8E\x9A\x90\x94(\x95\xB6\x8E\x9A\x90\x94,mb_len bytes) * @retval \x8Fo\x97͂\xB5\x82\xBDmultibyte\x95\xB6\x8E\x9A\x90\x94(byte\x90\x94) * 0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD) */ Modified: trunk/teraterm/teraterm/buffer.c =================================================================== --- trunk/teraterm/teraterm/buffer.c 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/teraterm/buffer.c 2020-12-28 14:29:48 UTC (rev 9115) @@ -2106,7 +2106,7 @@ // HFile: file handle // TERM: terminator character // = LF or VT or FF -void BuffDumpCurrentLine(BYTE TERM) +void BuffDumpCurrentLine(PrintFile *handle, BYTE TERM) { int i, j; buff_char_t *b = &CodeBuffW[LinePtr]; @@ -2127,12 +2127,12 @@ } p = bufA; for (j=0; j<i; j++) { - WriteToPrnFile(bufA[j],FALSE); + WriteToPrnFile(handle, bufA[j],FALSE); } - WriteToPrnFile(0,TRUE); + WriteToPrnFile(handle, 0,TRUE); if ((TERM>=LF) && (TERM<=FF)) { - WriteToPrnFile(0x0d,FALSE); - WriteToPrnFile(TERM,TRUE); + WriteToPrnFile(handle, 0x0d,FALSE); + WriteToPrnFile(handle, TERM,TRUE); } } Modified: trunk/teraterm/teraterm/buffer.h =================================================================== --- trunk/teraterm/teraterm/buffer.h 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/teraterm/buffer.h 2020-12-28 14:29:48 UTC (rev 9115) @@ -31,6 +31,8 @@ #pragma once +#include "teraprnfile.h" + #ifdef __cplusplus extern "C" { #endif @@ -100,7 +102,7 @@ void BuffChangeAttrStream(int XStart, int YStart, int XEnd, int YEnd, PCharAttr attr, PCharAttr mask); wchar_t *BuffCBCopyUnicode(BOOL Table); void BuffPrint(BOOL ScrollRegion); -void BuffDumpCurrentLine(BYTE TERM); +void BuffDumpCurrentLine(PrintFile *handle, BYTE TERM); void BuffPutChar(BYTE b, TCharAttr Attr, BOOL Insert); void BuffPutKanji(WORD w, TCharAttr Attr, BOOL Insert); int BuffPutUnicode(unsigned int uc, TCharAttr Attr, BOOL Insert); Modified: trunk/teraterm/teraterm/teraprn.cpp =================================================================== --- trunk/teraterm/teraterm/teraprn.cpp 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/teraterm/teraprn.cpp 2020-12-28 14:29:48 UTC (rev 9115) @@ -32,6 +32,8 @@ #include "tttypes.h" #include <commdlg.h> #include <stdio.h> +#define _CRTDBG_MAP_ALLOC +#include <stdlib.h> #include <crtdbg.h> #include "ttwinman.h" @@ -38,6 +40,7 @@ #include "commlib.h" #include "ttcommon.h" #include "ttlib.h" +#include "codeconv.h" #include "vtdisp.h" #include "tt_res.h" @@ -63,12 +66,6 @@ static BOOL Printing = FALSE; static BOOL PrintAbortFlag = FALSE; -/* pass-thru printing */ -static wchar_t PrnFName[MAX_PATH]; -static HANDLE HPrnFile = INVALID_HANDLE_VALUE; -static char PrnBuff[TermWidthMax]; -static int PrnBuffCount = 0; - static CPrnAbortDlg *PrnAbortDlg; static HWND HPrnAbortDlg; @@ -433,64 +430,94 @@ return; } +/* pass-thru printing */ +typedef struct PrintFileTag { + wchar_t *PrnFName; + HANDLE HPrnFile; + unsigned int PrnBuff[TermWidthMax*2]; + int PrnBuffCount; + void (*FinishCallback)(PrintFile *handle); +} PrintFile; + /* printer emulation routines */ -void OpenPrnFile() +PrintFile *OpenPrnFile(void) { + PrintFile *p = (PrintFile *)calloc(sizeof(PrintFile),1 ); + if (p == NULL) { + return NULL; + } + KillTimer(HVTWin, IdPrnStartTimer); - if (HPrnFile != INVALID_HANDLE_VALUE) { - return; + + wchar_t TempPath[MAX_PATH]; + GetTempPathW(_countof(TempPath), TempPath); + wchar_t Temp[MAX_PATH]; + if (GetTempFileNameW(TempPath, L"tmp", 0, Temp) == 0) { + free(p); + return NULL; } - if (PrnFName[0] == 0) { - wchar_t Temp[MAX_PATH]; - GetTempPathW(_countof(Temp), Temp); - if (GetTempFileNameW(Temp, L"tmp", 0, PrnFName) == 0) { - return; - } - HPrnFile = - CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + p->PrnFName = _wcsdup(Temp); + + HANDLE h = CreateFileW(p->PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + free(p); + return NULL; } - else { - HPrnFile = - CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (HPrnFile == INVALID_HANDLE_VALUE) { - HPrnFile = CreateFileW(PrnFName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, NULL); - } + SetFilePointer(h, 0, NULL, FILE_END); + p->HPrnFile = h; + + return p; +} + +static void DeletePrintFile(PrintFile *handle) +{ + if (handle->PrnFName == NULL) { + return; } - if (HPrnFile != INVALID_HANDLE_VALUE) { - SetFilePointer(HPrnFile, 0, NULL, FILE_END); - } + DeleteFileW(handle->PrnFName); + free(handle->PrnFName); + handle->PrnFName = NULL; } -static void PrintFile(void) +void PrnFinish(PrintFile *handle) { - char Buff[256]; - BOOL CRFlag = FALSE; - int c, i; - BYTE b; + DeletePrintFile(handle); + free(handle); +} +/** + * \x88p\x82ɕۑ\xB6\x82\xB5\x82Ă\xA2\x82\xBD\x83t\x83@\x83C\x83\x8B\x82\xA9\x82\xE7\x88\xB7\x82\xE9 + */ +static void PrintFile_(PrintFile *handle) +{ if (VTPrintInit(IdPrnFile)==IdPrnFile) { - HPrnFile = CreateFileW(PrnFName, - GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE HPrnFile = CreateFileW(handle->PrnFName, + GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (HPrnFile != INVALID_HANDLE_VALUE) { + char BuffA[TermWidthMax]; + size_t len_a; + wchar_t BuffW[TermWidthMax]; + size_t len_w; + BOOL CRFlag = FALSE; + int c; + unsigned int u32; do { - i = 0; + len_a = 0; + len_w = 0; do { DWORD NumberOfBytesRead; - BOOL r = ReadFile(HPrnFile, &b, 1, &NumberOfBytesRead, NULL); - c = 0; - if (r) { - c = NumberOfBytesRead; + BOOL r = ReadFile(HPrnFile, &u32, sizeof(u32), &NumberOfBytesRead, NULL); + if (r == TRUE && NumberOfBytesRead != 0) { + // \x88p\x91\xB1 + c = 1; } + else { + c = 0; + } if (c == 1) { - switch (b) { - case HT: - memset(&(Buff[i]),0x20,8); - i = i + 8; - CRFlag = FALSE; - break; + switch (u32) { case LF: CRFlag = ! CRFlag; break; @@ -498,25 +525,36 @@ case CR: CRFlag = TRUE; break; +#if 0 + case HT: + memset(&(Buff[i]),0x20,8); + i = i + 8; + CRFlag = FALSE; + break; +#endif default: - if (b >= 0x20) { - Buff[i] = b; - i++; + if (u32 >= 0x20) { + int codepage = CP_ACP; // \x88\xF3\x8D\xFC\x97p\x83R\x81[\x83h\x83y\x81[\x83W + size_t out_len = UTF32ToUTF16(u32, &BuffW[len_w], _countof(BuffW) - len_w); + len_w += out_len; + out_len = UTF32ToMBCP(u32, codepage, &BuffA[len_a], _countof(BuffA) - len_a); + len_a += out_len; } CRFlag = FALSE; break; } } - if (i>=(sizeof(Buff)-7)) { + if (len_w >= (_countof(BuffW)-7)) { CRFlag=TRUE; } } while ((c>0) && (! CRFlag)); - if (i>0) { - PrnOutText(Buff, i, NULL); + if (len_a >0) { + PrnOutText(BuffA, len_a, NULL); + //PrnOutTextW(BuffW, NULL, len_w, NULL); } if (CRFlag) { PrnX = Margin.left; - if ((b==FF) && (ts.PrnConvFF==0)) { // new page + if ((u32==FF) && (ts.PrnConvFF==0)) { // new page PrnY = Margin.bottom; } else { // new line @@ -523,7 +561,7 @@ PrnY = PrnY + PrnFH; } } - CRFlag = (b==CR); + CRFlag = (u32==CR); } while (c>0); CloseHandle(HPrnFile); } @@ -530,18 +568,16 @@ HPrnFile = INVALID_HANDLE_VALUE; VTPrintEnd(); } - DeleteFileW(PrnFName); - PrnFName[0] = 0; + handle->FinishCallback(handle); } -static void PrintFileDirect(void) +static void PrintFileDirect(PrintFile *handle) { HWND hParent; PrnAbortDlg = new CPrnAbortDlg(); if (PrnAbortDlg==NULL) { - DeleteFileW(PrnFName); - PrnFName[0] = 0; + DeletePrintFile(handle); return; } if (ActiveWin==IdVT) { @@ -553,18 +589,17 @@ PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts); HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd(); - HPrnFile = CreateFileW(PrnFName, - GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - PrintAbortFlag = (HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev); - PrnBuffCount = 0; + handle->HPrnFile = CreateFileW(handle->PrnFName, + GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + PrintAbortFlag = (handle->HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev); + handle->PrnBuffCount = 0; SetTimer(HVTWin,IdPrnProcTimer,0,NULL); } -void PrnFileDirectProc() +void PrnFileDirectProc(PrintFile *handle) { - int c; - + HANDLE HPrnFile = handle->HPrnFile; if (HPrnFile==INVALID_HANDLE_VALUE) { return; } @@ -574,26 +609,29 @@ PrnCancel(); } if (!PrintAbortFlag && (HPrnFile != INVALID_HANDLE_VALUE)) { + int c; do { - if (PrnBuffCount==0) { - PrnBuffCount = 0; + if (handle->PrnBuffCount==0) { + handle->PrnBuffCount = 0; DWORD NumberOfBytesRead; - BOOL r = ReadFile(HPrnFile, PrnBuff, 1, &NumberOfBytesRead, NULL); + BOOL r = ReadFile(HPrnFile, handle->PrnBuff, sizeof(handle->PrnBuff[0]), &NumberOfBytesRead, NULL); if (r) { - PrnBuffCount = NumberOfBytesRead; + handle->PrnBuffCount = NumberOfBytesRead; } - if (ts.Language==IdRussian) { - RussConvStr(ts.RussClient,ts.RussPrint,PrnBuff,PrnBuffCount); - } } - if (PrnBuffCount==1) { - c = PrnWrite(PrnBuff,1); + if (handle->PrnBuffCount != 0) { + // UTF-32 + unsigned int u32 = handle->PrnBuff[0]; + int codepage = CP_ACP; // \x88\xF3\x8D\xFC\x97p\x83R\x81[\x83h\x83y\x81[\x83W + char str[5]; + size_t out_len = UTF32ToMBCP(u32, codepage, str, _countof(str)); + c = PrnWrite(str, out_len); if (c==0) { SetTimer(HVTWin,IdPrnProcTimer,10,NULL); return; } - PrnBuffCount = 0; + handle->PrnBuffCount = 0; } else { c = 0; @@ -600,64 +638,79 @@ } } while (c>0); } - if (HPrnFile != INVALID_HANDLE_VALUE) { - CloseHandle(HPrnFile); - } - HPrnFile = INVALID_HANDLE_VALUE; PrnClose(); - DeleteFileW(PrnFName); - PrnFName[0] = 0; + if (PrnAbortDlg!=NULL) { PrnAbortDlg->DestroyWindow(); PrnAbortDlg = NULL; HPrnAbortDlg = NULL; } + + handle->FinishCallback(handle); } -void PrnFileStart() +/** + * \x83^\x83C\x83}\x81[\x8E\x9E\x8AԂ\xAA\x8Co\x89߁A\x88\xF0\x8AJ\x8En\x82\xB7\x82\xE9 + * ClosePrnFile() \x82\xCC SetTimer(IdPrnStartTimer) \x82\xAA\x83g\x83\x8A\x83K + */ +void PrnFileStart(PrintFile *handle) { - if (HPrnFile != INVALID_HANDLE_VALUE) { + if (handle->HPrnFile != INVALID_HANDLE_VALUE) { return; } - if (PrnFName[0]==0) { + if (handle->PrnFName == NULL) { return; } if (ts.PrnDev[0]!=0) { - PrintFileDirect(); // send file directry to printer port + PrintFileDirect(handle); // send file directry to printer port } else { // print file by using Windows API - PrintFile(); + PrintFile_(handle); } } -void ClosePrnFile() +/** + * \x83v\x83\x8A\x83\x93\x83g\x97p\x83t\x83@\x83C\x83\x8B\x82̏\x91\x82\xAB\x8D\x9E\x82݂\xF0\x8FI\x97\xB9 + * \x83v\x83\x8A\x83\x93\x83g\x82\xF0\x8AJ\x8En\x83^\x83C\x83}\x81[\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9 + */ +void ClosePrnFile(PrintFile *handle, void (*finish_callback)(PrintFile *handle)) { - PrnBuffCount = 0; - if (HPrnFile != INVALID_HANDLE_VALUE) { - CloseHandle(HPrnFile); + PrintFile *p = handle; + p->PrnBuffCount = 0; + p->FinishCallback = finish_callback; + if (p->HPrnFile != INVALID_HANDLE_VALUE) { + CloseHandle(p->HPrnFile); + p->HPrnFile = INVALID_HANDLE_VALUE; } - HPrnFile = INVALID_HANDLE_VALUE; SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL); } -void WriteToPrnFile(BYTE b, BOOL Write) -// (b,Write) = -// (0,FALSE): clear buffer -// (0,TRUE): write buffer to file -// (b,FALSE): put b in buff -// (b,TRUE): put b in buff and -// write buffer to file +/** + * (b,Write) = + * (0,FALSE): clear buffer + * (0,TRUE): write buffer to file + * (b,FALSE): put b in buff + * (b,TRUE): put b in buff and + * write buffer to file + */ +void WriteToPrnFileUTF32(PrintFile *handle, unsigned int u32, BOOL Write) { - if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) { - PrnBuff[PrnBuffCount++] = b; + PrintFile *p = handle; + if ((u32 > 0) && p->PrnBuffCount < _countof(p->PrnBuff)) { + p->PrnBuff[p->PrnBuffCount++] = u32; } if (Write) { DWORD NumberOfBytesWritten; - WriteFile(HPrnFile, PrnBuff, PrnBuffCount, &NumberOfBytesWritten, NULL); - PrnBuffCount = 0; + WriteFile(p->HPrnFile, p->PrnBuff, sizeof(p->PrnBuff[0]) * p->PrnBuffCount, &NumberOfBytesWritten, NULL); + p->PrnBuffCount = 0; } - if ((b==0) && ! Write) { - PrnBuffCount = 0; + if ((u32 == 0) && !Write) { + p->PrnBuffCount = 0; } } + +void WriteToPrnFile(PrintFile *handle, BYTE b, BOOL Write) +{ + WriteToPrnFileUTF32(handle, b, Write); +} Modified: trunk/teraterm/teraterm/teraprn.h =================================================================== --- trunk/teraterm/teraterm/teraprn.h 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/teraterm/teraprn.h 2020-12-28 14:29:48 UTC (rev 9115) @@ -53,12 +53,6 @@ void PrnNewLine(); void VTPrintEnd(); -void PrnFileDirectProc(); -void PrnFileStart(); -void OpenPrnFile(); -void ClosePrnFile(); -void WriteToPrnFile(BYTE b, BOOL Write); - #ifdef __cplusplus } #endif Copied: trunk/teraterm/teraterm/teraprnfile.h (from rev 9107, trunk/teraterm/teraterm/teraprn.h) =================================================================== --- trunk/teraterm/teraterm/teraprnfile.h (rev 0) +++ trunk/teraterm/teraterm/teraprnfile.h 2020-12-28 14:29:48 UTC (rev 9115) @@ -0,0 +1,47 @@ +/* + * (C) 2020- TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PrintFileTag PrintFile; + +PrintFile *OpenPrnFile(void); +void PrnFileDirectProc(PrintFile *handle); +void PrnFileStart(PrintFile *handle); +void ClosePrnFile(PrintFile *handle, void (*finish_callback)(PrintFile *handle)); +void WriteToPrnFileUTF32(PrintFile *handle, unsigned int u32, BOOL Write); +void WriteToPrnFile(PrintFile *handle, BYTE b, BOOL Write); +void PrnFinish(PrintFile *handle); + +#ifdef __cplusplus +} +#endif Modified: trunk/teraterm/teraterm/vtterm.c =================================================================== --- trunk/teraterm/teraterm/vtterm.c 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/teraterm/vtterm.c 2020-12-28 14:29:48 UTC (rev 9115) @@ -191,6 +191,7 @@ static BOOL AutoPrintMode = FALSE; static BOOL PrinterMode = FALSE; static BOOL DirectPrn = FALSE; +PrintFile *PrintFile_; /* User key */ static BYTE NewKeyStr[FuncKeyStrMax]; @@ -491,6 +492,10 @@ /** * 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 + * \x8Fo\x97͐\xE6 + * \x83\x8D\x83O\x83t\x83@\x83C\x83\x8B + * macro\x91\x97\x90M\x83o\x83b\x83t\x83@(DDEPut1()) + * \x83v\x83\x8A\x83\x93\x83g\x97p */ static void OutputLogUTF32(unsigned int u32) { @@ -497,32 +502,50 @@ vtterm_work_t *vtterm; CheckEOLRet r; - if (!FLogIsOpendText() && !DDELog) { + if (!FLogIsOpendText() && !DDELog && !PrinterMode) { return; } vtterm = &vtterm_work; r = CheckEOLCheck(vtterm->check_eol, u32); - if ((r & CheckEOLOutputEOL) != 0) { - // \x83\x8D\x83O\x81A\x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD - if (FLogIsOpendText()) { + + // \x83\x8D\x83O + if (FLogIsOpendText()) { + if ((r & CheckEOLOutputEOL) != 0) { + // \x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD OutputLogNewLine(vtterm); } - // \x83}\x83N\x83\x8D\x81A\x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD - if (DDELog) { + if ((r & CheckEOLOutputChar) != 0) { + // u32\x82\xF0\x8Fo\x97\xCD + FLogPutUTF32(u32); + } + } + + // \x83}\x83N\x83\x8D\x8Fo\x97\xCD + if (DDELog) { + if ((r & CheckEOLOutputEOL) != 0) { + // \x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD DDEPut1(CR); DDEPut1(LF); } + + // u32\x82\xF0\x8Fo\x97\xCD + if ((r & CheckEOLOutputChar) != 0) { + DDEPut1U32(u32); + } } - if ((r & CheckEOLOutputChar) != 0) { - // \x83\x8D\x83O\x81Au32\x82\xF0\x8Fo\x97\xCD - if (FLogIsOpendText()) { - FLogPutUTF32(u32); + + // \x83v\x83\x8A\x83\x93\x83g + if (PrinterMode) { + if ((r & CheckEOLOutputEOL) != 0) { + // \x89\xFC\x8Ds\x82\xF0\x8Fo\x97\xCD + WriteToPrnFile(PrintFile_, CR,TRUE); + WriteToPrnFile(PrintFile_, LF,TRUE); } - // \x83}\x83N\x83\x8D\x81Au32\x82\xF0\x8Fo\x97\xCD - if (DDELog) { - DDEPut1U32(u32); + // u32\x82\xF0\x8Fo\x97\xCD + if ((r & CheckEOLOutputChar) != 0) { + WriteToPrnFileUTF32(PrintFile_, u32, TRUE); } } } @@ -689,7 +712,7 @@ /* for auto print mode */ if ((AutoPrintMode) && (b>=LF) && (b<=FF)) - BuffDumpCurrentLine(b); + BuffDumpCurrentLine(PrintFile_, b); if (!ts.EnableContinuedLineCopy || logFlag) if (NeedsOutputBufs()) OutputLogByte(LF); @@ -792,7 +815,7 @@ LastPutCharacter = b; if (PrinterMode) { // printer mode - WriteToPrnFile(b,TRUE); + WriteToPrnFile(PrintFile_, b,TRUE); return; } @@ -905,7 +928,7 @@ CharAttrTmp = CharAttr; if (PrinterMode) { // printer mode - WriteToPrnFile(b, TRUE); + WriteToPrnFile(PrintFile_, b, TRUE); return; } @@ -958,8 +981,8 @@ Kanji = Kanji + b; if (PrinterMode && DirectPrn) { - WriteToPrnFile(HIBYTE(Kanji),FALSE); - WriteToPrnFile(LOBYTE(Kanji),TRUE); + WriteToPrnFile(PrintFile_, HIBYTE(Kanji),FALSE); + WriteToPrnFile(PrintFile_, LOBYTE(Kanji),TRUE); return; } @@ -967,8 +990,8 @@ Kanji = JIS2SJIS((WORD)(Kanji & 0x7f7f)); if (PrinterMode) { // printer mode - WriteToPrnFile(HIBYTE(Kanji),FALSE); - WriteToPrnFile(LOBYTE(Kanji),TRUE); + WriteToPrnFile(PrintFile_, HIBYTE(Kanji),FALSE); + WriteToPrnFile(PrintFile_, LOBYTE(Kanji),TRUE); return; } @@ -1169,7 +1192,7 @@ ICount = 0; JustAfterESC = TRUE; ParseMode = ModeESC; - WriteToPrnFile(0, TRUE); // flush prn buff + WriteToPrnFile(PrintFile_, 0, TRUE); // flush prn buff return; case CSI: if (! Accept8BitCtrl) { @@ -1179,12 +1202,12 @@ ClearParams(); FirstPrm = TRUE; ParseMode = ModeCSI; - WriteToPrnFile(0, TRUE); // flush prn buff - WriteToPrnFile(b, FALSE); + WriteToPrnFile(PrintFile_, 0, TRUE); // flush prn buff + WriteToPrnFile(PrintFile_, b, FALSE); return; } /* send the uninterpreted character to printer */ - WriteToPrnFile(b, TRUE); + WriteToPrnFile(PrintFile_, b, TRUE); } static void ParseControl(BYTE b) @@ -1603,8 +1626,8 @@ case '[': /* CSI */ ClearParams(); FirstPrm = TRUE; - WriteToPrnFile(ESC,FALSE); - WriteToPrnFile('[',FALSE); + WriteToPrnFile(PrintFile_, ESC,FALSE); + WriteToPrnFile(PrintFile_, '[',FALSE); ParseMode = ModeCSI; return; } /* end of case Icount=0 */ @@ -1642,10 +1665,10 @@ break; } // send the uninterpreted sequence to printer - WriteToPrnFile(ESC,FALSE); + WriteToPrnFile(PrintFile_, ESC,FALSE); for (i=1; i<=ICount; i++) - WriteToPrnFile(IntChar[i],FALSE); - WriteToPrnFile(b,TRUE); + WriteToPrnFile(PrintFile_, IntChar[i],FALSE); + WriteToPrnFile(PrintFile_, b,TRUE); } void ParseEscape(BYTE b) /* b is the final char */ @@ -2271,7 +2294,7 @@ case 5: if (ts.TermFlag&TF_PRINTERCTRL) { if (! AutoPrintMode) - OpenPrnFile(); + PrintFile_ = OpenPrnFile(); DirectPrn = (ts.PrnDev[0]!=0); PrinterMode = TRUE; } @@ -3259,21 +3282,28 @@ } } +static void PrintFileFinish(PrintFile *handle) +{ + PrnFinish(handle); + PrintFile_ = NULL; +} + void CSQ_i_Mode() // DECMC { switch (Param[1]) { case 1: if (ts.TermFlag&TF_PRINTERCTRL) { - OpenPrnFile(); - BuffDumpCurrentLine(LF); - if (! AutoPrintMode) - ClosePrnFile(); + PrintFile_ = OpenPrnFile(); + BuffDumpCurrentLine(PrintFile_, LF); + if (! AutoPrintMode) { + ClosePrnFile(PrintFile_, PrintFileFinish); + } } break; /* auto print mode off */ case 4: if (AutoPrintMode) { - ClosePrnFile(); + ClosePrnFile(PrintFile_, PrintFileFinish); AutoPrintMode = FALSE; } break; @@ -3281,7 +3311,7 @@ case 5: if (ts.TermFlag&TF_PRINTERCTRL) { if (! AutoPrintMode) { - OpenPrnFile(); + PrintFile_ = OpenPrnFile(); AutoPrintMode = TRUE; } } @@ -4183,9 +4213,10 @@ if (Param[1]==4) { PrinterMode = FALSE; // clear prn buff - WriteToPrnFile(0,FALSE); - if (! AutoPrintMode) - ClosePrnFile(); + WriteToPrnFile(PrintFile_, 0,FALSE); + if (! AutoPrintMode) { + ClosePrnFile(PrintFile_, PrintFileFinish); + } return; } break; @@ -4197,7 +4228,7 @@ case 1: break; } /* of case Icount */ - WriteToPrnFile(b,TRUE); + WriteToPrnFile(PrintFile_, b,TRUE); } void ParseCS(BYTE b) /* b is the final char */ @@ -4311,7 +4342,7 @@ ParseCS(b); /* terminate char */ else { if (PrinterMode) - WriteToPrnFile(b,FALSE); + WriteToPrnFile(PrintFile_, b,FALSE); if ((b>=0x20) && (b<=0x2F)) { /* intermediate char */ if (ICount<IntCharMax) ICount++; Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2020-12-22 15:49:19 UTC (rev 9114) +++ trunk/teraterm/teraterm/vtwin.cpp 2020-12-28 14:29:48 UTC (rev 9115) @@ -97,6 +97,7 @@ #include "setting.h" #include "broadcast.h" #include "asprintf.h" +#include "teraprn.h" #include "initguid.h" //#include "Usbiodef.h" @@ -122,6 +123,7 @@ #endif UnicodeDebugParam_t UnicodeDebugParam; +extern "C" PrintFile *PrintFile_; ///////////////////////////////////////////////////////////////////////////// // CVTWindow @@ -2914,10 +2916,10 @@ } break; case IdPrnStartTimer: - PrnFileStart(); + PrnFileStart(PrintFile_); break; case IdPrnProcTimer: - PrnFileDirectProc(); + PrnFileDirectProc(PrintFile_); break; } }