4141#include " config/system_constants.h"
4242#include " String_define.h"
4343
44- // "までを切り取る
45- static bool GetQuoteFilePath ( const wchar_t * pLine, wchar_t * pFile, size_t size ){
44+ // ! "までを切り取る
45+ // sizeは切り出し文字列のNULL終端を含む長さ(wstring::length()+1の値)
46+ static bool GetQuoteFilePath (const wchar_t * pLine, std::wstring& str, size_t size)
47+ {
4648 const wchar_t * pFileEnd = wcschr ( pLine, L' \" ' );
47- if ( pFileEnd ){
48- int nFileLen = pFileEnd - pLine;
49- if ( 0 < nFileLen && nFileLen < (int )size ){
50- wmemcpy ( pFile, pLine, nFileLen );
51- pFile[nFileLen] = L' \0 ' ;
52- return true ;
53- }
49+ str = L" " ;
50+ if (pFileEnd == nullptr ) {
51+ return false ;
5452 }
55- return false ;
53+ size_t nFileLen = pFileEnd - pLine;
54+ if (0 == nFileLen || size <= nFileLen) {
55+ return false ;
56+ }
57+ str.assign (pLine, nFileLen);
58+ return !str.empty ();
5659}
5760
5861static bool IsFileExists2 ( const wchar_t * pszFile )
@@ -77,6 +80,15 @@ static bool IsFileExists2( const wchar_t* pszFile )
7780 @date 2011.11.24 Moca Grepフォルダ毎表示対応
7881*/
7982bool CViewCommander::Command_TAGJUMP ( bool bClose )
83+ {
84+ bool ret = Command_TagJumpNoMessage (bClose);
85+ if (ret == false ){
86+ m_pCommanderView->SendStatusMessage (LS (STR_ERR_TAGJMP1)); // @@@ 2003.04.13
87+ }
88+ return ret;
89+ }
90+
91+ bool CViewCommander::Command_TagJumpNoMessage ( bool bClose )
8092{
8193 // 2004.05.13 Moca 初期値を1ではなく元の位置を継承するように
8294 // 0以下は未指定扱い。(1開始)
@@ -86,11 +98,8 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
8698 nJumpToColumn = 0 ;
8799
88100 // ファイル名バッファ
89- wchar_t szJumpToFile[1024 ];
90- wchar_t szFile[_MAX_PATH] = {L' \0 ' };
91101 size_t nBgn;
92102 size_t nPathLen;
93- wmemset ( szJumpToFile, 0 , _countof (szJumpToFile) );
94103
95104 /*
96105 カーソル位置変換
@@ -109,7 +118,7 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
109118 CLogicInt nLineLen;
110119 const wchar_t * pLine = CDocLine::GetDocLineStrWithEOL_Safe (GetDocument ()->m_cDocLineMgr .GetLine (ptXY.GetY2 ()), &nLineLen);
111120 if ( NULL == pLine ){
112- goto can_not_tagjump ;
121+ return false ;
113122 }
114123
115124 // ノーマル
@@ -131,6 +140,14 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
131140 // ・SubFolders\FileName2.ext(5396,11): str
132141 // ・SubFolders\FileName3.ext(123,11): str
133142
143+ // ノーマル/フォルダ毎
144+ // ■"C:\RootFolder"
145+ // ・FileName.cpp(5395,11): str
146+ // ■"C:\RootFolder\SubFolders"
147+ // ・FileName2.ext(5395,11): str
148+ // ・FileName2.ext(5396,11): str
149+ // ・FileName3.ext(123,11): str
150+
134151 // ファイル毎(WZ風)
135152 // ■"C:\RootFolder\FileName.ext"
136153 // ・( 5395,11 ): str
@@ -162,8 +179,41 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
162179 // ◆"FileName3.ext"
163180 // ・( 123,12 ): str
164181
182+ // ファイル毎/フォルダ毎
183+ // ■"C:\RootFolder"
184+ // ◆"FileName.ext"
185+ // ・( 5395,11 ): str
186+ // ■"C:\RootFolder\SubFolders"
187+ // ◆"FileName2.ext"
188+ // ・( 5395,11 ): str
189+ // ・( 5396,11 ): str
190+
191+
165192 // Grep結果のタグジャンプ検索
166193 // ・→◆→■→◎ の順に検索してパスを結合する
194+
195+ // 自動選択を選ぶとエンコード名表示
196+ // C:\RootFolder\SubFolders\FileName.ext(150,6) [UTF-8]: str
197+ // ・SubFolders\FileName.ext(150,6) [UTF-8]: str
198+ // ・FileName.ext(150,6) [UTF-8]: str
199+
200+ // ■"C:\RootFolder\SubFolders\FileName.ext" [UTF-8]
201+ // ・( 150,6 ): str
202+
203+ // ◎"C:\RootFolder"
204+ // ■"FileName.ext" [UTF-8]
205+ // ・( 5395,11 ): str
206+ // ■"SubFolders\FileName2.ext" [UTF-8]
207+ // ・( 5395,11 ): str
208+
209+ // ■"C:\RootFolder\SubFolders\"
210+ // ◆"FileName.ext" [UTF-8]
211+ // ・( 150,60 ): str
212+
213+ std::wstring strJumpToFile;
214+ std::wstring strFile;
215+ constexpr int MAX_TAG_PATH = MAX_PATH;
216+
167217 do {
168218 enum TagListSeachMode{
169219 TAGLIST_FILEPATH,
@@ -173,22 +223,22 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
173223 if ( 0 == wmemcmp ( pLine, L" ■\" " , 2 ) ){
174224 /* WZ風のタグリストか */
175225 if ( IsFilePath ( &pLine[2 ], &nBgn, &nPathLen ) && !_IS_REL_PATH ( &pLine[2 ] ) ){
176- wmemcpy ( szJumpToFile, &pLine[2 + nBgn], nPathLen );
226+ strJumpToFile. assign ( &pLine[2 + nBgn], nPathLen);
177227 GetLineColumn ( &pLine[2 + nPathLen], &nJumpToLine, &nJumpToColumn );
178228 break ;
179- }else if ( !GetQuoteFilePath ( &pLine[2 ], szFile, _countof (szFile) ) ) {
229+ }else if ( !GetQuoteFilePath (&pLine[2 ], strFile, MAX_TAG_PATH)) {
180230 break ;
181231 }
182232 searchMode = TAGLIST_ROOT;
183233 }else if ( 0 == wmemcmp ( pLine, L" ◆\" " , 2 ) ){
184- if ( !GetQuoteFilePath ( &pLine[2 ], szFile, _countof (szFile) ) ) {
234+ if ( !GetQuoteFilePath (&pLine[2 ], strFile, MAX_TAG_PATH)) {
185235 break ;
186236 }
187237 searchMode = TAGLIST_SUBPATH;
188238 }else if ( 0 == wmemcmp ( pLine, L" ・" , 1 ) ){
189239 if ( pLine[1 ] == L' "' ){
190240 // ・"FileName.ext"
191- if ( !GetQuoteFilePath ( &pLine[2 ], szFile, _countof (szFile) ) ) {
241+ if ( !GetQuoteFilePath (&pLine[2 ], strFile, MAX_TAG_PATH)) {
192242 break ;
193243 }
194244 searchMode = TAGLIST_SUBPATH;
@@ -224,9 +274,8 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
224274 for ( ; 1 < fileEnd && (L' 0' <= pLine[fileEnd] && pLine[fileEnd] <= L' 9' ); fileEnd-- ){}
225275 if ( 1 < fileEnd && (L' ,' == pLine[fileEnd]) ){ fileEnd--; }
226276 for ( ; 1 < fileEnd && (L' 0' <= pLine[fileEnd] && pLine[fileEnd] <= L' 9' ); fileEnd-- ){}
227- if ( 1 < fileEnd && L' (' == pLine[fileEnd] && fileEnd - 1 < (int )_countof (szFile) ){
228- wmemcpy ( szFile, pLine + 1 , fileEnd - 1 );
229- szFile[fileEnd - 1 ] = L' \0 ' ;
277+ if ( 1 < fileEnd && L' (' == pLine[fileEnd] && fileEnd - 1 < MAX_TAG_PATH ){
278+ strFile.assign (pLine + 1 , fileEnd - 1 );
230279 GetLineColumn ( &pLine[fileEnd + 1 ], &nJumpToLine, &nJumpToColumn );
231280 searchMode = TAGLIST_SUBPATH;
232281 }else {
@@ -251,7 +300,7 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
251300 continue ;
252301 }
253302 // フォルダ毎:ファイル名
254- if ( GetQuoteFilePath (&pLine[2 ], szFile, _countof (szFile )) ) {
303+ if ( GetQuoteFilePath (&pLine[2 ], strFile, MAX_TAG_PATH )) {
255304 searchMode = TAGLIST_SUBPATH;
256305 continue ;
257306 }
@@ -268,31 +317,39 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
268317 }
269318 // ファイル毎(WZ風):フルパス
270319 if ( IsFilePath ( &pLine[2 ], &nBgn, &nPathLen ) && !_IS_REL_PATH ( &pLine[2 ] ) ){
271- wmemcpy ( szJumpToFile, &pLine[2 + nBgn], nPathLen );
320+ strJumpToFile. assign ( &pLine[2 + nBgn], nPathLen);
272321 break ;
273322 }
274323 // 相対フォルダorファイル名
275- wchar_t szPath[_MAX_PATH] ;
276- if ( GetQuoteFilePath ( &pLine[2 ], szPath, _countof (szPath) ) ) {
277- if ( szFile[ 0 ] ) {
278- AddLastYenFromDirectoryPath ( szPath );
324+ std::wstring strPath ;
325+ if ( GetQuoteFilePath (&pLine[2 ], strPath, MAX_TAG_PATH)) {
326+ if (strFile. empty () == false ) {
327+ strPath = AddLastYenPath (strPath );
279328 }
280- wcscat ( szPath, szFile );
281- if ( IsFileExists2 ( szPath ) ){
282- wcscpy ( szJumpToFile, szPath );
329+ strPath.append (strFile);
330+ if ( MAX_TAG_PATH <= strPath.size () ){
331+ break ;
332+ }
333+ if ( IsFileExists2 (strPath.c_str ()) ){
334+ strJumpToFile = strPath;
283335 break ;
284336 }
285337 // 相対パスだった→◎”を探す
286- wcscpy ( szFile, szPath ) ;
338+ strFile = strPath ;
287339 searchMode = TAGLIST_ROOT;
288340 continue ;
289341 }
290342 break ;
291343 }else if ( 3 <= nLineLen && 0 == wmemcmp ( pLine, L" ◎\" " , 2 ) ){
292- if ( GetQuoteFilePath ( &pLine[2 ], szJumpToFile, _countof (szJumpToFile) ) ){
293- AddLastYenFromDirectoryPath ( szJumpToFile );
294- wcscat ( szJumpToFile, szFile );
295- if ( IsFileExists2 ( szJumpToFile ) ){
344+ std::wstring strPath;
345+ if (GetQuoteFilePath (&pLine[2 ], strPath, MAX_TAG_PATH)) {
346+ strPath = AddLastYenPath (strPath);
347+ strPath.append (strFile);
348+ if (MAX_TAG_PATH <= strPath.size ()) {
349+ break ;
350+ }
351+ if (IsFileExists2 (strPath.c_str ())) {
352+ strJumpToFile = strPath;
296353 break ;
297354 }
298355 }
@@ -304,10 +361,10 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
304361 }
305362 }while (0 );
306363
307- if ( szJumpToFile[ 0 ] == L ' \0 ' ) {
364+ if (strJumpToFile. empty ()) {
308365 pLine = GetDocument ()->m_cDocLineMgr .GetLine (ptXYOrg.GetY2 ())->GetDocLineStrWithEOL (&nLineLen);
309366 if ( NULL == pLine ){
310- goto can_not_tagjump ;
367+ return false ;
311368 }
312369 // @@@ 2001.12.31 YAZAKI
313370 const wchar_t *p = pLine;
@@ -324,7 +381,7 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
324381
325382 // Check Path
326383 if ( IsFilePath ( p, &nBgn, &nPathLen ) ){
327- wmemcpy ( szJumpToFile, &p[nBgn], nPathLen );
384+ strJumpToFile. assign ( &p[nBgn], nPathLen);
328385 GetLineColumn ( &p[nBgn + nPathLen], &nJumpToLine, &nJumpToColumn );
329386 break ;
330387 }
@@ -337,22 +394,17 @@ bool CViewCommander::Command_TAGJUMP( bool bClose )
337394 }
338395
339396 // 2011.11.29 Grep形式で失敗した後もTagsを検索する
340- if ( szJumpToFile[0 ] == L' \0 ' ){
341- if ( Command_TagJumpByTagsFile (bClose) ){ // @@@ 2003.04.13
342- return true ;
343- }
397+ if (strJumpToFile.empty () && Command_TagJumpByTagsFile (bClose) ){ // @@@ 2003.04.13
398+ return true ;
344399 // From Here Aug. 27, 2001 genta
345400 }
346401
347402 // Apr. 21, 2003 genta bClose追加
348- if ( szJumpToFile[0 ] ){
349- if ( m_pCommanderView->TagJumpSub ( szJumpToFile, CMyPoint (nJumpToColumn, nJumpToLine), bClose ) ){ // @@@ 2003.04.13
350- return true ;
351- }
403+ if (strJumpToFile.empty () == false &&
404+ m_pCommanderView->TagJumpSub (strJumpToFile.c_str (), CMyPoint (nJumpToColumn, nJumpToLine), bClose ) ){ // @@@ 2003.04.13
405+ return true ;
352406 }
353407
354- can_not_tagjump:;
355- m_pCommanderView->SendStatusMessage (LS (STR_ERR_TAGJMP1)); // @@@ 2003.04.13
356408 return false ;
357409}
358410
0 commit comments