Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp	(revision 696)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp	(revision 700)
@@ -1,3 +1,4 @@
 #include "stdafx.h"
+#include <hash_set>
 
 const std::string BasicSource::generateDirectiveName = "#generate";
@@ -10,7 +11,7 @@
 	void Init( bool isDebug, bool isDll, bool isUnicode, int majorVer );
 
-	BOOL add(char *name);
-	BOOL undef(char *name);
-	BOOL check(char *name);
+	BOOL add(char const *name);
+	BOOL undef(char const *name);
+	BOOL check(char const *name);
 	void preprocessor_ifdef(char *buffer,bool isNot);
 	void DirectiveIfdef(char *buffer);
@@ -22,49 +23,33 @@
 // #requireの管理
 //////////////////////////////////////
+namespace
+{
 class CRequireFiles{
-	Jenga::Common::Strings filepaths;
+	stdext::hash_set<std::string> filepaths;
 public:
-
 	void clear(){
 		filepaths.clear();
 	}
-	bool IsIncluded( const std::string &includeFilePath ){
-		// '/' → '\\'
+	//既に存在するものを追加しようとするとfalseを返す（旧IsIncludedと逆なことに注意）
+	bool TryAdd( const std::string &includeFilePath ){
 		char tempPath[MAX_PATH];
-		lstrcpy( tempPath, includeFilePath.c_str() );
-		for( int i=0; tempPath[i]; i++ ){
-			if( tempPath[i] == '/' ){
+		DWORD len = GetShortPathName(includeFilePath.c_str(), tempPath, MAX_PATH);
+		if (len >= MAX_PATH){
+			return false;
+		}
+		for( DWORD i = 0; i < len; ++i ){
+			char c = toupper(tempPath[i]);
+			if (c == '/'){
 				tempPath[i] = '\\';
 			}
-		}
-
-		BOOST_FOREACH( const std::string &filepath, filepaths )
-		{
-			if( lstrcmpi( filepath.c_str(), tempPath ) == 0 )
-			{
-				return true;
-			}
-		}
-		return false;
-	}
-	void Add( const std::string &includeFilePath ){
-		// '/' → '\\'
-		char tempPath[MAX_PATH];
-		lstrcpy( tempPath, includeFilePath.c_str() );
-		for( int i=0; tempPath[i]; i++ ){
-			if( tempPath[i] == '/' ){
-				tempPath[i] = '\\';
-			}
-		}
-
-		//既に読み込まれているとき
-		if( IsIncluded( tempPath ) ) return;
-
-		//追加
-		filepaths.push_back( tempPath );
+			else{
+				tempPath[i] = c;
+			}
+		}
+		return filepaths.insert( tempPath ).second;
 	}
 };
 CRequireFiles requireFiles;
-
+} //namespace
 
 //////////////////////////////////////
@@ -99,5 +84,5 @@
 	add(temporary);
 }
-BOOL CDefine::add(char *name)
+BOOL CDefine::add(char const *name)
 {
 	//重複チェック
@@ -109,5 +94,5 @@
 	return 1;
 }
-BOOL CDefine::undef(char *name){
+BOOL CDefine::undef(char const *name){
 	std::vector<std::string>::iterator i = names.begin();
 	BOOST_FOREACH( const std::string &temp, names ){
@@ -121,5 +106,5 @@
 	return 0;
 }
-BOOL CDefine::check(char *name){
+BOOL CDefine::check(char const *name){
 
 	//重複チェック
@@ -132,5 +117,5 @@
 }
 
-int Search_endif(char *buffer,int i, int *pLine = 0){
+int Search_endif(char const *buffer,int i, int *pLine = 0){
 	for(;;i++){
 		if(buffer[i]=='\0') break;
@@ -143,10 +128,10 @@
 
 		if(buffer[i-1]=='\n'){
-			if(memicmp(buffer+i,"#ifdef",6)==0||memicmp(buffer+i,"#ifndef",7)==0){
+			if(_memicmp(buffer+i,"#ifdef",6)==0||_memicmp(buffer+i,"#ifndef",7)==0){
 				i=Search_endif(buffer,i+6, pLine);
 				if(buffer[i]=='\0') break;
 				continue;
 			}
-			else if(memicmp(buffer+i,"#endif",6)==0){
+			else if(_memicmp(buffer+i,"#endif",6)==0){
 				break;
 			}
@@ -160,6 +145,6 @@
 	char temporary[VN_SIZE];
 
-	if(isNot) i=lstrlen("#ifndef");
-	else i=lstrlen("#ifdef");
+	if(isNot) i=strlen("#ifndef");
+	else i=strlen("#ifdef");
 	while(buffer[i]==' '||buffer[i]=='\t') i++;
 
@@ -445,6 +430,5 @@
 void BasicSource::RemoveComments(){
 	int i,i2,i3,IsStr;
-	char *temporary;
-	temporary=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(buffer)+1);
+	char *temporary=static_cast<char *>(malloc(strlen(buffer)+1));
 	for(i=0,i2=0,i3=0,IsStr=0;;i++,i2++){
 		if(buffer[i]=='\"') IsStr^=1;
@@ -487,6 +471,6 @@
 		if(buffer[i]=='\0') break;
 	}
-	lstrcpy(buffer,temporary);
-	GlobalFree(temporary);
+	strcpy(buffer,temporary);
+	free(temporary);
 }
 
@@ -538,5 +522,5 @@
 	std::string mainSourceFileDir = Jenga::Common::Path::ExtractDirPath( mainSourceFilePath );
 	LayerDir[0]=(char *)malloc(mainSourceFileDir.size()+1);
-	lstrcpy(LayerDir[0],mainSourceFileDir.c_str());
+	strcpy(LayerDir[0],mainSourceFileDir.c_str());
 
 	for(i=0;;i++){
@@ -584,9 +568,9 @@
 				if(sw1){
 					sprintf(temp2,"%s\\%s", includeDirPath.c_str(), temporary );
-					lstrcpy(findStr,temp2);
+					strcpy(findStr,temp2);
 				}
 				else{
 					Jenga::Common::Directory dir( LayerDir[layer] );
-					lstrcpy( findStr, dir.GetFullPath( temporary ).c_str() );
+					strcpy( findStr, dir.GetFullPath( temporary ).c_str() );
 				}
 			}
@@ -611,5 +595,6 @@
 			// インクルードファイルを列挙（ワイルドカード指定を想定）
 			Jenga::Common::Strings resultOfFullPath;
-			Jenga::Common::FileSystem::SearchFiles( resultOfFullPath, findStr );
+//			Jenga::Common::FileSystem::SearchFiles( resultOfFullPath, findStr );
+			resultOfFullPath.push_back(findStr);
 
 			if( resultOfFullPath.empty() )
@@ -644,7 +629,8 @@
 
 				//#requireの場合では、既に読み込まれているファイルは読み込まないようにする
+/*
 				bool isFake = false;
 				if( isRequire ){
-					if( requireFiles.IsIncluded( sourceFilePath ) ){
+					if( requireFiles.TryAdd( sourceFilePath ) ){
 						//既に読み込まれているとき
 						isFake = true;
@@ -668,6 +654,20 @@
 					}
 				}
-
-				Realloc( lstrlen(buffer) + source.GetLength() );
+*/
+				BasicSource source;
+
+				if( !requireFiles.TryAdd( sourceFilePath ) && isRequire ){
+					//既に読み込まれているときは空データ
+					source.SetBuffer( "" );
+				}
+				else{
+					//インクルードファイルを読み込む
+					if( !source.ReadFile_InIncludeDirective( sourceFilePath ) )
+					{
+						throw;
+					}
+				}
+
+				Realloc( strlen(buffer) + source.GetLength() );
 				Text::SlideString(
 					buffer + headIndex + includeDirectiveLength,
@@ -683,7 +683,7 @@
 				char temp4[MAX_PATH];
 				_splitpath(sourceFilePath.c_str(),temp2,temp4,0,0);
-				lstrcat(temp2,temp4);
-				LayerDir[layer]=(char *)malloc(lstrlen(temp2)+1);
-				lstrcpy(LayerDir[layer],temp2);
+				strcat(temp2,temp4);
+				LayerDir[layer]=(char *)malloc(strlen(temp2)+1);
+				strcpy(LayerDir[layer],temp2);
 
 				//ファイル範囲をスライド
@@ -702,5 +702,5 @@
 	free(LayerDir[0]);
 
-	length = lstrlen(buffer);
+	length = strlen(buffer);
 }
 
@@ -825,5 +825,5 @@
 	}
 
-	length = lstrlen(buffer);
+	length = strlen(buffer);
 }
 
@@ -840,8 +840,8 @@
 
 	//最終行には文字を含ませないようにする
-	if( lstrlen(buffer)>0 && buffer[lstrlen(buffer)-1] != '\n' )
+	if( strlen(buffer)>0 && buffer[strlen(buffer)-1] != '\n' )
 	{
 		Realloc( length + 1 );
-		lstrcat( buffer, "\n" );
+		strcat( buffer, "\n" );
 	}
 
@@ -851,7 +851,7 @@
 
 void BasicSource::SetBuffer( const char *buffer ){
-	this->buffer = (char *)calloc( lstrlen(buffer) + 1, 1 );
-	lstrcpy( this->buffer, buffer );
-	length = lstrlen(buffer);
+	this->buffer = (char *)calloc( strlen(buffer) + 1, 1 );
+	strcpy( this->buffer, buffer );
+	length = strlen(buffer);
 
 	// ダミー改行をセット
@@ -874,7 +874,7 @@
 	//const char *headCode = "#include <basic.sbp>\n";
 	const char *headCode = "";
-	Realloc( length + lstrlen(headCode) );
-	Text::SlideString( buffer, lstrlen(headCode) );
-	memcpy( buffer, headCode, lstrlen(headCode) );
+	Realloc( length + strlen(headCode) );
+	Text::SlideString( buffer, strlen(headCode) );
+	memcpy( buffer, headCode, strlen(headCode) );
 
 	// #defineと#requireを初期化
@@ -891,5 +891,5 @@
 	//最終行には文字を含ませないようにする
 	Realloc( length + 1 );
-	lstrcat( buffer, "\n" );
+	strcat( buffer, "\n" );
 
 	// #include / #require ディレクティブを処理
@@ -912,6 +912,6 @@
 
 void BasicSource::Addition( const char *buffer ){
-	Realloc( length + lstrlen(buffer) );
-	lstrcat( this->buffer, buffer );
+	Realloc( length + strlen(buffer) );
+	strcat( this->buffer, buffer );
 }
 
