Revision: 8988 https://osdn.net/projects/ttssh2/scm/svn/commits/8988 Author: zmatsuo Date: 2020-11-02 00:33:26 +0900 (Mon, 02 Nov 2020) Log Message: ----------- filesys_proto.cpp (プロトコル送受信)のコード整理 - xmodem.c 内でファイルをオープンするよう修正 - 修正前は filesys_proto.cpp でオープン - 他のプロトコルと同様の動作 - プロトコルの関数の仕様を変更 - 初期化関数の戻り値を void から BOOL に変更 - BOOL (*Init)(struct FileVarProto *fv, PComVar cv, PTTSet ts); - Desotry() を追加 - void (*Destroy)(struct FileVarProto *fv); Modified Paths: -------------- branches/proto_unicode/teraterm/common/ttlib.h branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp branches/proto_unicode/teraterm/teraterm/filesys_proto.h branches/proto_unicode/teraterm/ttpfile/bplus.c branches/proto_unicode/teraterm/ttpfile/kermit.c branches/proto_unicode/teraterm/ttpfile/quickvan.c branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp branches/proto_unicode/teraterm/ttpfile/xmodem.c branches/proto_unicode/teraterm/ttpfile/xmodem.h branches/proto_unicode/teraterm/ttpfile/ymodem.c branches/proto_unicode/teraterm/ttpfile/ymodem.h branches/proto_unicode/teraterm/ttpfile/zmodem.c branches/proto_unicode/teraterm/ttpfile/zmodem.h -------------- next part -------------- Modified: branches/proto_unicode/teraterm/common/ttlib.h =================================================================== --- branches/proto_unicode/teraterm/common/ttlib.h 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/common/ttlib.h 2020-11-01 15:33:26 UTC (rev 8988) @@ -46,6 +46,7 @@ DllExport BOOL ExtractDirName(PCHAR PathName, PCHAR DirName); void FitFileName(PCHAR FileName, int destlen, const char *DefExt); void AppendSlash(PCHAR Path, int destlen); +void AppendSlashW(wchar_t *Path, size_t destlen); void DeleteSlash(PCHAR Path); void Str2Hex(PCHAR Str, PCHAR Hex, int Len, int MaxHexLen, BOOL ConvSP); BYTE ConvHexChar(BYTE b); Modified: branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp 2020-11-01 15:33:26 UTC (rev 8988) @@ -614,3 +614,14 @@ CloseHandle(hFile); return file_size; } + +// Append a slash to the end of a path name +void AppendSlashW(wchar_t *Path, size_t destlen) +{ + size_t len = wcslen(Path); + if (len > 0) { + if (Path[len - 1] != L'\\') { + wcsncat_s(Path,destlen,L"\\",_TRUNCATE); + } + } +} Modified: branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp =================================================================== --- branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/teraterm/filesys_proto.cpp 2020-11-01 15:33:26 UTC (rev 8988) @@ -28,8 +28,6 @@ /* TERATERM.EXE, file transfer routines */ #include <stdio.h> -#include <io.h> -#include <process.h> #include <windows.h> #include <htmlhelp.h> #include <assert.h> @@ -37,7 +35,6 @@ #include "teraterm.h" #include "tttypes.h" #include "ttftypes.h" -#include "ftdlg.h" #include "protodlg.h" #include "ttwinman.h" #include "commlib.h" @@ -46,12 +43,10 @@ #include "ttlib.h" #include "dlglib.h" #include "vtterm.h" -#include "win16api.h" #include "ftlib.h" #include "buffer.h" #include "helpid.h" #include "layer_for_unicode.h" -#include "layer_for_unicode_crt.h" #include "codeconv.h" #include "filesys_log_res.h" @@ -187,19 +182,26 @@ return TRUE; } -static void FreeFileVar_(PFileVarProto *fv) +static void FreeFileVar_(PFileVarProto *pfv) { - if ((*fv)!=NULL) + PFileVarProto fv = *pfv; + if (fv == NULL) { + return; + } + + if (fv->Destroy != NULL) { + fv->Destroy(fv); + } + + if (fv->FileOpen) CloseHandle(fv->FileHandle); + if (fv->FnStrMemHandle != 0) { - if ((*fv)->FileOpen) CloseHandle((*fv)->FileHandle); - if ((*fv)->FnStrMemHandle != 0) - { - GlobalUnlock((*fv)->FnStrMemHandle); - GlobalFree((*fv)->FnStrMemHandle); - } - free(*fv); - *fv = NULL; + GlobalUnlock(fv->FnStrMemHandle); + GlobalFree(fv->FnStrMemHandle); } + free(fv); + + *pfv = NULL; } static BOOL OpenProtoDlg(PFileVarProto fv, int IdProto, int Mode, WORD Opt1, WORD Opt2) @@ -269,7 +271,12 @@ pd->Create(hInst, HVTWin, &info); fv->HWin = pd->m_hWnd; - _ProtoInit(ProtoId,FileVar,&cv,&ts); + BOOL r = fv->Init(fv, &cv, &ts); + if (r == FALSE) { + fv->Destroy(fv); + return FALSE; + } + SetWindowText(fv->HWin, fv->DlgCaption); PtDlg = pd; return TRUE; @@ -475,32 +482,68 @@ return FALSE; } -static BOOL _GetXFname(HWND HWin, BOOL Receive, LPLONG Option, PFileVarProto fv) +/** + * \x83_\x83C\x83A\x83\x8D\x83O\x82̃f\x83t\x83H\x83\x8B\x83g\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x95Ԃ\xB7 + * \x83t\x83B\x83\x8B\x83^(ts.FileSendFilter)\x82\xAA\x83\x8F\x83C\x83\x8B\x83h\x83J\x81[\x83h\x82ł͂Ȃ\xAD\x81A + * \x82\xBB\x82̃t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9\x8Fꍇ + * \x83f\x83t\x83H\x83\x8B\x83g\x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82Ƃ\xB5\x82ĕԂ\xB7 + * + * @param[in] path \x83t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82邩\x92\xB2\x82ׂ\xE9\x83p\x83X + * (lpstrInitialDir \x82ɐݒ肳\x82\xEA\x82\xE9\x83p\x83X) + * @retval NULL \x83f\x83t\x83H\x83\x8B\x83g\x83t\x83@\x83C\x83\x8B\x96\xBC\x82Ȃ\xB5 + * @retval NULL\x88ȊO \x83f\x83t\x83H\x83\x8B\x83g\x83t\x83@\x83C\x83\x8B(\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7free()\x82\xB7\x82邱\x82\xC6) + */ +static wchar_t *GetCommonDialogDefaultFilenameW(const wchar_t *path) { - LONG opt; - const char *FileSendFilter = ts.FileSendFilter; - const char *UILanguageFile = ts.UILanguageFile; + const char *FileSendFilterA = ts.FileSendFilter; + if (strlen(FileSendFilterA) == 0) { + return NULL; + } + // \x83t\x83B\x83\x8B\x83^\x82\xAA\x83\x8F\x83C\x83\x8B\x83h\x83J\x81[\x83h\x82ł͂Ȃ\xAD\x81A\x82\xBB\x82̃t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9\x8Fꍇ + // \x82\xA0\x82炩\x82\xB6\x82߃f\x83t\x83H\x83\x8B\x83g\x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x93\xFC\x82\xEA\x82Ă\xA8\x82\xAD (2008.5.18 maya) + wchar_t *filename = NULL; + if (!isInvalidFileNameChar(FileSendFilterA)) { + wchar_t file[MAX_PATH]; + wcsncpy_s(file, _countof(file), path, _TRUNCATE); + AppendSlashW(file, _countof(file)); + wchar_t *FileSendFilterW = ToWcharA(FileSendFilterA); + wcsncat_s(file, _countof(file), FileSendFilterW, _TRUNCATE); + DWORD attr = _GetFileAttributesW(file); + if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) { + // \x83t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9 + filename = _wcsdup(file); + } + free(FileSendFilterW); + } + + return filename; +} + +static char *GetCommonDialogDefaultFilenameA(const char *path) +{ + wchar_t *pathW = ToWcharA(path); + wchar_t *fileW = GetCommonDialogDefaultFilenameW(pathW); + char *fileA = ToCharW(fileW); + free(pathW); + free(fileW); + return fileA; +} + +static BOOL _GetXFname(HWND HWin, BOOL Receive, const char *caption, LPLONG Option, PFileVarProto fv) +{ char FileDirExpanded[MAX_PATH]; ExpandEnvironmentStrings(ts.FileDir, FileDirExpanded, sizeof(FileDirExpanded)); PCHAR CurDir = FileDirExpanded; - char *FNFilter = GetCommonDialogFilterA(!Receive ? FileSendFilter : NULL, UILanguageFile); + char *FNFilter = GetCommonDialogFilterA(!Receive ? ts.FileSendFilter : NULL, ts.UILanguageFile); fv->FullName[0] = 0; if (!Receive) { - if (strlen(FileSendFilter) > 0) { - // \x83t\x83B\x83\x8B\x83^\x82\xAA\x83\x8F\x83C\x83\x8B\x83h\x83J\x81[\x83h\x82ł͂Ȃ\xAD\x81A\x82\xBB\x82̃t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9\x8Fꍇ - // \x82\xA0\x82炩\x82\xB6\x82߃f\x83t\x83H\x83\x8B\x83g\x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x93\xFC\x82\xEA\x82Ă\xA8\x82\xAD (2008.5.18 maya) - if (!isInvalidFileNameChar(FileSendFilter)) { - char file[MAX_PATH]; - strncpy_s(file, sizeof(file), CurDir, _TRUNCATE); - AppendSlash(file, sizeof(file)); - strncat_s(file, sizeof(file), FileSendFilter, _TRUNCATE); - if (_access(file, 0) == 0) { - strncpy_s(fv->FullName, sizeof(fv->FullName), FileSendFilter, _TRUNCATE); - } - } + char *default_filename = GetCommonDialogDefaultFilenameA(CurDir); + if (default_filename != NULL) { + strncpy_s(fv->FullName, _countof(fv->FullName), default_filename, _TRUNCATE); + free(default_filename); } } @@ -510,9 +553,9 @@ ofn.lpstrFilter = FNFilter; ofn.nFilterIndex = 1; ofn.lpstrFile = fv->FullName; - ofn.nMaxFile = sizeof(fv->FullName); + ofn.nMaxFile = _countof(fv->FullName); ofn.lpstrInitialDir = CurDir; - opt = *Option; + LONG opt = *Option; if (! Receive) { ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; @@ -524,13 +567,13 @@ ofn.Flags |= OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLESIZING; ofn.Flags |= OFN_SHOWHELP; ofn.lCustData = (LPARAM)&opt; - ofn.lpstrTitle = fv->DlgCaption; + ofn.lpstrTitle = caption; ofn.lpfnHook = XFnHook; ofn.lpTemplateName = MAKEINTRESOURCE(IDD_XOPT); ofn.hInstance = hInst; /* save current dir */ - wchar_t TempDir[MAXPATHLEN]; + wchar_t TempDir[MAX_PATH]; _GetCurrentDirectoryW(_countof(TempDir), TempDir); BOOL Ok; if (!Receive) @@ -540,13 +583,12 @@ else { Ok = GetSaveFileName(&ofn); } + free(FNFilter); _SetCurrentDirectoryW(TempDir); if (Ok) { fv->DirLen = ofn.nFileOffset; fv->FnPtr = ofn.nFileOffset; - memcpy(CurDir,fv->FullName,fv->DirLen-1); - CurDir[fv->DirLen-1] = 0; if (Receive) *Option = opt; @@ -737,12 +779,9 @@ static BOOL _GetMultiFname(PFileVarProto fv, WORD FuncId, LPWORD Option) { - int i, len; - char *FNFilter; OPENFILENAME ofn; - wchar_t TempDir[MAXPATHLEN]; + wchar_t TempDir[MAX_PATH]; BOOL Ok; - char defaultFName[MAX_PATH]; const char *FileSendFilter = ts.FileSendFilter; const char *UILanguageFile = ts.UILanguageFile; @@ -771,8 +810,14 @@ } } - FNFilter = GetCommonDialogFilterA(FileSendFilter, UILanguageFile); + char *FNFilter = GetCommonDialogFilterA(FileSendFilter, UILanguageFile); + char *default_filename = GetCommonDialogDefaultFilenameA(CurDir); + if (default_filename != NULL) { + strncpy_s(fv->FnStrMem, _countof(fv->FullName), default_filename, _TRUNCATE); + free(default_filename); + } + memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = get_OPENFILENAME_SIZE(); ofn.hwndOwner = fv->HMainWin; @@ -798,23 +843,11 @@ ofn.hInstance = hInst; - // \x83t\x83B\x83\x8B\x83^\x82\xAA\x83\x8F\x83C\x83\x8B\x83h\x83J\x81[\x83h\x82ł͂Ȃ\xAD\x81A\x82\xBB\x82̃t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9\x8Fꍇ - // \x82\xA0\x82炩\x82\xB6\x82߃f\x83t\x83H\x83\x8B\x83g\x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x93\xFC\x82\xEA\x82Ă\xA8\x82\xAD (2008.5.18 maya) - if (strlen(FileSendFilter) > 0 && !isInvalidFileNameChar(FileSendFilter)) { - char file[MAX_PATH]; - strncpy_s(file, sizeof(file), CurDir, _TRUNCATE); - AppendSlash(file, sizeof(file)); - strncat_s(file, sizeof(file), FileSendFilter, _TRUNCATE); - if (_access(file, 0) == 0) { - strncpy_s(defaultFName, sizeof(defaultFName), FileSendFilter, _TRUNCATE); - ofn.lpstrFile = defaultFName; - } - } - Ok = GetOpenFileName(&ofn); free(FNFilter); if (Ok) { + int i, len; /* count number of file names */ len = strlen(fv->FnStrMem); i = 0; @@ -1032,7 +1065,7 @@ { Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt); if (! _GetXFname(FileVar->HMainWin, - mode==IdXReceive,&Option,FileVar)) + mode==IdXReceive, fv->DlgCaption, &Option,FileVar)) { ProtoEnd(); return; @@ -1079,25 +1112,14 @@ else _SetFileVar(FileVar); - if (mode==IdXReceive) - FileVar->FileHandle = _lcreat(FileVar->FullName,0); - else - FileVar->FileHandle = _lopen(FileVar->FullName,OF_READ); - - FileVar->FileOpen = FileVar->FileHandle != INVALID_HANDLE_VALUE; - if (! FileVar->FileOpen) - { - ProtoEnd(); - return; - } TalkStatus = IdTalkQuiet; /* disable transmit delay (serial port) */ cv.DelayFlag = FALSE; - if (! OpenProtoDlg(FileVar,PROTO_XM,mode, - ts.XmodemOpt,ts.XmodemBin)) + if (! OpenProtoDlg(FileVar,PROTO_XM,mode, ts.XmodemOpt,ts.XmodemBin)) { ProtoEnd(); + } } BOOL XMODEMStartReceive(const char *fiename, WORD ParamBinaryFlag, WORD ParamXmodemOpt) @@ -1339,7 +1361,7 @@ static BOOL _GetTransFname(PFileVarProto fv, const char *DlgCaption) { - wchar_t TempDir[MAXPATHLEN]; + wchar_t TempDir[MAX_PATH]; char FileName[MAX_PATH]; const char *UILanguageFile = ts.UILanguageFile; Modified: branches/proto_unicode/teraterm/teraterm/filesys_proto.h =================================================================== --- branches/proto_unicode/teraterm/teraterm/filesys_proto.h 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/teraterm/filesys_proto.h 2020-11-01 15:33:26 UTC (rev 8988) @@ -68,11 +68,12 @@ DWORD FileMtime; // protocol entrys, data - void (*Init)(struct FileVarProto *fv, PComVar cv, PTTSet ts); + BOOL (*Init)(struct FileVarProto *fv, PComVar cv, PTTSet ts); BOOL (*Parse)(struct FileVarProto *fv, PComVar cv); void (*TimeOutProc)(struct FileVarProto *fv, PComVar cv); void (*Cancel)(struct FileVarProto *fv, PComVar cv); int (*SetOptV)(struct FileVarProto *fv, int request, va_list ap); + void (*Destroy)(struct FileVarProto *fv); void *data; // file I/O Modified: branches/proto_unicode/teraterm/ttpfile/bplus.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/bplus.c 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/bplus.c 2020-11-01 15:33:26 UTC (rev 8988) @@ -129,7 +129,7 @@ SetWindowText(fv->HWin,fv->DlgCaption); } -void BPInit(PFileVarProto fv, PComVar cv, PTTSet ts) +static BOOL BPInit(PFileVarProto fv, PComVar cv, PTTSet ts) { int i; PBPVar bv = fv->data; @@ -204,6 +204,7 @@ fv->LogState = 0; fv->LogCount = 0; + return TRUE; } int BPRead1Byte(PFileVarProto fv, PBPVar bv, PComVar cv, LPBYTE b) @@ -970,6 +971,12 @@ return -1; } +static void Destroy(PFileVarProto fv) +{ + free(fv->data); + fv->data = NULL; +} + BOOL BPCreate(PFileVarProto fv) { PBPVar bv; @@ -980,6 +987,7 @@ memset(bv, 0, sizeof(*bv)); fv->data = bv; + fv->Destroy = Destroy; fv->Init = BPInit; fv->Parse = BPParse; fv->TimeOutProc = BPTimeOutProc; Modified: branches/proto_unicode/teraterm/ttpfile/kermit.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/kermit.c 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/kermit.c 2020-11-01 15:33:26 UTC (rev 8988) @@ -1169,32 +1169,10 @@ kv->KmtState = Finish; } -void KmtInit(PFileVarProto fv, PComVar cv, PTTSet ts) +static BOOL KmtInit(PFileVarProto fv, PComVar cv, PTTSet ts) { - char uimsg[MAX_UIMSG]; PKmtVar kv = fv->data; - UILanguageFile = ts->UILanguageFile; - strncpy_s(fv->DlgCaption,sizeof(fv->DlgCaption),"Tera Term: Kermit ",_TRUNCATE); - switch (kv->KmtMode) { - case IdKmtSend: - get_lang_msg("FILEDLG_TRANS_TITLE_KMTSEND", uimsg, sizeof(uimsg), TitKmtSend, UILanguageFile); - strncat_s(fv->DlgCaption, sizeof(fv->DlgCaption), uimsg, _TRUNCATE); - break; - case IdKmtReceive: - get_lang_msg("FILEDLG_TRANS_TITLE_KMTRCV", uimsg, sizeof(uimsg), TitKmtRcv, UILanguageFile); - strncat_s(fv->DlgCaption, sizeof(fv->DlgCaption), uimsg, _TRUNCATE); - break; - case IdKmtGet: - get_lang_msg("FILEDLG_TRANS_TITLE_KMTGET", uimsg, sizeof(uimsg), TitKmtGet, UILanguageFile); - strncat_s(fv->DlgCaption, sizeof(fv->DlgCaption), uimsg, _TRUNCATE); - break; - case IdKmtFinish: - get_lang_msg("FILEDLG_TRANS_TITLE_KMTFIN", uimsg, sizeof(uimsg), TitKmtFin, UILanguageFile); - strncat_s(fv->DlgCaption, sizeof(fv->DlgCaption), uimsg, _TRUNCATE); - break; - } - SetWindowText(fv->HWin,fv->DlgCaption); SetDlgItemText(fv->HWin, IDC_PROTOPROT, "Kermit"); @@ -1281,6 +1259,8 @@ KmtSendInitPkt(fv,kv,cv,'I'); break; } + + return TRUE; } void KmtTimeOutProc(PFileVarProto fv, PComVar cv) @@ -1643,6 +1623,12 @@ return -1; } +static void Destroy(PFileVarProto fv) +{ + free(fv->data); + fv->data = NULL; +} + BOOL KmtCreate(PFileVarProto fv) { PKmtVar kv; @@ -1653,6 +1639,7 @@ memset(kv, 0, sizeof(*kv)); fv->data = kv; + fv->Destroy = Destroy; fv->Init = KmtInit; fv->Parse = KmtReadPacket; fv->TimeOutProc = KmtTimeOutProc; Modified: branches/proto_unicode/teraterm/ttpfile/quickvan.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/quickvan.c 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/quickvan.c 2020-11-01 15:33:26 UTC (rev 8988) @@ -161,7 +161,7 @@ qv->QVState = QV_Close; } -void QVInit(PFileVarProto fv, PComVar cv, PTTSet ts) +BOOL QVInit(PFileVarProto fv, PComVar cv, PTTSet ts) { char uimsg[MAX_UIMSG]; PQVVar qv = fv->data; @@ -211,6 +211,8 @@ QVSendNAK(fv,qv,cv); break; } + + return TRUE; } void QVCancel(PFileVarProto fv, PComVar cv) @@ -1319,6 +1321,12 @@ return -1; } +static void Destroy(PFileVarProto fv) +{ + free(fv->data); + fv->data = NULL; +} + BOOL QVCreate(PFileVarProto fv) { PQVVar qv = malloc(sizeof(*qv)); @@ -1328,6 +1336,7 @@ memset(qv, 0, sizeof(*qv)); fv->data = qv; + fv->Destroy = Destroy; fv->Init = QVInit; fv->Parse = QVParse; fv->TimeOutProc = QVTimeOutProc; Modified: branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/ttfile_proto.cpp 2020-11-01 15:33:26 UTC (rev 8988) @@ -53,6 +53,7 @@ #include <io.h> #include <assert.h> +#if 0 void _ProtoInit(int Proto, PFileVarProto fv, PComVar cv, PTTSet ts) { switch (Proto) { @@ -76,6 +77,7 @@ break; } } +#endif BOOL _ProtoParse(int Proto, PFileVarProto fv, PComVar cv) { Modified: branches/proto_unicode/teraterm/ttpfile/xmodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/xmodem.c 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/xmodem.c 2020-11-01 15:33:26 UTC (rev 8988) @@ -218,7 +218,7 @@ (LOBYTE(Check) == xv->PktIn[xv->DataLen + 4])); } -void XInit(PFileVarProto fv, PComVar cv, PTTSet ts) +BOOL XInit(PFileVarProto fv, PComVar cv, PTTSet ts) { PXVar xv = fv->data; fv->LogFlag = ((ts->LogFlag & LOG_X) != 0); @@ -228,10 +228,19 @@ fv->LogCount = 0; fv->FileSize = 0; - if ((xv->XMode == IdXSend) && fv->FileOpen) { + if (xv->XMode == IdXSend) { + fv->FileHandle = _lopen(fv->FullName,OF_READ); + if (fv->FileHandle == INVALID_HANDLE_VALUE) { + return FALSE; + } + fv->FileOpen = TRUE; fv->FileSize = fv->GetFSize(fv, fv->FullName); fv->InitDlgProgress(fv, &fv->ProgStat); } else { + fv->FileHandle = _lcreat(fv->FullName,0); + if (fv->FileHandle == INVALID_HANDLE_VALUE) { + return FALSE; + } fv->ProgStat = -1; } fv->StartTime = GetTickCount(); @@ -289,6 +298,8 @@ XSendNAK(fv, xv, cv); break; } + + return TRUE; } void XCancel(PFileVarProto fv, PComVar cv) @@ -644,6 +655,12 @@ return -1; } +static void Destroy(PFileVarProto fv) +{ + free(fv->data); + fv->data = NULL; +} + BOOL XCreate(PFileVarProto fv) { PXVar xv; @@ -654,6 +671,7 @@ memset(xv, 0, sizeof(*xv)); fv->data = xv; + fv->Destroy = Destroy; fv->Init = XInit; fv->Parse = XParse; fv->TimeOutProc = XTimeOutProc; Modified: branches/proto_unicode/teraterm/ttpfile/xmodem.h =================================================================== --- branches/proto_unicode/teraterm/ttpfile/xmodem.h 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/xmodem.h 2020-11-01 15:33:26 UTC (rev 8988) @@ -42,12 +42,6 @@ }; BOOL XCreate(PFileVarProto fv); -#if 0 -void XInit(PFileVarProto fv, PComVar cv, PTTSet ts); -void XCancel(PFileVarProto fv, PComVar cv); -void XTimeOutProc(PFileVarProto fv, PComVar cv); -BOOL XParse(PFileVarProto fv, PComVar cv); -#endif #ifdef __cplusplus } Modified: branches/proto_unicode/teraterm/ttpfile/ymodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ymodem.c 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/ymodem.c 2020-11-01 15:33:26 UTC (rev 8988) @@ -96,7 +96,9 @@ #define XnakNAK 1 #define XnakC 2 -int YRead1Byte(PFileVarProto fv, PYVar yv, PComVar cv, LPBYTE b) +static void YCancel(PFileVarProto fv, PComVar cv); + +static int YRead1Byte(PFileVarProto fv, PYVar yv, PComVar cv, LPBYTE b) { if (CommRead1Byte(cv,b) == 0) return 0; @@ -120,7 +122,7 @@ return 1; } -int YWrite(PFileVarProto fv, PYVar yv, PComVar cv, PCHAR B, int C) +static int YWrite(PFileVarProto fv, PYVar yv, PComVar cv, PCHAR B, int C) { int i, j; @@ -334,7 +336,7 @@ yv->LastMessage = 0; } -void YInit(PFileVarProto fv, PComVar cv, PTTSet ts) +BOOL YInit(PFileVarProto fv, PComVar cv, PTTSet ts) { char inistr[MAX_PATH + 10]; PYVar yv = fv->data; @@ -341,7 +343,7 @@ if (yv->YMode == IdYSend) { if (!GetNextFname(fv)) { - return; + return FALSE; } } @@ -420,9 +422,11 @@ break; } + + return TRUE; } -void YCancel(PFileVarProto fv, PComVar cv) +static void YCancel(PFileVarProto fv, PComVar cv) { // five cancels & five backspaces per spec BYTE cancel[] = { CAN, CAN, CAN, CAN, CAN, BS, BS, BS, BS, BS }; @@ -1120,6 +1124,12 @@ return -1; } +static void Destroy(PFileVarProto fv) +{ + free(fv->data); + fv->data = NULL; +} + BOOL YCreate(PFileVarProto fv) { PYVar pv; @@ -1130,6 +1140,7 @@ memset(pv, 0, sizeof(*pv)); fv->data = pv; + fv->Destroy = Destroy; fv->Init = YInit; fv->Parse = YParse; fv->TimeOutProc = YTimeOutProc; Modified: branches/proto_unicode/teraterm/ttpfile/ymodem.h =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ymodem.h 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/ymodem.h 2020-11-01 15:33:26 UTC (rev 8988) @@ -41,11 +41,6 @@ /* prototypes */ BOOL YCreate(PFileVarProto fv); -#if 1 -void YInit(PFileVarProto fv, PComVar cv, PTTSet ts); -void YCancel(PFileVarProto fv, PComVar cv); -void YTimeOutProc(PFileVarProto fv, PComVar cv); -#endif #ifdef __cplusplus } Modified: branches/proto_unicode/teraterm/ttpfile/zmodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/zmodem.c 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/zmodem.c 2020-11-01 15:33:26 UTC (rev 8988) @@ -692,7 +692,8 @@ add_sendbuf("%s: ", __FUNCTION__); } -void ZInit(PFileVarProto fv, PComVar cv, PTTSet ts) { +BOOL ZInit(PFileVarProto fv, PComVar cv, PTTSet ts) +{ int Max; char uimsg[MAX_UIMSG]; const char *UILanguageFile = ts->UILanguageFile; @@ -808,6 +809,8 @@ ZSendRQInit(fv, zv, cv); break; } + + return TRUE; } void ZTimeOutProc(PFileVarProto fv, PComVar cv) @@ -1497,6 +1500,12 @@ return -1; } +static void Destroy(PFileVarProto fv) +{ + free(fv->data); + fv->data = NULL; +} + BOOL ZCreate(PFileVarProto fv) { PZVar zv; @@ -1507,6 +1516,7 @@ memset(zv, 0, sizeof(*zv)); fv->data = zv; + fv->Destroy = Destroy; fv->Init = ZInit; fv->Parse = ZParse; fv->TimeOutProc = ZTimeOutProc; Modified: branches/proto_unicode/teraterm/ttpfile/zmodem.h =================================================================== --- branches/proto_unicode/teraterm/ttpfile/zmodem.h 2020-11-01 15:33:08 UTC (rev 8987) +++ branches/proto_unicode/teraterm/ttpfile/zmodem.h 2020-11-01 15:33:26 UTC (rev 8988) @@ -40,12 +40,6 @@ /* prototypes */ BOOL ZCreate(PFileVarProto fv); -#if 0 -void ZInit(PFileVarProto fv, PComVar cv, PTTSet ts); -void ZTimeOutProc(PFileVarProto fv, PComVar cv); -BOOL ZParse(PFileVarProto fv, PComVar cv); -void ZCancel(PFileVarProto fv, PComVar cv); -#endif #ifdef __cplusplus }