Revision: 9467 https://osdn.net/projects/ttssh2/scm/svn/commits/9467 Author: zmatsuo Date: 2021-10-14 23:51:47 +0900 (Thu, 14 Oct 2021) Log Message: ----------- ファイル転送時のログをログフォルダへ出力するようにした - bplus,kermit,quickvan,xmodem,ymodem,zmodem - TProtoLog.LogState を各プロトコルへ移動 - ログ部分を別ファイルへ分離 - protolog.cpp,h Modified Paths: -------------- trunk/teraterm/teraterm/CMakeLists.txt trunk/teraterm/teraterm/ttermpro.v16.vcxproj trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters trunk/teraterm/teraterm/ttermpro.v8.vcproj trunk/teraterm/ttpfile/bplus.c trunk/teraterm/ttpfile/ftlib.c trunk/teraterm/ttpfile/ftlib.h trunk/teraterm/ttpfile/kermit.c trunk/teraterm/ttpfile/quickvan.c trunk/teraterm/ttpfile/xmodem.c trunk/teraterm/ttpfile/ymodem.c trunk/teraterm/ttpfile/zmodem.c Added Paths: ----------- trunk/teraterm/ttpfile/protolog.cpp trunk/teraterm/ttpfile/protolog.h -------------- next part -------------- Modified: trunk/teraterm/teraterm/CMakeLists.txt =================================================================== --- trunk/teraterm/teraterm/CMakeLists.txt 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/teraterm/CMakeLists.txt 2021-10-14 14:51:47 UTC (rev 9467) @@ -190,6 +190,8 @@ ../ttpfile/ftlib.h ../ttpfile/kermit.c ../ttpfile/kermit.h + ../ttpfile/protolog.cpp + ../ttpfile/protolog.h ../ttpfile/quickvan.c ../ttpfile/quickvan.h ../ttpfile/xmodem.c Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.v16.vcxproj 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj 2021-10-14 14:51:47 UTC (rev 9467) @@ -141,6 +141,7 @@ <ClCompile Include="..\ttpfile\filesys_win32.cpp" /> <ClCompile Include="..\ttpfile\ftlib.c" /> <ClCompile Include="..\ttpfile\kermit.c" /> + <ClCompile Include="..\ttpfile\protolog.cpp" /> <ClCompile Include="..\ttpfile\quickvan.c" /> <ClCompile Include="..\ttpfile\xmodem.c" /> <ClCompile Include="..\ttpfile\ymodem.c" /> @@ -194,6 +195,7 @@ <ClInclude Include="..\ttpfile\file_res.h" /> <ClInclude Include="..\ttpfile\ftlib.h" /> <ClInclude Include="..\ttpfile\kermit.h" /> + <ClInclude Include="..\ttpfile\protolog.h" /> <ClInclude Include="..\ttpfile\quickvan.h" /> <ClInclude Include="..\ttpfile\xmodem.h" /> <ClInclude Include="..\ttpfile\ymodem.h" /> Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters =================================================================== --- trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters 2021-10-14 14:51:47 UTC (rev 9467) @@ -22,7 +22,7 @@ <Filter Include="ttpdlg"> <UniqueIdentifier>{1cdaec4a-75c1-4600-b434-45286f5bec80}</UniqueIdentifier> </Filter> - <Filter Include="ffpfile"> + <Filter Include="ttpfile"> <UniqueIdentifier>{0494dec4-73a6-4271-9dfa-ad4b61e2b62c}</UniqueIdentifier> </Filter> </ItemGroup> @@ -157,31 +157,31 @@ <Filter>Source Files</Filter> </ClCompile> <ClCompile Include="..\ttpfile\bplus.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="..\ttpfile\ftlib.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="..\ttpfile\kermit.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="..\ttpfile\quickvan.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="..\ttpfile\xmodem.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="..\ttpfile\ymodem.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="..\ttpfile\zmodem.c"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="filesys_proto.cpp"> <Filter>Source Files</Filter> </ClCompile> <ClCompile Include="..\ttpfile\filesys_win32.cpp"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClCompile> <ClCompile Include="ttdebug.cpp"> <Filter>Source Files</Filter> @@ -192,6 +192,9 @@ <ClCompile Include="setupdirdlg.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\ttpfile\protolog.cpp"> + <Filter>ttpfile</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <Image Include="..\..\cygterm\cygterm.ico"> @@ -415,31 +418,31 @@ <Filter>Header Files</Filter> </ClInclude> <ClInclude Include="..\ttpfile\bplus.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\ftlib.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\kermit.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\quickvan.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\xmodem.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\ymodem.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\zmodem.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\file_res.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="..\ttpfile\filesys_win32.h"> - <Filter>ffpfile</Filter> + <Filter>ttpfile</Filter> </ClInclude> <ClInclude Include="ttdebug.h"> <Filter>Header Files</Filter> @@ -447,5 +450,8 @@ <ClInclude Include="setupdirdlg.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\ttpfile\protolog.h"> + <Filter>ttpfile</Filter> + </ClInclude> </ItemGroup> </Project> \ No newline at end of file Modified: trunk/teraterm/teraterm/ttermpro.v8.vcproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.v8.vcproj 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/teraterm/ttermpro.v8.vcproj 2021-10-14 14:51:47 UTC (rev 9467) @@ -749,6 +749,14 @@ > </File> <File + RelativePath="..\ttpfile\protolog.cpp" + > + </File> + <File + RelativePath="..\ttpfile\protolog.h" + > + </File> + <File RelativePath="..\ttpfile\quickvan.c" > </File> Modified: trunk/teraterm/ttpfile/bplus.c =================================================================== --- trunk/teraterm/ttpfile/bplus.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/bplus.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -75,6 +75,7 @@ BYTE Q[8]; TProtoLog *log; const char *FullName; // Windows\x8F\xE3\x82̃t\x83@\x83C\x83\x8B\x96\xBC UTF-8 + WORD LogState; } TBPVar; typedef TBPVar far *PBPVar; @@ -205,8 +206,9 @@ if ((ts->LogFlag & LOG_BP)!=0) { TProtoLog* log = ProtoLogCreate(); bv->log = log; + log->SetFolderW(log, ts->LogDirW); log->Open(log, "BPLUS.LOG"); - log->LogState = 0; + bv->LogState = 0; } return TRUE; @@ -220,9 +222,9 @@ if (bv->log != NULL) { TProtoLog *log = bv->log; - if (log->LogState==0) + if (bv->LogState==0) { - log->LogState = 1; + bv->LogState = 1; log->WriteRaw(log, "\015\012<<<\015\012", 7); } log->DumpByte(log, *b); @@ -239,9 +241,9 @@ if (bv->log != NULL && (i>0)) { TProtoLog* log = bv->log; - if (log->LogState != 0) + if (bv->LogState != 0) { - log->LogState = 0; + bv->LogState = 0; log->WriteRaw(log,"\015\012>>>\015\012",7); } for (j=0 ; j <= i-1 ; j++) Modified: trunk/teraterm/ttpfile/ftlib.c =================================================================== --- trunk/teraterm/ttpfile/ftlib.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/ftlib.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -63,121 +63,3 @@ CRC = CRC >> 1; return CRC; } - -// -// \x83v\x83\x8D\x83g\x83R\x83\x8B\x97p\x83\x8D\x83O -// - -static BOOL Open(TProtoLog *pv, const char *file) -{ - pv->LogFile = CreateFileA(file, - GENERIC_WRITE, FILE_SHARE_WRITE, NULL, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - pv->LogCount = 0; - pv->LogState = 0; - return pv->LogFile == INVALID_HANDLE_VALUE ? FALSE : TRUE; -} - -static void Close(TProtoLog *pv) -{ - if (pv->LogFile != INVALID_HANDLE_VALUE) { - if (pv->LogCount > 0) { - pv->DumpFlush(pv); - } - CloseHandle(pv->LogFile); - pv->LogFile = INVALID_HANDLE_VALUE; - } -} - -static size_t WriteRawData(struct ProtoLog *pv, const void *data, size_t len) -{ - DWORD NumberOfBytesWritten; - BOOL result = WriteFile(pv->LogFile, data, len, &NumberOfBytesWritten, NULL); - if (result == FALSE) { - return 0; - } - return NumberOfBytesWritten; -} - -static size_t WriteStr(TProtoLog *pv, const char *str) -{ - size_t len = strlen(str); - size_t r = WriteRawData(pv, str, len); - return r; -} - -static void DumpByte(TProtoLog *pv, BYTE b) -{ - char d[3]; - - if (pv->LogCount == _countof(pv->LogLineBuf)) { - pv->DumpFlush(pv); - } - - if (b<=0x9f) - d[0] = (b >> 4) + 0x30; - else - d[0] = (b >> 4) + 0x37; - - if ((b & 0x0f) <= 0x9) - d[1] = (b & 0x0F) + 0x30; - else - d[1] = (b & 0x0F) + 0x37; - - d[2] = 0x20; - pv->WriteRaw(pv,d,3); - pv->LogLineBuf[pv->LogCount] = b; // add (2008.6.3 yutaka) - pv->LogCount++; -} - -static void DumpFlush(TProtoLog *pv) -{ - int rest = 16 - pv->LogCount; - int i; - - for (i = 0 ; i < rest ; i++) - pv->WriteRaw(pv," ", 3); - - // ASCII\x95\\x8E\xA6\x82\xF0\x92lj\xC1 (2008.6.3 yutaka) - pv->WriteRaw(pv," ", 4); - for (i = 0 ; i < pv->LogCount ; i++) { - char ch[5]; - if (isprint(pv->LogLineBuf[i])) { - _snprintf_s(ch, sizeof(ch), _TRUNCATE, "%c", pv->LogLineBuf[i]); - pv->WriteRaw(pv, ch, 1); - - } else { - pv->WriteRaw(pv, ".", 1); - - } - - } - - pv->LogCount = 0; - pv->WriteRaw(pv,"\015\012",2); -} - -static void ProtoLogDestroy(TProtoLog *pv) -{ - pv->Close(pv); - free(pv); -} - -TProtoLog *ProtoLogCreate() -{ - TProtoLog *pv = (TProtoLog *)malloc(sizeof(TProtoLog)); - if (pv == NULL) { - return NULL; - } - - memset(pv, 0, sizeof(TProtoLog)); - pv->Open = Open; - pv->Close = Close; - pv->WriteStr = WriteStr; - pv->DumpByte = DumpByte; - pv->DumpFlush = DumpFlush; - pv->WriteRaw = WriteRawData; - pv->Destory = ProtoLogDestroy; - pv->LogFile = INVALID_HANDLE_VALUE; - return pv; -} Modified: trunk/teraterm/ttpfile/ftlib.h =================================================================== --- trunk/teraterm/ttpfile/ftlib.h 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/ftlib.h 2021-10-14 14:51:47 UTC (rev 9467) @@ -29,6 +29,8 @@ /* TTFILE.DLL, routines for file transfer protocol */ +#pragma once + #ifdef __cplusplus extern "C" { #endif @@ -36,24 +38,8 @@ WORD UpdateCRC(BYTE b, WORD CRC); LONG UpdateCRC32(BYTE b, LONG CRC); -typedef struct ProtoLog { - // public - WORD LogState; // \x8E\xA9\x97R\x82Ɏg\x82\xC1\x82Ă\xE0\x97ǂ\xA2\x95ϐ\x94 - BOOL (*Open)(struct ProtoLog *pv, const char *file); - void (*Close)(struct ProtoLog *pv); - size_t (*WriteRaw)(struct ProtoLog *pv, const void *data, size_t len); - size_t (*WriteStr)(struct ProtoLog *pv, const char *str); - void (*DumpByte)(struct ProtoLog *pv, BYTE b); - void (*DumpFlush)(struct ProtoLog *pv); - void (*Destory)(struct ProtoLog *pv); - // private - HANDLE LogFile; - WORD LogCount; - BYTE LogLineBuf[16]; -} TProtoLog; - -TProtoLog *ProtoLogCreate(void); - #ifdef __cplusplus } #endif + +#include "protolog.h" Modified: trunk/teraterm/ttpfile/kermit.c =================================================================== --- trunk/teraterm/ttpfile/kermit.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/kermit.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -1248,8 +1248,8 @@ ctime_s(ctime_str, sizeof(ctime_str), &tm); kv->log = log; + log->SetFolderW(log, ts->LogDirW); log->Open(log, "KERMIT.LOG"); - log->LogState = 0; _snprintf_s(buf, sizeof(buf), _TRUNCATE, "KERMIT %s start: %s\n", kv->KmtMode == IdKmtSend ? "Send" : kv->KmtMode == IdKmtReceive ? "Receive" : Added: trunk/teraterm/ttpfile/protolog.cpp =================================================================== --- trunk/teraterm/ttpfile/protolog.cpp (rev 0) +++ trunk/teraterm/ttpfile/protolog.cpp 2021-10-14 14:51:47 UTC (rev 9467) @@ -0,0 +1,217 @@ +/* + * (C) 2021- 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. + */ + +#include <stdio.h> +#include <string.h> + +#include "asprintf.h" +#include "codeconv.h" + +#include "protolog.h" + +typedef struct { + HANDLE LogFile; + WORD LogCount; + BYTE LogLineBuf[16]; + wchar_t *Folder; +} PrivateData_t; + +static BOOL OpenW(struct ProtoLog *pv, const wchar_t *file) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + wchar_t *full_path; + if (pdata->Folder != NULL) { + aswprintf(&full_path, L"%s\\%s", pdata->Folder, file); + } else { + full_path = _wcsdup(file); + } + pdata->LogFile = CreateFileW(full_path, + GENERIC_WRITE, FILE_SHARE_WRITE, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + free(full_path); + pdata->LogCount = 0; + return pdata->LogFile == INVALID_HANDLE_VALUE ? FALSE : TRUE; +} + +static BOOL OpenA(TProtoLog *pv, const char *file) +{ + wchar_t *fileW = ToWcharA(file); + BOOL r = OpenW(pv, fileW); + free(fileW); + return r; +} + +static BOOL OpenU8(TProtoLog *pv, const char *fileU8) +{ + wchar_t *fileW = ToWcharU8(fileU8); + BOOL r = OpenW(pv, fileW); + free(fileW); + return r; +} + +static void Close(TProtoLog *pv) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + if (pdata->LogFile != INVALID_HANDLE_VALUE) { + if (pdata->LogCount > 0) { + pv->DumpFlush(pv); + } + CloseHandle(pdata->LogFile); + pdata->LogFile = INVALID_HANDLE_VALUE; + } +} + +static size_t WriteRawData(struct ProtoLog *pv, const void *data, size_t len) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + DWORD NumberOfBytesWritten; + BOOL result = WriteFile(pdata->LogFile, data, (DWORD)len, &NumberOfBytesWritten, NULL); + if (result == FALSE) { + return 0; + } + return NumberOfBytesWritten; +} + +static size_t WriteStr(TProtoLog *pv, const char *str) +{ + size_t len = strlen(str); + size_t r = WriteRawData(pv, str, len); + return r; +} + +static void DumpByte(TProtoLog *pv, BYTE b) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + char d[3]; + + if (pdata->LogCount == _countof(pdata->LogLineBuf)) { + pv->DumpFlush(pv); + } + + if (b<=0x9f) + d[0] = (b >> 4) + 0x30; + else + d[0] = (b >> 4) + 0x37; + + if ((b & 0x0f) <= 0x9) + d[1] = (b & 0x0F) + 0x30; + else + d[1] = (b & 0x0F) + 0x37; + + d[2] = 0x20; + pv->WriteRaw(pv,d,3); + pdata->LogLineBuf[pdata->LogCount] = b; // add (2008.6.3 yutaka) + pdata->LogCount++; +} + +static void NewLine(TProtoLog *pv) +{ + pv->WriteRaw(pv,"\015\012",2); // 0x0d 0x0a "\r\n" +} + +static void DumpFlush(TProtoLog *pv) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + int rest = 16 - pdata->LogCount; + int i; + + for (i = 0 ; i < rest ; i++) + pv->WriteRaw(pv," ", 3); + + // ASCII\x95\\x8E\xA6\x82\xF0\x92lj\xC1 (2008.6.3 yutaka) + pv->WriteRaw(pv," ", 4); + for (i = 0 ; i < pdata->LogCount ; i++) { + char ch[5]; + if (isprint(pdata->LogLineBuf[i])) { + _snprintf_s(ch, sizeof(ch), _TRUNCATE, "%c", pdata->LogLineBuf[i]); + pv->WriteRaw(pv, ch, 1); + + } else { + pv->WriteRaw(pv, ".", 1); + + } + + } + pdata->LogCount = 0; + + NewLine(pv); +} + +static void SetFolderW(struct ProtoLog *pv, const wchar_t *folder) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + if (pdata->Folder != NULL) { + free(pdata->Folder); + } + if (folder != NULL) { + pdata->Folder = _wcsdup(folder); + } +} + +static void ProtoLogDestroy(TProtoLog *pv) +{ + PrivateData_t *pdata = (PrivateData_t *)pv->private_data; + if (pdata->Folder != NULL) { + free(pdata->Folder); + pdata->Folder = NULL; + } + free(pdata); + pv->private_data = NULL; + pv->Close(pv); + free(pv); +} + +TProtoLog *ProtoLogCreate() +{ + TProtoLog *pv = (TProtoLog *)calloc(sizeof(*pv), 1); + if (pv == NULL) { + return NULL; + } + + PrivateData_t *pdata = (PrivateData_t *)calloc(sizeof(*pdata), 1); + if (pdata == NULL) { + free(pv); + return NULL; + } + + pv->Open = OpenA; + pv->OpenA = OpenA; + pv->OpenW = OpenW; + pv->OpenU8 = OpenU8; + pv->Close = Close; + pv->SetFolderW = SetFolderW; + pv->WriteStr = WriteStr; + pv->DumpByte = DumpByte; + pv->DumpFlush = DumpFlush; + pv->WriteRaw = WriteRawData; + pv->Destory = ProtoLogDestroy; + + pdata->LogFile = INVALID_HANDLE_VALUE; + + return pv; +} Copied: trunk/teraterm/ttpfile/protolog.h (from rev 9466, trunk/teraterm/ttpfile/ftlib.h) =================================================================== --- trunk/teraterm/ttpfile/protolog.h (rev 0) +++ trunk/teraterm/ttpfile/protolog.h 2021-10-14 14:51:47 UTC (rev 9467) @@ -0,0 +1,63 @@ +/* + * (C) 2021- 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 + +#include <stdlib.h> // for size_t +#include <windows.h> // for BOOL + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ProtoLog { + // public + BOOL (*Open)(struct ProtoLog *pv, const char *file); + BOOL (*OpenA)(struct ProtoLog *pv, const char *file); + BOOL (*OpenW)(struct ProtoLog *pv, const wchar_t *file); + BOOL (*OpenU8)(struct ProtoLog *pv, const char *fileU8); + void (*Close)(struct ProtoLog *pv); + /** + * \x83t\x83H\x83\x8B\x83_\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9 + * @param[in] \x83t\x83H\x83\x8B\x83_(NULL\x82̂Ƃ\xAB\x83t\x83H\x83\x8B\x83_\x96\xA2\x90ݒ\xE8\x82ƂȂ\xE9) + */ + void (*SetFolderW)(struct ProtoLog *pv, const wchar_t *folder); + size_t (*WriteRaw)(struct ProtoLog *pv, const void *data, size_t len); + size_t (*WriteStr)(struct ProtoLog *pv, const char *str); + void (*DumpByte)(struct ProtoLog *pv, BYTE b); + void (*DumpFlush)(struct ProtoLog *pv); + void (*Destory)(struct ProtoLog *pv); + // private + void *private_data; +} TProtoLog; + +TProtoLog *ProtoLogCreate(void); + +#ifdef __cplusplus +} +#endif Modified: trunk/teraterm/ttpfile/quickvan.c =================================================================== --- trunk/teraterm/ttpfile/quickvan.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/quickvan.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -62,6 +62,7 @@ BYTE CheckSum; TProtoLog *log; const char *FullName; // Windows\x8F\xE3\x82̃t\x83@\x83C\x83\x8B\x96\xBC UTF-8 + WORD LogState; } TQVVar; typedef TQVVar far *PQVVar; @@ -109,9 +110,9 @@ if (qv->log != NULL) { TProtoLog *log = qv->log; - if (log->LogState!=1) + if (qv->LogState!=1) { - log->LogState = 1; + qv->LogState = 1; log->WriteRaw(log, "\015\012<<<\015\012", 7); } log->DumpByte(log, *b); @@ -127,8 +128,8 @@ if (qv->log != NULL && (i>0)) { TProtoLog* log = qv->log; - if (log->LogState != 0) { - log->LogState = 0; + if (qv->LogState != 0) { + qv->LogState = 0; log->WriteRaw(log, "\015\012>>>\015\012", 7); } for (j=0 ; j <= i-1 ; j++) @@ -165,8 +166,9 @@ if ((ts->LogFlag & LOG_QV)!=0) { TProtoLog* log = ProtoLogCreate(); qv->log = log; + log->SetFolderW(log, ts->LogDirW); log->Open(log, "QUICKVAN.LOG"); - log->LogState = 2; + qv->LogState = 2; } fv->FileOpen = FALSE; Modified: trunk/teraterm/ttpfile/xmodem.c =================================================================== --- trunk/teraterm/ttpfile/xmodem.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/xmodem.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -58,6 +58,7 @@ int CANCount; TProtoLog *log; const char *FullName; // Windows\x8F\xE3\x82̃t\x83@\x83C\x83\x8B\x96\xBC UTF-8 + WORD LogState; } TXVar; typedef TXVar far *PXVar; @@ -85,11 +86,11 @@ if (xv->log != NULL) { TProtoLog *log = xv->log; - if (log->LogState == 0) { + if (xv->LogState == 0) { // \x8Ec\x82\xE8\x82\xCCASCII\x95\\x8E\xA6\x82\xF0\x8Ds\x82\xA4 log->DumpFlush(log); - log->LogState = 1; + xv->LogState = 1; log->WriteRaw(log, "\015\012<<<\015\012", 7); } log->DumpByte(log, *b); @@ -104,11 +105,11 @@ i = CommBinaryOut(cv, B, C); if (xv->log != NULL && (i > 0)) { TProtoLog* log = xv->log; - if (log->LogState != 0) { + if (xv->LogState != 0) { // \x8Ec\x82\xE8\x82\xCCASCII\x95\\x8E\xA6\x82\xF0\x8Ds\x82\xA4 log->DumpFlush(log); - log->LogState = 0; + xv->LogState = 0; log->WriteRaw(log, "\015\012>>>\015\012", 7); } for (j = 0; j <= i - 1; j++) @@ -224,8 +225,9 @@ if (LogFlag) { TProtoLog* log = ProtoLogCreate(); xv->log = log; + log->SetFolderW(log, ts->LogDirW); log->Open(log, "XMODEM.LOG"); - log->LogState = 0; + xv->LogState = 0; } xv->FullName = fv->GetNextFname(fv); Modified: trunk/teraterm/ttpfile/ymodem.c =================================================================== --- trunk/teraterm/ttpfile/ymodem.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/ymodem.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -69,6 +69,7 @@ BOOL RecvFilesize; TProtoLog *log; const char *FullName; // Windows\x8F\xE3\x82̃t\x83@\x83C\x83\x8B\x96\xBC UTF-8 + WORD LogState; } TYVar; typedef TYVar *PYVar; @@ -106,12 +107,12 @@ if (yv->log != NULL) { TProtoLog *log = yv->log; - if (log->LogState==0) + if (yv->LogState==0) { // \x8Ec\x82\xE8\x82\xCCASCII\x95\\x8E\xA6\x82\xF0\x8Ds\x82\xA4 log->DumpFlush(log); - log->LogState = 1; + yv->LogState = 1; log->WriteRaw(log, "\015\012<<<\015\012", 7); } log->DumpByte(log, *b); @@ -127,12 +128,12 @@ if (yv->log != NULL && (i>0)) { TProtoLog* log = yv->log; - if (log->LogState != 0) + if (yv->LogState != 0) { // \x8Ec\x82\xE8\x82\xCCASCII\x95\\x8E\xA6\x82\xF0\x8Ds\x82\xA4 log->DumpFlush(log); - log->LogState = 0; + yv->LogState = 0; log->WriteRaw(log, "\015\012>>>\015\012", 7); } for (j=0 ; j <= i-1 ; j++) @@ -346,8 +347,9 @@ if ((ts->LogFlag & LOG_Y)!=0) { TProtoLog* log = ProtoLogCreate(); yv->log = log; + log->SetFolderW(log, ts->LogDirW); log->Open(log, "YMODEM.LOG"); - log->LogState = 0; + yv->LogState = 0; } initialize_file_info(fv, yv); Modified: trunk/teraterm/ttpfile/zmodem.c =================================================================== --- trunk/teraterm/ttpfile/zmodem.c 2021-10-14 14:51:37 UTC (rev 9466) +++ trunk/teraterm/ttpfile/zmodem.c 2021-10-14 14:51:47 UTC (rev 9467) @@ -80,6 +80,7 @@ int TOutFin; TProtoLog *log; const char *FullName; // Windows\x8F\xE3\x82̃t\x83@\x83C\x83\x8B\x96\xBC UTF-8 + WORD LogState; } TZVar; typedef TZVar far *PZVar; @@ -256,13 +257,13 @@ if (zv->log != NULL) { TProtoLog *log = zv->log; - if (log->LogState == 0) { + if (zv->LogState == 0) { // \x8Ec\x82\xE8\x82\xCCASCII\x95\\x8E\xA6\x82\xF0\x8Ds\x82\xA4 log->DumpFlush(log); show_sendbuf(log); - log->LogState = 1; + zv->LogState = 1; s = "\015\012<<< Received\015\012"; log->WriteRaw(log, s, strlen(s)); } @@ -283,13 +284,13 @@ if (zv->log != NULL && (i > 0)) { TProtoLog* log = zv->log; - if (log->LogState != 0) { + if (zv->LogState != 0) { // \x8Ec\x82\xE8\x82\xCCASCII\x95\\x8E\xA6\x82\xF0\x8Ds\x82\xA4 log->DumpFlush(log); show_recvbuf(log); - log->LogState = 0; + zv->LogState = 0; s = "\015\012Sending >>>\015\012"; log->WriteRaw(log, s, strlen(s)); } @@ -767,8 +768,9 @@ if ((ts->LogFlag & LOG_Z) != 0) { TProtoLog* log = ProtoLogCreate(); zv->log = log; + log->SetFolderW(log, ts->LogDirW); log->Open(log, "ZMODEM.LOG"); - log->LogState = 0; + zv->LogState = 0; } switch (zv->ZMode) {