[ttssh2-commit] [9428] iniファイル読み書きAPIのファイル引数のみを Unicode にしたAPIを追加

アーカイブの一覧に戻る
scmno****@osdn***** scmno****@osdn*****
2021年 9月 20日 (月) 00:13:35 JST


Revision: 9428
          https://osdn.net/projects/ttssh2/scm/svn/commits/9428
Author:   zmatsuo
Date:     2021-09-20 00:13:34 +0900 (Mon, 20 Sep 2021)
Log Message:
-----------
iniファイル読み書きAPIのファイル引数のみを Unicode にしたAPIを追加

- teraterm/common/inifile_com.c,h 追加
- Get(Write)Private...A() を置き換えて使用
  - GetPrivateProfileStringAFileW()
  - WritePrivateProfileStringAFileW()
  - GetPrivateProfileIntAFileW()
  - WritePrivateProfileIntAFileW()

Modified Paths:
--------------
    trunk/teraterm/common/CMakeLists.txt
    trunk/teraterm/common/common_static.v16.vcxproj
    trunk/teraterm/common/common_static.v8.vcproj

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

-------------- next part --------------
Modified: trunk/teraterm/common/CMakeLists.txt
===================================================================
--- trunk/teraterm/common/CMakeLists.txt	2021-09-18 15:47:47 UTC (rev 9427)
+++ trunk/teraterm/common/CMakeLists.txt	2021-09-19 15:13:34 UTC (rev 9428)
@@ -25,6 +25,8 @@
   getcontent.h
   i18n.h
   i18n_static.c
+  inifile_com.h
+  inifile_com.cpp
   tipwin.cpp
   tipwin.h
   tmfc.cpp

Modified: trunk/teraterm/common/common_static.v16.vcxproj
===================================================================
--- trunk/teraterm/common/common_static.v16.vcxproj	2021-09-18 15:47:47 UTC (rev 9427)
+++ trunk/teraterm/common/common_static.v16.vcxproj	2021-09-19 15:13:34 UTC (rev 9428)
@@ -137,6 +137,7 @@
     <ClCompile Include="dlglib_cpp.cpp" />
     <ClCompile Include="dlglib_tmpl.cpp" />
     <ClCompile Include="fileread.cpp" />
+    <ClCompile Include="inifile_com.cpp" />
     <ClCompile Include="tipwin.cpp" />
     <ClCompile Include="tmfc.cpp" />
     <ClCompile Include="tmfc_frame.cpp" />
@@ -156,6 +157,7 @@
     <ClInclude Include="comportinfo.h" />
     <ClInclude Include="dlglib.h" />
     <ClInclude Include="fileread.h" />
+    <ClInclude Include="inifile_com.h" />
     <ClInclude Include="tipwin.h" />
     <ClInclude Include="tmfc.h" />
     <ClInclude Include="compat_win.h" />

Modified: trunk/teraterm/common/common_static.v8.vcproj
===================================================================
--- trunk/teraterm/common/common_static.v8.vcproj	2021-09-18 15:47:47 UTC (rev 9427)
+++ trunk/teraterm/common/common_static.v8.vcproj	2021-09-19 15:13:34 UTC (rev 9428)
@@ -249,6 +249,14 @@
 			>
 		</File>
 		<File
+			RelativePath=".\inifile_com.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\inifile_com.h"
+			>
+		</File>
+		<File
 			RelativePath=".\tipwin.cpp"
 			>
 		</File>

Added: trunk/teraterm/common/inifile_com.cpp
===================================================================
--- trunk/teraterm/common/inifile_com.cpp	                        (rev 0)
+++ trunk/teraterm/common/inifile_com.cpp	2021-09-19 15:13:34 UTC (rev 9428)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (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>
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+
+#include "codeconv.h"
+
+#include "inifile_com.h"
+
+/**
+ *	GetPrivateProfileStringA() \x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xBE\x82\xAF\x82\xAA wchar_t \x94\xC5
+ */
+DWORD GetPrivateProfileStringAFileW(const char *appA, const char *keyA, const char* defA, char *strA, DWORD size, const wchar_t *filenameW)
+{
+	DWORD lenA;
+	wchar_t *appW = ToWcharA(appA);
+	wchar_t *keyW = ToWcharA(keyA);
+	wchar_t *defW = ToWcharA(defA);
+	DWORD lenW_max = size;
+	wchar_t *strW = (wchar_t *)malloc(sizeof(wchar_t) * lenW_max);
+	DWORD lenW = GetPrivateProfileStringW(appW, keyW, defW, strW, lenW_max, filenameW);
+	free(appW);
+	free(keyW);
+	free(defW);
+	if (lenW == 0) {
+		free(strW);
+		*strA = '\0';
+		return 0;
+	}
+	if (lenW < lenW_max) {
+		lenW++;	// for L'\0'
+	}
+	lenA = WideCharToMultiByte(CP_ACP, 0, strW, lenW, strA, size, NULL, NULL);
+	// GetPrivateProfileStringW() \x82̖߂\xE8\x92l\x82\xCD '\0' \x82\xF0\x8A܂܂Ȃ\xA2\x95\xB6\x8E\x9A\x97\xF1\x92\xB7
+	// WideCharToMultiByte() \x82̖߂\xE8\x92l\x82\xCD '\0' \x82\xF0\x8A܂ޕ\xB6\x8E\x9A\x97\xF1\x92\xB7
+	if (lenW != 0 && strA[lenA-1] == 0) {
+		lenA--;
+	}
+	free(strW);
+	return lenA;
+}
+
+/**
+ *	WritePrivateProfileStringA() \x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xBE\x82\xAF\x82\xAA wchar_t \x94\xC5
+ */
+BOOL WritePrivateProfileStringAFileW(const char *appA, const char *keyA, const char *strA, const wchar_t *filenameW)
+{
+	wchar_t *appW = ToWcharA(appA);
+	wchar_t *keyW = ToWcharA(keyA);
+	wchar_t *strW = ToWcharA(strA);
+	BOOL r = WritePrivateProfileStringW(appW, keyW, strW, filenameW);
+	free(appW);
+	free(keyW);
+	free(strW);
+	return r;
+}
+
+/**
+ *	GetPrivateProfileIntFileA() \x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xBE\x82\xAF\x82\xAA wchar_t \x94\xC5
+ */
+UINT GetPrivateProfileIntAFileW(const char *appA, const char *keyA, int def, const wchar_t *filenameW)
+{
+	wchar_t *appW = ToWcharA(appA);
+	wchar_t *keyW = ToWcharA(keyA);
+	UINT r = GetPrivateProfileIntW(appW, keyW, def, filenameW);
+	free(appW);
+	free(keyW);
+	return r;
+}
+
+/**
+ *	WritePrivateProfileIntA() \x82̃t\x83@\x83C\x83\x8B\x96\xBC\x82\xBE\x82\xAF\x82\xAA wchar_t \x94\xC5
+ */
+BOOL WritePrivateProfileIntAFileW(const char *appA, const char *keyA, int val, const wchar_t *filenameW)
+{
+	wchar_t strW[MAX_PATH];
+	wchar_t *appW = ToWcharA(appA);
+	wchar_t *keyW = ToWcharA(keyA);
+	BOOL r;
+	_snwprintf_s(strW, _countof(strW), _TRUNCATE, L"%d", val);
+	r = WritePrivateProfileStringW(appW, keyW, strW, filenameW);
+	free(appW);
+	free(keyW);
+	return r;
+}

Added: trunk/teraterm/common/inifile_com.h
===================================================================
--- trunk/teraterm/common/inifile_com.h	                        (rev 0)
+++ trunk/teraterm/common/inifile_com.h	2021-09-19 15:13:34 UTC (rev 9428)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (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 <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DWORD GetPrivateProfileStringAFileW(const char *appA, const char *keyA, const char* defA, char *strA, DWORD size, const wchar_t *filenameW);
+BOOL WritePrivateProfileStringAFileW(const char *appA, const char *keyA, const char *strA, const wchar_t *filenameW);
+UINT GetPrivateProfileIntAFileW(const char *appA, const char *keyA, int def, const wchar_t *filenameW);
+BOOL WritePrivateProfileIntAFileW(const char *appA, const char *keyA, int val, const wchar_t *filenameW);
+DWORD GetPrivateProfileSectionNamesAFileW(const char *lpszReturnBuffer, DWORD nSize, const wchar_t *filenameW);
+
+#ifdef __cplusplus
+}
+#endif


ttssh2-commit メーリングリストの案内
アーカイブの一覧に戻る