티스토리 뷰




프로그램의 솔루션 디렉토리를 선택 하면

해당 프로그램에 들어간 소스의 라인 수를 계산하여 출력해 주는 프로그램.

현재 c, cpp, h, java, cs, py 확장자만 지원한다.

소스는 너무 간단해서.. 걍 대충 주석써서 올리겠음.

void CCodeLineSearcherDlg::FindLine( int &nTotalLine, CString strPath )
{

	CFileFind finder;


	finder.FindFile( strPath );

	int res = 1;
	while( res )
	{
		res = finder.FindNextFile();
		
		if( ( m_bC && finder.GetFileName().Right(2) == _T(".c") ) ||
			( m_bCPP && finder.GetFileName().Right(4) == _T(".cpp") ) ||
			( m_bH && finder.GetFileName().Right(2) == _T(".h") ) ||
			( m_bJava && finder.GetFileName().Right(5) == _T(".java") ) ||
			( m_bCS && finder.GetFileName().Right(3) == _T(".cs") ) ||
			( m_bPY && finder.GetFileName().Right(3) == _T(".py") ) ||
			( m_bALL )
		  )
		{
			CStdioFile file;
			if( file.Open( finder.GetFilePath(), CFile::modeRead ) )
			{
				int nRead = 1;
				CString strTmp = _T("");
				
				//한줄한줄 읽음
				while( file.ReadString( strTmp ) )
					nRead++;

				//전체 라인수에 더해줌
				nTotalLine += nRead;
			}
		}
		
		if( m_bIncludeSubDirectory &&
			finder.IsDirectory() && 
			finder.GetFileName() != _T(".") && 
			finder.GetFileName() != _T("..") )
		{
			CString strSubPath = _T("\\*.*");
			strSubPath = finder.GetFilePath() + strSubPath;
			FindLine( nTotalLine, strSubPath );
		}

		

	}




}

void CCodeLineSearcherDlg::OnBnClickedButton1()
{
	UpdateData();

	TCHAR strPath[MAX_PATH];

	BROWSEINFO browse;

	browse.hwndOwner = this->m_hWnd;
	browse.pidlRoot = NULL;
	browse.pszDisplayName = NULL;
	browse.lpszTitle = _T("솔루션 폴더를 선택하세요");
	browse.ulFlags = BIF_RETURNONLYFSDIRS;
	browse.lpfn = NULL;
	browse.lParam = 0;

	LPITEMIDLIST pidl = SHBrowseForFolder(&browse);

	if(pidl == NULL) return;
	if( SHGetPathFromIDList(pidl,strPath) )
	{
		CFileFind finder;

		CString strTotalPath = _T("");
		strTotalPath.Format( _T("%s\\*.*"),strPath );
		finder.FindFile( strTotalPath );
		
		int nTotalLine = 0;
		FindLine( nTotalLine, strTotalPath );

		CString strOutput = _T("");
		strOutput.Format(_T("Total Line Count : %d"), nTotalLine );
		AfxMessageBox( strOutput );
	}

}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함