[Ttssh2-commit] [8586] ttpmacro/fileread.cpp,h を common/ へ移動

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 3月 11日 (水) 00:30:12 JST


Revision: 8586
          https://osdn.net/projects/ttssh2/scm/svn/commits/8586
Author:   zmatsuo
Date:     2020-03-11 00:30:10 +0900 (Wed, 11 Mar 2020)
Log Message:
-----------
ttpmacro/fileread.cpp,h を common/ へ移動

Modified Paths:
--------------
    trunk/teraterm/common/CMakeLists.txt
    trunk/teraterm/common/common_static.v8.vcproj
    trunk/teraterm/teraterm/CMakeLists.txt
    trunk/teraterm/teraterm/clipboar.c
    trunk/teraterm/teraterm/sendmem.cpp
    trunk/teraterm/teraterm/ttermpro.vcproj
    trunk/teraterm/ttpmacro/CMakeLists.txt
    trunk/teraterm/ttpmacro/ttpmacro.vcproj

Added Paths:
-----------
    trunk/teraterm/common/fileread.cpp
    trunk/teraterm/common/fileread.h

Removed Paths:
-------------
    trunk/teraterm/ttpmacro/fileread.cpp
    trunk/teraterm/ttpmacro/fileread.h

-------------- next part --------------
Modified: trunk/teraterm/common/CMakeLists.txt
===================================================================
--- trunk/teraterm/common/CMakeLists.txt	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/common/CMakeLists.txt	2020-03-10 15:30:10 UTC (rev 8586)
@@ -19,6 +19,8 @@
   dlglib_tmpl.cpp
   dllutil.cpp
   dllutil.h
+  fileread.cpp
+  fileread.h
   getcontent.cpp
   getcontent.h
   i18n.h

Modified: trunk/teraterm/common/common_static.v8.vcproj
===================================================================
--- trunk/teraterm/common/common_static.v8.vcproj	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/common/common_static.v8.vcproj	2020-03-10 15:30:10 UTC (rev 8586)
@@ -221,6 +221,14 @@
 			>
 		</File>
 		<File
+			RelativePath=".\fileread.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\fileread.h"
+			>
+		</File>
+		<File
 			RelativePath=".\getcontent.cpp"
 			>
 		</File>

Copied: trunk/teraterm/common/fileread.cpp (from rev 8585, trunk/teraterm/ttpmacro/fileread.cpp)
===================================================================
--- trunk/teraterm/common/fileread.cpp	                        (rev 0)
+++ trunk/teraterm/common/fileread.cpp	2020-03-10 15:30:10 UTC (rev 8586)
@@ -0,0 +1,295 @@
+/*
+ * Copyright (C) 2018-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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || !defined(_MSC_VER)
+#include <stdint.h>
+#endif
+#include <windows.h>
+#include <tchar.h>
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+
+#include "codeconv.h"
+#include "fileread.h"
+
+#if defined(_MSC_VER) && (_MSC_VER < 1600)
+typedef unsigned char uint8_t;
+#endif
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	@param[out]	*_len		\x83T\x83C\x83Y(terminater\x8A܂\xDE)
+ *	@param[in]	terminate	TRUE	\x8DŌ\xE3\x82\xC9 L'\0' ("\0\0")\x82\xF0\x95t\x89\xC1
+ *							FALSE	\x83t\x83@\x83C\x83\x8B\x82\xF0\x82\xBB\x82̂܂ܓǂݍ\x9E\x82\xDE
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[ (fclose()\x82\xB7\x82邱\x82\xC6)
+ */
+static void *LoadRawFile(FILE *fp, size_t *_len, BOOL terminate)
+{
+    fseek(fp, 0L, SEEK_END);
+	fpos_t pos;
+	fgetpos(fp, &pos);
+    fseek(fp, 0L, SEEK_SET);
+	size_t len = (size_t)pos;
+	size_t alloc_len = terminate ? len + 2 : len;
+	char *buf = (char *)malloc(alloc_len);
+	if (buf == NULL) {
+		return NULL;
+	}
+	size_t rlen = fread(buf, 1, len, fp);
+	if (rlen != len) {
+		free(buf);
+		return NULL;
+	}
+	if (terminate) {
+		buf[len] = 0;
+		buf[len+1] = 0;		// UTF-16\x91΍\xF4
+	}
+	*_len = alloc_len;
+	return buf;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0\0"\x82\xF0\x8A܂\xDE)
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+static void *LoadRawFile(FILE *fp, size_t *_len)
+{
+	return LoadRawFile(fp, _len, TRUE);
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	\x89\xC1\x8DH\x82͍s\x82\xED\x82Ȃ\xA2
+ *	@param[out]	*_len	\x83T\x83C\x83Y
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+uint8_t *LoadFileBinary(const wchar_t *FileName, size_t *_len)
+{
+	FILE *fp;
+	_wfopen_s(&fp, FileName, L"rb");
+	if (fp == NULL) {
+		return NULL;
+	}
+	uint8_t *ptr = (uint8_t *)LoadRawFile(fp, _len, FALSE);
+	fclose(fp);
+	return ptr;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	\x92\x86\x90g\x82\xCDUTF-8\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+ *	\x83t\x83@\x83C\x83\x8B\x82̍Ō\xE3\x82\xCD '\0'\x82Ń^\x81[\x83~\x83l\x81[\x83g\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9
+ *
+ *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
+ *						NULL\x82̂Ƃ\xAB\x82͒\xB7\x82\xB3\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+char *LoadFileU8(FILE *fp, size_t *_len)
+{
+	size_t len;
+	void *vbuf = LoadRawFile(fp, &len);
+	if (vbuf == NULL) {
+		if (_len != NULL) {
+			*_len = 0;
+		}
+		return NULL;
+	}
+
+	uint8_t *buf = (uint8_t *)vbuf;
+	if (len >= 3 && (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)) {
+		// UTF-8 BOM
+		//		trim BOM
+		len -= 3;
+		memmove(&buf[0], &buf[3], len);
+	} else if(len >= 2 && (buf[0] == 0xff && buf[1] == 0xfe)) {
+		// UTF-16LE BOM
+		//		UTF-16LE -> UTF-8
+		const char *u8 = ToU8W((wchar_t *)&buf[2]);
+
+		free(buf);
+		buf = (uint8_t *)u8;
+	} else if(len >= 2 && (buf[0] == 0xfe && buf[1] == 0xff)) {
+		// UTF-16BE BOM
+		//		UTF-16BE -> UTF-16LE
+		{
+			uint8_t *p = &buf[2];
+			len -= 2;
+			len /= 2;
+			for (size_t i=0; i<len; i++) {
+				uint8_t t = *p;
+				*p = *(p+1);
+				*(p+1) = t;
+				p += 2;
+			};
+		}
+		//		UTF-16LE -> UTF-8
+		const char *u8 = ToU8W((wchar_t *)&buf[2]);
+
+		free(buf);
+		buf = (uint8_t *)u8;
+	} else {
+		// ACP? -> UTF-8
+		const char *u8 = ToU8A((char *)buf);
+		if (u8 != NULL) {
+			// ACP -> UTF-8
+			free(buf);
+			buf = (uint8_t *)u8;
+		}
+	}
+
+	if (_len != NULL) {
+		*_len = strlen((char *)buf)+1;	// \x89\xFC\x82߂Ē\xB7\x82\xB3\x82\xF0\x8Cv\x82\xE9
+	}
+	return (char *)buf;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	\x92\x86\x90g\x82\xCDUTF-8\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+ *
+ *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+char *LoadFileU8A(const char *FileName, size_t *_len)
+{
+	*_len = 0;
+	FILE *fp = fopen(FileName, "rb");
+	if (fp == NULL) {
+		return NULL;
+	}
+	size_t len;
+	char *u8 = LoadFileU8(fp, &len);
+	fclose(fp);
+	if (u8 == NULL) {
+		return NULL;
+	}
+	*_len = len;
+	return u8;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	\x92\x86\x90g\x82\xCDwchar_t\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+ *
+ *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
+ *						NULL\x82̂Ƃ\xAB\x82͒\xB7\x82\xB3\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+wchar_t *LoadFileWA(const char *FileName, size_t *_len)
+{
+	if (_len != NULL) {
+		*_len = 0;
+	}
+	FILE *fp = fopen(FileName, "rb");
+	if (fp == NULL) {
+		return NULL;
+	}
+	char *u8 = LoadFileU8(fp, NULL);
+	fclose(fp);
+	if (u8 == NULL) {
+		return NULL;
+	}
+	wchar_t *u16 = ToWcharU8(u8);
+	free(u8);
+	if (u16 == NULL) {
+		return NULL;
+	}
+	if (_len != NULL) {
+		*_len = wcslen(u16);
+	}
+	return u16;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	\x92\x86\x90g\x82\xCDwchar_t\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+ *
+ *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
+ *						NULL\x82̂Ƃ\xAB\x82͒\xB7\x82\xB3\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+wchar_t *LoadFileWW(const wchar_t *FileName, size_t *_len)
+{
+	if (_len != NULL) {
+		*_len = 0;
+	}
+	FILE *fp = _wfopen(FileName, L"rb");
+	if (fp == NULL) {
+		return NULL;
+	}
+	char *u8 = LoadFileU8(fp, NULL);
+	fclose(fp);
+	if (u8 == NULL) {
+		return NULL;
+	}
+	wchar_t *u16 = ToWcharU8(u8);
+	free(u8);
+	if (u16 == NULL) {
+		return NULL;
+	}
+	if (_len != NULL) {
+		*_len = wcslen(u16);
+	}
+	return u16;
+}
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
+ *	\x92\x86\x90g\x82\xCDANSI Codepage\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+ *
+ *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
+ *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
+ *				NULL=\x83G\x83\x89\x81[
+ */
+char *LoadFileAA(const char *FileName, size_t *_len)
+{
+	*_len = 0;
+	size_t len;
+	char *u8 = LoadFileU8A(FileName, &len);
+	if (u8 == NULL) {
+		return NULL;
+	}
+	char *strA = (char *)ToCharU8(u8);
+	free(u8);
+	if (strA == NULL) {
+		return NULL;
+	}
+	len = strlen(strA);
+	*_len = len;
+	return strA;
+}

Copied: trunk/teraterm/common/fileread.h (from rev 8585, trunk/teraterm/ttpmacro/fileread.h)
===================================================================
--- trunk/teraterm/common/fileread.h	                        (rev 0)
+++ trunk/teraterm/common/fileread.h	2020-03-10 15:30:10 UTC (rev 8586)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018-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.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif//__cplusplus
+
+char *LoadFileU8A(const char *FileName, size_t *_len);
+char *LoadFileU8T(const TCHAR *FileName, size_t *_len);
+wchar_t *LoadFileWA(const char *FileName, size_t *_len);
+char *LoadFileAA(const char *FileName, size_t *_len);
+wchar_t *LoadFileWW(const wchar_t *FileName, size_t *_len);
+unsigned char *LoadFileBinary(const wchar_t *FileName, size_t *_len);
+
+#ifdef __cplusplus
+}
+#endif//__cplusplus

Modified: trunk/teraterm/teraterm/CMakeLists.txt
===================================================================
--- trunk/teraterm/teraterm/CMakeLists.txt	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/teraterm/CMakeLists.txt	2020-03-10 15:30:10 UTC (rev 8586)
@@ -86,8 +86,6 @@
   unicode_combine.tbl
   unicode_emoji.tbl
   #
-  ../ttpmacro/fileread.h
-  ../ttpmacro/fileread.cpp
   ftdlg_lite.h
   ftdlg_lite.cpp
   clipboarddlg.h

Modified: trunk/teraterm/teraterm/clipboar.c
===================================================================
--- trunk/teraterm/teraterm/clipboar.c	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/teraterm/clipboar.c	2020-03-10 15:30:10 UTC (rev 8586)
@@ -48,7 +48,7 @@
 
 #include "clipboar.h"
 #include "tt_res.h"
-#include "../ttpmacro/fileread.h"
+#include "fileread.h"
 #include "unicode_test.h"
 #include "sendmem.h"
 #include "clipboarddlg.h"

Modified: trunk/teraterm/teraterm/sendmem.cpp
===================================================================
--- trunk/teraterm/teraterm/sendmem.cpp	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/teraterm/sendmem.cpp	2020-03-10 15:30:10 UTC (rev 8586)
@@ -47,7 +47,7 @@
 #include "filesys.h"		// for SendVar
 #include "codeconv.h"		// for ToCharW()
 #else
-#include "../ttpmacro/fileread.h"
+#include "fileread.h"
 #endif
 
 #include "sendmem.h"

Modified: trunk/teraterm/teraterm/ttermpro.vcproj
===================================================================
--- trunk/teraterm/teraterm/ttermpro.vcproj	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/teraterm/ttermpro.vcproj	2020-03-10 15:30:10 UTC (rev 8586)
@@ -567,14 +567,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\ttpmacro\fileread.cpp"
-				>
-			</File>
-			<File
-				RelativePath="..\ttpmacro\fileread.h"
-				>
-			</File>
-			<File
 				RelativePath="ftdlg.cpp"
 				>
 			</File>

Modified: trunk/teraterm/ttpmacro/CMakeLists.txt
===================================================================
--- trunk/teraterm/ttpmacro/CMakeLists.txt	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/ttpmacro/CMakeLists.txt	2020-03-10 15:30:10 UTC (rev 8586)
@@ -47,8 +47,6 @@
   ttpmacro.rc
   ttm-version.rc
   ttmacro_manifest.rc
-  fileread.h
-  fileread.cpp
   )
 
 target_sources(

Deleted: trunk/teraterm/ttpmacro/fileread.cpp
===================================================================
--- trunk/teraterm/ttpmacro/fileread.cpp	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/ttpmacro/fileread.cpp	2020-03-10 15:30:10 UTC (rev 8586)
@@ -1,295 +0,0 @@
-/*
- * Copyright (C) 2018-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.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || !defined(_MSC_VER)
-#include <stdint.h>
-#endif
-#include <windows.h>
-#include <tchar.h>
-#define _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-
-#include "codeconv.h"
-#include "fileread.h"
-
-#if defined(_MSC_VER) && (_MSC_VER < 1600)
-typedef unsigned char uint8_t;
-#endif
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	@param[out]	*_len		\x83T\x83C\x83Y(terminater\x8A܂\xDE)
- *	@param[in]	terminate	TRUE	\x8DŌ\xE3\x82\xC9 L'\0' ("\0\0")\x82\xF0\x95t\x89\xC1
- *							FALSE	\x83t\x83@\x83C\x83\x8B\x82\xF0\x82\xBB\x82̂܂ܓǂݍ\x9E\x82\xDE
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[ (fclose()\x82\xB7\x82邱\x82\xC6)
- */
-static void *LoadRawFile(FILE *fp, size_t *_len, BOOL terminate)
-{
-    fseek(fp, 0L, SEEK_END);
-	fpos_t pos;
-	fgetpos(fp, &pos);
-    fseek(fp, 0L, SEEK_SET);
-	size_t len = (size_t)pos;
-	size_t alloc_len = terminate ? len + 2 : len;
-	char *buf = (char *)malloc(alloc_len);
-	if (buf == NULL) {
-		return NULL;
-	}
-	size_t rlen = fread(buf, 1, len, fp);
-	if (rlen != len) {
-		free(buf);
-		return NULL;
-	}
-	if (terminate) {
-		buf[len] = 0;
-		buf[len+1] = 0;		// UTF-16\x91΍\xF4
-	}
-	*_len = alloc_len;
-	return buf;
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0\0"\x82\xF0\x8A܂\xDE)
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-static void *LoadRawFile(FILE *fp, size_t *_len)
-{
-	return LoadRawFile(fp, _len, TRUE);
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	\x89\xC1\x8DH\x82͍s\x82\xED\x82Ȃ\xA2
- *	@param[out]	*_len	\x83T\x83C\x83Y
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-uint8_t *LoadFileBinary(const wchar_t *FileName, size_t *_len)
-{
-	FILE *fp;
-	_wfopen_s(&fp, FileName, L"rb");
-	if (fp == NULL) {
-		return NULL;
-	}
-	uint8_t *ptr = (uint8_t *)LoadRawFile(fp, _len, FALSE);
-	fclose(fp);
-	return ptr;
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	\x92\x86\x90g\x82\xCDUTF-8\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
- *	\x83t\x83@\x83C\x83\x8B\x82̍Ō\xE3\x82\xCD '\0'\x82Ń^\x81[\x83~\x83l\x81[\x83g\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9
- *
- *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
- *						NULL\x82̂Ƃ\xAB\x82͒\xB7\x82\xB3\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-char *LoadFileU8(FILE *fp, size_t *_len)
-{
-	size_t len;
-	void *vbuf = LoadRawFile(fp, &len);
-	if (vbuf == NULL) {
-		if (_len != NULL) {
-			*_len = 0;
-		}
-		return NULL;
-	}
-
-	uint8_t *buf = (uint8_t *)vbuf;
-	if (len >= 3 && (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)) {
-		// UTF-8 BOM
-		//		trim BOM
-		len -= 3;
-		memmove(&buf[0], &buf[3], len);
-	} else if(len >= 2 && (buf[0] == 0xff && buf[1] == 0xfe)) {
-		// UTF-16LE BOM
-		//		UTF-16LE -> UTF-8
-		const char *u8 = ToU8W((wchar_t *)&buf[2]);
-
-		free(buf);
-		buf = (uint8_t *)u8;
-	} else if(len >= 2 && (buf[0] == 0xfe && buf[1] == 0xff)) {
-		// UTF-16BE BOM
-		//		UTF-16BE -> UTF-16LE
-		{
-			uint8_t *p = &buf[2];
-			len -= 2;
-			len /= 2;
-			for (size_t i=0; i<len; i++) {
-				uint8_t t = *p;
-				*p = *(p+1);
-				*(p+1) = t;
-				p += 2;
-			};
-		}
-		//		UTF-16LE -> UTF-8
-		const char *u8 = ToU8W((wchar_t *)&buf[2]);
-
-		free(buf);
-		buf = (uint8_t *)u8;
-	} else {
-		// ACP? -> UTF-8
-		const char *u8 = ToU8A((char *)buf);
-		if (u8 != NULL) {
-			// ACP -> UTF-8
-			free(buf);
-			buf = (uint8_t *)u8;
-		}
-	}
-
-	if (_len != NULL) {
-		*_len = strlen((char *)buf)+1;	// \x89\xFC\x82߂Ē\xB7\x82\xB3\x82\xF0\x8Cv\x82\xE9
-	}
-	return (char *)buf;
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	\x92\x86\x90g\x82\xCDUTF-8\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
- *
- *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-char *LoadFileU8A(const char *FileName, size_t *_len)
-{
-	*_len = 0;
-	FILE *fp = fopen(FileName, "rb");
-	if (fp == NULL) {
-		return NULL;
-	}
-	size_t len;
-	char *u8 = LoadFileU8(fp, &len);
-	fclose(fp);
-	if (u8 == NULL) {
-		return NULL;
-	}
-	*_len = len;
-	return u8;
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	\x92\x86\x90g\x82\xCDwchar_t\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
- *
- *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
- *						NULL\x82̂Ƃ\xAB\x82͒\xB7\x82\xB3\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-wchar_t *LoadFileWA(const char *FileName, size_t *_len)
-{
-	if (_len != NULL) {
-		*_len = 0;
-	}
-	FILE *fp = fopen(FileName, "rb");
-	if (fp == NULL) {
-		return NULL;
-	}
-	char *u8 = LoadFileU8(fp, NULL);
-	fclose(fp);
-	if (u8 == NULL) {
-		return NULL;
-	}
-	wchar_t *u16 = ToWcharU8(u8);
-	free(u8);
-	if (u16 == NULL) {
-		return NULL;
-	}
-	if (_len != NULL) {
-		*_len = wcslen(u16);
-	}
-	return u16;
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	\x92\x86\x90g\x82\xCDwchar_t\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
- *
- *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
- *						NULL\x82̂Ƃ\xAB\x82͒\xB7\x82\xB3\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-wchar_t *LoadFileWW(const wchar_t *FileName, size_t *_len)
-{
-	if (_len != NULL) {
-		*_len = 0;
-	}
-	FILE *fp = _wfopen(FileName, L"rb");
-	if (fp == NULL) {
-		return NULL;
-	}
-	char *u8 = LoadFileU8(fp, NULL);
-	fclose(fp);
-	if (u8 == NULL) {
-		return NULL;
-	}
-	wchar_t *u16 = ToWcharU8(u8);
-	free(u8);
-	if (u16 == NULL) {
-		return NULL;
-	}
-	if (_len != NULL) {
-		*_len = wcslen(u16);
-	}
-	return u16;
-}
-
-/**
- *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE
- *	\x92\x86\x90g\x82\xCDANSI Codepage\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
- *
- *	@param[out]	*_len	\x83T\x83C\x83Y(\x8DŌ\xE3\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9"\0"\x82\xF0\x8A܂\xDE)
- *	@retval		\x83t\x83@\x83C\x83\x8B\x82̒\x86\x90g\x82ւ̃|\x83C\x83\x93\x83^(\x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6)
- *				NULL=\x83G\x83\x89\x81[
- */
-char *LoadFileAA(const char *FileName, size_t *_len)
-{
-	*_len = 0;
-	size_t len;
-	char *u8 = LoadFileU8A(FileName, &len);
-	if (u8 == NULL) {
-		return NULL;
-	}
-	char *strA = (char *)ToCharU8(u8);
-	free(u8);
-	if (strA == NULL) {
-		return NULL;
-	}
-	len = strlen(strA);
-	*_len = len;
-	return strA;
-}

Deleted: trunk/teraterm/ttpmacro/fileread.h
===================================================================
--- trunk/teraterm/ttpmacro/fileread.h	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/ttpmacro/fileread.h	2020-03-10 15:30:10 UTC (rev 8586)
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2018-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.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif//__cplusplus
-
-char *LoadFileU8A(const char *FileName, size_t *_len);
-char *LoadFileU8T(const TCHAR *FileName, size_t *_len);
-wchar_t *LoadFileWA(const char *FileName, size_t *_len);
-char *LoadFileAA(const char *FileName, size_t *_len);
-wchar_t *LoadFileWW(const wchar_t *FileName, size_t *_len);
-unsigned char *LoadFileBinary(const wchar_t *FileName, size_t *_len);
-
-#ifdef __cplusplus
-}
-#endif//__cplusplus

Modified: trunk/teraterm/ttpmacro/ttpmacro.vcproj
===================================================================
--- trunk/teraterm/ttpmacro/ttpmacro.vcproj	2020-03-10 15:29:58 UTC (rev 8585)
+++ trunk/teraterm/ttpmacro/ttpmacro.vcproj	2020-03-10 15:30:10 UTC (rev 8586)
@@ -216,10 +216,6 @@
 				>
 			</File>
 			<File
-				RelativePath="fileread.cpp"
-				>
-			</File>
-			<File
 				RelativePath="inpdlg.cpp"
 				>
 			</File>
@@ -277,10 +273,6 @@
 				>
 			</File>
 			<File
-				RelativePath="fileread.h"
-				>
-			</File>
-			<File
 				RelativePath="inpdlg.h"
 				>
 			</File>


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