[Ttssh2-commit] [9092] ファイル関連を分離

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 12月 20日 (日) 21:13:46 JST


Revision: 9092
          https://osdn.net/projects/ttssh2/scm/svn/commits/9092
Author:   zmatsuo
Date:     2020-12-20 21:13:46 +0900 (Sun, 20 Dec 2020)
Log Message:
-----------
ファイル関連を分離

- filesys_io.h 追加
  - ファイルに関連するインターフェイス
  - プロトコル関連のファイルioはこのインターフェイスを使用する
- filesys_win32.c,h を Windows ファイル関連として分離
  - ANSI, UTF-8 を切り替えられる

Modified Paths:
--------------
    trunk/teraterm/teraterm/CMakeLists.txt
    trunk/teraterm/teraterm/filesys_proto.cpp
    trunk/teraterm/teraterm/filesys_proto.h
    trunk/teraterm/ttpfile/bplus.c
    trunk/teraterm/ttpfile/filesys_win32.cpp
    trunk/teraterm/ttpfile/filesys_win32.h
    trunk/teraterm/ttpfile/ftlib.c
    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/filesys_io.h

-------------- next part --------------
Modified: trunk/teraterm/teraterm/CMakeLists.txt
===================================================================
--- trunk/teraterm/teraterm/CMakeLists.txt	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/teraterm/CMakeLists.txt	2020-12-20 12:13:46 UTC (rev 9092)
@@ -182,6 +182,7 @@
   PRIVATE
   ../ttpfile/bplus.c
   ../ttpfile/bplus.h
+  ../ttpfile/filesys_io.h
   ../ttpfile/filesys_win32.cpp
   ../ttpfile/filesys_win32.h
   ../ttpfile/ftlib.c

Modified: trunk/teraterm/teraterm/filesys_proto.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys_proto.cpp	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/teraterm/filesys_proto.cpp	2020-12-20 12:13:46 UTC (rev 9092)
@@ -155,7 +155,7 @@
 	fv->NoMsg = FALSE;
 	fv->HideDialog = FALSE;
 
-	FilesysCreate(fv);
+	fv->file = FilesysCreateWin32();
 
 	fv->InitDlgProgress = _InitDlgProgress;
 	fv->SetDlgTime = _SetDlgTime;
@@ -180,24 +180,10 @@
 		fv->Destroy(fv);
 	}
 
-	if (fv->FileOpen) {
-		fv->Close(fv);
-		fv->FileOpen = FALSE;
-	}
-#if 0
-	if (fv->FnStrMem != NULL) {
-		free(fv->FnStrMem);
-	}
-	if (fv->FnStrMemHandle != 0)
-	{
-		GlobalUnlock(fv->FnStrMemHandle);
-		GlobalFree(fv->FnStrMemHandle);
-	}
-#endif
 	if (fv->FileNames != NULL) {
 		free(fv->FileNames);
 	}
-	fv->FileSysDestroy(fv);
+	fv->file->FileSysDestroy(fv->file);
 	free(fv);
 
 	*pfv = NULL;

Modified: trunk/teraterm/teraterm/filesys_proto.h
===================================================================
--- trunk/teraterm/teraterm/filesys_proto.h	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/teraterm/filesys_proto.h	2020-12-20 12:13:46 UTC (rev 9092)
@@ -28,7 +28,7 @@
 
 #pragma once
 
-#include <sys/types.h>	// for struct utimbuf
+#include "filesys_io.h"
 
 typedef struct FileVarProto {
 	// protosys_proto.cpp\x93\xE0\x82̂ݎg\x97p
@@ -73,21 +73,6 @@
 	void (*Destroy)(struct FileVarProto *fv);
 	void *data;
 
-	// file I/O, Filename related functions
-	BOOL (*OpenRead)(struct FileVarProto *fv, const char *filename);
-	BOOL (*OpenWrite)(struct FileVarProto *fv, const char *filename);
-	size_t (*ReadFile)(struct FileVarProto *fv, void *buf, size_t bytes);
-	size_t (*WriteFile)(struct FileVarProto *fv, const void *buf, size_t bytes);
-	void (*Close)(struct FileVarProto *fv);
-	int (*Seek)(struct FileVarProto *fv, size_t offset);
-	void (*FileSysDestroy)(struct FileVarProto *fv);
-	HANDLE FileHandle;
-	//
-	size_t (*GetFSize)(struct FileVarProto *fv, const char *filename);
-	int (*utime)(const char *filename, struct _utimbuf* const _Time);
-	int (*stat)(const char *filename, struct _stati64* _Stat);
-	BOOL (*SetFilenameEncodeUTF8)(BOOL utf8);
-
 	// UI
 	void (*InitDlgProgress)(struct FileVarProto *fv, int *CurProgStat);
 	void (*SetDlgTime)(struct FileVarProto *fv, DWORD elapsed, int bytes);
@@ -96,5 +81,7 @@
 	void (*SetDlgPercent)(struct FileVarProto *fv, LONG a, LONG b, int *p);
 	void (*SetDlgProtoText)(struct FileVarProto *fv, const char *text);
 	void (*SetDlgProtoFileName)(struct FileVarProto *fv, const char *text);
+
+	TFileIO *file;
 } TFileVarProto;
 typedef TFileVarProto *PFileVarProto;

Modified: trunk/teraterm/ttpfile/bplus.c
===================================================================
--- trunk/teraterm/ttpfile/bplus.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/bplus.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -102,15 +102,16 @@
 static BOOL BPOpenFileToBeSent(PFileVarProto fv)
 {
   BOOL r;
+  TFileIO *fileio = fv->file;
 
   if (fv->FileOpen) return TRUE;
   if (fv->FullName[0]==0) return FALSE;
 
-  r = fv->OpenRead(fv, fv->FullName);
+  r = fileio->OpenRead(fileio, fv->FullName);
   fv->FileOpen = r;
   if (r == TRUE) {
     fv->SetDlgProtoFileName(fv, fv->FullName);
-    fv->FileSize = fv->GetFSize(fv, fv->FullName);
+    fv->FileSize = fileio->GetFSize(fileio, fv->FullName);
   }
   return fv->FileOpen;
 }
@@ -504,12 +505,13 @@
 {
   int i, c;
   BYTE b;
+  TFileIO *fileio = fv->file;
 
   i = 4;
   c = 1;
   while ((i-4 < bv->PktSize-1) && (c>0))
   {
-    c = fv->ReadFile(fv, &b, 1);
+    c = fileio->ReadFile(fileio, &b, 1);
     if (c==1)
       BPPut1Byte(bv,b,&i);
     fv->ByteCount = fv->ByteCount + c;
@@ -516,7 +518,7 @@
   }
   if (c==0)
   {
-    fv->Close(fv);
+    fileio->Close(fileio);
     fv->FileOpen = FALSE;
   }
   i = i - 4;
@@ -578,12 +580,13 @@
 //  char Temp[HostNameMaxLength + 1]; // 81(yutaka)
   char Temp[81]; // 81(yutaka)
   int FnPos;
+  TFileIO *fileio = fv->file;
 
   switch (bv->PktIn[2]) {
     case 'C': /* Close */
       if (fv->FileOpen)
       {
-	fv->Close(fv);
+	fileio->Close(fileio);
 	fv->FileOpen = FALSE;
       }
       fv->Success = TRUE;
@@ -699,6 +702,7 @@
 
 static void BPParsePacket(PFileVarProto fv, PBPVar bv)
 {
+  TFileIO *fileio = fv->file;
   bv->GetPacket = FALSE;
   /* Packet type */
 
@@ -724,7 +728,7 @@
 	BPSendFailure(bv,'E');
 	return;
       }
-      fv->WriteFile(fv, &(bv->PktIn[2]), bv->PktInCount-2);
+      fileio->WriteFile(fileio, &(bv->PktIn[2]), bv->PktInCount-2);
       fv->ByteCount = fv->ByteCount +
 		      bv->PktInCount - 2;
       SetDlgNum(fv->HWin, IDC_PROTOBYTECOUNT, fv->ByteCount);

Copied: trunk/teraterm/ttpfile/filesys_io.h (from rev 9091, trunk/teraterm/ttpfile/filesys_win32.h)
===================================================================
--- trunk/teraterm/ttpfile/filesys_io.h	                        (rev 0)
+++ trunk/teraterm/ttpfile/filesys_io.h	2020-12-20 12:13:46 UTC (rev 9092)
@@ -0,0 +1,52 @@
+/*
+ * (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
+
+#include <sys/types.h>	// for struct utimbuf
+#include <sys/stat.h>
+#include <sys/utime.h>
+
+typedef struct FileIO {
+	// file I/O, Filename related functions
+	BOOL (*OpenRead)(struct FileIO *fv, const char *filename);
+	BOOL (*OpenWrite)(struct FileIO *fv, const char *filename);
+	size_t (*ReadFile)(struct FileIO *fv, void *buf, size_t bytes);
+	size_t (*WriteFile)(struct FileIO *fv, const void *buf, size_t bytes);
+	void (*Close)(struct FileIO *fv);
+	int (*Seek)(struct FileIO *fv, size_t offset);
+	void (*FileSysDestroy)(struct FileIO *fv);
+	//
+	size_t (*GetFSize)(struct FileIO *fv, const char *filename);
+	int (*utime)(struct FileIO *fv, const char *filename, struct _utimbuf* const _Time);
+	int (*stat)(struct FileIO *fv, const char *filename, struct _stati64* _Stat);
+	//
+	BOOL (*SetFilenameEncodeUTF8)(struct FileIO *fv, BOOL utf8);
+	//
+	void *data;
+} TFileIO;

Modified: trunk/teraterm/ttpfile/filesys_win32.cpp
===================================================================
--- trunk/teraterm/ttpfile/filesys_win32.cpp	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/filesys_win32.cpp	2020-12-20 12:13:46 UTC (rev 9092)
@@ -30,40 +30,64 @@
 #include <sys/stat.h>
 #include <sys/utime.h>
 
+#include "filesys_io.h"
+#include "filesys_win32.h"
+
 #include "tttypes.h"
+#include "layer_for_unicode.h"
 #include "codeconv.h"
 
-#include "filesys_win32.h"
+typedef struct FileIOWin32 {
+	HANDLE FileHandle;
+	BOOL utf32;
+} TFileIOWin32;
 
-static BOOL _OpenRead(TFileVarProto *fv, const char *filename)
+static wc GetFilenameW(TFileIOWin32 *data, const char *filename)
 {
-	HANDLE hFile = CreateFileA(filename,
+	wc filenameW;
+	if (data->utf32) {
+		filenameW = wc::fromUtf8(filename);
+	}
+	else {
+		filenameW = wc(filename);
+	}
+	return filenameW;
+}
+
+static BOOL _OpenRead(TFileIO *fv, const char *filename)
+{
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	wc filenameW = GetFilenameW(data, filename);
+	HANDLE hFile = _CreateFileW(filenameW,
 							   GENERIC_READ, FILE_SHARE_READ, NULL,
 							   OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 	if (hFile == INVALID_HANDLE_VALUE) {
-		fv->FileHandle = INVALID_HANDLE_VALUE;
+		data->FileHandle = INVALID_HANDLE_VALUE;
 		return FALSE;
 	}
-	fv->FileHandle = hFile;
+	data->FileHandle = hFile;
 	return TRUE;
 }
 
-static BOOL _OpenWrite(TFileVarProto *fv, const char *filename)
+static BOOL _OpenWrite(TFileIO *fv, const char *filename)
 {
-	HANDLE hFile = CreateFileA(filename,
-							   GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
-							   CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	wc filenameW = GetFilenameW(data, filename);
+	HANDLE hFile = _CreateFileW(filenameW,
+								GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
+								CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 	if (hFile == INVALID_HANDLE_VALUE) {
-		fv->FileHandle = INVALID_HANDLE_VALUE;
+		data->FileHandle = INVALID_HANDLE_VALUE;
 		return FALSE;
 	}
-	fv->FileHandle = hFile;
+	data->FileHandle = hFile;
 	return TRUE;
 }
 
-static size_t _ReadFile(TFileVarProto *fv, void *buf, size_t bytes)
+static size_t _ReadFile(TFileIO *fv, void *buf, size_t bytes)
 {
-	HANDLE hFile = fv->FileHandle;
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	HANDLE hFile = data->FileHandle;
 	DWORD NumberOfBytesRead;
 	BOOL Result = ReadFile(hFile, buf, (UINT)bytes, &NumberOfBytesRead, NULL);
 	if (Result == FALSE) {
@@ -72,9 +96,10 @@
 	return NumberOfBytesRead;
 }
 
-static size_t _WriteFile(TFileVarProto *fv, const void *buf, size_t bytes)
+static size_t _WriteFile(TFileIO *fv, const void *buf, size_t bytes)
 {
-	HANDLE hFile = fv->FileHandle;
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	HANDLE hFile = data->FileHandle;
 	DWORD NumberOfBytesWritten;
 	UINT length = (UINT)bytes;
 	BOOL result = WriteFile(hFile, buf, length, &NumberOfBytesWritten, NULL);
@@ -84,11 +109,12 @@
 	return NumberOfBytesWritten;
 }
 
-static void _Close(TFileVarProto *fv)
+static void _Close(TFileIO *fv)
 {
-	if (fv->FileHandle != INVALID_HANDLE_VALUE) {
-		CloseHandle(fv->FileHandle);
-		fv->FileHandle = INVALID_HANDLE_VALUE;
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	if (data->FileHandle != INVALID_HANDLE_VALUE) {
+		CloseHandle(data->FileHandle);
+		data->FileHandle = INVALID_HANDLE_VALUE;
 	}
 }
 
@@ -97,9 +123,11 @@
  *	@param[in]	filename		\x83t\x83@\x83C\x83\x8B\x96\xBC(UTF-8)
  *	@retval		\x83t\x83@\x83C\x83\x8B\x83T\x83C\x83Y
  */
-static size_t _GetFSize(struct FileVarProto *fv, const char *filename)
+static size_t _GetFSize(TFileIO *fv, const char *filename)
 {
-	size_t file_size = GetFSize64W(wc::fromUtf8(filename));
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	wc filenameW = GetFilenameW(data, filename);
+	size_t file_size = GetFSize64W(filenameW);
 	return file_size;
 }
 
@@ -109,8 +137,9 @@
  * TODO size_t \x88ȏ\xE3\x82̃t\x83@\x83C\x83\x8B\x82̈\xB5\x82\xA2
  *
  */
-static int Seek(struct FileVarProto *fv, size_t offset)
+static int Seek(TFileIO *fv, size_t offset)
 {
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
 #if _M_X64
 	// sizeof(size_t) == 8
 	LONG lo = (LONG)((offset >> 0) & 0xffffffff);
@@ -120,7 +149,7 @@
 	LONG lo = (LONG)((offset >> 0) & 0xffffffff);
 	LONG hi = 0;
 #endif
-	SetFilePointer(fv->FileHandle, lo, &hi, 0);
+	SetFilePointer(data->FileHandle, lo, &hi, 0);
 	if (GetLastError() != 0) {
 		return -1;
 	}
@@ -127,24 +156,43 @@
 	return 0;
 }
 
-static int _stat(const char *filename, struct _stati64* _Stat)
+static int __stat(TFileIO *fv, const char *filename, struct _stati64* _Stat)
 {
-	return _stati64(filename, _Stat);
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	wc filenameW = GetFilenameW(data, filename);
+	return _wstati64(filenameW, _Stat);
 }
 
-static int __utime(const char *filename, struct _utimbuf* const _Time)
+static int __utime(TFileIO *fv, const char *filename, struct _utimbuf* const _Time)
 {
-	return _utime(filename, _Time);
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
+	wc filenameW = GetFilenameW(data, filename);
+	return _wutime(filenameW, _Time);
 }
 
-static void FileSysDestroy(TFileVarProto *fv)
+static void FileSysDestroy(TFileIO *fv)
 {
+	TFileIOWin32 *data = (TFileIOWin32 *)fv->data;
 	fv->Close(fv);
+	free(data);
+	fv->data = NULL;
+	free(fv);
 }
 
-void FilesysCreate(TFileVarProto *fv)
+TFileIO *FilesysCreateWin32(void)
 {
-	fv->FileHandle = INVALID_HANDLE_VALUE;
+	TFileIOWin32 *data = (TFileIOWin32 *)calloc(sizeof(TFileIOWin32), 1);
+	if (data == NULL) {
+		return NULL;
+	}
+	data->FileHandle = INVALID_HANDLE_VALUE;
+	data->utf32 = FALSE;
+	TFileIO *fv = (TFileIO *)calloc(sizeof(TFileIO), 1);
+	if (fv == NULL) {
+		free(data);
+		return NULL;
+	}
+	fv->data = data;
 	fv->OpenRead = _OpenRead;
 	fv->OpenWrite = _OpenWrite;
 	fv->ReadFile = _ReadFile;
@@ -152,7 +200,8 @@
 	fv->Close = _Close;
 	fv->Seek = Seek;
 	fv->GetFSize = _GetFSize;
-	fv->utime = _utime;
-	fv->stat = _stat;
+	fv->utime = __utime;
+	fv->stat = __stat;
 	fv->FileSysDestroy = FileSysDestroy;
+	return fv;
 }

Modified: trunk/teraterm/ttpfile/filesys_win32.h
===================================================================
--- trunk/teraterm/ttpfile/filesys_win32.h	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/filesys_win32.h	2020-12-20 12:13:46 UTC (rev 9092)
@@ -27,8 +27,8 @@
  */
 
 #pragma once
-#include <windows.h>
-#include "tttypes.h"
-#include "filesys_proto.h"
 
-void FilesysCreate(TFileVarProto *fv);
+#include "filesys_io.h"
+#include "filesys_win32.h"
+
+TFileIO *FilesysCreateWin32(void);

Modified: trunk/teraterm/ttpfile/ftlib.c
===================================================================
--- trunk/teraterm/ttpfile/ftlib.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/ftlib.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -121,6 +121,7 @@
   int i;
   char Temp[MAX_PATH];
   int DirLen;
+  TFileIO *file = fv->file;
 
   GetFileNamePos(fv->FullName, &DirLen, &i);
   DirLen++;	// \x88\xEA\x94ԍŌ\xE3\x82\xCC '\\' \x82\xF0\x8Ew\x82\xB5\x82Ă\xA2\x82\xE9\x82̂\xC5 +1 \x82\xB5\x82Ă\xA8\x82\xAD
@@ -144,7 +145,7 @@
     }
     strncpy_s(fv->FullName, sizeof(fv->FullName),Temp, _TRUNCATE);
   }
-  fv->FileOpen = fv->OpenWrite(fv, fv->FullName);
+  fv->FileOpen = file->OpenWrite(file, fv->FullName);
   if (! fv->FileOpen && ! fv->NoMsg)
     MessageBox(fv->HMainWin,"Cannot create file",
 	       "Tera Term: Error",MB_ICONEXCLAMATION);

Modified: trunk/teraterm/ttpfile/kermit.c
===================================================================
--- trunk/teraterm/ttpfile/kermit.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/kermit.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -703,9 +703,10 @@
 			if (kv->Quote8 && BINflag) b = b ^ 0x80;
 			for (j = 1 ; j <= kv->RepeatCount ; j++)
 			{
-				if (Buff==NULL) /* write to file */
-					fv->WriteFile(fv,&b,1);
-				else /* write to buffer */
+				if (Buff==NULL) { /* write to file */
+					TFileIO *fileio = fv->file;
+					fileio->WriteFile(fileio,&b,1);
+				} else /* write to buffer */
 					if (BuffPtr < *BuffLen)
 					{
 						Buff[BuffPtr] = b;
@@ -872,6 +873,7 @@
 	BYTE b, b2, b7;
 	int Len;
 	char TempStr[4];
+	TFileIO *file = fv->file;
 
 	if ((kv->RepeatCount>0) && (strlen(kv->ByteStr)>0))
 	{
@@ -884,7 +886,7 @@
 		b = kv->NextByte;
 		kv->NextByteFlag = FALSE;
 	}
-	else if (fv->ReadFile(fv,&b,1)==0)
+	else if (file->ReadFile(file,&b,1)==0)
 		return FALSE;
 	else fv->ByteCount++;
 
@@ -921,7 +923,7 @@
 	TempStr[Len] = 0;
 
 	kv->RepeatCount = 1;
-	if (fv->ReadFile(fv,&(kv->NextByte),1)==1)
+	if (file->ReadFile(file,&(kv->NextByte),1)==1)
 	{
 		fv->ByteCount++;
 		kv->NextByteFlag = TRUE;
@@ -931,7 +933,7 @@
 		(kv->NextByte==b) && (kv->RepeatCount<94))
 	{
 		kv->RepeatCount++;
-		if (fv->ReadFile(fv,&(kv->NextByte),1)==0)
+		if (file->ReadFile(file,&(kv->NextByte),1)==0)
 			kv->NextByteFlag = FALSE;
 		else fv->ByteCount++;
 	}
@@ -961,8 +963,10 @@
 static void KmtSendEOFPacket(PFileVarProto fv, PKmtVar kv, PComVar cv)
 {
 	/* close file */
-	if (fv->FileOpen)
-		fv->Close(fv);
+	if (fv->FileOpen) {
+		TFileIO *file = fv->file;
+		file->Close(file);
+	}
 	fv->FileOpen = FALSE;
 
 	KmtIncPacketNum(kv);
@@ -1041,6 +1045,7 @@
 
 static BOOL KmtSendNextFile(PFileVarProto fv, PKmtVar kv, PComVar cv)
 {
+	TFileIO *file = fv->file;
 	struct _stati64 st;
 	BOOL r;
 	int FnPos;
@@ -1051,7 +1056,7 @@
 		return TRUE;
 	}
 
-	if (fv->stat(fv->FullName, &st) == 0) {
+	if (file->stat(file, fv->FullName, &st) == 0) {
 		kv->FileAttrFlag = KMT_ATTR_TIME | KMT_ATTR_MODE | KMT_ATTR_SIZE | KMT_ATTR_TYPE;
 		kv->FileType = FALSE; // Binary
 		kv->FileTime = st.st_mtime;
@@ -1062,7 +1067,7 @@
 	}
 
 	/* file open */
-	r = fv->OpenRead(fv, fv->FullName);
+	r = file->OpenRead(file, fv->FullName);
 	fv->FileOpen = r;
 	if (! fv->FileOpen)
 	{
@@ -1076,7 +1081,7 @@
 		return FALSE;
 	}
 	else
-		fv->FileSize = fv->GetFSize(fv, fv->FullName);
+		fv->FileSize = file->GetFSize(file, fv->FullName);
 
 	fv->ByteCount = 0;
 	fv->ProgStat = 0;
@@ -1577,7 +1582,8 @@
 	case 'Z':
 		if (kv->KmtState == ReceiveData)
 		{
-			if (fv->FileOpen) fv->Close(fv);
+			TFileIO *file = fv->file;
+			if (fv->FileOpen) file->Close(file);
 			fv->FileOpen = FALSE;
 			kv->KmtState = ReceiveFile;
 
@@ -1587,7 +1593,7 @@
 				memset(&utm, 0, sizeof(utm));
 				utm.actime  = kv->FileTime;
 				utm.modtime = kv->FileTime;
-				fv->utime(fv->FullName, &utm);
+				file->utime(file, fv->FullName, &utm);
 			}
 		}
 	}

Modified: trunk/teraterm/ttpfile/quickvan.c
===================================================================
--- trunk/teraterm/ttpfile/quickvan.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/quickvan.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -481,6 +481,7 @@
 
 static BOOL QVParseVENQ(PFileVarProto fv, PQVVar qv)
 {
+  TFileIO *file = fv->file;
   struct tm time;
   struct utimbuf timebuf;
 
@@ -494,7 +495,7 @@
     {
       if (fv->FileOpen)
       {
-	fv->Close(fv);
+	file->Close(file);
 	fv->FileOpen = FALSE;
 	/* set file date & time */
 	if ((qv->Year >= 1900) && (qv->Hour < 24))
@@ -533,6 +534,7 @@
 
 static void QVWriteToFile(PFileVarProto fv, PQVVar qv)
 {
+  TFileIO *file = fv->file;
   int C;
 
   if (fv->FileSize - fv->ByteCount < 128)
@@ -539,7 +541,7 @@
     C = fv->FileSize - fv->ByteCount;
   else
     C = 128;
-  fv->WriteFile(fv,&(qv->PktIn[3]),C);
+  file->WriteFile(file,&(qv->PktIn[3]),C);
   fv->ByteCount = fv->ByteCount + C;
 
   SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, qv->SeqNum);
@@ -829,6 +831,7 @@
   char fullname_upper[MAX_PATH];
   BOOL r;
   int FnPos;
+  TFileIO *file = fv->file;
 
   if (! GetNextFname(fv))
   {
@@ -837,7 +840,7 @@
   }
 
   /* find file and get file info */
-  fv->FileSize = fv->GetFSize(fv, fv->FullName);
+  fv->FileSize = file->GetFSize(file, fv->FullName);
   if (fv->FileSize>0)
   {
     qv->FileEnd = (WORD)(fv->FileSize >> 7);
@@ -850,7 +853,7 @@
   }
 
   /* file open */
-  r = fv->OpenRead(fv, fv->FullName);
+  r = file->OpenRead(file, fv->FullName);
   fv->FileOpen = r;
   if (! fv->FileOpen)
   {
@@ -907,6 +910,7 @@
 {
   int i, C;
   LONG Pos;
+  TFileIO *file = fv->file;
 
   if ((qv->QVState != QV_SendData) &&
       (qv->QVState != QV_SendDataRetry))
@@ -923,8 +927,8 @@
     else
       C = 128;
     /* read data from file */
-	fv->Seek(fv, Pos);
-    fv->ReadFile(fv,&(qv->PktOut[3]),C);
+	file->Seek(file, Pos);
+    file->ReadFile(file,&(qv->PktOut[3]),C);
     fv->ByteCount = Pos + (LONG)C;
     SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, qv->SeqSent);
     SetDlgNum(fv->HWin, IDC_PROTOBYTECOUNT, fv->ByteCount);
@@ -1095,8 +1099,9 @@
 
   if (qv->EnqFlag && (qv->PktIn[3]==0x30))
   {
+	TFileIO *file = fv->file;
     if (fv->FileOpen)
-      fv->Close(fv);
+      file->Close(file);
     fv->FileOpen = FALSE;
     qv->EnqFlag = FALSE;
     qv->RetryCount = 10;

Modified: trunk/teraterm/ttpfile/xmodem.c
===================================================================
--- trunk/teraterm/ttpfile/xmodem.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/xmodem.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -217,6 +217,7 @@
 
 BOOL XInit(PFileVarProto fv, PComVar cv, PTTSet ts)
 {
+	TFileIO *file = fv->file;
 	PXVar xv = fv->data;
 	BOOL LogFlag = ((ts->LogFlag & LOG_X) != 0);
 	if (LogFlag) {
@@ -228,14 +229,14 @@
 
 	fv->FileSize = 0;
 	if (xv->XMode == IdXSend) {
-		fv->FileOpen = fv->OpenRead(fv, fv->FullName);
+		fv->FileOpen = file->OpenRead(file, fv->FullName);
 		if (fv->FileOpen == FALSE) {
 			return FALSE;
 		}
-		fv->FileSize = fv->GetFSize(fv, fv->FullName);
+		fv->FileSize = file->GetFSize(file, fv->FullName);
 		fv->InitDlgProgress(fv, &fv->ProgStat);
 	} else {
-		fv->FileOpen = fv->OpenWrite(fv, fv->FullName);
+		fv->FileOpen = file->OpenWrite(file, fv->FullName);
 		if (fv->FileOpen == FALSE) {
 			return FALSE;
 		}
@@ -328,6 +329,7 @@
 	BYTE b, d;
 	int i, c;
 	BOOL GetPkt = FALSE;
+	TFileIO *file = fv->file;
 
 	for (c=XRead1Byte(fv, xv, cv, &b); (c > 0) && !GetPkt; c=XRead1Byte(fv, xv, cv, &b)) {
 		switch (xv->PktReadMode) {
@@ -450,13 +452,13 @@
 		for (i = 0; i <= c - 1; i++) {
 			b = xv->PktIn[3 + i];
 			if ((b == LF) && (!xv->CRRecv))
-				fv->WriteFile(fv, "\015", 1);
+				file->WriteFile(file, "\015", 1);
 			if (xv->CRRecv && (b != LF))
-				fv->WriteFile(fv, "\012", 1);
+				file->WriteFile(file, "\012", 1);
 			xv->CRRecv = b == CR;
-			fv->WriteFile(fv, &b, 1);
+			file->WriteFile(file, &b, 1);
 	} else
-		fv->WriteFile(fv, &(xv->PktIn[3]), c);
+		file->WriteFile(file, &(xv->PktIn[3]), c);
 
 	fv->ByteCount = fv->ByteCount + c;
 
@@ -538,6 +540,8 @@
 		} while (i != 0);
 
 		if (xv->PktNumSent == xv->PktNum) {	/* make a new packet */
+			TFileIO *file = fv->file;
+
 			xv->PktNumSent++;
 			if (xv->DataLen == 128)
 				xv->PktOut[0] = SOH;
@@ -548,7 +552,7 @@
 
 			i = 1;
 			while ((i <= xv->DataLen) && fv->FileOpen &&
-				   (fv->ReadFile(fv, &b, 1) == 1)) {
+				   (file->ReadFile(file, &b, 1) == 1)) {
 				xv->PktOut[2 + i] = b;
 				i++;
 				fv->ByteCount++;
@@ -570,7 +574,7 @@
 				xv->PktBufCount = 3 + xv->DataLen + xv->CheckLen;
 			} else {			/* send EOT */
 				if (fv->FileOpen) {
-					fv->Close(fv);
+					file->Close(file);
 					fv->FileOpen = FALSE;
 				}
 				xv->PktOut[0] = EOT;

Modified: trunk/teraterm/ttpfile/ymodem.c
===================================================================
--- trunk/teraterm/ttpfile/ymodem.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/ymodem.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -293,16 +293,17 @@
 
 static void initialize_file_info(PFileVarProto fv, PYVar yv)
 {
+	TFileIO *file = fv->file;
 	if (yv->YMode == IdYSend) {
 		if (fv->FileOpen) {
-			fv->Close(fv);
+			file->Close(file);
 
 			if (fv->FileMtime > 0) {
 				SetFMtime(fv->FullName, fv->FileMtime);
 			}
 		}
-		fv->FileOpen = fv->OpenRead(fv, fv->FullName);
-		fv->FileSize = fv->GetFSize(fv, fv->FullName);
+		fv->FileOpen = file->OpenRead(file, fv->FullName);
+		fv->FileSize = file->GetFSize(file, fv->FullName);
 	} else {
 		fv->FileOpen = FALSE;
 		fv->FileSize = 0;
@@ -459,6 +460,7 @@
 	BYTE b, d;
 	int i, c, nak;
 	BOOL GetPkt;
+	TFileIO *file = fv->file;
 
 	c = YRead1Byte(fv,yv,cv,&b);
 
@@ -487,7 +489,7 @@
 			{
 				// EOT\x82\xAA\x97\x88\x82\xBD\x82\xE7\x81A1\x82‚̃t\x83@\x83C\x83\x8B\x8E\xF3\x90M\x82\xAA\x8A\xAE\x97\xB9\x82\xB5\x82\xBD\x82\xB1\x82Ƃ\xF0\x8E\xA6\x82\xB7\x81B
 				if (fv->FileOpen) {
-					fv->Close(fv);
+					file->Close(file);
 					fv->FileOpen = FALSE;
 
 					if (fv->FileMtime > 0) {
@@ -669,14 +671,14 @@
 		{
 			b = yv->PktIn[3+i];
 			if ((b==LF) && (! yv->CRRecv))
-				fv->WriteFile(fv,"\015",1);
+				file->WriteFile(file,"\015",1);
 			if (yv->CRRecv && (b!=LF))
-				fv->WriteFile(fv,"\012",1);
+				file->WriteFile(file,"\012",1);
 			yv->CRRecv = b==CR;
-			fv->WriteFile(fv,&b,1);
+			file->WriteFile(file,&b,1);
 		}
 	else
-		fv->WriteFile(fv, &(yv->PktIn[3]), c);
+		file->WriteFile(file, &(yv->PktIn[3]), c);
 
 	fv->ByteCount = fv->ByteCount + c;
 
@@ -950,6 +952,7 @@
 
 			else
 			{
+				TFileIO *file = fv->file;
 				BYTE fsym = 0;
 				size_t idx = 1;
 
@@ -956,7 +959,7 @@
 				yv->__DataLen = current_packet_size;
 
 				while ((idx <= current_packet_size) && fv->FileOpen &&
-				       (1 == fv->ReadFile(fv, &fsym, 1)))
+				       (1 == file->ReadFile(file, &fsym, 1)))
 				{
 					// TODO: remove magic number.
 					yv->PktOut[2 + idx] = fsym;
@@ -970,7 +973,7 @@
 					// Close file handle.
 					if (fv->FileOpen)
 					{
-						fv->Close(fv);
+						file->Close(file);
 						fv->FileOpen = FALSE;
 					}
 

Modified: trunk/teraterm/ttpfile/zmodem.c
===================================================================
--- trunk/teraterm/ttpfile/zmodem.c	2020-12-20 12:13:34 UTC (rev 9091)
+++ trunk/teraterm/ttpfile/zmodem.c	2020-12-20 12:13:46 UTC (rev 9092)
@@ -561,6 +561,7 @@
 {
 	int i, j;
 	int FNPos;
+	TFileIO *file = fv->file;
 
 	if (!fv->FileOpen) {
 		ZSendCancel(zv);
@@ -579,7 +580,7 @@
 	ZPutBin(zv, &(zv->PktOutCount), 0);
 	zv->CRC = UpdateCRC(0, zv->CRC);
 	/* file size */
-	fv->FileSize = fv->GetFSize(fv, fv->FullName);
+	fv->FileSize = file->GetFSize(file, fv->FullName);
 
 	/* timestamp */
 	fv->FileMtime = GetFMtime(fv->FullName);
@@ -635,6 +636,7 @@
 {
 	int c;
 	BYTE b;
+	TFileIO *file = fv->file;
 
 	if (zv->Pos >= fv->FileSize) {
 		zv->Pos = fv->FileSize;
@@ -645,12 +647,12 @@
 	fv->ByteCount = zv->Pos;
 
 	if (fv->FileOpen && (zv->Pos < fv->FileSize))
-		fv->Seek(fv, zv->Pos);
+		file->Seek(file, zv->Pos);
 
 	zv->CRC = 0;
 	zv->PktOutCount = 0;
 	do {
-		c = fv->ReadFile(fv, &b, 1);
+		c = file->ReadFile(file, &b, 1);
 		if (c > 0) {
 			ZPutBin(zv, &(zv->PktOutCount), b);
 			zv->CRC = UpdateCRC(b, zv->CRC);
@@ -847,6 +849,7 @@
 static void ZParseRInit(PFileVarProto fv, PZVar zv)
 {
 	int Max;
+	TFileIO *file = fv->file;
 
 	if ((zv->ZState != Z_SendInit) && (zv->ZState != Z_SendEOF))
 		return;
@@ -853,7 +856,7 @@
 
 	if (fv->FileOpen)			// close previous file
 	{
-		fv->Close(fv);
+		file->Close(file);
 		fv->FileOpen = FALSE;
 
 		if (fv->FileMtime > 0) {
@@ -868,7 +871,7 @@
 	}
 
 	/* file open */
-	fv->FileOpen = fv->OpenRead(fv, fv->FullName);
+	fv->FileOpen = file->OpenRead(file, fv->FullName);
 
 	if (zv->CtlEsc) {
 		if ((zv->RxHdr[ZF0] & ESCCTL) == 0) {
@@ -900,6 +903,7 @@
 
 static void ZParseHdr(PFileVarProto fv, PZVar zv, PComVar cv)
 {
+	TFileIO *file = fv->file;
 	add_recvbuf("%s: RxType %s ", __FUNCTION__, hdrtype_name(zv->RxType));
 
 	switch (zv->RxType) {
@@ -940,7 +944,7 @@
 		break;
 	case ZSKIP:
 		if (fv->FileOpen) {
-			fv->Close(fv);
+			file->Close(file);
 			// \x83T\x81[\x83o\x91\xA4\x82ɑ\xB6\x8D݂\xB7\x82\xE9\x83t\x83@\x83C\x83\x8B\x82𑗐M\x82\xB5\x82悤\x82Ƃ\xB7\x82\xE9\x82ƁAZParseRInit()\x82œ\xF1\x8Fdclose\x82ɂȂ邽\x82߁A
 			// \x82\xB1\x82\xB1\x82Ńt\x83\x89\x83O\x82𗎂Ƃ\xB5\x82Ă\xA8\x82\xAD\x81B (2007.12.20 yutaka)
 			fv->FileOpen = FALSE;
@@ -1013,9 +1017,9 @@
 			if (fv->FileOpen) {
 				if (zv->CRRecv) {
 					zv->CRRecv = FALSE;
-					fv->WriteFile(fv, "\012", 1);
+					file->WriteFile(file, "\012", 1);
 				}
-				fv->Close(fv);
+				file->Close(file);
 				fv->FileOpen = FALSE;
 
 				if (fv->FileMtime > 0) {
@@ -1096,6 +1100,7 @@
 
 static BOOL ZWriteData(PFileVarProto fv, PZVar zv)
 {
+	TFileIO *file = fv->file;
 	int i;
 	BYTE b;
 
@@ -1105,16 +1110,16 @@
 	FTSetTimeOut(fv, 0);
 
 	if (zv->BinFlag)
-		fv->WriteFile(fv, zv->PktIn, zv->PktInPtr);
+		file->WriteFile(file, zv->PktIn, zv->PktInPtr);
 	else
 		for (i = 0; i <= zv->PktInPtr - 1; i++) {
 			b = zv->PktIn[i];
 			if ((b == 0x0A) && (!zv->CRRecv))
-				fv->WriteFile(fv, "\015", 1);
+				file->WriteFile(file, "\015", 1);
 			if (zv->CRRecv && (b != 0x0A))
-				fv->WriteFile(fv, "\012", 1);
+				file->WriteFile(file, "\012", 1);
 			zv->CRRecv = b == 0x0D;
-			fv->WriteFile(fv, &b, 1);
+			file->WriteFile(file, &b, 1);
 		}
 
 	fv->ByteCount = fv->ByteCount + zv->PktInPtr;


Ttssh2-commit メーリングリストの案内
Back to archive index