[ttssh2-commit] [9433] Unicode用に使用を修正、関数を追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 9月 20日 (月) 00:14:38 JST


Revision: 9433
          https://osdn.net/projects/ttssh2/scm/svn/commits/9433
Author:   zmatsuo
Date:     2021-09-20 00:14:38 +0900 (Mon, 20 Sep 2021)
Log Message:
-----------
Unicode用に使用を修正、関数を追加

- ttlib.c, h
  - GetParam() を Unicodeに切り替え
    - コマンドラインパース時に使用する関数
    - 併用しないため、仕様を変更
  - FitFileNameW() を追加
    - FitFileName() の Unicode版
- ファイル読み込み fileread.cpp,h
  - LoadFileU8T() 削除
  - LoadFileU8W() 追加
- ConvFNameW() を追加
  - ConvFName() の Unicode版
- parse_port_from_buf() の引数に const を追加

Modified Paths:
--------------
    trunk/teraterm/common/fileread.cpp
    trunk/teraterm/common/fileread.h
    trunk/teraterm/common/servicenames.c
    trunk/teraterm/common/servicenames.h
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/ttlib_static_cpp.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/fileread.cpp
===================================================================
--- trunk/teraterm/common/fileread.cpp	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/fileread.cpp	2021-09-19 15:14:38 UTC (rev 9433)
@@ -205,6 +205,32 @@
 
 /**
  *	\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 *LoadFileU8W(const wchar_t *FileName, size_t *_len)
+{
+	*_len = 0;
+	FILE *fp;
+	_wfopen_s(&fp, FileName, L"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)

Modified: trunk/teraterm/common/fileread.h
===================================================================
--- trunk/teraterm/common/fileread.h	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/fileread.h	2021-09-19 15:14:38 UTC (rev 9433)
@@ -31,7 +31,7 @@
 #endif//__cplusplus
 
 char *LoadFileU8A(const char *FileName, size_t *_len);
-char *LoadFileU8T(const TCHAR *FileName, size_t *_len);
+char *LoadFileU8W(const wchar_t *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);

Modified: trunk/teraterm/common/servicenames.c
===================================================================
--- trunk/teraterm/common/servicenames.c	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/servicenames.c	2021-09-19 15:14:38 UTC (rev 9433)
@@ -379,7 +379,7 @@
 	return (isalnum(ch) || ch == '_' || ch == '-');
 }
 
-int PASCAL parse_port_from_buf(char * buf)
+int PASCAL parse_port_from_buf(const char * buf)
 {
 	int i;
 	char lower_buf[32];

Modified: trunk/teraterm/common/servicenames.h
===================================================================
--- trunk/teraterm/common/servicenames.h	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/servicenames.h	2021-09-19 15:14:38 UTC (rev 9433)
@@ -37,7 +37,7 @@
 #endif
 /* proto types */
 DllExport int PASCAL parse_port(char *str, char *buf, int bufsize);
-DllExport int PASCAL parse_port_from_buf(char *buf);
+DllExport int PASCAL parse_port_from_buf(const char *buf);
 DllExport char * PASCAL service_name(int num);
 
 #ifdef __cplusplus

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/ttlib.c	2021-09-19 15:14:38 UTC (rev 9433)
@@ -1247,9 +1247,9 @@
 	return strtime;
 }
 
-PCHAR PASCAL GetParam(PCHAR buff, int size, PCHAR param)
+wchar_t * PASCAL GetParam(wchar_t *buff, size_t size, wchar_t *param)
 {
-	int i = 0;
+	size_t i = 0;
 	BOOL quoted = FALSE;
 
 	while (*param == ' ' || *param == '\t') {
@@ -1285,10 +1285,10 @@
 	return (param);
 }
 
-void PASCAL DequoteParam(PCHAR dest, int dest_len, PCHAR src)
+void PASCAL DequoteParam(wchar_t *dest, size_t dest_len, wchar_t *src)
 {
 	BOOL quoted = FALSE;
-	PCHAR dest_end = dest + dest_len - 1;
+	wchar_t *dest_end = dest + dest_len - 1;
 
 	if (src == dest) {
 		while (*src != '\0' && *src != '"' && dest < dest_end) {

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/ttlib.h	2021-09-19 15:14:38 UTC (rev 9433)
@@ -49,6 +49,7 @@
 wchar_t *ExtractDirNameW(const wchar_t *PathName);
 wchar_t *ExtractFileNameW(const wchar_t *PathName);
 void FitFileName(PCHAR FileName, int destlen, const char *DefExt);
+void FitFileNameW(wchar_t *FileName, size_t destlen, const wchar_t *DefExt);
 void AppendSlash(PCHAR Path, int destlen);
 void AppendSlashW(wchar_t *Path, size_t destlen);
 void DeleteSlash(PCHAR Path);
@@ -75,6 +76,7 @@
 void deleteInvalidStrftimeChar(PCHAR FName);
 void ParseStrftimeFileName(PCHAR FName, int destlen);
 void ConvFName(const char *HomeDir, PCHAR Temp, int templen, const char *DefExt, PCHAR FName, int destlen);
+void ConvFNameW(const wchar_t *HomeDir, wchar_t *Temp, size_t templen, const wchar_t *DefExt, wchar_t *FName, size_t destlen);
 void RestoreNewLine(PCHAR Text);
 size_t RestoreNewLineW(wchar_t *Text);
 BOOL GetNthString(PCHAR Source, int Nth, int Size, PCHAR Dest);
@@ -118,8 +120,8 @@
 void b64encode(PCHAR dst, int dsize, PCHAR src, int len);
 DllExport int b64decode(PCHAR dst, int dsize, PCHAR src);
 
-DllExport PCHAR PASCAL GetParam(PCHAR buff, int size, PCHAR param);
-DllExport void PASCAL DequoteParam(PCHAR dest, int dest_len, PCHAR src);
+DllExport wchar_t * PASCAL GetParam(wchar_t *buff, size_t size, wchar_t *param);
+DllExport void PASCAL DequoteParam(wchar_t *dest, size_t dest_len, wchar_t *src);
 void PASCAL DeleteComment(PCHAR dest, int dest_size, PCHAR src);
 
 void split_buffer(char *buffer, int delimiter, char **head, char **body);

Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2021-09-19 15:14:27 UTC (rev 9432)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2021-09-19 15:14:38 UTC (rev 9433)
@@ -1128,3 +1128,59 @@
 	CoTaskMemFree(pidlBrowse);
 	return TRUE;
 }
+
+/* fit a filename to the windows-filename format */
+/* FileName must contain filename part only. */
+void FitFileNameW(wchar_t *FileName, size_t destlen, const wchar_t *DefExt)
+{
+	int i, j, NumOfDots;
+	wchar_t Temp[MAX_PATH];
+	wchar_t b;
+
+	NumOfDots = 0;
+	i = 0;
+	j = 0;
+	/* filename started with a dot is illeagal */
+	if (FileName[0]==L'.') {
+		Temp[0] = L'_';  /* insert an underscore char */
+		j++;
+	}
+
+	do {
+		b = FileName[i];
+		i++;
+		if (b==L'.')
+			NumOfDots++;
+		if ((b!=0) &&
+		    (j < MAX_PATH-1)) {
+			Temp[j] = b;
+			j++;
+		}
+	} while (b!=0);
+	Temp[j] = 0;
+
+	if ((NumOfDots==0) &&
+	    (DefExt!=NULL)) {
+		/* add the default extension */
+		wcsncat_s(Temp,_countof(Temp),DefExt,_TRUNCATE);
+	}
+
+	wcsncpy_s(FileName,destlen,Temp,_TRUNCATE);
+}
+
+void ConvFNameW(const wchar_t *HomeDir, wchar_t *Temp, size_t templen, const wchar_t *DefExt, wchar_t *FName, size_t destlen)
+{
+	// destlen = sizeof FName
+	size_t DirLen, FNPos;
+
+	FName[0] = 0;
+	if ( ! GetFileNamePosW(Temp,&DirLen,&FNPos) ) {
+		return;
+	}
+	FitFileNameW(&Temp[FNPos],templen - FNPos,DefExt);
+	if ( DirLen==0 ) {
+		wcsncpy_s(FName,destlen,HomeDir,_TRUNCATE);
+		AppendSlashW(FName,destlen);
+	}
+	wcsncat_s(FName,destlen,Temp,_TRUNCATE);
+}


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