Changeset 700 in dev for trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp
- Timestamp:
- Jul 21, 2008, 1:04:12 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp
r696 r700 1 1 #include "stdafx.h" 2 #include <hash_set> 2 3 3 4 const std::string BasicSource::generateDirectiveName = "#generate"; … … 10 11 void Init( bool isDebug, bool isDll, bool isUnicode, int majorVer ); 11 12 12 BOOL add(char *name);13 BOOL undef(char *name);14 BOOL check(char *name);13 BOOL add(char const *name); 14 BOOL undef(char const *name); 15 BOOL check(char const *name); 15 16 void preprocessor_ifdef(char *buffer,bool isNot); 16 17 void DirectiveIfdef(char *buffer); … … 22 23 // #requireの管理 23 24 ////////////////////////////////////// 25 namespace 26 { 24 27 class CRequireFiles{ 25 Jenga::Common::Stringsfilepaths;28 stdext::hash_set<std::string> filepaths; 26 29 public: 27 28 30 void clear(){ 29 31 filepaths.clear(); 30 32 } 31 bool IsIncluded( const std::string &includeFilePath ){32 // '/' → '\\'33 //既に存在するものを追加しようとするとfalseを返す(旧IsIncludedと逆なことに注意) 34 bool TryAdd( const std::string &includeFilePath ){ 33 35 char tempPath[MAX_PATH]; 34 lstrcpy( tempPath, includeFilePath.c_str() ); 35 for( int i=0; tempPath[i]; i++ ){ 36 if( tempPath[i] == '/' ){ 36 DWORD len = GetShortPathName(includeFilePath.c_str(), tempPath, MAX_PATH); 37 if (len >= MAX_PATH){ 38 return false; 39 } 40 for( DWORD i = 0; i < len; ++i ){ 41 char c = toupper(tempPath[i]); 42 if (c == '/'){ 37 43 tempPath[i] = '\\'; 38 44 } 39 } 40 41 BOOST_FOREACH( const std::string &filepath, filepaths ) 42 { 43 if( lstrcmpi( filepath.c_str(), tempPath ) == 0 ) 44 { 45 return true; 46 } 47 } 48 return false; 49 } 50 void Add( const std::string &includeFilePath ){ 51 // '/' → '\\' 52 char tempPath[MAX_PATH]; 53 lstrcpy( tempPath, includeFilePath.c_str() ); 54 for( int i=0; tempPath[i]; i++ ){ 55 if( tempPath[i] == '/' ){ 56 tempPath[i] = '\\'; 57 } 58 } 59 60 //既に読み込まれているとき 61 if( IsIncluded( tempPath ) ) return; 62 63 //追加 64 filepaths.push_back( tempPath ); 45 else{ 46 tempPath[i] = c; 47 } 48 } 49 return filepaths.insert( tempPath ).second; 65 50 } 66 51 }; 67 52 CRequireFiles requireFiles; 68 53 } //namespace 69 54 70 55 ////////////////////////////////////// … … 99 84 add(temporary); 100 85 } 101 BOOL CDefine::add(char *name)86 BOOL CDefine::add(char const *name) 102 87 { 103 88 //重複チェック … … 109 94 return 1; 110 95 } 111 BOOL CDefine::undef(char *name){96 BOOL CDefine::undef(char const *name){ 112 97 std::vector<std::string>::iterator i = names.begin(); 113 98 BOOST_FOREACH( const std::string &temp, names ){ … … 121 106 return 0; 122 107 } 123 BOOL CDefine::check(char *name){108 BOOL CDefine::check(char const *name){ 124 109 125 110 //重複チェック … … 132 117 } 133 118 134 int Search_endif(char *buffer,int i, int *pLine = 0){119 int Search_endif(char const *buffer,int i, int *pLine = 0){ 135 120 for(;;i++){ 136 121 if(buffer[i]=='\0') break; … … 143 128 144 129 if(buffer[i-1]=='\n'){ 145 if( memicmp(buffer+i,"#ifdef",6)==0||memicmp(buffer+i,"#ifndef",7)==0){130 if(_memicmp(buffer+i,"#ifdef",6)==0||_memicmp(buffer+i,"#ifndef",7)==0){ 146 131 i=Search_endif(buffer,i+6, pLine); 147 132 if(buffer[i]=='\0') break; 148 133 continue; 149 134 } 150 else if( memicmp(buffer+i,"#endif",6)==0){135 else if(_memicmp(buffer+i,"#endif",6)==0){ 151 136 break; 152 137 } … … 160 145 char temporary[VN_SIZE]; 161 146 162 if(isNot) i= lstrlen("#ifndef");163 else i= lstrlen("#ifdef");147 if(isNot) i=strlen("#ifndef"); 148 else i=strlen("#ifdef"); 164 149 while(buffer[i]==' '||buffer[i]=='\t') i++; 165 150 … … 445 430 void BasicSource::RemoveComments(){ 446 431 int i,i2,i3,IsStr; 447 char *temporary; 448 temporary=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(buffer)+1); 432 char *temporary=static_cast<char *>(malloc(strlen(buffer)+1)); 449 433 for(i=0,i2=0,i3=0,IsStr=0;;i++,i2++){ 450 434 if(buffer[i]=='\"') IsStr^=1; … … 487 471 if(buffer[i]=='\0') break; 488 472 } 489 lstrcpy(buffer,temporary);490 GlobalFree(temporary);473 strcpy(buffer,temporary); 474 free(temporary); 491 475 } 492 476 … … 538 522 std::string mainSourceFileDir = Jenga::Common::Path::ExtractDirPath( mainSourceFilePath ); 539 523 LayerDir[0]=(char *)malloc(mainSourceFileDir.size()+1); 540 lstrcpy(LayerDir[0],mainSourceFileDir.c_str());524 strcpy(LayerDir[0],mainSourceFileDir.c_str()); 541 525 542 526 for(i=0;;i++){ … … 584 568 if(sw1){ 585 569 sprintf(temp2,"%s\\%s", includeDirPath.c_str(), temporary ); 586 lstrcpy(findStr,temp2);570 strcpy(findStr,temp2); 587 571 } 588 572 else{ 589 573 Jenga::Common::Directory dir( LayerDir[layer] ); 590 lstrcpy( findStr, dir.GetFullPath( temporary ).c_str() );574 strcpy( findStr, dir.GetFullPath( temporary ).c_str() ); 591 575 } 592 576 } … … 611 595 // インクルードファイルを列挙(ワイルドカード指定を想定) 612 596 Jenga::Common::Strings resultOfFullPath; 613 Jenga::Common::FileSystem::SearchFiles( resultOfFullPath, findStr ); 597 // Jenga::Common::FileSystem::SearchFiles( resultOfFullPath, findStr ); 598 resultOfFullPath.push_back(findStr); 614 599 615 600 if( resultOfFullPath.empty() ) … … 644 629 645 630 //#requireの場合では、既に読み込まれているファイルは読み込まないようにする 631 /* 646 632 bool isFake = false; 647 633 if( isRequire ){ 648 if( requireFiles. IsIncluded( sourceFilePath ) ){634 if( requireFiles.TryAdd( sourceFilePath ) ){ 649 635 //既に読み込まれているとき 650 636 isFake = true; … … 668 654 } 669 655 } 670 671 Realloc( lstrlen(buffer) + source.GetLength() ); 656 */ 657 BasicSource source; 658 659 if( !requireFiles.TryAdd( sourceFilePath ) && isRequire ){ 660 //既に読み込まれているときは空データ 661 source.SetBuffer( "" ); 662 } 663 else{ 664 //インクルードファイルを読み込む 665 if( !source.ReadFile_InIncludeDirective( sourceFilePath ) ) 666 { 667 throw; 668 } 669 } 670 671 Realloc( strlen(buffer) + source.GetLength() ); 672 672 Text::SlideString( 673 673 buffer + headIndex + includeDirectiveLength, … … 683 683 char temp4[MAX_PATH]; 684 684 _splitpath(sourceFilePath.c_str(),temp2,temp4,0,0); 685 lstrcat(temp2,temp4);686 LayerDir[layer]=(char *)malloc( lstrlen(temp2)+1);687 lstrcpy(LayerDir[layer],temp2);685 strcat(temp2,temp4); 686 LayerDir[layer]=(char *)malloc(strlen(temp2)+1); 687 strcpy(LayerDir[layer],temp2); 688 688 689 689 //ファイル範囲をスライド … … 702 702 free(LayerDir[0]); 703 703 704 length = lstrlen(buffer);704 length = strlen(buffer); 705 705 } 706 706 … … 825 825 } 826 826 827 length = lstrlen(buffer);827 length = strlen(buffer); 828 828 } 829 829 … … 840 840 841 841 //最終行には文字を含ませないようにする 842 if( lstrlen(buffer)>0 && buffer[lstrlen(buffer)-1] != '\n' )842 if( strlen(buffer)>0 && buffer[strlen(buffer)-1] != '\n' ) 843 843 { 844 844 Realloc( length + 1 ); 845 lstrcat( buffer, "\n" );845 strcat( buffer, "\n" ); 846 846 } 847 847 … … 851 851 852 852 void BasicSource::SetBuffer( const char *buffer ){ 853 this->buffer = (char *)calloc( lstrlen(buffer) + 1, 1 );854 lstrcpy( this->buffer, buffer );855 length = lstrlen(buffer);853 this->buffer = (char *)calloc( strlen(buffer) + 1, 1 ); 854 strcpy( this->buffer, buffer ); 855 length = strlen(buffer); 856 856 857 857 // ダミー改行をセット … … 874 874 //const char *headCode = "#include <basic.sbp>\n"; 875 875 const char *headCode = ""; 876 Realloc( length + lstrlen(headCode) );877 Text::SlideString( buffer, lstrlen(headCode) );878 memcpy( buffer, headCode, lstrlen(headCode) );876 Realloc( length + strlen(headCode) ); 877 Text::SlideString( buffer, strlen(headCode) ); 878 memcpy( buffer, headCode, strlen(headCode) ); 879 879 880 880 // #defineと#requireを初期化 … … 891 891 //最終行には文字を含ませないようにする 892 892 Realloc( length + 1 ); 893 lstrcat( buffer, "\n" );893 strcat( buffer, "\n" ); 894 894 895 895 // #include / #require ディレクティブを処理 … … 912 912 913 913 void BasicSource::Addition( const char *buffer ){ 914 Realloc( length + lstrlen(buffer) );915 lstrcat( this->buffer, buffer );914 Realloc( length + strlen(buffer) ); 915 strcat( this->buffer, buffer ); 916 916 } 917 917
Note:
See TracChangeset
for help on using the changeset viewer.