X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=_src%2FTest%2Ftools%2Fvbslib_helper_src%2F_setup_generated%2Fclib.c;h=618bee3b8de656a90b4114c7f3b21cb27919a103;hb=5b8eb2f715a8c86c0d7166a96b01f3ec72e03880;hp=a1f8c6969523ef6fbe5789b46deae0a3009b8afd;hpb=f224366b97f57671eb9cbe3d5ec716704edbb869;p=vbslib%2Fmain.git diff --git a/_src/Test/tools/vbslib_helper_src/_setup_generated/clib.c b/_src/Test/tools/vbslib_helper_src/_setup_generated/clib.c index a1f8c69..618bee3 100644 --- a/_src/Test/tools/vbslib_helper_src/_setup_generated/clib.c +++ b/_src/Test/tools/vbslib_helper_src/_setup_generated/clib.c @@ -9,10 +9,10 @@ /*=================================================================*/ /*********************************************************************** - <<< [Globals_init_const] >>> + <<< [Globals_initConst] >>> ************************************************************************/ -void Globals_init_const() +void Globals_initConst() { AppKey_initGlobal_const(); } @@ -126,7 +126,7 @@ int GetCommandLineUnnamed( int Index1, TCHAR* out_AParam, size_t AParamSize ) err_nf: if ( AParamSize >= sizeof(TCHAR) ) *out_AParam = _T('\0'); - IF ( Index1 >= 2 ) return E_NotFoundSymbol; + IF ( Index1 >= 2 ) return E_NOT_FOUND_SYMBOL; return 0; } @@ -196,7 +196,7 @@ int GetCommandLineNamed_sub( const TCHAR* Name, bool bCase, bool* out_IsExist, } } else { - IF( bMatch ) return E_NotFoundSymbol; // no value error + IF( bMatch ) return E_NOT_FOUND_SYMBOL; // no value error } } @@ -215,7 +215,7 @@ int GetCommandLineNamed_sub( const TCHAR* Name, bool bCase, bool* out_IsExist, } *out_IsExist = false; - return E_NotFoundSymbol; + return E_NOT_FOUND_SYMBOL; } @@ -273,7 +273,7 @@ bool GetCommandLineExist( const TCHAR* Name, bool bCase ) TCHAR v[1]; e = GetCommandLineNamed_sub( Name, bCase, &is_exist, v, sizeof(v) ); - if ( e == E_NotFoundSymbol ) Err2_clear(); + if ( e == E_NOT_FOUND_SYMBOL ) ClearError(); return is_exist; } @@ -299,7 +299,7 @@ int env_part( TCHAR* Str, unsigned StrSize, TCHAR* StrStart, TCHAR** out_StrL IF_D( StrStart < Str || StrStart >= o_last ) goto err; c = *p; - IF_D( StrSize <= 2 ) return E_FewArray; + IF_D( StrSize <= 2 ) return E_FEW_ARRAY; while ( c != _T('\0') ) { if ( c == _T('%') ) { @@ -345,9 +345,9 @@ fin: if ( out_StrLast != NULL ) *out_StrLast = o; return e; -err_fa: e = E_FewArray; goto fin; -err_ns: e = E_NotFoundSymbol; goto fin; -err: e = E_Others; goto fin; +err_fa: e = E_FEW_ARRAY; goto fin; +err_ns: e = E_NOT_FOUND_SYMBOL; goto fin; +err: e = E_OTHERS; goto fin; } @@ -378,7 +378,7 @@ int env_malloc( TCHAR** out_Value, size_t* out_ValueLen, const TCHAR* Name ) fin: return e; -err_fm: e = E_FewMemory; goto fin; +err_fm: e = E_FEW_MEMORY; goto fin; } @@ -426,27 +426,27 @@ bool FileT_isExist( const TCHAR* path ) { #if ! FileT_isExistWildcard - DWORD r; + DWORD r; - if ( path[0] == _T('\0') ) return false; - r = GetFileAttributes( path ); - return r != (DWORD)-1; + if ( path[0] == _T('\0') ) return false; + r = GetFileAttributes( path ); + return r != (DWORD)-1; #else - HANDLE find; - WIN32_FIND_DATA data; + HANDLE find; + WIN32_FIND_DATA data; - find = FindFirstFileEx( path, FindExInfoStandard, &data, - FindExSearchNameMatch, NULL, 0 ); + find = FindFirstFileEx( path, FindExInfoStandard, &data, + FindExSearchNameMatch, NULL, 0 ); - if ( find == INVALID_HANDLE_VALUE ) { - return false; - } - else { - FindClose( find ); - return true; - } + if ( find == INVALID_HANDLE_VALUE ) { + return false; + } + else { + FindClose( find ); + return true; + } #endif } @@ -458,9 +458,9 @@ bool FileT_isExist( const TCHAR* path ) ************************************************************************/ bool FileT_isFile( const TCHAR* path ) { - DWORD r = GetFileAttributes( path ); - return ( r & (FILE_ATTRIBUTE_DIRECTORY | 0x80000000) ) == 0; - // 0x80000000 ‚́Aƒtƒ@ƒCƒ‹‚âƒtƒHƒ‹ƒ_‚ª‘¶Ý‚µ‚È‚¢‚±‚Æ‚ð”»’è‚·‚邽‚ß + DWORD r = GetFileAttributes( path ); + return ( r & (FILE_ATTRIBUTE_DIRECTORY | 0x80000000) ) == 0; + // 0x80000000 ‚́Aƒtƒ@ƒCƒ‹‚âƒtƒHƒ‹ƒ_‚ª‘¶Ý‚µ‚È‚¢‚±‚Æ‚ð”»’è‚·‚邽‚ß } @@ -470,9 +470,9 @@ bool FileT_isFile( const TCHAR* path ) ************************************************************************/ bool FileT_isDir( const TCHAR* path ) { - DWORD r = GetFileAttributes( path ); - return ( r & (FILE_ATTRIBUTE_DIRECTORY | 0x80000000) ) == FILE_ATTRIBUTE_DIRECTORY; - // 0x80000000 ‚́Aƒtƒ@ƒCƒ‹‚âƒtƒHƒ‹ƒ_‚ª‘¶Ý‚µ‚È‚¢‚±‚Æ‚ð”»’è‚·‚邽‚ß + DWORD r = GetFileAttributes( path ); + return ( r & (FILE_ATTRIBUTE_DIRECTORY | 0x80000000) ) == FILE_ATTRIBUTE_DIRECTORY; + // 0x80000000 ‚́Aƒtƒ@ƒCƒ‹‚âƒtƒHƒ‹ƒ_‚ª‘¶Ý‚µ‚È‚¢‚±‚Æ‚ð”»’è‚·‚邽‚ß } @@ -481,17 +481,17 @@ bool FileT_isDir( const TCHAR* path ) <<< [FileT_callByNestFind] ƒTƒuƒtƒHƒ‹ƒ_‚àŠÜ‚ß‚ÄŠeƒtƒ@ƒCƒ‹‚̃pƒX‚ð“n‚· >>> ************************************************************************/ typedef struct { - /*--- inherit from FileT_CallByNestFindData */ - void* CallerArgument; - TCHAR* AbsPath; // abstruct path - TCHAR* StepPath; - TCHAR* FileName; - DWORD FileAttributes; - - /*---*/ - BitField Flags; - FuncType CallbackFromNestFind; - TCHAR AbsPathMem[4096]; + /*--- inherit from FileT_CallByNestFindData */ + void* CallerArgument; + TCHAR* AbsPath; // abstruct path + TCHAR* StepPath; + TCHAR* FileName; + DWORD FileAttributes; + + /*---*/ + BitField Flags; + FuncType CallbackFromNestFind; + TCHAR AbsPathMem[4096]; } FileT_CallByNestFindDataIn; int FileT_callByNestFind_sub( FileT_CallByNestFindDataIn* m ); @@ -499,151 +499,151 @@ int FileT_callByNestFind_sub( FileT_CallByNestFindDataIn* m ); int FileT_callByNestFind( const TCHAR* Path, BitField Flags, void* Argument, FuncType Callback ) { - int e; - FileT_CallByNestFindDataIn data; + int e; + FileT_CallByNestFindDataIn data; - { - TCHAR* p; + { + TCHAR* p; - e= StrT_cpy( data.AbsPathMem, sizeof(data.AbsPathMem), Path ); IF(e)goto fin; + e= StrT_cpy( data.AbsPathMem, sizeof(data.AbsPathMem), Path ); IF(e)goto fin; - /* AbsPathMem ‚̍Ōã‚É \ ‚ª–³‚¢‚È‚ç’ljÁ‚·‚é */ - p = _tcschr( data.AbsPathMem, _T('\0') ); - p--; - if ( *p != _T('\\') ) { - p++; - IF( p >= data.AbsPathMem + (sizeof(data.AbsPathMem) / sizeof(TCHAR)) - 1 )goto err_fa; - *p = _T('\\'); - } + /* AbsPathMem ‚̍Ōã‚É \ ‚ª–³‚¢‚È‚ç’ljÁ‚·‚é */ + p = _tcschr( data.AbsPathMem, _T('\0') ); + p--; + if ( *p != _T('\\') ) { + p++; + IF( p >= data.AbsPathMem + (sizeof(data.AbsPathMem) / sizeof(TCHAR)) - 1 )goto err_fa; + *p = _T('\\'); + } - /* data ‚ð‰Šú‰»‚·‚é */ - data.CallerArgument = Argument; - data.AbsPath = data.AbsPathMem; - data.StepPath = p + 1; - data.FileName = p + 1; - data.Flags = Flags; - data.CallbackFromNestFind = Callback; - } + /* data ‚ð‰Šú‰»‚·‚é */ + data.CallerArgument = Argument; + data.AbsPath = data.AbsPathMem; + data.StepPath = p + 1; + data.FileName = p + 1; + data.Flags = Flags; + data.CallbackFromNestFind = Callback; + } - /* Ä‹NŒÄ‚яo‚µŠÖ”‚Ö */ - e= FileT_callByNestFind_sub( &data ); IF(e)goto fin; + /* Ä‹NŒÄ‚яo‚µŠÖ”‚Ö */ + e= FileT_callByNestFind_sub( &data ); IF(e)goto fin; - e=0; + e=0; fin: - return e; -err_fa: e= E_FewArray; goto fin; + return e; +err_fa: e= E_FEW_ARRAY; goto fin; } int FileT_callByNestFind_sub( FileT_CallByNestFindDataIn* m ) { - int e; - HANDLE find; - WIN32_FIND_DATA data; - TCHAR* p; - int done; + int e; + HANDLE find; + WIN32_FIND_DATA data; + TCHAR* p; + int done; - /* Path ‚ÉŽw’肵‚½ƒtƒHƒ‹ƒ_‚ɑ΂µ‚ăR[ƒ‹ƒoƒbƒN‚·‚é */ - if ( m->Flags & FileT_FolderBeforeFiles ) { - *( m->FileName - 1 ) = _T('\0'); // m->AbsPath ‚̍Ōã‚Ì \ ‚ðˆêŽž“I‚ɃJƒbƒg - *( m->FileName ) = _T('\0'); // m->FileName, m->StepPath ‚ð "" ‚É‚·‚é - m->FileAttributes = FILE_ATTRIBUTE_DIRECTORY; + /* Path ‚ÉŽw’肵‚½ƒtƒHƒ‹ƒ_‚ɑ΂µ‚ăR[ƒ‹ƒoƒbƒN‚·‚é */ + if ( m->Flags & FileT_FolderBeforeFiles ) { + *( m->FileName - 1 ) = _T('\0'); // m->AbsPath ‚̍Ōã‚Ì \ ‚ðˆêŽž“I‚ɃJƒbƒg + *( m->FileName ) = _T('\0'); // m->FileName, m->StepPath ‚ð "" ‚É‚·‚é + m->FileAttributes = FILE_ATTRIBUTE_DIRECTORY; - if ( m->StepPath[0] == _T('\0') ) { - TCHAR* step_path = m->StepPath; - TCHAR* fname = m->FileName; + if ( m->StepPath[0] == _T('\0') ) { + TCHAR* step_path = m->StepPath; + TCHAR* fname = m->FileName; - m->StepPath = _T("."); - m->FileName = StrT_refFName( m->AbsPath ); - e= m->CallbackFromNestFind( m ); IF(e)goto fin; - m->StepPath = step_path; - m->FileName = fname; - } - else if ( m->FileName[0] == _T('\0') ) { - TCHAR* fname = m->FileName; + m->StepPath = _T("."); + m->FileName = StrT_refFName( m->AbsPath ); + e= m->CallbackFromNestFind( m ); IF(e)goto fin; + m->StepPath = step_path; + m->FileName = fname; + } + else if ( m->FileName[0] == _T('\0') ) { + TCHAR* fname = m->FileName; - m->FileName = StrT_refFName( m->AbsPath ); - e= m->CallbackFromNestFind( m ); IF(e)goto fin; - m->FileName = fname; - } - else { - e= m->CallbackFromNestFind( m ); IF(e)goto fin; - } - *( m->FileName - 1 ) = _T('\\'); - } + m->FileName = StrT_refFName( m->AbsPath ); + e= m->CallbackFromNestFind( m ); IF(e)goto fin; + m->FileName = fname; + } + else { + e= m->CallbackFromNestFind( m ); IF(e)goto fin; + } + *( m->FileName - 1 ) = _T('\\'); + } - /* * ‚ð’ljÁ */ - p = m->FileName; - IF( p >= m->AbsPathMem + (sizeof(m->AbsPathMem) / sizeof(TCHAR)) - 2 )goto err_fa; - *p = _T('*'); *(p+1) = _T('\0'); + /* * ‚ð’ljÁ */ + p = m->FileName; + IF( p >= m->AbsPathMem + (sizeof(m->AbsPathMem) / sizeof(TCHAR)) - 2 )goto err_fa; + *p = _T('*'); *(p+1) = _T('\0'); - /* ƒtƒ@ƒCƒ‹‚©ƒtƒHƒ‹ƒ_‚ð—ñ‹“‚µ‚Ü‚· */ - find = FindFirstFileEx( m->AbsPathMem, FindExInfoStandard, &data, - FindExSearchNameMatch, NULL, 0 ); - done = ( find == INVALID_HANDLE_VALUE ); + /* ƒtƒ@ƒCƒ‹‚©ƒtƒHƒ‹ƒ_‚ð—ñ‹“‚µ‚Ü‚· */ + find = FindFirstFileEx( m->AbsPathMem, FindExInfoStandard, &data, + FindExSearchNameMatch, NULL, 0 ); + done = ( find == INVALID_HANDLE_VALUE ); - while (!done) - { - if ( _tcscmp( data.cFileName, _T(".") ) == 0 || - _tcscmp( data.cFileName, _T("..") ) == 0 ) { - done = ! FindNextFile( find, &data ); - continue; - } + while (!done) + { + if ( _tcscmp( data.cFileName, _T(".") ) == 0 || + _tcscmp( data.cFileName, _T("..") ) == 0 ) { + done = ! FindNextFile( find, &data ); + continue; + } - StrT_cpy( m->FileName, - sizeof(m->AbsPathMem) - ( (char*)m->FileName - (char*)m->AbsPathMem ), - data.cFileName ); - m->FileAttributes = data.dwFileAttributes; + StrT_cpy( m->FileName, + sizeof(m->AbsPathMem) - ( (char*)m->FileName - (char*)m->AbsPathMem ), + data.cFileName ); + m->FileAttributes = data.dwFileAttributes; - if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { - TCHAR* prev_fname = m->FileName; + if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { + TCHAR* prev_fname = m->FileName; - p = _tcschr( m->FileName, _T('\0') ); + p = _tcschr( m->FileName, _T('\0') ); - IF( p >= m->AbsPathMem + (sizeof(m->AbsPathMem) / sizeof(TCHAR)) - 2 )goto err_fa; - *p = _T('\\'); *(p+1) = _T('\0'); - m->FileName = p + 1; + IF( p >= m->AbsPathMem + (sizeof(m->AbsPathMem) / sizeof(TCHAR)) - 2 )goto err_fa; + *p = _T('\\'); *(p+1) = _T('\0'); + m->FileName = p + 1; - e= FileT_callByNestFind_sub( m ); IF(e)goto fin; /* Ä‹NŒÄ‚яo‚µ */ + e= FileT_callByNestFind_sub( m ); IF(e)goto fin; /* Ä‹NŒÄ‚яo‚µ */ - m->FileName = prev_fname; - } - else { - e= m->CallbackFromNestFind( m ); IF(e)goto fin; - } + m->FileName = prev_fname; + } + else { + e= m->CallbackFromNestFind( m ); IF(e)goto fin; + } - done = ! FindNextFile( find, &data ); - } - FindClose( find ); + done = ! FindNextFile( find, &data ); + } + FindClose( find ); - /* Path ‚ÉŽw’肵‚½ƒtƒHƒ‹ƒ_‚ɑ΂µ‚ăR[ƒ‹ƒoƒbƒN‚·‚é */ - if ( m->Flags & FileT_FolderAfterFiles ) { - TCHAR* step_path = m->StepPath; - TCHAR* fname = m->FileName; + /* Path ‚ÉŽw’肵‚½ƒtƒHƒ‹ƒ_‚ɑ΂µ‚ăR[ƒ‹ƒoƒbƒN‚·‚é */ + if ( m->Flags & FileT_FolderAfterFiles ) { + TCHAR* step_path = m->StepPath; + TCHAR* fname = m->FileName; - *( m->FileName - 1 ) = _T('\0'); - m->FileAttributes = FILE_ATTRIBUTE_DIRECTORY; - if ( ( *( m->StepPath - 1 ) == _T('\0') ) && ( m->StepPath > m->AbsPath ) ) { - m->StepPath = _T("."); - } - m->FileName = StrT_refFName( m->AbsPath ); + *( m->FileName - 1 ) = _T('\0'); + m->FileAttributes = FILE_ATTRIBUTE_DIRECTORY; + if ( ( *( m->StepPath - 1 ) == _T('\0') ) && ( m->StepPath > m->AbsPath ) ) { + m->StepPath = _T("."); + } + m->FileName = StrT_refFName( m->AbsPath ); - e= m->CallbackFromNestFind( m ); IF(e)goto fin; + e= m->CallbackFromNestFind( m ); IF(e)goto fin; - m->StepPath = step_path; - m->FileName = fname; - } + m->StepPath = step_path; + m->FileName = fname; + } - e=0; + e=0; fin: - return e; -err_fa: e= E_FewArray; goto fin; + return e; +err_fa: e= E_FEW_ARRAY; goto fin; } @@ -653,32 +653,36 @@ err_fa: e= E_FewArray; goto fin; ************************************************************************/ int FileT_openForRead( FILE** out_pFile, const TCHAR* Path ) { - errno_t en; + errno_t en; - assert( Locale_isInited() ); + assert( Locale_isInited() ); - #if DEBUGTOOLS_USES - { int e= Debug_onOpen( Path ); if(e) return e; } - #endif + #if DEBUGTOOLS_USES + { int e= Debug_onOpen( Path ); if(e) return e; } + #endif - en = _tfopen_s( out_pFile, Path, _T("r")_T(fopen_ccs) ); - if ( en == 2 ) { - _tprintf( _T("not found \"%s\"\n"), Path ); + en = _tfopen_s( out_pFile, Path, _T("r")_T(fopen_ccs) ); + if ( en == ENOENT ) { + _tprintf( _T("not found \"%s\"\n"), Path ); - #ifndef UNDER_CE - { - TCHAR cwd[512]; + #ifndef UNDER_CE + { + TCHAR cwd[512]; - if ( _tgetcwd( cwd, _countof(cwd) ) != NULL ) - _tprintf( _T("current = \"%s\"\n"), cwd ); - } - #endif + if ( _tgetcwd( cwd, _countof(cwd) ) != NULL ) + _tprintf( _T("current = \"%s\"\n"), cwd ); + } + #endif - return E_NotFoundSymbol; - } - IF(en)return E_Others; + return E_NOT_FOUND_SYMBOL; + } + if ( en == EACCES ) { + _tprintf( _T("access denied \"%s\"\n"), Path ); + return E_ACCESS_DENIED; + } + IF(en)return E_OTHERS; - return 0; + return 0; } @@ -694,7 +698,7 @@ int FileT_openForWrite( FILE** out_pFile, const TCHAR* Path, int Flags ) BOOL b; int retry_count; - IF_D( ! Locale_isInited() ) return E_NotInitGlobal; + IF_D( ! Locale_isInited() ) return E_NOT_INIT_GLOBAL; #if Uses_AppKey e= AppKey_addNewWritableFolder( Path ); IF(e)goto fin; @@ -734,7 +738,7 @@ int FileT_openForWrite( FILE** out_pFile, const TCHAR* Path, int Flags ) } #endif - e = E_NotFoundSymbol; + e = E_NOT_FOUND_SYMBOL; goto fin; } } @@ -744,8 +748,8 @@ int FileT_openForWrite( FILE** out_pFile, const TCHAR* Path, int Flags ) fin: return e; -err: e = E_Others; goto fin; -err_gt: e = E_GetLastError; goto fin; +err: e = E_OTHERS; goto fin; +err_gt: e = SaveWindowsLastError(); goto fin; } @@ -755,59 +759,81 @@ err_gt: e = E_GetLastError; goto fin; ************************************************************************/ int FileT_close( FILE* File, int e ) { - if ( File != NULL ) { - int r = fclose( File ); - IF(r&&!e)e=E_Errno; - } - return e; + if ( File != NULL ) { + int r = fclose( File ); + IF(r&&!e)e=E_ERRNO; + } + return e; } /*********************************************************************** + <<< [FileT_writePart] >>> +************************************************************************/ +errnum_t FileT_writePart( FILE* File, TCHAR* Start, TCHAR* Over ) +{ + errnum_t e; + TCHAR back_char; + int r; + + back_char = *Over; + *Over = _T('\0'); + + r= _ftprintf_s( File, _T("%s"), Start ); IF(r<0){ e=E_ERRNO; goto fin; } + + e=0; +fin: + *Over = back_char; + return e; +} + + + +/*********************************************************************** <<< [FileT_mkdir] >>> ************************************************************************/ int FileT_mkdir( const TCHAR* Path ) { - int e; - DWORD r; - TCHAR* p; - BOOL b; - int n_folder = 0; - TCHAR path2[MAX_PATH]; + int e; + DWORD r; + TCHAR* p = (TCHAR*) DUMMY_INITIAL_VALUE; + BOOL b; + int n_folder = 0; + TCHAR path2[MAX_PATH]; - e= StrT_getAbsPath( path2, sizeof(path2), Path, NULL ); IF(e)goto fin; - #if Uses_AppKey - e= AppKey_addNewWritableFolder( path2 ); IF(e)goto fin; - #endif + e= StrT_getAbsPath( path2, sizeof(path2), Path, NULL ); IF(e)goto fin; + #if Uses_AppKey + e= AppKey_addNewWritableFolder( path2 ); IF(e)goto fin; + #endif - //=== ‘¶Ý‚·‚éƒtƒHƒ‹ƒ_‚ð’T‚· - for (;;) { - r = GetFileAttributes( path2 ); - if ( r != (DWORD)-1 ) break; // "C:" ‚àƒtƒHƒ‹ƒ_‚Æ”»’肳‚ê‚é + //=== ‘¶Ý‚·‚éƒtƒHƒ‹ƒ_‚ð’T‚· + for (;;) { + r = GetFileAttributes( path2 ); + if ( r != (DWORD)-1 ) break; // "C:" ‚àƒtƒHƒ‹ƒ_‚Æ”»’肳‚ê‚é - p = StrT_refFName( path2 ) - 1; // â‘΃pƒX‚È‚Ì‚Å•K‚¸ *p=='\\' - *p = _T('\0'); - n_folder ++; - } - IF ( ! (r & FILE_ATTRIBUTE_DIRECTORY) ) goto err; // ƒtƒ@ƒCƒ‹‚È‚çƒGƒ‰[ + p = StrT_refFName( path2 ) - 1; // â‘΃pƒX‚È‚Ì‚Å•K‚¸ *p=='\\' + *p = _T('\0'); + n_folder ++; + } + IF ( ! (r & FILE_ATTRIBUTE_DIRECTORY) ) goto err; // ƒtƒ@ƒCƒ‹‚È‚çƒGƒ‰[ - //=== ƒtƒHƒ‹ƒ_‚ðì¬‚·‚é - for ( ; n_folder > 0; n_folder -- ) { - *p = _T('\\'); - b= CreateDirectory( path2, NULL ); IF(!b)goto err; - p = _tcschr( p, _T('\0') ); - } + //=== ƒtƒHƒ‹ƒ_‚ðì¬‚·‚é + for ( ; n_folder > 0; n_folder -- ) { + *p = _T('\\'); + b= CreateDirectory( path2, NULL ); IF(!b)goto err; + p = _tcschr( p, _T('\0') ); + } - e=0; + e=0; fin: - return e; + return e; -err: e = E_Others; goto fin; +err: e = E_OTHERS; goto fin; } @@ -820,96 +846,96 @@ int FileT_copy_sub( FileT_CallByNestFindData* m ); int FileT_copy( const TCHAR* SrcPath, const TCHAR* DstPath ) { - const TCHAR* p_last; - int e; - BOOL b; - TCHAR path[MAX_PATH*4]; - + const TCHAR* p_last; + int e; + BOOL b; + TCHAR path[MAX_PATH*4]; - #if Uses_AppKey - e= AppKey_addNewWritableFolder( DstPath ); IF(e)goto fin; - #endif - p_last = _tcschr( SrcPath, _T('\0') ); - IF_D( p_last <= SrcPath + 1 )goto err_ni; + #if Uses_AppKey + e= AppKey_addNewWritableFolder( DstPath ); IF(e)goto fin; + #endif + p_last = _tcschr( SrcPath, _T('\0') ); + IF_D( p_last <= SrcPath + 1 )goto err_ni; - //=== ƒtƒHƒ‹ƒ_‚ðƒRƒs[‚·‚é - if ( *(p_last - 1) == _T('*') ) { - IF_D( *(p_last - 2) != _T('\\') ) goto err_ni; - e= StrT_getParentAbsPath( path, sizeof(path), SrcPath, NULL ); IF(e)goto fin; - IF_D( ! FileT_isDir( path ) )goto err_nf; + //=== ƒtƒHƒ‹ƒ_‚ðƒRƒs[‚·‚é + if ( *(p_last - 1) == _T('*') ) { + IF_D( *(p_last - 2) != _T('\\') ) goto err_ni; - e= FileT_callByNestFind( path, FileT_FolderBeforeFiles, (void*) DstPath, (FuncType) FileT_copy_sub ); - IF(e)goto fin; - } + e= StrT_getParentAbsPath( path, sizeof(path), SrcPath, NULL ); IF(e)goto fin; + IF_D( ! FileT_isDir( path ) )goto err_nf; + e= FileT_callByNestFind( path, FileT_FolderBeforeFiles, (void*) DstPath, (FuncType) FileT_copy_sub ); + IF(e)goto fin; + } - //=== ƒtƒ@ƒCƒ‹‚ðƒRƒs[‚·‚é - else { - IF_D( _tcschr( SrcPath, _T('*') ) != NULL )goto err_ni; - IF_D( ! FileT_isFile( SrcPath ) ) goto err_nf; - b= CopyFile( SrcPath, DstPath, FALSE ); - if (!b) { - if ( FileT_isDir( DstPath ) ) { - e= stprintf_r( path, sizeof(path), _T("%s\\%s"), DstPath, StrT_refFName( SrcPath ) ); IF(e)goto fin; - b= CopyFile( SrcPath, path, FALSE ); IF(!b)goto err_gt; - } - else { - int ee; - - p_last = _tcschr( DstPath, _T('\0') ) - 1; - IF_D( p_last < DstPath )goto err; - if ( *p_last == _T('\\') ) { - ee= FileT_mkdir( DstPath ); IF(ee)goto fin; - e= stprintf_r( path, sizeof(path), _T("%s%s"), DstPath, StrT_refFName( SrcPath ) ); IF(e)goto fin; - b= CopyFile( SrcPath, path, FALSE ); IF(!b)goto err_gt; - } - else { - e = E_AccessDenied; - ee= StrT_getParentAbsPath( path, sizeof(path), DstPath, NULL ); IF(ee)goto fin; - ee= FileT_mkdir( path ); IF(ee)goto fin; - b= CopyFile( SrcPath, DstPath, FALSE ); IF(!b)goto err_gt; - } - } - } - } + //=== ƒtƒ@ƒCƒ‹‚ðƒRƒs[‚·‚é + else { + IF_D( _tcschr( SrcPath, _T('*') ) != NULL )goto err_ni; + IF_D( ! FileT_isFile( SrcPath ) ) goto err_nf; + + b= CopyFile( SrcPath, DstPath, FALSE ); + if (!b) { + if ( FileT_isDir( DstPath ) ) { + e= stprintf_r( path, sizeof(path), _T("%s\\%s"), DstPath, StrT_refFName( SrcPath ) ); IF(e)goto fin; + b= CopyFile( SrcPath, path, FALSE ); IF(!b)goto err_gt; + } + else { + int ee; + + p_last = _tcschr( DstPath, _T('\0') ) - 1; + IF_D( p_last < DstPath )goto err; + if ( *p_last == _T('\\') ) { + ee= FileT_mkdir( DstPath ); IF(ee)goto fin; + e= stprintf_r( path, sizeof(path), _T("%s%s"), DstPath, StrT_refFName( SrcPath ) ); IF(e)goto fin; + b= CopyFile( SrcPath, path, FALSE ); IF(!b)goto err_gt; + } + else { + e = E_ACCESS_DENIED; + ee= StrT_getParentAbsPath( path, sizeof(path), DstPath, NULL ); IF(ee)goto fin; + ee= FileT_mkdir( path ); IF(ee)goto fin; + b= CopyFile( SrcPath, DstPath, FALSE ); IF(!b)goto err_gt; + } + } + } + } - e=0; + e=0; fin: - return e; + return e; -err_ni: e = E_NotImplementYet; goto fin; -err_nf: e = E_PathNotFound; goto fin; -err_gt: e = E_GetLastError; goto fin; -err: e = E_Others; goto fin; +err_ni: e = E_NOT_IMPLEMENT_YET; goto fin; +err_nf: e = E_PATH_NOT_FOUND; goto fin; +err_gt: e = SaveWindowsLastError(); goto fin; +err: e = E_OTHERS; goto fin; } int FileT_copy_sub( FileT_CallByNestFindData* m ) { - const TCHAR* DstPath = (const TCHAR*) m->CallerArgument; - int e; - BOOL b; - TCHAR path[MAX_PATH*4]; + const TCHAR* DstPath = (const TCHAR*) m->CallerArgument; + int e; + BOOL b; + TCHAR path[MAX_PATH*4]; - e= stprintf_r( path, sizeof(path), _T("%s\\%s"), DstPath, m->StepPath ); IF(e)goto fin; + e= stprintf_r( path, sizeof(path), _T("%s\\%s"), DstPath, m->StepPath ); IF(e)goto fin; - if ( m->FileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { - if ( ! FileT_isDir( path ) ) - { b= CreateDirectory( path, NULL ); IF(!b)goto err_gt; } - } - else { - b= CopyFile( m->AbsPath, path, FALSE ); IF(!b)goto err_gt; - } + if ( m->FileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { + if ( ! FileT_isDir( path ) ) + { b= CreateDirectory( path, NULL ); IF(!b)goto err_gt; } + } + else { + b= CopyFile( m->AbsPath, path, FALSE ); IF(!b)goto err_gt; + } - e=0; + e=0; fin: - return e; + return e; -err_gt: e = E_GetLastError; goto fin; +err_gt: e = SaveWindowsLastError(); goto fin; } @@ -922,137 +948,136 @@ int FileT_del_sub( FileT_CallByNestFindData* m ); int FileT_del( const TCHAR* Path ) { - int e; - DWORD r; - TCHAR abs_path[MAX_PATH]; + int e; + DWORD r; + TCHAR abs_path[MAX_PATH]; - e= StrT_getAbsPath( abs_path, sizeof(abs_path), Path, NULL ); IF(e)goto fin; - #if Uses_AppKey - e= AppKey_addNewWritableFolder( abs_path ); IF(e)goto fin; - #endif + e= StrT_getAbsPath( abs_path, sizeof(abs_path), Path, NULL ); IF(e)goto fin; + #if Uses_AppKey + e= AppKey_addNewWritableFolder( abs_path ); IF(e)goto fin; + #endif - r= GetFileAttributes( Path ); - if ( r != (DWORD)-1 ) { - if ( r & FILE_ATTRIBUTE_DIRECTORY ) { - e= FileT_callByNestFind( Path, FileT_FolderAfterFiles, NULL, (FuncType) FileT_del_sub ); - } - else { - BOOL b= DeleteFile( Path ); IF(!b)goto err_gt; - } - } - IF_D( FileT_isExist( Path ) )goto err_ad; + r= GetFileAttributes( Path ); + if ( r != (DWORD)-1 ) { + if ( r & FILE_ATTRIBUTE_DIRECTORY ) { + e= FileT_callByNestFind( Path, FileT_FolderAfterFiles, NULL, (FuncType) FileT_del_sub ); + } + else { + BOOL b= DeleteFile( Path ); IF(!b)goto err_gt; + } + } + IF_D( FileT_isExist( Path ) )goto err_ad; - e=0; + e=0; fin: - return e; + return e; -err_gt: e = E_GetLastError; goto fin; -err_ad: e = E_AccessDenied; goto fin; +err_gt: e = SaveWindowsLastError(); goto fin; +err_ad: e = E_ACCESS_DENIED; goto fin; } int FileT_del_sub( FileT_CallByNestFindData* m ) { - int e; - BOOL b; + int e; + BOOL b; - if ( m->FileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { - b= RemoveDirectory( m->AbsPath ); IF(!b)goto err_gt; - } - else { - b= DeleteFile( m->AbsPath ); IF(!b)goto err_gt; - } + if ( m->FileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { + b= RemoveDirectory( m->AbsPath ); IF(!b)goto err_gt; + } + else { + b= DeleteFile( m->AbsPath ); IF(!b)goto err_gt; + } - e=0; + e=0; fin: - return e; + return e; -err_gt: e = E_GetLastError; goto fin; +err_gt: e = SaveWindowsLastError(); goto fin; } /*********************************************************************** <<< [AppKey] >>> ************************************************************************/ -int AppKey_create( AppKey** out_m ); -bool AppKey_isSame( AppKey* m ); -void Writables_init_const( Writables* m ); -int Writables_init( Writables* m, AppKey* Key ); -int Writables_finish( Writables* m, int e ); -int Writables_isInited( Writables* m ); -int Writables_clearPaths( Writables* m ); -int Writables_create( Writables** out_m, AppKey* Key ); -int Writables_copyToConst( Writables* To, Writables* From ); +static errnum_t AppKey_create( AppKey** out_m ); +static bool AppKey_isSame( AppKey* m ); +static void Writables_initConst( Writables* m ); +static errnum_t Writables_init( Writables* m, AppKey* Key ); +static errnum_t Writables_finish( Writables* m, int e ); +static bool Writables_isInited( Writables* m ); +static errnum_t Writables_clearPaths( Writables* m ); +static errnum_t Writables_create( Writables** out_m, AppKey* Key ); +static errnum_t Writables_copyToConst( Writables* To, Writables* From ); typedef struct _CurrentWritables CurrentWritables; struct _CurrentWritables { - Writables m_CurrentWritables; - TCHAR* m_ProgramFiles; size_t m_ProgramFiles_Len; - TCHAR* m_windir; size_t m_windir_Len; - TCHAR* m_APPDATA; size_t m_APPDATA_Len; - TCHAR* m_LOCALAPPDATA; size_t m_LOCALAPPDATA_Len; + Writables m_CurrentWritables; + TCHAR* m_ProgramFiles; size_t m_ProgramFiles_Len; + TCHAR* m_windir; size_t m_windir_Len; + TCHAR* m_APPDATA; size_t m_APPDATA_Len; + TCHAR* m_LOCALAPPDATA; size_t m_LOCALAPPDATA_Len; }; -void CurrentWritables_init_const( CurrentWritables* m ); -int CurrentWritables_init( CurrentWritables* m ); -int CurrentWritables_finish( CurrentWritables* m, int e ); -int CurrentWritables_askFileAccess( CurrentWritables* m, const TCHAR* AbsPath ); +static void CurrentWritables_initConst( CurrentWritables* m ); +static errnum_t CurrentWritables_init( CurrentWritables* m ); +static errnum_t CurrentWritables_finish( CurrentWritables* m, int e ); +static errnum_t CurrentWritables_askFileAccess( CurrentWritables* m, const TCHAR* AbsPath ); ////////////////////////////// - static AppKey g_AppKey; static AppKey* g_AppKeyPrivate; // under g_AppKey - Writables g_DefaultWritables; - Writables g_CurrentWritables; // public - static CurrentWritables g_CurrentWritablesPrivate; +Writables g_DefaultWritables; +Writables g_CurrentWritables; // public +static CurrentWritables g_CurrentWritablesPrivate; -static int AppKey_create( AppKey** out_m ) +static errnum_t AppKey_create( AppKey** out_m ) { - int e; + errnum_t e; - IF( g_AppKeyPrivate != NULL ) { e=1; goto fin; } - // AppKey_newWritable ‚Ì in_out_m = NULL ‚Ì‚Æ‚«‚́A2‰ñŒÄ‚яo‚·‚±‚Æ‚Í‚Å‚«‚Ü‚¹‚ñB + IF( g_AppKeyPrivate != NULL ) { e=1; goto fin; } + // AppKey_newWritable ‚Ì in_out_m = NULL ‚Ì‚Æ‚«‚́A2‰ñŒÄ‚яo‚·‚±‚Æ‚Í‚Å‚«‚Ü‚¹‚ñB - Writables_init_const( &g_DefaultWritables ); - CurrentWritables_init_const( &g_CurrentWritablesPrivate ); + Writables_initConst( &g_DefaultWritables ); + CurrentWritables_initConst( &g_CurrentWritablesPrivate ); - e= CurrentWritables_init( &g_CurrentWritablesPrivate ); IF(e)goto fin; - e= Writables_copyToConst( &g_CurrentWritables, NULL ); IF(e)goto fin; + e= CurrentWritables_init( &g_CurrentWritablesPrivate ); IF(e)goto fin; + e= Writables_copyToConst( &g_CurrentWritables, NULL ); IF(e)goto fin; - *out_m = &g_AppKey; - g_AppKeyPrivate = &g_AppKey; + *out_m = &g_AppKey; + g_AppKeyPrivate = &g_AppKey; - e=0; + e=0; fin: - return e; + return e; } static bool AppKey_isSame( AppKey* m ) { - return ( m == g_AppKeyPrivate ); + return ( m == g_AppKeyPrivate ); } void AppKey_initGlobal_const() { - Writables_init_const( &g_DefaultWritables ); + Writables_initConst( &g_DefaultWritables ); } -int AppKey_finishGlobal( int e ) +errnum_t AppKey_finishGlobal( errnum_t e ) { - int ee; + errnum_t ee; - e= Writables_finish( &g_DefaultWritables, e ); - e= CurrentWritables_finish( &g_CurrentWritablesPrivate, e ); - ee= Writables_copyToConst( &g_CurrentWritables, NULL ); IF(ee&&!e)e=ee; + e= Writables_finish( &g_DefaultWritables, e ); + e= CurrentWritables_finish( &g_CurrentWritablesPrivate, e ); + ee= Writables_copyToConst( &g_CurrentWritables, NULL ); IF(ee&&!e)e=ee; - return e; + return e; } @@ -1060,94 +1085,94 @@ int AppKey_finishGlobal( int e ) /*********************************************************************** <<< [AppKey_newWritable] >>> ************************************************************************/ -int AppKey_newWritable( AppKey** in_out_m, Writables** out_Writable, ... ) +errnum_t AppKey_newWritable( AppKey** in_out_m, Writables** out_Writable, ... ) { - int e; - AppKey* m = NULL; - Writables* wr = NULL; + errnum_t e; + AppKey* m = NULL; + Writables* wr = NULL; #if Uses_OutMallocIDTool - bool is_prev_out_malloc; + bool is_prev_out_malloc; - is_prev_out_malloc = OutMallocID_setEnable( false ); + is_prev_out_malloc = OutMallocID_setEnable( false ); #endif - //=== AppKey* m ‚ð—LŒø‚É‚·‚é - if ( in_out_m == NULL ) { // ¡‰ñ‚̊֐”‚Ì’†‚¾‚¯‚ÅŽQÆ‚·‚é - e= AppKey_create( &m ); IF(e)goto resume; - } - else if ( *in_out_m == NULL ) { // ‚P‰ñ–Ú‚É–{ŠÖ”‚ðŒÄ‚яo‚µ‚½ƒ‚ƒWƒ…[ƒ‹‚É“n‚· - e= AppKey_create( &m ); IF(e)goto resume; - *in_out_m = m; - } - else { // –{ŠÖ”‚ðŒÄ‚яo‚µ‚½ƒ‚ƒWƒ…[ƒ‹‚©‚ç“n‚Á‚½‚à‚Ì‚ðŽg‚¤ - m = *in_out_m; - } + //=== AppKey* m ‚ð—LŒø‚É‚·‚é + if ( in_out_m == NULL ) { // ¡‰ñ‚̊֐”‚Ì’†‚¾‚¯‚ÅŽQÆ‚·‚é + e= AppKey_create( &m ); IF(e)goto resume; + } + else if ( *in_out_m == NULL ) { // ‚P‰ñ–Ú‚É–{ŠÖ”‚ðŒÄ‚яo‚µ‚½ƒ‚ƒWƒ…[ƒ‹‚É“n‚· + e= AppKey_create( &m ); IF(e)goto resume; + *in_out_m = m; + } + else { // –{ŠÖ”‚ðŒÄ‚яo‚µ‚½ƒ‚ƒWƒ…[ƒ‹‚©‚ç“n‚Á‚½‚à‚Ì‚ðŽg‚¤ + m = *in_out_m; + } - //=== ³‹K‚Ì AppKey ‚©ƒ`ƒFƒbƒN‚·‚é - IF( ! AppKey_isSame( m ) )goto err; + //=== ³‹K‚Ì AppKey ‚©ƒ`ƒFƒbƒN‚·‚é + IF( ! AppKey_isSame( m ) )goto err; - //=== Writable ‚𐶐¬‚·‚é - if ( out_Writable == NULL ) { - wr = &g_DefaultWritables; - e= Writables_finish( wr, 0 ); IF(e)goto resume; - e= Writables_init( wr, m ); IF(e)goto resume; - } - else { - e= Writables_create( &wr, m ); IF(e)goto resume; - *out_Writable = wr; - } + //=== Writable ‚𐶐¬‚·‚é + if ( out_Writable == NULL ) { + wr = &g_DefaultWritables; + e= Writables_finish( wr, 0 ); IF(e)goto resume; + e= Writables_init( wr, m ); IF(e)goto resume; + } + else { + e= Writables_create( &wr, m ); IF(e)goto resume; + *out_Writable = wr; + } - //=== Writable ‚ɃpƒX‚ð“o˜^‚·‚é - { - va_list va; - TCHAR* path; - int i; + //=== Writable ‚ɃpƒX‚ð“o˜^‚·‚é + { + va_list va; + TCHAR* path; + int i; - va_start( va, out_Writable ); - for ( i=0; ; i++ ) { - path = va_arg( va, TCHAR* ); - if ( path == NULL ) break; - IF( i == 5 ) goto err; // ÅŒã‚Ì NULL –Y‚ê‘΍ô + va_start( va, out_Writable ); + for ( i=0; ; i++ ) { + path = va_arg( va, TCHAR* ); + if ( path == NULL ) break; + IF( i == 5 ) goto err; // ÅŒã‚Ì NULL –Y‚ê‘΍ô - e= Writables_add( wr, m, path ); IF(e)goto resume; - } - va_end( va ); - } - #if defined(TempFile_get) - { - TempFile* temp; + e= Writables_add( wr, m, path ); IF(e)goto resume; + } + va_end( va ); + } + #if defined(TempFile_get) + { + TempFile* temp; - e= TempFile_get( &temp ); IF(e)goto resume; - e= Writables_add( wr, m, temp->TempPath ); IF(e)goto resume; - } - #endif + e= TempFile_get( &temp ); IF(e)goto resume; + e= Writables_add( wr, m, temp->TempPath ); IF(e)goto resume; + } + #endif - //=== ‚·‚®‚É Writable ‚ð—LŒø‚É‚·‚é - if ( out_Writable == NULL ) { - e= Writables_enable( wr ); IF(e)goto resume; - } + //=== ‚·‚®‚É Writable ‚ð—LŒø‚É‚·‚é + if ( out_Writable == NULL ) { + e= Writables_enable( wr ); IF(e)goto resume; + } - e=0; + e=0; fin: - #if Uses_OutMallocIDTool - OutMallocID_setEnable( is_prev_out_malloc ); - #endif - return e; + #if Uses_OutMallocIDTool + OutMallocID_setEnable( is_prev_out_malloc ); + #endif + return e; -err: e = E_Others; goto resume; +err: e = E_OTHERS; goto resume; resume: - if ( wr != NULL ) { - if ( out_Writable == NULL ) - e= Writables_finish( wr, e ); // g_DefaultWritables - else - e= Writables_delete( wr, e ); - } - goto fin; + if ( wr != NULL ) { + if ( out_Writable == NULL ) + e= Writables_finish( wr, e ); // g_DefaultWritables + else + e= Writables_delete( wr, e ); + } + goto fin; } @@ -1156,116 +1181,124 @@ resume: <<< [AppKey_addNewWritableFolder] ƒ`ƒFƒbƒN‚·‚éA‚Ü‚½‚͒ljÁ‚·‚é >>> i’ljÁ‚Í–¢‘Ήžj ************************************************************************/ -int AppKey_addNewWritableFolder( const TCHAR* Path ) +errnum_t AppKey_addNewWritableFolder( const TCHAR* Path ) { - int e; - TCHAR** pp; - TCHAR** pp_over; - Writables* wr = &g_CurrentWritablesPrivate.m_CurrentWritables; - size_t path_len; - TCHAR abs_path[MAX_PATH]; - - if ( g_AppKeyPrivate == NULL ) { - e= AppKey_newWritable( NULL, NULL, ".", NULL ); IF(e)goto fin; - } + errnum_t e; + TCHAR** pp; + TCHAR** pp_over; + Writables* wr = &g_CurrentWritablesPrivate.m_CurrentWritables; + size_t path_len; + TCHAR abs_path[MAX_PATH]; - e= StrT_getAbsPath( abs_path, sizeof(abs_path), Path, NULL ); IF(e)goto fin; + if ( g_AppKeyPrivate == NULL ) { + e= AppKey_newWritable( NULL, NULL, ".", NULL ); IF(e){goto fin;} + } - pp_over = wr->m_Paths + wr->m_nPath; - for ( pp = wr->m_Paths; ; pp++ ) { - IF ( pp >= pp_over )goto err_wr; - // Path (abs_path) ‚́AAppKey_newWritable ‚Å‹–‰Â‚³‚ê‚Ä‚¢‚Ü‚¹‚ñB - // ƒEƒHƒbƒ`EƒEƒBƒ“ƒhƒE‚É g_CurrentWritables.m_Paths,3 ‚È‚Ç‚ð“ü—Í‚µ‚Ä - // ‹–‰Â‚³‚ê‚Ä‚¢‚éƒpƒX‚ðŠm”F‚µ‚Ä‚­‚¾‚³‚¢B + e= StrT_getAbsPath( abs_path, sizeof(abs_path), Path, NULL ); IF(e){goto fin;} - path_len = _tcslen( *pp ); - if ( _tcsnicmp( *pp, abs_path, path_len ) == 0 && - ( abs_path[ path_len ] == _T('\\') || abs_path[ path_len ] == _T('\0') ) ) break; - } + pp_over = wr->m_Paths + wr->m_nPath; + for ( pp = wr->m_Paths; ; pp++ ) { + IF ( pp >= pp_over ) { e=E_OUT_OF_WRITABLE; goto fin; } + // Path (abs_path) ‚́AAppKey_newWritable ‚Å‹–‰Â‚³‚ê‚Ä‚¢‚Ü‚¹‚ñB + // ƒEƒHƒbƒ`EƒEƒBƒ“ƒhƒE‚É g_CurrentWritables.m_Paths,3 ‚È‚Ç‚ð“ü—Í‚µ‚Ä + // ‹–‰Â‚³‚ê‚Ä‚¢‚éƒpƒX‚ðŠm”F‚µ‚Ä‚­‚¾‚³‚¢B - e=0; -fin: - return e; + path_len = _tcslen( *pp ); + if ( _tcsnicmp( *pp, abs_path, path_len ) == 0 && + ( abs_path[ path_len ] == _T('\\') || abs_path[ path_len ] == _T('\0') ) ) break; + } -err_wr: e = E_OutOfWritable; goto fin; + e=0; +fin: + return e; } + +/*********************************************************************** + <<< [AppKey_checkWritable] >>> +************************************************************************/ +errnum_t AppKey_checkWritable( const TCHAR* Path ) +{ + return AppKey_addNewWritableFolder( Path ); +} + /*********************************************************************** <<< [Writables_init] >>> ************************************************************************/ -static void Writables_init_const( Writables* m ) +static void Writables_initConst( Writables* m ) { - m->m_Paths = NULL; - m->m_nPath = -1; + m->m_Paths = NULL; + m->m_nPath = -1; } -static int Writables_init( Writables* m, AppKey* Key ) +static errnum_t Writables_init( Writables* m, AppKey* Key ) { - IF( ! AppKey_isSame( Key ) ) return E_Others; + IF( ! AppKey_isSame( Key ) ) return E_OTHERS; - m->m_Paths = NULL; - m->m_nPath = 0; - return 0; + m->m_Paths = NULL; + m->m_nPath = 0; + return 0; } -static int Writables_finish( Writables* m, int e ) +static errnum_t Writables_finish( Writables* m, int e ) { - int ee; + errnum_t ee; - ee= Writables_clearPaths( m ); IF(ee&&!e) e=ee; - m->m_nPath = -1; - return e; + ee= Writables_clearPaths( m ); IF(ee&&!e) e=ee; + m->m_nPath = -1; + return e; } -static int Writables_isInited( Writables* m ) +static bool Writables_isInited( Writables* m ) { - return ( m->m_nPath != -1 ); + return ( m->m_nPath != -1 ); } -static int Writables_clearPaths( Writables* m ) +static errnum_t Writables_clearPaths( Writables* m ) { - TCHAR** p; - TCHAR** p_over; + TCHAR** p; + TCHAR** p_over; - if ( m->m_Paths != NULL ) { - p_over = m->m_Paths + m->m_nPath; - for ( p = m->m_Paths; p < p_over; p++ ) { - free( *p ); - } - free( m->m_Paths ); m->m_Paths = NULL; - } - m->m_nPath = 0; - return 0; + if ( m->m_Paths != NULL ) { + p_over = m->m_Paths + m->m_nPath; + for ( p = m->m_Paths; p < p_over; p++ ) { + free( *p ); + } + free( m->m_Paths ); m->m_Paths = NULL; + } + m->m_nPath = 0; + return 0; } -static int Writables_create( Writables** out_m, AppKey* Key ) +static errnum_t Writables_create( Writables** out_m, AppKey* Key ) { - Writables* m; int e; + errnum_t e; + Writables* m; - m = (Writables*) malloc( sizeof(*m) ); IF(m==NULL)return E_FewMemory; - Writables_init_const( m ); - e= Writables_init( m, Key ); IF(e)goto resume; - *out_m = m; - return 0; + m = (Writables*) malloc( sizeof(*m) ); IF(m==NULL)return E_FEW_MEMORY; + Writables_initConst( m ); + e= Writables_init( m, Key ); IF(e)goto resume; + *out_m = m; + return 0; resume: Writables_delete( m, 0 ); free(m); return e; } -int Writables_delete( Writables* m, int e ) +errnum_t Writables_delete( Writables* m, errnum_t e ) { - if ( m == NULL ) goto fin; - e= Writables_finish( m, e ); - free( m ); + if ( m == NULL ) goto fin; + e= Writables_finish( m, e ); + free( m ); fin: - return e; + return e; } @@ -1275,63 +1308,63 @@ fin: ************************************************************************/ int Writables_add( Writables* m, AppKey* Key, TCHAR* Path ) { - int e; - TCHAR** pp; - TCHAR* p = NULL; - size_t path_size; - TCHAR abs_path[MAX_PATH]; + int e; + TCHAR** pp; + TCHAR* p = NULL; + size_t path_size; + TCHAR abs_path[MAX_PATH]; - IF( ! AppKey_isSame( Key ) )goto err; - if ( Path[0] == _T('\0') ) return 0; + IF( ! AppKey_isSame( Key ) )goto err; + if ( Path[0] == _T('\0') ) return 0; - e= StrT_getAbsPath( abs_path, sizeof(abs_path), Path, NULL ); IF(e)goto resume; + e= StrT_getAbsPath( abs_path, sizeof(abs_path), Path, NULL ); IF(e)goto resume; - e= CurrentWritables_askFileAccess( &g_CurrentWritablesPrivate, abs_path ); IF(e)goto resume; + e= CurrentWritables_askFileAccess( &g_CurrentWritablesPrivate, abs_path ); IF(e)goto resume; - pp = (TCHAR**) realloc( m->m_Paths, (m->m_nPath + 1) * sizeof(TCHAR*) ); - IF( pp == NULL ) goto err; - m->m_Paths = pp; + pp = (TCHAR**) realloc( m->m_Paths, (m->m_nPath + 1) * sizeof(TCHAR*) ); + IF( pp == NULL ) goto err; + m->m_Paths = pp; - path_size = (_tcslen( abs_path ) + 1) * sizeof(TCHAR); - p = (TCHAR*) malloc( path_size ); - m->m_Paths[ m->m_nPath ] = p; - IF( p == NULL )goto err; + path_size = (_tcslen( abs_path ) + 1) * sizeof(TCHAR); + p = (TCHAR*) malloc( path_size ); + m->m_Paths[ m->m_nPath ] = p; + IF( p == NULL )goto err; - memcpy( p, abs_path, path_size ); - if ( p[ path_size/sizeof(TCHAR) - 2 ] == _T('\\') ) - p[ path_size/sizeof(TCHAR) - 2 ] = _T('\0'); - m->m_nPath ++; + memcpy( p, abs_path, path_size ); + if ( p[ path_size/sizeof(TCHAR) - 2 ] == _T('\\') ) + p[ path_size/sizeof(TCHAR) - 2 ] = _T('\0'); + m->m_nPath ++; - e=0; + e=0; fin: - return e; + return e; -err: e = E_Others; goto resume; +err: e = E_OTHERS; goto resume; resume: - if ( p != NULL ) free( p ); - goto fin; + if ( p != NULL ) free( p ); + goto fin; } int Writables_remove( Writables* m, TCHAR* Path ) { - TCHAR** pp; - TCHAR** pp_over; + TCHAR** pp; + TCHAR** pp_over; - pp_over = m->m_Paths + m->m_nPath; - for ( pp = m->m_Paths; ; pp++ ) { - if ( pp >= pp_over ) return 0; - if ( _tcscmp( *pp, Path ) == 0 ) break; - } - free( *pp ); - memmove( pp, pp+1, (char*)pp - (char*)pp_over - sizeof(TCHAR) ); - m->m_nPath --; + pp_over = m->m_Paths + m->m_nPath; + for ( pp = m->m_Paths; ; pp++ ) { + if ( pp >= pp_over ) return 0; + if ( _tcscmp( *pp, Path ) == 0 ) break; + } + free( *pp ); + memmove( pp, pp+1, (char*)pp - (char*)pp_over - sizeof(TCHAR) ); + m->m_nPath --; - #if _DEBUG - *( pp_over - 1 ) = NULL; - #endif + #if _DEBUG + *( pp_over - 1 ) = NULL; + #endif - return 0; + return 0; } @@ -1341,167 +1374,169 @@ int Writables_remove( Writables* m, TCHAR* Path ) ************************************************************************/ int Writables_enable( Writables* m ) { - int e; + int e; - e= Writables_copyToConst( &g_CurrentWritablesPrivate.m_CurrentWritables, m ); IF(e)goto fin; - e= Writables_copyToConst( &g_CurrentWritables, &g_CurrentWritablesPrivate.m_CurrentWritables ); IF(e)goto fin; + e= Writables_copyToConst( &g_CurrentWritablesPrivate.m_CurrentWritables, m ); IF(e)goto fin; + e= Writables_copyToConst( &g_CurrentWritables, &g_CurrentWritablesPrivate.m_CurrentWritables ); IF(e)goto fin; - e=0; + e=0; fin: - return e; + return e; } int Writables_disable( Writables* m, int e ) { - int ee; + int ee; - ee= Writables_copyToConst( &g_CurrentWritablesPrivate.m_CurrentWritables, NULL ); IF(ee&&!e)goto fin; - ee= Writables_copyToConst( &g_CurrentWritables, NULL ); IF(ee&&!e)goto fin; + UNREFERENCED_VARIABLES( m ); - e=0; + ee= Writables_copyToConst( &g_CurrentWritablesPrivate.m_CurrentWritables, NULL ); IF(ee&&!e)goto fin; + ee= Writables_copyToConst( &g_CurrentWritables, NULL ); IF(ee&&!e)goto fin; + + e=0; fin: - return e; + return e; } static int Writables_copyToConst( Writables* To, Writables* From ) { - int e; - TCHAR** pp; - TCHAR** pp_over; - TCHAR* p2; - TCHAR** pp2; - size_t path_size; - - if ( To->m_Paths != NULL ) { - free( To->m_Paths ); - To->m_Paths = NULL; - To->m_nPath = 0; - } + int e; + TCHAR** pp; + TCHAR** pp_over; + TCHAR* p2; + TCHAR** pp2; + size_t path_size; + + if ( To->m_Paths != NULL ) { + free( To->m_Paths ); + To->m_Paths = NULL; + To->m_nPath = 0; + } - if ( From != NULL && From->m_nPath > 0 ) { + if ( From != NULL && From->m_nPath > 0 ) { - path_size = 0; - pp_over = From->m_Paths + From->m_nPath; - for ( pp = From->m_Paths; pp < pp_over; pp++ ) { - path_size += _tcslen( *pp ) + 1; - } + path_size = 0; + pp_over = From->m_Paths + From->m_nPath; + for ( pp = From->m_Paths; pp < pp_over; pp++ ) { + path_size += _tcslen( *pp ) + 1; + } - path_size = From->m_nPath * sizeof(TCHAR*) + path_size * sizeof(TCHAR); - To->m_Paths = (TCHAR**) malloc( path_size ); - IF( To->m_Paths == NULL ) goto err; - - p2 = (TCHAR*)( (char*)To->m_Paths + From->m_nPath * sizeof(TCHAR*) ); - pp2 = To->m_Paths; - for ( pp = From->m_Paths; pp < pp_over; pp++ ) { - *pp2 = p2; - path_size = (_tcslen( *pp ) + 1) * sizeof(TCHAR); - memcpy( p2, *pp, path_size ); - p2 = (TCHAR*)( (char*)p2 + path_size ); - pp2 ++; - } - To->m_nPath = From->m_nPath; - } + path_size = From->m_nPath * sizeof(TCHAR*) + path_size * sizeof(TCHAR); + To->m_Paths = (TCHAR**) malloc( path_size ); + IF( To->m_Paths == NULL ) goto err; + + p2 = (TCHAR*)( (char*)To->m_Paths + From->m_nPath * sizeof(TCHAR*) ); + pp2 = To->m_Paths; + for ( pp = From->m_Paths; pp < pp_over; pp++ ) { + *pp2 = p2; + path_size = (_tcslen( *pp ) + 1) * sizeof(TCHAR); + memcpy( p2, *pp, path_size ); + p2 = (TCHAR*)( (char*)p2 + path_size ); + pp2 ++; + } + To->m_nPath = From->m_nPath; + } - e=0; + e=0; fin: - return e; + return e; -err: e = E_Others; goto fin; +err: e = E_OTHERS; goto fin; } /*********************************************************************** <<< [CurrentWritables] >>> ************************************************************************/ -static void CurrentWritables_init_const( CurrentWritables* m ) +static void CurrentWritables_initConst( CurrentWritables* m ) { - Writables_init_const( &m->m_CurrentWritables ); - m->m_ProgramFiles = NULL; - m->m_windir = NULL; - m->m_APPDATA = NULL; - m->m_LOCALAPPDATA = NULL; + Writables_initConst( &m->m_CurrentWritables ); + m->m_ProgramFiles = NULL; + m->m_windir = NULL; + m->m_APPDATA = NULL; + m->m_LOCALAPPDATA = NULL; } static int CurrentWritables_init( CurrentWritables* m ) { - int e; + int e; #if Uses_OutMallocIDTool - bool is_prev_out_malloc; + bool is_prev_out_malloc; - is_prev_out_malloc = OutMallocID_setEnable( false ); + is_prev_out_malloc = OutMallocID_setEnable( false ); #endif - e= Writables_copyToConst( &m->m_CurrentWritables, NULL ); IF(e)goto fin; + e= Writables_copyToConst( &m->m_CurrentWritables, NULL ); IF(e)goto fin; - e= env_malloc( &m->m_ProgramFiles, &m->m_ProgramFiles_Len, _T("ProgramFiles") ); IF(e)goto fin; - e= env_malloc( &m->m_windir, &m->m_windir_Len, _T("windir") ); IF(e)goto fin; - e= env_malloc( &m->m_APPDATA, &m->m_APPDATA_Len, _T("APPDATA") ); IF(e)goto fin; - // e= env_malloc( &m->m_LOCALAPPDATA, &m->m_LOCALAPPDATA_Len, _T("LOCALAPPDATA") ); IF(e)goto fin; + e= env_malloc( &m->m_ProgramFiles, &m->m_ProgramFiles_Len, _T("ProgramFiles") ); IF(e)goto fin; + e= env_malloc( &m->m_windir, &m->m_windir_Len, _T("windir") ); IF(e)goto fin; + e= env_malloc( &m->m_APPDATA, &m->m_APPDATA_Len, _T("APPDATA") ); IF(e)goto fin; + // e= env_malloc( &m->m_LOCALAPPDATA, &m->m_LOCALAPPDATA_Len, _T("LOCALAPPDATA") ); IF(e)goto fin; - e=0; + e=0; fin: #if Uses_OutMallocIDTool - OutMallocID_setEnable( is_prev_out_malloc ); + OutMallocID_setEnable( is_prev_out_malloc ); #endif - return e; + return e; } static int CurrentWritables_finish( CurrentWritables* m, int e ) { - int ee; + int ee; - ee= Writables_copyToConst( &m->m_CurrentWritables, NULL ); IF(ee&&!e)e=ee; + ee= Writables_copyToConst( &m->m_CurrentWritables, NULL ); IF(ee&&!e)e=ee; - if ( m->m_ProgramFiles != NULL ) free( m->m_ProgramFiles ); - if ( m->m_windir != NULL ) free( m->m_windir ); - if ( m->m_APPDATA != NULL ) free( m->m_APPDATA ); - if ( m->m_LOCALAPPDATA != NULL ) free( m->m_LOCALAPPDATA ); + if ( m->m_ProgramFiles != NULL ) free( m->m_ProgramFiles ); + if ( m->m_windir != NULL ) free( m->m_windir ); + if ( m->m_APPDATA != NULL ) free( m->m_APPDATA ); + if ( m->m_LOCALAPPDATA != NULL ) free( m->m_LOCALAPPDATA ); - m->m_ProgramFiles = NULL; - m->m_windir = NULL; - m->m_APPDATA = NULL; - m->m_LOCALAPPDATA = NULL; + m->m_ProgramFiles = NULL; + m->m_windir = NULL; + m->m_APPDATA = NULL; + m->m_LOCALAPPDATA = NULL; - return e; + return e; } -int CurrentWritables_askFileAccess_sub( - const TCHAR* SystemPath, size_t SystemPath_Len, const TCHAR* AbsPath, size_t AbsPath_Len ); +static int CurrentWritables_askFileAccess_sub( + const TCHAR* SystemPath, size_t SystemPath_Len, const TCHAR* AbsPath, size_t AbsPath_Len ); static int CurrentWritables_askFileAccess( CurrentWritables* m, const TCHAR* AbsPath ) { - int e; - size_t abs_len; + int e; + size_t abs_len; - abs_len = _tcslen( AbsPath ); - e= CurrentWritables_askFileAccess_sub( m->m_ProgramFiles, m->m_ProgramFiles_Len, AbsPath, abs_len ); IF(e)goto fin; - e= CurrentWritables_askFileAccess_sub( m->m_windir, m->m_windir_Len, AbsPath, abs_len ); IF(e)goto fin; - e= CurrentWritables_askFileAccess_sub( m->m_APPDATA, m->m_APPDATA_Len, AbsPath, abs_len ); IF(e)goto fin; - e= CurrentWritables_askFileAccess_sub( m->m_LOCALAPPDATA, m->m_LOCALAPPDATA_Len, AbsPath, abs_len ); IF(e)goto fin; + abs_len = _tcslen( AbsPath ); + e= CurrentWritables_askFileAccess_sub( m->m_ProgramFiles, m->m_ProgramFiles_Len, AbsPath, abs_len ); IF(e)goto fin; + e= CurrentWritables_askFileAccess_sub( m->m_windir, m->m_windir_Len, AbsPath, abs_len ); IF(e)goto fin; + e= CurrentWritables_askFileAccess_sub( m->m_APPDATA, m->m_APPDATA_Len, AbsPath, abs_len ); IF(e)goto fin; + e= CurrentWritables_askFileAccess_sub( m->m_LOCALAPPDATA, m->m_LOCALAPPDATA_Len, AbsPath, abs_len ); IF(e)goto fin; - e=0; + e=0; fin: - return e; + return e; } static int CurrentWritables_askFileAccess_sub( - const TCHAR* SystemPath, size_t SystemPath_Len, const TCHAR* AbsPath, size_t AbsPath_Len ) + const TCHAR* SystemPath, size_t SystemPath_Len, const TCHAR* AbsPath, size_t AbsPath_Len ) { - if ( SystemPath == NULL ) return 0; + if ( SystemPath == NULL ) return 0; - IF ( _tcsncmp( SystemPath, AbsPath, SystemPath_Len ) == 0 ) - return E_OutOfWritable; // ƒVƒXƒeƒ€ƒtƒHƒ‹ƒ_‚Ì’†‚ð‘‚«ž‚Ý‹–‰Â‚µ‚悤‚Æ‚µ‚Ä‚¢‚é + IF ( _tcsncmp( SystemPath, AbsPath, SystemPath_Len ) == 0 ) + return E_OUT_OF_WRITABLE; // ƒVƒXƒeƒ€ƒtƒHƒ‹ƒ_‚Ì’†‚ð‘‚«ž‚Ý‹–‰Â‚µ‚悤‚Æ‚µ‚Ä‚¢‚é - IF ( _tcsncmp( SystemPath, AbsPath, AbsPath_Len ) == 0 ) - return E_OutOfWritable; // ƒVƒXƒeƒ€ƒtƒHƒ‹ƒ_‚ðŠÜ‚ß‚Ä‹–‰Â‘‚«ž‚Ý‹–‰Â‚µ‚悤‚Æ‚µ‚Ä‚¢‚é + IF ( _tcsncmp( SystemPath, AbsPath, AbsPath_Len ) == 0 ) + return E_OUT_OF_WRITABLE; // ƒVƒXƒeƒ€ƒtƒHƒ‹ƒ_‚ðŠÜ‚ß‚Ä‹–‰Â‘‚«ž‚Ý‹–‰Â‚µ‚悤‚Æ‚µ‚Ä‚¢‚é - return 0; + return 0; } @@ -1512,9 +1547,9 @@ static int CurrentWritables_askFileAccess_sub( /*********************************************************************** <<< [StrT_cpy] >>> -- _tcscpy is raising exception, if E_FewArray +- _tcscpy is raising exception, if E_FEW_ARRAY ************************************************************************/ -int StrT_cpy( TCHAR* Dst, size_t DstSize, const TCHAR* Src ) +errnum_t StrT_cpy( TCHAR* Dst, size_t DstSize, const TCHAR* Src ) { size_t size; @@ -1526,59 +1561,79 @@ int StrT_cpy( TCHAR* Dst, size_t DstSize, const TCHAR* Src ) else { memcpy( Dst, Src, DstSize - sizeof(TCHAR) ); *(TCHAR*)( (char*) Dst + DstSize ) = _T('\0'); - return E_FewArray; + return E_FEW_ARRAY; } } /*********************************************************************** - <<< [StrT_malloc_cpy] >>> + <<< [MallocAndCopyString] >>> ************************************************************************/ -TCHAR* StrT_malloc_cpy( const TCHAR* Src ) +errnum_t MallocAndCopyString( TCHAR** out_NewString, const TCHAR* SourceString ) { - TCHAR* p; - size_t size; + TCHAR* str; + size_t size = ( _tcslen( SourceString ) + 1 ) * sizeof(TCHAR); - size = ( _tcslen( Src ) + 1 ) * sizeof(TCHAR); - p = (TCHAR*) malloc( size ); IF(p==NULL) return NULL; - memcpy( p, Src, size ); - return p; + ASSERT_D( *out_NewString == NULL, __noop() ); + + str = (TCHAR*) malloc( size ); + if ( str == NULL ) { return E_FEW_MEMORY; } + + memcpy( str, SourceString, size ); + + *out_NewString = str; + return 0; } + /*********************************************************************** - <<< [StrT_malloc_cpy_from_char] >>> + <<< [MallocAndCopyString_char] >>> ************************************************************************/ -TCHAR* StrT_malloc_cpy_from_char( const char* Src ) +#ifdef _UNICODE +errnum_t MallocAndCopyString_char( TCHAR** out_NewString, const char* SourceString ) { - #if _UNICODE - TCHAR* p = NULL; - size_t size; - int r; + TCHAR* str; + size_t size = ( strlen( SourceString ) + 1 ) * sizeof(TCHAR); + int r; - size = ( strlen( Src ) + 1 ) * sizeof(TCHAR); - p = (TCHAR*) malloc( size ); IF(p==NULL) return NULL; + str = (TCHAR*) malloc( size ); + if ( str == NULL ) { return E_FEW_MEMORY; } - r = MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, Src, -1, p, size / 2 ); - IF( r == 0 ) goto err; - return p; + r = MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, SourceString, -1, str, size / sizeof(TCHAR) ); + IF ( r == 0 ) { + free( str ); + return E_GET_LAST_ERROR; + } + *out_NewString = str; + return 0; +} +#endif - err: - free( p ); - return NULL; - #else - TCHAR* p; - size_t size; + +/*********************************************************************** + <<< [MallocAndCopyStringByLength] >>> +************************************************************************/ +errnum_t MallocAndCopyStringByLength( TCHAR** out_NewString, const TCHAR* SourceString, + unsigned CountOfCharacter ) +{ + TCHAR* str; + size_t size = ( CountOfCharacter + 1 ) * sizeof(TCHAR); - size = ( _tcslen( Src ) + 1 ) * sizeof(TCHAR); - p = (TCHAR*) malloc( size ); IF(p==NULL) return NULL; - memcpy( p, Src, size ); + ASSERT_D( *out_NewString == NULL, __noop() ); - return p; - #endif + str = (TCHAR*) malloc( size ); + if ( str == NULL ) { return E_FEW_MEMORY; } + + memcpy( str, SourceString, size - sizeof(TCHAR) ); + str[ CountOfCharacter ] = _T('\0'); + + *out_NewString = str; + return 0; } + /*********************************************************************** <<< [StrT_chrs] >>> @@ -1656,6 +1711,342 @@ TCHAR* StrT_refExt( const TCHAR* s ) /*********************************************************************** + <<< [StrT_replace1] >>> +************************************************************************/ +errnum_t StrT_replace1( TCHAR* in_out_String, TCHAR FromCharacter, TCHAR ToCharacter, + unsigned Opt ) +{ + TCHAR* p; + + UNREFERENCED_VARIABLE( Opt ); + + IF ( FromCharacter == _T('\0') ) { return E_OTHERS; } + + p = in_out_String; + for (;;) { + p = _tcschr( p, FromCharacter ); + if ( p == NULL ) { break; } + *p = ToCharacter; + p += 1; + } + + return 0; +} + + + +/*********************************************************************** + <<< [StrT_trim] >>> +************************************************************************/ +errnum_t StrT_trim( TCHAR* out_Str, size_t out_Str_Size, const TCHAR* in_Str ) +{ + const TCHAR* p1; + const TCHAR* p2; + TCHAR c; + + p1 = in_Str; while ( *p1 == _T(' ') || *p1 == _T('\t') ) p1++; + for ( p2 = _tcschr( p1, _T('\0') ) - 1; p2 >= p1; p2-- ) { + c = *p2; + if ( c != _T(' ') && c != _T('\t') && c != _T('\n') && c != _T('\r') ) + break; + } + return stcpy_part_r( out_Str, out_Str_Size, out_Str, NULL, p1, p2+1 ); +} + + + +/*********************************************************************** + <<< [StrT_cutLastOf] >>> +************************************************************************/ +errnum_t StrT_cutLastOf( TCHAR* in_out_Str, TCHAR Charactor ) +{ + TCHAR* last = _tcschr( in_out_Str, _T('\0') ); + + if ( last > in_out_Str ) { + if ( *( last - 1 ) == Charactor ) + { *( last - 1 ) = _T('\0'); } + } + return 0; +} + + + +/*********************************************************************** + <<< [StrT_cutLineComment] >>> +************************************************************************/ +errnum_t StrT_cutLineComment( TCHAR* out_Str, size_t out_Str_Size, const TCHAR* in_Str, const TCHAR* CommentSign ) +{ + const TCHAR* p1; + const TCHAR* p2; + TCHAR c; + + p1 = in_Str; while ( *p1 == _T(' ') || *p1 == _T('\t') ) p1++; + + p2 = _tcsstr( p1, CommentSign ); + if ( p2 == NULL ) p2 = _tcschr( p1, _T('\0') ); + + for ( p2 = p2 - 1; p2 >= p1; p2-- ) { + c = *p2; + if ( c != _T(' ') && c != _T('\t') && c != _T('\n') && c != _T('\r') ) + break; + } + return stcpy_part_r( out_Str, out_Str_Size, out_Str, NULL, p1, p2+1 ); +} + + + +/************************************************************************** + <<< [StrT_meltCSV] >>> +*************************************************************************/ +errnum_t StrT_meltCSV( TCHAR* out_Str, size_t out_Str_Size, const TCHAR** pCSV ) +{ + errnum_t e = 0; + TCHAR* t; + TCHAR* t_last = (TCHAR*)( (char*)out_Str + out_Str_Size - sizeof(TCHAR) ); + const TCHAR* s; + TCHAR dummy[2]; + TCHAR c; + + t = out_Str; + s = *pCSV; + if ( out_Str_Size <= 1 ) { t = dummy; t_last = dummy; } + + if ( s == NULL ) { *t = _T('\0'); return 0; } + + + /* “ª‚Ì‹ó”’‚ðœ‚­ */ + while ( *s == _T(' ') || *s == _T('\t') ) s++; + + switch ( *s ) { + + /* "" ‚ň͂܂ê‚Ä‚¢‚éê‡ */ + case _T('"'): + s++; + c = *s; + while ( c != _T('"') || *(s+1) == _T('"') ) { /* " •¶Žš‚Ü‚Å */ + if ( t == t_last ) { e = E_FEW_ARRAY; t = dummy; t_last = dummy + 1; } + if ( c == *(s+1) && c == _T('"') ) s++; /* " •¶ŽšŽ©‘Ì */ + if ( c == _T('\0') ) break; + *t = c; t++; s++; c = *s; + } + *t = _T('\0'); + + s++; + for (;;) { + if ( *s == _T(',') ) { s = s+1; break; } + if ( *s == _T('\0') ) { s = NULL; break; } + s++; + } + *pCSV = s; + return e; + + /* ‹ó‚̍€–ڂ̏ꍇ */ + case ',': + *t = _T('\0'); + *pCSV = s+1; + return 0; + + case '\0': + *t = _T('\0'); + *pCSV = NULL; + return 0; + + /* "" ‚ň͂܂ê‚Ä‚¢‚È‚¢ê‡ */ + default: { + TCHAR* sp = NULL; /* ÅŒã‚̘A‘±‚µ‚½‹ó”’‚̐擪 */ + + c = *s; + while ( c != _T(',') && c != _T('\0') && c != _T('\r') && c != _T('\n') ) { /* , •¶Žš‚Ü‚Å */ + + /* sp ‚ðÝ’è‚·‚é */ + if ( c == ' ' ) { + if ( sp == NULL ) sp = t; + } + else sp = NULL; + + if ( t == t_last ) { e = E_FEW_ARRAY; t = dummy; t_last = dummy + 1; } + + /* ƒRƒs[‚·‚é */ + *t = c; t++; s++; c = *s; + } + + /* •Ô‚è’l‚ðŒˆ’è‚·‚é */ + if ( c == _T(',') ) s = s + 1; + else s = NULL; + + /* ––”ö‚Ì‹ó”’‚ðŽæ‚菜‚­ */ + if ( sp != NULL ) *sp = '\0'; + else *t = _T('\0'); + + *pCSV = s; + return e; + } + } +} + + + +/*********************************************************************** + <<< [StrT_getExistSymbols] >>> +************************************************************************/ +errnum_t StrT_getExistSymbols( unsigned* out, bool bCase, const TCHAR* Str, const TCHAR* Symbols, ... ) +{ + errnum_t e; + int i; + TCHAR** syms = NULL; + bool* syms_exists = NULL; + bool b_nosym = false; + TCHAR* sym = NULL; + size_t sym_size = ( _tcslen( Symbols ) + 1 ) * sizeof(TCHAR); + int n_sym = 0; + const TCHAR* p; + + UNREFERENCED_VARIABLES(( bCase )); + + sym = (TCHAR*) malloc( sym_size ); IF(sym==NULL)goto err_fm; + + + //=== Get Symbols + p = Symbols; + do { + e= StrT_meltCSV( sym, sym_size, &p ); IF(e)goto fin; + if ( sym[0] != _T('\0') ) n_sym ++; + } while ( p != NULL ); + + syms = (TCHAR**) malloc( n_sym * sizeof(TCHAR*) ); IF(syms==NULL)goto err_fm; + memset( syms, 0, n_sym * sizeof(TCHAR*) ); + syms_exists = (bool*) malloc( n_sym * sizeof(bool) ); IF(syms_exists==NULL)goto err_fm; + memset( syms_exists, 0, n_sym * sizeof(bool) ); + + p = Symbols; i = 0; + do { + e= StrT_meltCSV( sym, sym_size, &p ); IF(e)goto fin; + if ( sym[0] != _T('\0') ) { + e= MallocAndCopyString( &syms[i], sym ); IF(e)goto fin; + i++; + } + } while ( p != NULL ); + + + //=== Check Str whether having Symbols + p = Str; + do { + e= StrT_meltCSV( sym, sym_size, &p ); IF(e)goto fin; + if ( sym[0] != _T('\0') ) { + for ( i = 0; i < n_sym; i++ ) { + if ( _tcscmp( sym, syms[i] ) == 0 ) { syms_exists[i] = true; break; } + } + if ( i == n_sym ) b_nosym = true; + } + } while ( p != NULL ); + + + //=== Sum numbers + { + va_list va; + unsigned num; + + va_start( va, Symbols ); + *out = 0; + for ( i = 0; i < n_sym; i++ ) { + num = va_arg( va, unsigned ); + if ( syms_exists[i] ) *out |= num; + } + va_end( va ); + } + + e = ( b_nosym ? E_NOT_FOUND_SYMBOL : 0 ); +fin: + if ( syms != NULL ) { + for ( i = 0; i < n_sym; i++ ) { + if ( syms[i] != NULL ) free( syms[i] ); + } + free( syms ); + } + if ( syms_exists != NULL ) free( syms_exists ); + if ( sym != NULL ) free( sym ); + return e; +err_fm: e= E_FEW_MEMORY; goto fin; +} + + +/************************************************************************** + <<< [StrT_meltCmdLine] >>> +*************************************************************************/ +errnum_t StrT_meltCmdLine( TCHAR* out_Str, size_t out_Str_Size, const TCHAR** pLine ) +{ + errnum_t e = 0; + TCHAR* t; + TCHAR* t_last = (TCHAR*)( (char*)out_Str + out_Str_Size - sizeof(TCHAR) ); + const TCHAR* s; + TCHAR dummy; + TCHAR c; + + t = out_Str; + s = *pLine; + if ( out_Str_Size <= 1 ) { t = &dummy; t_last = &dummy; } + + if ( s == NULL ) { *t = _T('\0'); return 0; } + + + /* “ª‚Ì‹ó”’‚ðœ‚­ */ + while ( *s == _T(' ') || *s == _T('\t') ) s++; + + switch ( *s ) { + + /* "" ‚ň͂܂ê‚Ä‚¢‚éê‡ */ + case _T('"'): + s++; + c = *s; + while ( c != _T('"') || *(s+1) == _T('"') ) { /* " •¶Žš‚Ü‚Å */ + if ( t == t_last ) { e = E_FEW_ARRAY; t = &dummy; t_last = &dummy + 1; } + if ( c == *(s+1) && c == _T('"') ) s++; /* " •¶ŽšŽ©‘Ì */ + if ( c == _T('\0') ) break; + *t = c; t++; s++; c = *s; + } + *t = _T('\0'); + + s++; + for (;;) { + if ( *s == _T(' ') ) { s = s+1; break; } + if ( *s == _T('\0') ) { s = NULL; break; } + s++; + } + *pLine = s; + return e; + + case '\0': + *t = _T('\0'); + *pLine = NULL; + return 0; + + /* "" ‚ň͂܂ê‚Ä‚¢‚È‚¢ê‡ */ + default: { + c = *s; + while ( c != _T(' ') && c != _T('\0') && c != _T('\r') && c != _T('\n') ) { /* ‹ó”’•¶Žš‚Ü‚Å */ + + if ( t == t_last ) { e = E_FEW_ARRAY; t = &dummy; t_last = &dummy + 1; } + + /* ƒRƒs[‚·‚é */ + *t = c; t++; s++; c = *s; + } + + /* *pLine‚ðŒˆ’è‚·‚é */ + while ( *s == _T(' ') ) s = s + 1; + if ( *s == _T('\0') ) s = NULL; + + /* ––”ö */ + *t = _T('\0'); + + *pLine = s; + return e; + } + } +} + + + +/*********************************************************************** <<< [StrT_isAbsPath] >>> ************************************************************************/ bool StrT_isAbsPath( const TCHAR* s ) @@ -1668,237 +2059,1175 @@ bool StrT_isAbsPath( const TCHAR* s ) } -/*********************************************************************** - <<< [StrT_getAbsPath_part]:shlwapi >>> -************************************************************************/ -int StrT_getAbsPath_part( TCHAR* Out, size_t OutSize, TCHAR* OutStart, +/************************************************************************** + <<< [StrT_getAbsPath_part] >>> +*************************************************************************/ +errnum_t StrT_getAbsPath_part( TCHAR* out_AbsPath, size_t AbsPathSize, TCHAR* OutStart, TCHAR** out_OutLast, const TCHAR* StepPath, const TCHAR* BasePath ) { - int e; - TCHAR* p; - TCHAR base_path_x[512]; + errnum_t e; + TCHAR separator = (TCHAR) DUMMY_INITIAL_VALUE_TCHAR; + const TCHAR* separator_path; + TCHAR* out_abs_path_over = (TCHAR*)( (uint8_t*) out_AbsPath + AbsPathSize ); + TCHAR* null_position = NULL; - IF_D( OutStart < Out || (char*) OutStart >= (char*)Out + OutSize )goto err; + #if CHECK_ARG + /* "BasePath" must be out of "out_AbsPath" */ + ASSERT_R( BasePath < out_AbsPath || + (uint8_t*) BasePath >= (uint8_t*) out_AbsPath + AbsPathSize, + goto err ); + #endif + + + /* If "StepPath" == "", out_AbsPath = "" */ if ( StepPath[0] == _T('\0') ) { - *OutStart = _T('\0'); - return 0; + ASSERT_R( AbsPathSize >= sizeof(TCHAR), goto err_fm ); + out_AbsPath[0] = _T('\0'); + e=0; goto fin; } + + + /* Set "OutStart" */ + if ( OutStart == NULL ) + { OutStart = out_AbsPath; } + + + /* Set "separator" : \ or / from "BasePath" */ if ( StrT_isAbsPath( StepPath ) ) { - if ( Out == StepPath ) - return 0; + separator_path = StepPath; + } + else if ( BasePath == NULL ) { + separator = _T('\\'); + separator_path = NULL; + } + else { + separator_path = BasePath; + } + if ( separator_path != NULL ) { + const TCHAR* p; + const TCHAR* p2; + + p = _tcschr( separator_path, _T('\\') ); + p2 = _tcschr( separator_path, _T('/') ); + if ( p == NULL ) { + if ( p2 == NULL ) + { separator = _T('\\'); } + else + { separator = _T('/'); } + } else { + if ( p2 == NULL ) + { separator = _T('\\'); } + else { + if ( p < p2 ) + { separator = _T('\\'); } + else + { separator = _T('/'); } + } + } + } + + + /* Set "OutStart" : "BasePath" + / + "StepPath" */ + if ( StrT_isAbsPath( StepPath ) ) { + size_t step_path_length = _tcslen( StepPath ); + + IF( OutStart + step_path_length >= out_abs_path_over ) goto err_fa; + memmove( OutStart, StepPath, ( step_path_length + 1 ) * sizeof(TCHAR) ); + + /* Set "null_position" */ + null_position = OutStart + step_path_length; + } + else { + TCHAR c; + TCHAR* p; + size_t base_path_length; + size_t step_path_length = _tcslen( StepPath ); + + if ( BasePath == NULL ) { + base_path_length = GetCurrentDirectory( 0, NULL ) - 1; + } + else { + base_path_length = _tcslen( BasePath ); + c = BasePath[ base_path_length - 1 ]; + if ( c == _T('\\') || c == _T('/') ) + { base_path_length -= 1; } + } + + p = OutStart + base_path_length + 1; + IF( p + step_path_length >= out_abs_path_over ) goto err_fa; + memmove( p, StepPath, ( step_path_length + 1 ) * sizeof(TCHAR) ); + /* memmove is for "out_AbsPath" == "StepPath" */ + + if ( BasePath == NULL ) { + GetCurrentDirectory( base_path_length + 1, OutStart ); + if ( OutStart[ base_path_length - 1 ] == _T('\\') ) + { base_path_length -= 1; } + } else { + memcpy( OutStart, BasePath, base_path_length * sizeof(TCHAR) ); + } + OutStart[ base_path_length ] = separator; + + + /* Set "null_position" */ + null_position = p + step_path_length; + } + + + /* Replace \ and / to "separator" in "OutStart" */ + { + TCHAR other_separator; + + if ( separator == _T('/') ) + { other_separator = _T('\\'); } else - return stcpy_part_r( Out, OutSize, OutStart, out_OutLast, StepPath, NULL ); + { other_separator = _T('/'); } + + e= StrT_replace1( OutStart, other_separator, separator, 0 ); IF(e)goto fin; } - if ( BasePath == NULL ) { - p = _tgetcwd( base_path_x, _countof(base_path_x) ); IF( p == NULL )goto err; - BasePath = base_path_x; + + /* Replace \*\..\ to \ */ + { + enum { length = 4 }; + TCHAR parent[ length + 1 ]; /* \..\ or /../ */ + TCHAR* parent_position; + TCHAR* p; + + parent[0] = separator; + parent[1] = _T('.'); + parent[2] = _T('.'); + parent[3] = separator; + parent[4] = _T('\0'); + + for (;;) { + parent_position = _tcsstr( OutStart, parent ); + if ( parent_position == NULL ) { break; } + + p = parent_position - 1; + for (;;) { + IF( p < OutStart ) goto err; /* "../" are too many */ + if ( *p == separator ) { break; } + p -= 1; + } + + memmove( p + 1, + parent_position + length, + ( null_position - ( parent_position + length ) + 1 ) * sizeof(TCHAR) ); + + null_position -= ( parent_position + length ) - ( p + 1 ); + } + } + + + /* Cut last \*\.. */ + { + enum { length = 3 }; + TCHAR* p; + + while ( null_position - length >= OutStart ) { + if ( *( null_position - 3 ) != separator || + *( null_position - 2 ) != _T('.') || + *( null_position - 1 ) != _T('.') ) + { break; } + + p = null_position - 4; + for (;;) { + IF( p < OutStart ) goto err; /* "../" are too many */ + if ( *p == separator ) { break; } + p -= 1; + } + + *p = _T('\0'); + + null_position = p; + } + } + + + /* Replace \.\ to \ */ + { + enum { length = 3 }; + TCHAR current[ length + 1 ]; /* \.\ or /./ */ + TCHAR* current_position; + + current[0] = separator; + current[1] = _T('.'); + current[2] = separator; + current[3] = _T('\0'); + + for (;;) { + current_position = _tcsstr( OutStart, current ); + if ( current_position == NULL ) { break; } + + memmove( current_position + 1, + current_position + length, + ( null_position - ( current_position + length ) + 1 ) * sizeof(TCHAR) ); + + null_position -= length - 1; + } + } + + + /* Cut last \. */ + { + TCHAR* over = _tcschr( OutStart, _T('\0') ); + + while ( over - 2 >= OutStart && + *( over - 1 ) == _T('.') && *( over - 2 ) == separator ) { + over -= 2; + *over = _T('\0'); + } + } + + + /* Add root / */ + if ( null_position - 1 >= OutStart ) { + if ( *( null_position - 1 ) == _T(':') ) { + IF( null_position + 1 >= out_abs_path_over ) goto err_fa; + + *( null_position + 0 ) = separator; + *( null_position + 1 ) = _T('\0'); + null_position += 1; + } } - //=== â‘΃pƒX‚É‚·‚éB ".." ‚àˆ—‚·‚é - IF( OutSize - ((char*)OutStart - (char*)Out) < MAX_PATH*sizeof(TCHAR) ) return E_FewArray; - _tcscpy_s( OutStart, MAX_PATH, BasePath ); - PathAppend( OutStart, StepPath ); // PathAppend ‚Ì‘æ1ˆø”‚̃TƒCƒY‚Í MAX_PATH*sizeof(TCHAR) ˆÈã + /* Set "*out_OutLast" */ + if ( out_OutLast != NULL ) + { *out_OutLast = null_position; } + + e=0; +fin: + return e; + +err: e = E_OTHERS; goto fin; +err_fa: e = E_FEW_ARRAY; goto fin; +err_fm: e = E_FEW_MEMORY; goto fin; +} - //=== ––”ö‚Ì \ ‚ðƒJƒbƒg‚·‚é - p = _tcschr( OutStart, _T('\0') ); - if ( *(p-1) == _T('\\') && p > OutStart + 3 ) { p--; *p = _T('\0'); } + +/*********************************************************************** + <<< [StrT_getParentAbsPath_part] >>> +************************************************************************/ +errnum_t StrT_getParentAbsPath_part( TCHAR* Str, size_t StrSize, TCHAR* StrStart, + TCHAR** out_StrLast, const TCHAR* StepPath, const TCHAR* BasePath ) +{ + errnum_t e; + TCHAR* p; + + IF_D( StrStart < Str || (char*) StrStart >= (char*)Str + StrSize )goto err; + + if ( StepPath[0] == _T('\0') ) { + *StrStart = _T('\0'); + return 0; + } + + /* â‘΃pƒX‚É‚·‚é */ + e= StrT_getAbsPath( StrStart, + StrSize - ( (char*)StrStart - (char*)Str ), + StepPath, BasePath ); IF(e)goto fin; + + + /* Cut last \ */ + p = _tcschr( StrStart, _T('\0') ); + if ( p > StrStart ) { + TCHAR c = *( p - 1 ); + if ( c == _T('\\') || c == _T('/') ) + { *( p - 1 ) = _T('\0'); } + } + + + /* e‚Ö */ + p = StrT_refFName( StrStart ); + if ( p > StrStart ) p--; + *p = _T('\0'); + + + /* ƒ‹[ƒg‚È‚ç \ ‚ð•t‚¯‚é */ + if ( p == StrStart + 2 ) { + *p = _T('\\'); p++; *p = _T('\0'); + } + + if ( out_StrLast != NULL ) *out_StrLast = p; + + e=0; +fin: + return e; + +err: e = E_OTHERS; goto fin; +} + + + +/*********************************************************************** + <<< [StrT_isOverOfFileName] >>> +- "" or "\" or "/" +************************************************************************/ +inline bool StrT_isOverOfFileName( const TCHAR* PointerInPath ) +{ + return PointerInPath == NULL || + *PointerInPath == _T('\0') || + ( ( *PointerInPath == _T('\\') || *PointerInPath == _T('/') ) && + *(PointerInPath + 1) == _T('\0') ); +} + + + +/*********************************************************************** + <<< [StrT_getStepPath] >>> +************************************************************************/ +errnum_t StrT_getStepPath( TCHAR* out_StepPath, size_t StepPathSize, + const TCHAR* AbsPath, const TCHAR* BasePath ) +{ + errnum_t e; + const TCHAR* abs_pointer; + const TCHAR* base_pointer; + TCHAR abs_char; + TCHAR base_char; + TCHAR separator; + const TCHAR* abs_separator_pointer = (const TCHAR*) DUMMY_INITIAL_VALUE; + const TCHAR* base_separator_pointer = (const TCHAR*) DUMMY_INITIAL_VALUE; + TCHAR* step_pointer; + TCHAR parent_symbol[4] = { _T('.'), _T('.'), _T('\\'), _T('\0') }; + TCHAR base_path_2[ MAX_PATH ]; + + + ASSERT_D( out_StepPath != AbsPath, goto err ); + + abs_pointer = AbsPath; + + + /* Set "base_pointer" */ + if ( BasePath == NULL ) { + base_pointer = _tgetcwd( base_path_2, _countof(base_path_2) ); + IF( base_pointer == NULL ) goto err; + } + else { + base_pointer = BasePath; + } + + + /* Set "abs_separator_pointer", "base_separator_pointer" : after same parent folder path */ + separator = 0; + for (;;) { /* while abs_char == base_char */ + abs_char = *abs_pointer; + base_char = *base_pointer; + + abs_char = (TCHAR) _totlower( abs_char ); + base_char = (TCHAR) _totlower( base_char ); + + if ( abs_char == _T('\0') ) { + + /* out_StepPath = ".", if AbsPath == BasePath */ + if ( base_char == _T('\0') ) { + e= StrT_cpy( out_StepPath, StepPathSize, _T(".") ); IF(e)goto fin; + e=0; goto fin; + } + break; + } + if ( base_char == _T('\0') ) { break; } + + if ( abs_char != base_char ) { + if ( ( abs_char == _T('/') || abs_char == _T('\\') ) && + ( base_char == _T('/') || base_char == _T('\\') ) ) + { /* Do nothing */ } + else + { break; } + } + + /* Set "separator", "abs_separator_pointer", "base_separator_pointer" */ + if ( base_char == _T('/') || base_char == _T('\\') ) { + if ( separator == 0 ) + { separator = base_char; } + + abs_separator_pointer = abs_pointer; + base_separator_pointer = base_pointer; + } + + abs_pointer += 1; + base_pointer += 1; + } + + + /* AbsPath ‚Æ BasePath ‚ÌŠÖŒW‚ªA•Ð•û‚̈ꕔ‚ª‚à‚¤•Ð•û‚Ì‘S‘Ì‚Å‚ ‚é‚Æ‚« */ + if ( abs_char == _T('/') || abs_char == _T('\\') || + base_char == _T('/') || base_char == _T('\\') ) { + /* other character is '\0' */ + + if ( separator == 0 ) + { separator = abs_char; } + + abs_separator_pointer = abs_pointer; + base_separator_pointer = base_pointer; + } + + + /* out_StepPath = AbsPath, if there is not same folder */ + if ( separator == 0 ) { + e= StrT_cpy( out_StepPath, StepPathSize, AbsPath ); IF(e)goto fin; + e=0; goto fin; + } + + + /* Add "..\" to "out_StepPath" */ + parent_symbol[2] = separator; + step_pointer = out_StepPath; + for (;;) { + const TCHAR* p1; + const TCHAR* p2; + + if ( StrT_isOverOfFileName( base_separator_pointer ) ) + { break; } + + + /* Set "base_separator_pointer" : next separator */ + p1 = _tcschr( base_separator_pointer + 1, _T('/') ); + p2 = _tcschr( base_separator_pointer + 1, _T('\\') ); + + if ( p1 == NULL ) { + if ( p2 == NULL ) + { base_separator_pointer = NULL; } + else + { base_separator_pointer = p2; } + } + else { + if ( p2 == NULL ) { + base_separator_pointer = p1; + } else { + if ( p1 < p2 ) + { base_separator_pointer = p1; } + else + { base_separator_pointer = p2; } + } + } + + + /* Add "..\" to "out_StepPath" */ + e= stcpy_part_r( out_StepPath, StepPathSize, step_pointer, &step_pointer, + parent_symbol, NULL ); IF(e)goto fin; + } + + + /* Copy a part of "AbsPath" to "out_StepPath" */ + if ( StrT_isOverOfFileName( abs_separator_pointer ) ) { + ASSERT_D( step_pointer > out_StepPath, goto err ); + *( step_pointer - 1 ) = _T('\0'); + } + else { + e= stcpy_part_r( out_StepPath, StepPathSize, step_pointer, NULL, + abs_separator_pointer + 1, NULL ); IF(e)goto fin; + } + + e=0; +fin: + return e; + +err: e = E_OTHERS; goto fin; +} + + + +/*********************************************************************** + <<< [StrT_getBaseName_part] >>> +************************************************************************/ +errnum_t StrT_getBaseName_part( TCHAR* Str, size_t StrSize, TCHAR* StrStart, + TCHAR** out_StrLast, const TCHAR* SrcPath ) +{ + const TCHAR* p1; + const TCHAR* p2; + const TCHAR* p3; + const TCHAR* ps; + + p1 = StrT_refFName( SrcPath ); + + + //=== # ‚ª–³‚¢‚Æ‚«AÅŒã‚̃sƒŠƒIƒh‚Ì‘O‚Ü‚Å‚ªABaseName + ps = _tcschr( p1, _T('#') ); + if ( ps == NULL ) { + p2 = _tcsrchr( p1, _T('.') ); + if ( p2 == NULL ) p2 = _tcsrchr( p1, _T('\0') ); + } + + //=== # ‚ª‚ ‚é‚Æ‚«A# ‚æ‚è‘O‚ŁAÅŒã‚̃sƒŠƒIƒh‚Ì‘O‚Ü‚Å‚ªABaseName + else { + p2 = ps; + + p3 = p1; + for (;;) { + p3 = _tcschr( p3, _T('.') ); + if ( p3 == NULL || p3 > ps ) break; + p2 = p3; + p3 ++; + } + } + + return stcpy_part_r( Str, StrSize, StrStart, out_StrLast, p1, p2 ); +} + + +/*********************************************************************** + <<< [StrT_addLastOfFileName] >>> +************************************************************************/ +errnum_t StrT_addLastOfFileName( TCHAR* out_Path, size_t PathSize, + const TCHAR* BasePath, const TCHAR* AddName ) +{ + TCHAR c; + size_t copy_size; + size_t free_size; + char* out_pos; + const TCHAR* last_pos_in_base = _tcschr( BasePath, _T('\0') ); + const TCHAR* term_pos_in_base; + const TCHAR* add_pos_in_base; + const TCHAR* period_pos_in_base = _tcsrchr( BasePath, _T('.') ); // > term_pos_in_base + const TCHAR* last_pos_in_add = _tcschr( AddName, _T('\0') ); + const TCHAR* term_pos_in_add; + const TCHAR* period_pos_in_add = _tcsrchr( AddName, _T('.') ); // > term_pos_in_add + + + MEMSET_TO_NOT_INIT( out_Path, PathSize ); + + + //=== term_pos_in_base + for ( term_pos_in_base = last_pos_in_base; term_pos_in_base >= BasePath; term_pos_in_base -- ) { + c = *term_pos_in_base; + if ( c == _T('/') || c == _T('\\') ) break; + } + + + //=== term_pos_in_add + for ( term_pos_in_add = last_pos_in_add; term_pos_in_add >= AddName; term_pos_in_add -- ) { + c = *term_pos_in_add; + if ( c == _T('/') || c == _T('\\') ) break; + } + + + //=== add_pos_in_base + if ( term_pos_in_base < period_pos_in_base ) { + add_pos_in_base = period_pos_in_base; + } + else { + if ( term_pos_in_base < BasePath ) + add_pos_in_base = _tcschr( BasePath, _T('\0') ); + else + add_pos_in_base = _tcschr( term_pos_in_base, _T('\0') ); + } + + + //=== setup output parameters + out_pos = (char*) out_Path; + free_size = PathSize; + + + //=== copy BasePath .. add_pos_in_base + copy_size = (char*)add_pos_in_base - (char*)BasePath; + if ( copy_size > free_size ) goto err_fa; + memcpy( out_pos, BasePath, copy_size ); + out_pos += copy_size; + free_size -= copy_size; + + + //=== copy AddName .. last_pos_in_add + copy_size = (char*)last_pos_in_add - (char*)AddName; + if ( copy_size > free_size ) goto err_fa; + memcpy( out_pos, AddName, copy_size ); + out_pos += copy_size; + free_size -= copy_size; + + + //=== add name and not change extension + if ( period_pos_in_add == NULL ) { + + //=== copy period_pos_in_base .. last_pos_in_base + if ( period_pos_in_base > term_pos_in_base ) { + copy_size = (char*)last_pos_in_base - (char*)period_pos_in_base + sizeof(TCHAR); + if ( copy_size > free_size ) goto err_fa; + memcpy( out_pos, period_pos_in_base, copy_size ); + } + else { + *(TCHAR*)out_pos = _T('\0'); + } + } + + + //=== add name and change extension + else { + + if ( *(period_pos_in_add + 1) == _T('\0') ) + *( (TCHAR*)out_pos - 1 ) = _T('\0'); + else + *(TCHAR*)out_pos = _T('\0'); + } + + return 0; + +err_fa: + return E_FEW_ARRAY; +} + + + +/*********************************************************************** + <<< [Strs_init] >>> +************************************************************************/ +enum { Strs_FirstSize = 0x0F00 }; + +errnum_t Strs_init( Strs* self ) +{ + char* p; + + self->MemoryAddress = NULL; + + p = (char*) malloc( Strs_FirstSize ); + IF( p == NULL ) return E_FEW_MEMORY; + + self->MemoryAddress = p; + self->MemoryOver = p + Strs_FirstSize; + self->NextElem = p + sizeof(TCHAR*); + self->PointerToNextStrInPrevElem = (TCHAR**) p; + self->Prev_PointerToNextStrInPrevElem = NULL; + *(TCHAR**) p = NULL; + + self->FirstOfStrs = self; + self->NextStrs = NULL; + + return 0; +} + + + +/*********************************************************************** + <<< [Strs_finish] >>> +************************************************************************/ +errnum_t Strs_finish( Strs* self, errnum_t e ) +{ + Strs* mp; + Strs* next_mp; + + if ( self->MemoryAddress == NULL ) return 0; + + mp = self->FirstOfStrs; + for (;;) { + free( mp->MemoryAddress ); + if ( mp == self ) break; + + next_mp = mp->NextStrs; + free( mp ); + mp = next_mp; + } + self->MemoryAddress = NULL; + + return e; +} + + + +/*********************************************************************** + <<< [Strs_toEmpty] >>> +************************************************************************/ +errnum_t Strs_toEmpty( Strs* self ) +{ + Strs_finish( self, 0 ); + return Strs_init( self ); +} + + + +/*********************************************************************** + <<< [Strs_add] >>> +************************************************************************/ +errnum_t Strs_add( Strs* self, const TCHAR* Str, const TCHAR** out_AllocStr ) +{ + return Strs_addBinary( self, Str, _tcschr( Str, _T('\0') ) + 1, out_AllocStr ); +} + + +errnum_t Strs_addBinary( Strs* self, const TCHAR* Str, const TCHAR* StrOver, const TCHAR** out_AllocStr ) +{ + errnum_t e; + size_t str_size; + size_t elem_size; + + str_size = ( (char*) StrOver - (char*) Str ); + elem_size = ( sizeof(TCHAR*) + str_size + sizeof(void*) - 1 ) & ~(sizeof(void*) - 1); + + if ( self->NextElem + elem_size > self->MemoryOver ) + { e= Strs_expandSize( self, str_size ); IF(e)goto fin; } + + + // [ NULL | ... ] + // [ FirstStr | NULL | TCHAR[] | ... ] + // [ FirstStr | NextStr | TCHAR[] | NULL | TCHAR[] | ... ] + // [ FirstStr | NextStr | TCHAR[] | NextStr | TCHAR[] ], [ NULL | TCHAR[] | ... ] + + if ( out_AllocStr != NULL ) *out_AllocStr = (TCHAR*)( self->NextElem + sizeof(TCHAR*) ); + + //=== fill elem + *(TCHAR**) self->NextElem = NULL; + memcpy( self->NextElem + sizeof(TCHAR*), Str, str_size ); + + //=== link to elem from previous elem + *self->PointerToNextStrInPrevElem = (TCHAR*)( self->NextElem + sizeof(TCHAR*) ); + + //=== update self + self->Prev_PointerToNextStrInPrevElem = self->PointerToNextStrInPrevElem; + self->PointerToNextStrInPrevElem = (TCHAR**) self->NextElem; + self->NextElem = self->NextElem + elem_size; + + e=0; +fin: + return e; +} + + + +/*********************************************************************** + <<< [Strs_freeLast] >>> +************************************************************************/ +errnum_t Strs_freeLast( Strs* self, TCHAR* AllocStr ) +{ + errnum_t e; + TCHAR* str; + TCHAR* last_str; + TCHAR* prev_of_last_str; + Strs* mp; + Strs* prev_of_last_mp; + + if ( self->Prev_PointerToNextStrInPrevElem == NULL ) { + prev_of_last_str = NULL; + last_str = NULL; + for ( Strs_forEach( self, &str ) ) { + prev_of_last_str = last_str; + last_str = str; + } + } + else { + prev_of_last_str = (TCHAR*)( self->Prev_PointerToNextStrInPrevElem + 1 ); + last_str = (TCHAR*)( self->PointerToNextStrInPrevElem + 1 ); + } + + // [ NULL | ... ] + IF( last_str != AllocStr ) goto err; + + // [ FirstStr | NULL | TCHAR[] | ... ] + if ( prev_of_last_str == NULL ) { + self->NextElem = self->MemoryAddress + sizeof(TCHAR*); + self->PointerToNextStrInPrevElem = (TCHAR**) self->MemoryAddress; + } + + // [ FirstStr | NextStr | TCHAR[] | NULL | TCHAR[] | ... ] + else if ( (char*) prev_of_last_str >= self->MemoryAddress && + (char*) prev_of_last_str < self->MemoryOver ) { + self->NextElem = (char*)last_str - sizeof(TCHAR*); + self->PointerToNextStrInPrevElem = (TCHAR**)( (char*)prev_of_last_str - sizeof(TCHAR*) ); + } + + // [ FirstStr | NextStr | TCHAR[] | NextStr | TCHAR[] ], [ NULL | TCHAR[] | ... ] + else { + prev_of_last_mp = NULL; + for ( mp = self->FirstOfStrs; mp->NextStrs != self; mp = mp->NextStrs ) { + prev_of_last_mp = mp; + } + + free( self->MemoryAddress ); + + *self = *mp; + + if ( prev_of_last_mp == NULL ) { + self->FirstOfStrs = self; + self->NextStrs = NULL; + } + else { + prev_of_last_mp->NextStrs = self; + } + + free( mp ); + } + *self->PointerToNextStrInPrevElem = NULL; + self->Prev_PointerToNextStrInPrevElem = NULL; + + e=0; +fin: + return e; + +err: e = E_OTHERS; goto fin; +} + + + +/*********************************************************************** + <<< [Strs_expandSize] >>> +************************************************************************/ +errnum_t Strs_expandSize( Strs* self, size_t FreeSize ) +{ + Strs* mp; + Strs* mp2; + size_t elem_size = ( sizeof(TCHAR*) + FreeSize + sizeof(void*) - 1 ) & ~(sizeof(void*) - 1); + size_t memory_size; + char* new_memory; + + // [ NULL | ... ] + // [ FirstStr | NULL | TCHAR[] | ... ] + // [ FirstStr | NextStr | TCHAR[] | NULL | TCHAR[] | ... ] + // [ FirstStr | NextStr | TCHAR[] | NextStr | TCHAR[] ], [ NULL | TCHAR[] | ... ] + + while ( self->NextElem + elem_size > self->MemoryOver ) { + + //=== alloc + mp = (Strs*) malloc( sizeof(Strs) ); IF(mp==NULL) goto err_fm; + memory_size = ( self->MemoryOver - self->MemoryAddress ) * 2; + new_memory = (char*) malloc( memory_size ); + IF( new_memory == NULL ) { free( mp ); goto err_fm; } + + //=== move old memory + if ( self->FirstOfStrs == self ) { + self->FirstOfStrs = mp; + } + else { + for ( mp2 = self->FirstOfStrs; mp2->NextStrs != self; mp2 = mp2->NextStrs ); + mp2->NextStrs = mp; + } + *mp = *self; + mp->NextStrs = self; + + //=== setup new memory + self->MemoryAddress = new_memory; + self->MemoryOver = new_memory + memory_size; + self->NextElem = new_memory; + // self->PointerToNextStrInPrevElem is same value + // self->FirstOfStrs is same value + // self->NextStrs is always NULL + } + return 0; + +err_fm: return E_FEW_ARRAY; +} + + +/*********************************************************************** + <<< [Strs_commit] >>> +************************************************************************/ +errnum_t Strs_commit( Strs* self, TCHAR* StrOver ) +{ + size_t elem_size; + + if ( StrOver == NULL ) + { StrOver = _tcschr( (TCHAR*)( self->NextElem + sizeof(TCHAR*) ), _T('\0') ) + 1; } + elem_size = ( ( (char*)StrOver - self->NextElem ) + sizeof(void*) - 1 ) & ~(sizeof(void*) - 1); + + //=== fill elem + *(TCHAR**) self->NextElem = NULL; + + //=== link to elem from previous elem + *self->PointerToNextStrInPrevElem = (TCHAR*)( self->NextElem + sizeof(TCHAR*) ); + + //=== update self + self->PointerToNextStrInPrevElem = (TCHAR**) self->NextElem; + self->NextElem = self->NextElem + elem_size; + + return 0; +} + + + +/*********************************************************************** + <<< [StrArr] >>> +************************************************************************/ + +/*[StrArr_init]*/ +errnum_t StrArr_init( StrArr* self ) +{ + errnum_t e; + + Set2_initConst( &self->Array ); + Strs_initConst( &self->Chars ); + + e= Set2_init( &self->Array, 0x100 ); IF(e)goto cancel; + e= Strs_init( &self->Chars ); IF(e)goto cancel; + return 0; + +cancel: StrArr_finish( self, e ); return e; +} + + +/*[StrArr_finish]*/ +errnum_t StrArr_finish( StrArr* self, errnum_t e ) +{ + if ( ! Set2_isInited( &self->Array ) ) return 0; + + e= Set2_finish( &self->Array, e ); + e= Strs_finish( &self->Chars, e ); + return e; +} + + +/*[StrArr_add]*/ +errnum_t StrArr_add( StrArr* self, const TCHAR* Str, int* out_I ) +{ + errnum_t e; + + e= StrArr_expandCount( self, _tcslen( Str ) ); IF(e)goto fin; + _tcscpy_s( StrArr_getFreeAddr( self ), StrArr_getFreeCount( self ), Str ); + e= StrArr_commit( self ); IF(e)goto fin; + if ( out_I != NULL ) *out_I = Set2_getCount( &self->Array, TCHAR* ) - 1; + + e=0; +fin: + return e; +} + + +/*[StrArr_commit]*/ +errnum_t StrArr_commit( StrArr* self ) +{ + errnum_t e; + TCHAR* p; + TCHAR** pp = NULL; + Set2* arr = &self->Array; + Strs* ss = &self->Chars; + + p = Strs_getFreeAddr( ss ); + e= Set2_alloc( arr, &pp, TCHAR* ); IF(e)goto fin; + e= Strs_commit( ss, NULL ); IF(e)goto fin; + *pp = p; + + e=0; +fin: + if ( e && pp != NULL ) e= Set2_freeLast( arr, pp, TCHAR*, e ); + return e; +} + + +/*[StrArr_fillTo]*/ +errnum_t StrArr_fillTo( StrArr* self, int n, const TCHAR* Str ) +{ + errnum_t e; + const TCHAR* p; + const TCHAR** pp; + const TCHAR** pp_over; + + n -= Set2_getCount( &self->Array, TCHAR* ); + if ( n <= 0 ) return 0; + + if ( Str == NULL ) { + p = NULL; + } + else { + e= Strs_add( &self->Chars, Str, &p ); IF(e)goto fin; + } + + e= Set2_allocMulti( &self->Array, &pp, TCHAR*, n ); IF(e)goto fin; + pp_over = pp + n; + for ( ; pp < pp_over; pp++ ) + *pp = p; + + e=0; +fin: + return e; +} + + +/*[StrArr_toEmpty]*/ +errnum_t StrArr_toEmpty( StrArr* self ) +{ + errnum_t e, ee; + + e=0; + ee= Set2_toEmpty( &self->Array ); IF(ee&&!e)e=ee; + ee= Strs_toEmpty( &self->Chars ); IF(ee&&!e)e=ee; + return e; +} + + + +/*********************************************************************** + <<< [StrArr_parseCSV] >>> +************************************************************************/ +errnum_t StrArr_parseCSV( StrArr* self, const TCHAR* CSVLine ) +{ + errnum_t e; + const TCHAR* p = CSVLine; + + e= StrArr_toEmpty( self ); IF(e)goto fin; + + do { + e= StrT_meltCSV( StrArr_getFreeAddr( self ), StrArr_getFreeSize( self ), &p ); + if ( e == E_FEW_ARRAY ) { + e= StrArr_expandSize( self, StrArr_getFreeSize( self ) * 2 ); IF(e)goto fin; + continue; + } + IF(e)goto fin; + + e = StrArr_commit( self ); IF(e)goto fin; + } while ( p != NULL ); + + e=0; +fin: + return e; +} + + + +/*=================================================================*/ +/* <<< [SetX/SetX.c] >>> */ +/*=================================================================*/ + +/*********************************************************************** + <<< [Set2_init] >>> +************************************************************************/ +int Set2_init( Set2* m, int FirstSize ) +{ + m->First = malloc( FirstSize ); + if ( m->First == NULL ) return E_FEW_MEMORY; + m->Next = m->First; + m->Over = (char*)m->First + FirstSize; + + #ifdef _DEBUG + m->PointerOfDebugArray = NULL; + #endif + + return 0; +} + +/*********************************************************************** + <<< [Set2_finish] >>> +************************************************************************/ +int Set2_finish( Set2* m, int e ) +{ + if ( m->First != NULL ) { free( m->First ); m->First = NULL; } + return e; +} + +/*********************************************************************** + <<< [Set2_ref_imp] >>> +************************************************************************/ +int Set2_ref_imp( Set2* m, int iElem, void* out_pElem, size_t ElemSize ) +{ + int e; + char* p; - if ( out_OutLast != NULL ) *out_OutLast = p; + IF( iElem < 0 ) goto err_ns; + p = (char*) m->First + ( (unsigned)iElem * ElemSize ); + IF( p >= (char*)m->Next ) goto err_ns; + *(char**)out_pElem = p; e=0; fin: return e; -err: e = E_Others; goto fin; +err_ns: e = E_NOT_FOUND_SYMBOL; goto fin; } /*********************************************************************** - <<< [StrT_getParentAbsPath_part] >>> + <<< [Set2_alloc_imp] >>> ************************************************************************/ -int StrT_getParentAbsPath_part( TCHAR* Str, size_t StrSize, TCHAR* StrStart, - TCHAR** out_StrLast, const TCHAR* StepPath, const TCHAR* BasePath ) +int Set2_alloc_imp( Set2* m, void* pp, size_t size ) { int e; - TCHAR* p; - - IF_D( StrStart < Str || (char*) StrStart >= (char*)Str + StrSize )goto err; - - if ( StepPath[0] == _T('\0') ) { - *StrStart = _T('\0'); - return 0; - } - /* â‘΃pƒX‚É‚·‚é */ - e= StrT_getAbsPath( StrStart, - StrSize - ( (char*)StrStart - (char*)Str ), - StepPath, BasePath ); IF(e)goto fin; + e= Set2_expandIfOverByAddr( m, (char*) m->Next + size ); IF(e)goto fin; + *(void**)pp = m->Next; + m->Next = (char*) m->Next + size; + MEMSET_TO_NOT_INIT( *(void**)pp, size ); - /* e‚Ö */ - p = StrT_refFName( StrStart ); - if ( p > StrStart ) p--; - *p = _T('\0'); + e=0; +fin: + return e; +} - /* ƒ‹[ƒg‚È‚ç \ ‚ð•t‚¯‚é */ - if ( p == StrStart + 2 ) { - *p = _T('\\'); p++; *p = _T('\0'); - } +int Set2_allocMulti_sub( Set2* m, void* out_pElem, size_t ElemsSize ) +{ + int e; + char* p; - if ( out_StrLast != NULL ) *out_StrLast = p; + e= Set2_expandIfOverByAddr( m, (char*) m->Next + ElemsSize ); IF(e)goto fin; + p = (char*) m->Next; + m->Next = p + ElemsSize; + *(char**)out_pElem = p; e=0; fin: return e; - -err: e = E_Others; goto fin; } /*********************************************************************** - <<< [StrT_getBaseName_part] >>> + <<< [Set2_expandIfOverByAddr_imp] >>> ************************************************************************/ -int StrT_getBaseName_part( TCHAR* Str, size_t StrSize, TCHAR* StrStart, - TCHAR** out_StrLast, const TCHAR* SrcPath ) +int Set2_expandIfOverByAddr_imp( Set2* m, void* OverAddrBasedOnNowFirst ) { - const TCHAR* p1; - const TCHAR* p2; - const TCHAR* p3; - const TCHAR* ps; + void* new_first; + unsigned offset_of_over; + unsigned offset_of_next; - p1 = StrT_refFName( SrcPath ); + if ( OverAddrBasedOnNowFirst <= m->Over ) return E_OTHERS; + offset_of_next = (unsigned)( (char*)OverAddrBasedOnNowFirst - (char*)m->First ); + offset_of_over = (unsigned)( ( (char*)m->Over - (char*)m->First ) ) * 2; + IF_D( offset_of_next >= 0x80000000 ) goto err; + while ( offset_of_over < offset_of_next ) offset_of_over *= 2; + IF( offset_of_over >= 0x10000000 ) goto err; - //=== # ‚ª–³‚¢‚Æ‚«AÅŒã‚̃sƒŠƒIƒh‚Ì‘O‚Ü‚Å‚ªABaseName - ps = _tcschr( p1, _T('#') ); - if ( ps == NULL ) { - p2 = _tcsrchr( p1, _T('.') ); - if ( p2 == NULL ) p2 = _tcsrchr( p1, _T('\0') ); - } + new_first = realloc( m->First, offset_of_over * 2 ); + IF( new_first == NULL ) goto err_fm; - //=== # ‚ª‚ ‚é‚Æ‚«A# ‚æ‚è‘O‚ŁAÅŒã‚̃sƒŠƒIƒh‚Ì‘O‚Ü‚Å‚ªABaseName - else { - p2 = ps; + m->Next = (char*) new_first + ( (char*)m->Next - (char*)m->First ); + m->Over = (char*) new_first + offset_of_over * 2; + m->First = new_first; - p3 = p1; - for (;;) { - p3 = _tcschr( p3, _T('.') ); - if ( p3 == NULL || p3 > ps ) break; - p2 = p3; - p3 ++; - } - } + #ifdef _DEBUG + if ( m->PointerOfDebugArray != NULL ) + { *m->PointerOfDebugArray = m->First; } + #endif - return stcpy_part_r( Str, StrSize, StrStart, out_StrLast, p1, p2 ); + return 0; + +err: return E_OTHERS; +err_fm: return E_FEW_MEMORY; } /*********************************************************************** - <<< [StrT_addLastOfFileName] >>> + <<< [Set2_separate] >>> ************************************************************************/ -int StrT_addLastOfFileName( TCHAR* out_Path, size_t PathSize, - const TCHAR* BasePath, const TCHAR* AddName ) +int Set2_separate( Set2* m, int NextSize, void** allocate_Array ) { - TCHAR c; - size_t copy_size; - size_t free_size; - char* out_pos; - const TCHAR* last_pos_in_base = _tcschr( BasePath, _T('\0') ); - const TCHAR* term_pos_in_base; - const TCHAR* add_pos_in_base; - const TCHAR* period_pos_in_base = _tcsrchr( BasePath, _T('.') ); // > term_pos_in_base - const TCHAR* last_pos_in_add = _tcschr( AddName, _T('\0') ); - const TCHAR* term_pos_in_add; - const TCHAR* period_pos_in_add = _tcsrchr( AddName, _T('.') ); // > term_pos_in_add - - - MEMSET_TO_NOT_INIT( out_Path, PathSize ); - - - //=== term_pos_in_base - for ( term_pos_in_base = last_pos_in_base; term_pos_in_base >= BasePath; term_pos_in_base -- ) { - c = *term_pos_in_base; - if ( c == _T('/') || c == _T('\\') ) break; - } - - - //=== term_pos_in_add - for ( term_pos_in_add = last_pos_in_add; term_pos_in_add >= AddName; term_pos_in_add -- ) { - c = *term_pos_in_add; - if ( c == _T('/') || c == _T('\\') ) break; - } - + int e; + void* p = m->First; - //=== add_pos_in_base - if ( term_pos_in_base < period_pos_in_base ) { - add_pos_in_base = period_pos_in_base; + if ( NextSize == 0 ) { + MEMSET_TO_NOT_INIT( m, sizeof(*m) ); + m->First = NULL; } else { - if ( term_pos_in_base < BasePath ) - add_pos_in_base = _tcschr( BasePath, _T('\0') ); - else - add_pos_in_base = _tcschr( term_pos_in_base, _T('\0') ); - } - - - //=== setup output parameters - out_pos = (char*) out_Path; - free_size = PathSize; - - - //=== copy BasePath .. add_pos_in_base - copy_size = (char*)add_pos_in_base - (char*)BasePath; - if ( copy_size > free_size ) goto err_fa; - memcpy( out_pos, BasePath, copy_size ); - out_pos += copy_size; - free_size -= copy_size; - - - //=== copy AddName .. last_pos_in_add - copy_size = (char*)last_pos_in_add - (char*)AddName; - if ( copy_size > free_size ) goto err_fa; - memcpy( out_pos, AddName, copy_size ); - out_pos += copy_size; - free_size -= copy_size; - - - //=== add name and not change extension - if ( period_pos_in_add == NULL ) { - - //=== copy period_pos_in_base .. last_pos_in_base - if ( period_pos_in_base > term_pos_in_base ) { - copy_size = (char*)last_pos_in_base - (char*)period_pos_in_base + sizeof(TCHAR); - if ( copy_size > free_size ) goto err_fa; - memcpy( out_pos, period_pos_in_base, copy_size ); - } - else { - *(TCHAR*)out_pos = _T('\0'); - } + e= Set2_init( m, NextSize ); IF(e)goto fin; } + *allocate_Array = p; + e=0; +fin: + return e; +} - //=== add name and change extension - else { - - if ( *(period_pos_in_add + 1) == _T('\0') ) - *( (TCHAR*)out_pos - 1 ) = _T('\0'); - else - *(TCHAR*)out_pos = _T('\0'); - } - - return 0; -err_fa: - return E_FewArray; + +/*********************************************************************** + <<< [Set2_setDebug] >>> +************************************************************************/ +#ifdef _DEBUG +void Set2_setDebug( Set2* m, void** PointerOfDebugArray ) +{ + m->PointerOfDebugArray = PointerOfDebugArray; + *m->PointerOfDebugArray = m->First; } +#endif @@ -1956,7 +3285,7 @@ void wprintf_to_debugger( const wchar_t* format, ... ) /*********************************************************************** <<< [vsprintf_r] >>> ************************************************************************/ -int vsprintf_r( char* s, size_t s_size, const char* format, va_list va ) +errnum_t vsprintf_r( char* s, size_t s_size, const char* format, va_list va ) { #if _MSC_VER #pragma warning(push) @@ -1969,15 +3298,21 @@ int vsprintf_r( char* s, size_t s_size, const char* format, va_list va ) #pragma warning(pop) #endif - if ( r == (int) s_size || r == -1 ) { s[s_size-1] = '\0'; return E_FewArray; } - else return 0; + IF( r == (int) s_size ) + { s[s_size-1] = '\0'; return E_FEW_ARRAY; } + IF( r == -1 ) + { return E_NOT_FOUND_SYMBOL; } /* Bad character code */ + + return 0; } + + /*********************************************************************** <<< [vswprintf_r] >>> ************************************************************************/ #ifndef __linux__ -int vswprintf_r( wchar_t* s, size_t s_size, const wchar_t* format, va_list va ) +errnum_t vswprintf_r( wchar_t* s, size_t s_size, const wchar_t* format, va_list va ) { size_t tsize = s_size / sizeof(wchar_t); @@ -1986,23 +3321,25 @@ int vswprintf_r( wchar_t* s, size_t s_size, const wchar_t* format, va_list va ) int r = _vsnwprintf( s, tsize, format, va ); #pragma warning(pop) - if ( r == (int) tsize || r == -1 ) { s[tsize-1] = '\0'; return E_FewArray; } + if ( r == (int) tsize || r == -1 ) { s[tsize-1] = '\0'; return E_FEW_ARRAY; } else return 0; } #endif + + /*********************************************************************** <<< [stprintf_r] >>> ************************************************************************/ -int stprintf_r( TCHAR* s, size_t s_size, const TCHAR* format, ... ) +errnum_t stprintf_r( TCHAR* s, size_t s_size, const TCHAR* format, ... ) { - int e; - va_list va; + errnum_t e; + va_list va; - va_start( va, format ); - e = vstprintf_r( s, s_size, format, va ); - va_end( va ); - return e; + va_start( va, format ); + e = vstprintf_r( s, s_size, format, va ); + va_end( va ); + return e; } @@ -2010,28 +3347,32 @@ int stprintf_r( TCHAR* s, size_t s_size, const TCHAR* format, ... ) /*********************************************************************** <<< [stcpy_part_r] >>> ************************************************************************/ -int stcpy_part_r( TCHAR* s, size_t s_size, TCHAR* s_start, TCHAR** p_s_last, +errnum_t stcpy_part_r( TCHAR* s, size_t s_size, TCHAR* s_start, TCHAR** p_s_last, const TCHAR* src, const TCHAR* src_over ) { - size_t s_space = (char*)s + s_size - (char*)s_start; - size_t src_size; + size_t s_space = (char*)s + s_size - (char*)s_start; + size_t src_size; - IF_D( s_start < s || (char*)s_start >= (char*)s + s_size ) return 1; + IF_D( s_start < s || (char*)s_start >= (char*)s + s_size ) { return 1; } - if ( src_over == NULL ) src_over = _tcschr( src, _T('\0') ); - src_size = (char*)src_over - (char*)src; - if ( src_size < s_space ) { - memcpy( s_start, src, src_size + sizeof(TCHAR) ); - s_start = (TCHAR*)((char*)s_start + src_size); *s_start = _T('\0'); - if ( p_s_last != NULL ) *p_s_last = s_start; - return 0; - } - else { - s_space -= sizeof(TCHAR); memcpy( s, src, s_space ); - s_start = (TCHAR*)((char*)s_start + s_space ); *s_start = '\0'; - if ( p_s_last != NULL ) *p_s_last=s_start; - return E_FewArray; - } + if ( src_over == NULL ) { src_over = _tcschr( src, _T('\0') ); } + src_size = (char*)src_over - (char*)src; + IF ( src_size >= s_space ) { + s_space -= sizeof(TCHAR); + memcpy( s, src, s_space ); + + s_start = (TCHAR*)((char*)s_start + s_space ); + *s_start = '\0'; + + if ( p_s_last != NULL ) { *p_s_last=s_start; } + return E_FEW_ARRAY; + } + + memcpy( s_start, src, src_size + sizeof(TCHAR) ); + s_start = (TCHAR*)((char*)s_start + src_size); *s_start = _T('\0'); + if ( p_s_last != NULL ) { *p_s_last = s_start; } + + return 0; } @@ -2039,53 +3380,48 @@ int stcpy_part_r( TCHAR* s, size_t s_size, TCHAR* s_start, TCHAR** p_s_last, /*********************************************************************** <<< [stprintf_part_r] >>> ************************************************************************/ -int stprintf_part_r( TCHAR* s, size_t s_size, TCHAR* s_start, TCHAR** p_s_last, +errnum_t stprintf_part_r( TCHAR* s, size_t s_size, TCHAR* s_start, TCHAR** p_s_last, const TCHAR* format, ... ) { - int e; va_list va; va_start( va, format ); + errnum_t e; + va_list va; + va_start( va, format ); - IF_D( s_start < s || (char*)s_start >= (char*)s + s_size ) return 1; + IF_D( s_start < s || (char*)s_start >= (char*)s + s_size ) {return E_OTHERS;} - e = vstprintf_r( s_start, s_size - ( (char*)s - (char*)s_start), format, va ); - va_end( va ); if ( p_s_last != NULL ) *p_s_last = _tcschr( s_start, '\0' ); - return e; + e = vstprintf_r( s_start, s_size - ( (char*)s_start - (char*)s), format, va ); + va_end( va ); if ( p_s_last != NULL ) *p_s_last = _tcschr( s_start, '\0' ); + return e; } /*=================================================================*/ -/* <<< [DebugTools/DebugTools.c] >>> */ +/* <<< [Error4/Error4.c] >>> */ /*=================================================================*/ /*********************************************************************** - <<< [TestableDebugBreak] >>> + <<< [Get_Error4_Variables] >>> ************************************************************************/ -dll_global_g_DebugBreakCount int g_bTestableDebugBreak_Disable; -dll_global_g_DebugBreakCount int g_DebugBreakCount; - +static Error4_VariablesClass gs; +#ifdef _DEBUG + extern Error4_VariablesClass* g_Error4_Variables = &gs; +#endif - -/*********************************************************************** - <<< [TestableDebugBreak_isEnabled] >>> -************************************************************************/ -int TestableDebugBreak_isEnabled() +Error4_VariablesClass* Get_Error4_Variables() { - return g_bTestableDebugBreak_Disable == 0; + return &gs; } -/*=================================================================*/ -/* <<< [Error4/Error4.c] >>> */ -/*=================================================================*/ - /*********************************************************************** - <<< [Err2_setBreakErrID] >>> + <<< [SetBreakErrorID] >>> ************************************************************************/ #if ERR2_ENABLE_ERROR_BREAK -Err2 g_Err2; /* ‰Šú’l‚Í‚·‚ׂă[ƒ */ +dll_global_g_DebugBreakCount Err2 g_Err2; /* ‰Šú’l‚Í‚·‚ׂă[ƒ */ -void Err2_setBreakErrID( int ID ) +void SetBreakErrorID( int ID ) { Err2* m = &g_Err2; @@ -2093,7 +3429,7 @@ void Err2_setBreakErrID( int ID ) } -int TryOnIfTrue_imp() +int TryOnIfTrue_imp( const char* FilePath, int LineNum ) // •Ô‚è’l‚́AƒuƒŒ[ƒN‚·‚é‚©‚Ç‚¤‚© { //=== ƒGƒ‰[Žž‚Ì’†’fˆ—iƒWƒƒƒ“ƒvj‚ð‚µ‚Ä‚¢‚é‚Æ‚« @@ -2106,6 +3442,8 @@ int TryOnIfTrue_imp() m->IsErr = 1; m->ErrID ++; + m->FilePath = FilePath; + m->LineNum = LineNum; #if ERR2_ENABLE_ERROR_LOG printf( "\n", m->ErrID, (int) m ); @@ -2116,8 +3454,8 @@ int TryOnIfTrue_imp() } -//[Err2_clear] -void Err2_clear() +//[ClearError] +void ClearError() { Err2* m = &g_Err2; @@ -2130,19 +3468,33 @@ void Err2_clear() } +//[IsErrorMode] +bool IsErrorMode() +{ + return ( g_Err2.IsErr != 0 ); +} + + //[IfErrThenBreak] void IfErrThenBreak() { if ( g_Err2.IsErr && ( g_Err2.ErrID != g_Err2.BreakErrID || g_Err2.BreakErrID == 0 ) ) { TestableDebugBreak(); // ƒEƒHƒbƒ`‚ŁAg_Err2.ErrID ‚Ì’l(N‚Æ‚·‚é)‚ðŠm”F‚µ‚āA - // ƒƒCƒ“ŠÖ”‚Å Err2_setBreakErrID( N ); ‚ðŒÄ‚яo‚µ‚Ä‚­‚¾‚³‚¢B + // ƒƒCƒ“ŠÖ”‚Å SetBreakErrorID( N ); ‚ðŒÄ‚яo‚µ‚Ä‚­‚¾‚³‚¢B + // ƒGƒ‰[‚ª”­¶‚µ‚½êŠ‚́Ag_Err2.FilePath, g_Err2.LineNum ‚Å‚·B // ³íI—¹‚µ‚Ä‚¢‚é‚‚à‚è‚È‚Ì‚É‚±‚±‚ŃuƒŒ[ƒN‚·‚é‚Æ‚«‚́A - // Err2_clear() ‚ð–Y‚ê‚Ä‚¢‚é‰Â”\«‚ª‚ ‚è‚Ü‚·B + // ClearError() ‚ð–Y‚ê‚Ä‚¢‚é‰Â”\«‚ª‚ ‚è‚Ü‚·B #if ERR2_ENABLE_ERROR_LOG printf( "\n", g_Err2.ErrID, g_Err2.BreakErrID ); #endif + + { + char str[512]; + sprintf_s( str, _countof(str), "\n", g_Err2.FilePath, g_Err2.LineNum ); + OutputDebugStringA( str ); + } } - Err2_clear(); + ClearError(); } //[PushErr] @@ -2164,3 +3516,99 @@ void PopErr( ErrStackAreaClass* ErrStackArea ) #endif // ERR2_ENABLE_ERROR_BREAK +/*********************************************************************** + <<< [g_Error4_String] >>> +************************************************************************/ +TCHAR g_Error4_String[4096]; + + + +/*********************************************************************** + <<< [Error4_printf] >>> +************************************************************************/ +void Error4_printf( const TCHAR* format, ... ) +{ + va_list va; + va_start( va, format ); + vstprintf_r( g_Error4_String, sizeof(g_Error4_String), format, va ); + va_end( va ); +} + + + +/*********************************************************************** + <<< [Error4_getErrStr] >>> +************************************************************************/ +void Error4_getErrStr( int ErrNum, TCHAR* out_ErrStr, size_t ErrStrSize ) +{ + switch ( ErrNum ) { + + case 0: + stprintf_r( out_ErrStr, ErrStrSize, _T("no error") ); + break; + + #ifndef __linux__ + case E_GET_LAST_ERROR: { + DWORD err_win; + TCHAR* str_pointer; + + err_win = gs.WindowsLastError; + if ( err_win == 0 ) { err_win = GetLastError(); } + + stprintf_part_r( out_ErrStr, ErrStrSize, out_ErrStr, &str_pointer, + _T(""), NULL ); + break; + } + #endif + + default: + if ( g_Error4_String[0] != '\0' ) + stprintf_r( out_ErrStr, ErrStrSize, _T("%s"), g_Error4_String ); + else + stprintf_r( out_ErrStr, ErrStrSize, _T(""), ErrNum ); + break; + } +} + + + +/*********************************************************************** + <<< [SaveWindowsLastError] >>> +************************************************************************/ +errnum_t SaveWindowsLastError() +{ + gs.WindowsLastError = GetLastError(); + return E_GET_LAST_ERROR; +} + + + +/*=================================================================*/ +/* <<< [DebugTools/DebugTools.c] >>> */ +/*=================================================================*/ + +/*********************************************************************** + <<< [TestableDebugBreak] >>> +************************************************************************/ +dll_global_g_DebugBreakCount int g_bTestableDebugBreak_Disable; +dll_global_g_DebugBreakCount int g_DebugBreakCount; + + + +/*********************************************************************** + <<< [TestableDebugBreak_isEnabled] >>> +************************************************************************/ +int TestableDebugBreak_isEnabled() +{ + return g_bTestableDebugBreak_Disable == 0; +} + + +