[Ttssh2-commit] [4777] ・不正な文字の置き換えと deleteInvalidFileNameChar の処理を共通化

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 12月 9日 (金) 10:01:02 JST


Revision: 4777
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4777
Author:   doda
Date:     2011-12-09 10:01:02 +0900 (Fri, 09 Dec 2011)
Log Message:
-----------
・不正な文字の置き換えと deleteInvalidFileNameChar の処理を共通化
・0x00~0x1f も不正な文字として扱うように変更

Modified Paths:
--------------
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/ttpfile/ftlib.c

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2011-12-07 11:41:43 UTC (rev 4776)
+++ trunk/teraterm/common/ttlib.c	2011-12-09 01:01:02 UTC (rev 4777)
@@ -15,6 +15,9 @@
 // for _ismbblead
 #include <mbctype.h>
 
+// for isInvalidFileNameChar / replaceInvalidFileNameChar
+static char *invalidFileNameChars = "\\/:*?\"<>|";
+
 // for b64encode/b64decode
 static char *b64enc_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 static char b64dec_table[] = {
@@ -442,27 +445,23 @@
 			i++;
 			continue;
 		}
-		switch (FName[i]) {
-			case '\\':
-			case '/':
-			case ':':
-			case '*':
-			case '?':
-			case '"':
-			case '<':
-			case '>':
-			case '|':
-				return 1;
+		if ((FName[i] >= 0 && FName[i] < ' ') || strchr(invalidFileNameChars, FName[i])) {
+			return 1;
 		}
 	}
 	return 0;
 }
 
-// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82Ɏg\x97p\x82ł\xAB\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0\x8D폜\x82\xB7\x82\xE9 (2006.8.28 maya)
-void deleteInvalidFileNameChar(PCHAR FName)
+// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82Ɏg\x97p\x82ł\xAB\x82Ȃ\xA2\x95\xB6\x8E\x9A\x82\xF0 c \x82ɒu\x82\xAB\x8A\xB7\x82\xA6\x82\xE9
+// c \x82\xC9 0 \x82\xF0\x8Ew\x92肵\x82\xBD\x8Fꍇ\x82͕\xB6\x8E\x9A\x82\xF0\x8D폜\x82\xB7\x82\xE9
+void replaceInvalidFileNameChar(PCHAR FName, unsigned char c)
 {
 	int i, j=0, len;
 
+	if ((c >= 0 && c < ' ') || strchr(invalidFileNameChars, c)) {
+		c = 0;
+	}
+
 	len = strlen(FName);
 	for (i=0; i<len; i++) {
 		if (_ismbblead(FName[i])) {
@@ -470,21 +469,14 @@
 			FName[j++] = FName[++i];
 			continue;
 		}
-		switch (FName[i]) {
-			case '\\':
-			case '/':
-			case ':':
-			case '*':
-			case '?':
-			case '"':
-			case '<':
-			case '>':
-			case '|':
-				break;
-			default:
-				FName[j] = FName[i];
-				j++;
+		if ((FName[i] >= 0 && FName[i] < ' ') || strchr(invalidFileNameChars, FName[i])) {
+			if (c) {
+				FName[j++] = c;
+			}
 		}
+		else {
+			FName[j++] = FName[i];
+		}
 	}
 	FName[j] = 0;
 }

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2011-12-07 11:41:43 UTC (rev 4776)
+++ trunk/teraterm/common/ttlib.h	2011-12-09 01:01:02 UTC (rev 4777)
@@ -25,7 +25,8 @@
 void QuoteFName(PCHAR FName);
 #endif
 int isInvalidFileNameChar(PCHAR FName);
-void deleteInvalidFileNameChar(PCHAR FName);
+#define deleteInvalidFileNameChar(name) replaceInvalidFileNameChar(name, 0)
+void replaceInvalidFileNameChar(PCHAR FName, unsigned char c);
 int isInvalidStrftimeChar(PCHAR FName);
 void deleteInvalidStrftimeChar(PCHAR FName);
 void ParseStrftimeFileName(PCHAR FName, int destlen);

Modified: trunk/teraterm/ttpfile/ftlib.c
===================================================================
--- trunk/teraterm/ttpfile/ftlib.c	2011-12-07 11:41:43 UTC (rev 4776)
+++ trunk/teraterm/ttpfile/ftlib.c	2011-12-09 01:01:02 UTC (rev 4777)
@@ -158,13 +158,8 @@
 {
   int i;
   char Temp[MAX_PATH];
-  char *p;
 
-  for (p=&(fv->FullName[fv->DirLen]); *p; p++) {
-    if (strchr("\\/:*?\"<>|", *p)) {
-      *p = '_';
-    }
-  }
+  replaceInvalidFileNameChar(&(fv->FullName[fv->DirLen]), '_');
 
   if (fv->FullName[fv->DirLen] == 0) {
     strncpy_s(&(fv->FullName[fv->DirLen]), sizeof(fv->FullName) - fv->DirLen, "noname", _TRUNCATE);



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