请设计一个程序:使用多线程,统计项目程序源代码行数;源代码是可以编译通过的合法的代码,统计其物理总行数、其中的空行行数、其中含有有效代码的行数、其中含有注释内容的行数;(要求必须利用多线程编程,如果代码框架能更容易的扩展到支持多种语言的源代码行数统计,将获得更高的评价。)
其中包括以下文件:
Test4.h /Test.cpp /TestStaticHtmlFile.h /TestStaticHtmlFile.cpp /TestStaticCFile.h /TestStaticCFile.cpp /TestStaticPythonFile.h /TestStaticPythonFile.cpp /TestStaticShellFile.h /TestStaticShellFile.cpp
Test4.h
#ifndef TEST_H
#define TEST_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <linux/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
using namespace std;
#define MAX_LEN 128
#define MAX_NUM 256
class CTestObjectDir
{
public:
CTestObjectDir(string& sFilePath);
~CTestObjectDir();
public:
void InitObjectDir();
map<string,string> GetFileMap(){return _mFileName;}
static void TrimString(string& sStr);
private:
int JudgeDirType();
string GetFileName();
void GetFile(const string& sDirName);
void JudgeFileType(const string& sDirName,const string& sFile);
private:
string _sFilePath;
string _sSingleFileName;
int _iType;
map<string,string> _mFileName;
};
#endif
#include "Test4.h"
using namespace std;
CTestObjectDir::CTestObjectDir(string& filepath)
{
cout<<"TestDir Test!!"<<endl;
_sFilePath = filepath;
}
CTestObjectDir::~CTestObjectDir()
{
cout<<"~TestDir Test!!"<<endl;
}
void CTestObjectDir::InitObjectDir()
{
if(_sFilePath.empty())
return;
_sSingleFileName = "";
_iType = -1;
//cout<<"[main]"<<endl;
_iType = this->JudgeDirType();
//cout<<"[main] file : "<<this->_sFilePath<<" _sSingleFileName:"<<this->_sSingleFileName<<" _iType:"<<this->_iType<<" "<<this->GetFileName()<<endl;
this->GetFile(this->_sFilePath);
}
int CTestObjectDir::JudgeDirType()
{
if(_sFilePath.empty())
return -1;
int index = _sFilePath.find(".");
if(0 < index)
{
int index_0 = _sFilePath.find_last_of("/");
if(0 < index_0)
{
_sSingleFileName = _sFilePath.substr(index_0+1,_sFilePath.length());
//cout<<"filename:"<<_sSingleFileName<<endl;
}
else
{
//cout<<"###000"<<endl;
_sSingleFileName = _sFilePath;
}
return 1;
}
else
{
//cout<<"###111"<<endl;
int index_1 = _sFilePath.find_last_of("/");
if(0 <= index_1)
{
if(index_1+1 != _sFilePath.length())
_sFilePath.append("/");
return 0;
}
}
}
string CTestObjectDir::GetFileName()// /XX.cpp or XX.cpp
{
if(_sFilePath.empty())
return "";
int index = _sFilePath.find_last_of("/");
if(0 <= index)
return _sFilePath.substr(index+1,_sFilePath.length());
else
return _sFilePath;
}
void CTestObjectDir::GetFile(const string& sDirName)
{
struct dirent *sDir = NULL;
DIR *dDir;
cout<<sDirName<<endl;
dDir = opendir(sDirName.c_str());
if(NULL == dDir)
return;
//cout<<"***000 sDirName = "<<sDirName<<endl;
sDir = readdir(dDir);
//cout<<"***000 "<<endl;
while(NULL != (sDir = readdir(dDir)))
{
//cout<<"***111 "<<sDir->d_name<<" "<<(int)(sDir->d_type)<<endl;
if('.' == sDir->d_name[0])
{
//cout<<"$"<<endl;
continue;
}
if(4 == (int)(sDir->d_type))
{
//cout<<"$$"<<endl;
string sNewDir = "";
sNewDir.append(sDirName);
sNewDir.append(sDir->d_name);
sNewDir.append("/");
//cout<<"sNewDir : "<<sNewDir<<endl;
GetFile(sNewDir);
}
else if(8 == (int)(sDir->d_type))
{
string sFile = "";
sFile.append(sDir->d_name);
//cout<<"$$$ "<<sFile<<endl;
JudgeFileType(sDirName,sFile);
}
}
}
void CTestObjectDir::JudgeFileType(const string& sDirName,const string& sFile)
{
if(sDirName.empty() || sFile.empty())
return;
int index = sFile.find(".");
if(0 < index)
{
if(".c" == sFile.substr(index,sFile.length()) || ".h" == sFile.substr(index,sFile.length()) ||
".cpp" == sFile.substr(index,sFile.length()) || ".hpp" == sFile.substr(index,sFile.length()) ||
".java" == sFile.substr(index,sFile.length()))
{
string sFileUrl = "";
sFileUrl.append(sDirName);
sFileUrl.append(sFile);
_mFileName[sFileUrl] = "C";
//cout<<"get a [C] file name:"<<sFileUrl<<" size:"<<_mFileName.size()<<endl;
return;
}
else if(".sh" == sFile.substr(index,sFile.length()))
{
string sFileUrl = "";
sFileUrl.append(sDirName);
sFileUrl.append(sFile);
_mFileName[sFileUrl] = "Shell";
//cout<<"get a [Shell] file name:"<<sFileUrl<<" size:"<<_mFileName.size()<<endl;
return;
}
else if(".py" == sFile.substr(index,sFile.length()))
{
string sFileUrl = "";
sFileUrl.append(sDirName);
sFileUrl.append(sFile);
_mFileName[sFileUrl] = "Python";
//cout<<"get a [Python] file name:"<<sFileUrl<<" size:"<<_mFileName.size()<<endl;
return;
}
else if(".html" == sFile.substr(index,sFile.length()))
{
string sFileUrl = "";
sFileUrl.append(sDirName);
sFileUrl.append(sFile);
_mFileName[sFileUrl] = "Html";
//cout<<"get a [Html] file name:"<<sFileUrl<<" size:"<<_mFileName.size()<<endl;
return;
}
}
else if(0 == strcasecmp(sFile.c_str(),"makefile"))
{
string sFileUrl = "";
sFileUrl.append(sDirName);
sFileUrl.append(sFile);
_mFileName[sFileUrl] = "C";
//cout<<"get a [Makefile] file name:"<<sFileUrl<<" size:"<<_mFileName.size()<<endl;
return;
}
}
void CTestObjectDir::TrimString(string& sStr)
{
if(sStr.empty())
return;
sStr.erase(0,sStr.find_first_not_of("\t"));
sStr.erase(sStr.find_last_not_of("\t") + 1);
sStr.erase(0,sStr.find_first_not_of("\r"));
sStr.erase(sStr.find_last_not_of("\r") + 1);
sStr.erase(0,sStr.find_first_not_of("\n"));
sStr.erase(sStr.find_last_not_of("\n") + 1);
sStr.erase(0,sStr.find_first_not_of(" "));
sStr.erase(sStr.find_last_not_of(" ") + 1);
}
#ifndef TEST_STATIC_C_FILE_H
#define TEST_STATIC_C_FILE_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <linux/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
using namespace std;
class CTestStaticCFile
{
public:
CTestStaticCFile(const string& sFilePath):_sFilePath(sFilePath) {}
~CTestStaticCFile(){}
public:
void InitStaticCFile();
static void *GetTotalLine(void *pParam);
static void *GetBlankLine(void *pParam);
static void *GetValidLine(void *pParam);
static void *GetNoteLine(void *pParam);
inline int GetTotalNum() {return _iTotalLine;}
inline int GetBlankNum() {return _iBlankLine;}
inline int GetValidNum() {return _iValidLine;}
inline int GetNoteNum() {return _iNoteLine;}
inline string GetFilePath() {return _sFilePath;}
private:
void CreateThread();
private:
string _sFilePath;
long _iTotalLine;
long _iBlankLine;
long _iValidLine;
long _iNoteLine;
};
#endif
TestStaticCFile.cpp
#include "TestStaticCFile.h"
#include "Test4.h"
using namespace std;
void CTestStaticCFile::InitStaticCFile()
{
this->_iTotalLine = -1;
this->_iBlankLine = -1;
this->_iValidLine = -1;
this->_iNoteLine = -1;
this->CreateThread();
}
void CTestStaticCFile::CreateThread()
{
void *it,*ib,*iv,*in;
pthread_t pidt,pidb,pidv,pidn;
int iError_t = pthread_create(&pidt,NULL,GetTotalLine,this);
if(iError_t)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetTotalLine> is failed!"<<endl;
return;
}
int iError_b = pthread_create(&pidb,NULL,GetBlankLine,this);
if(iError_b)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetBlankLine> is failed!"<<endl;
return;
}
int iError_v = pthread_create(&pidv,NULL,GetValidLine,this);
if(iError_v)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetValidLine> is failed!"<<endl;
return;
}
int iError_n = pthread_create(&pidn,NULL,GetNoteLine,this);
if(iError_n)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetNoteLine> is failed!"<<endl;
return;
}
int iError_rt = pthread_join(pidt,&it);
if(iError_rt)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidt> is failed!"<<endl;
return;
}
int iError_rb = pthread_join(pidb,&ib);
if(iError_rb)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidb> is failed!"<<endl;
return;
}
int iError_rv = pthread_join(pidv,&iv);
if(iError_rv)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidv> is failed!"<<endl;
return;
}
int iError_rn = pthread_join(pidn,&in);
if(iError_rn)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidn> is failed!"<<endl;
return;
}
_iTotalLine = (long)it;
_iBlankLine = (long)ib;
_iValidLine = (long)iv;
_iNoteLine = (long)in;
}
void *CTestStaticCFile::GetTotalLine(void *pParam)
{
CTestStaticCFile *pThis = (CTestStaticCFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char cBuffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetTotalLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return NULL;
}
int iCount = 0;
while(!iStaticFile.eof() && iStaticFile.getline(cBuffer,MAX_NUM-1))
iCount++;
iStaticFile.close();
return (void *)iCount;
}
void *CTestStaticCFile::GetBlankLine(void *pParam)
{
CTestStaticCFile *pThis = (CTestStaticCFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char cBuffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetBlankLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return 0;
}
int iCount = 0;
while(!iStaticFile.eof() && iStaticFile.getline(cBuffer,MAX_NUM-1))
{
string sStr(cBuffer);
CTestObjectDir::TrimString(sStr);
if(sStr.empty())
iCount++;
}
iStaticFile.close();
return (void *)(iCount);
}
void *CTestStaticCFile::GetValidLine(void *pParam)
{
CTestStaticCFile *pThis = (CTestStaticCFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char cBuffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetValidLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return (void *)0;
}
int iCount = 0;
bool flag = false;
while(!iStaticFile.eof() && iStaticFile.getline(cBuffer,MAX_NUM-1))
{
string sStr(cBuffer);
CTestObjectDir::TrimString(sStr);
if(!sStr.empty())
{
int index_s = sStr.find("//");
if(0 == index_s)
continue;
int index_f = sStr.find("/*");
if(0 == index_f)
{
flag = true;
}
else if(0 < index_f)
{
flag = true;
iCount++;
int index = sStr.find("*/");
if(0 < index)
flag = false;
continue;
}
if(flag)
{
int index_l = sStr.find("*/");
if(0 <= index_l)
{
if(index_l + 2 == sStr.length())
{
flag = false;
continue;
}
else
{
flag = false;
iCount++;
continue;
}
}
else
continue;
}
else
{
iCount++;
continue;
}
}
}
iStaticFile.close();
return (void *)iCount;
}
void *CTestStaticCFile::GetNoteLine(void *pParam)
{
CTestStaticCFile *pThis = (CTestStaticCFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char buffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetNoteLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return (void *)0;
}
int iCount = 0;
bool flag = false;
while(!iStaticFile.eof() && iStaticFile.getline(buffer,MAX_NUM-1))
{
string sStr(buffer);
CTestObjectDir::TrimString(sStr);
if(!sStr.empty())
{
int index_s = sStr.find("//");
if(0 <= index_s)
{
iCount++;
continue;
}
int index_f = sStr.find("/*");
if(0 <= index_f)
flag = true;
if(flag)
{
int index_l = sStr.find("*/");
if(0 <= index_l)
{
flag = false;
iCount++;
continue;
}
else
{
iCount++;
continue;
}
}
}
}
iStaticFile.close();
return (void *)iCount;
}
TestStaticHtmlFile.h
#ifndef TEST_STATIC_HTML_FILE_H
#define TEST_STATIC_HTML_FILE_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <linux/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
using namespace std;
class CTestStaticHtmlFile
{
public:
CTestStaticHtmlFile(const string& sFilePath):_sFilePath(sFilePath) {}
~CTestStaticHtmlFile(){}
public:
void InitStaticCFile();
static void *GetTotalLine(void *pParam);
static void *GetBlankLine(void *pParam);
static void *GetValidLine(void *pParam);
static void *GetNoteLine(void *pParam);
inline int GetTotalNum() {return _iTotalLine;}
inline int GetBlankNum() {return _iBlankLine;}
inline int GetValidNum() {return _iValidLine;}
inline int GetNoteNum() {return _iNoteLine;}
inline string GetFilePath() {return _sFilePath;}
private:
void CreateThread();
private:
string _sFilePath;
long _iTotalLine;
long _iBlankLine;
long _iValidLine;
long _iNoteLine;
};
#endif
TestStaticHtmlFile.cpp
#include "TestStaticHtmlFile.h"
#include "Test4.h"
using namespace std;
void CTestStaticHtmlFile::InitStaticCFile()
{
this->_iTotalLine = -1;
this->_iBlankLine = -1;
this->_iValidLine = -1;
this->_iNoteLine = -1;
this->CreateThread();
}
void CTestStaticHtmlFile::CreateThread()
{
void *it,*ib,*iv,*in;
pthread_t pidt,pidb,pidv,pidn;
int iError_t = pthread_create(&pidt,NULL,GetTotalLine,this);
if(iError_t)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetTotalLine> is failed!"<<endl;
return;
}
int iError_b = pthread_create(&pidb,NULL,GetBlankLine,this);
if(iError_b)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetBlankLine> is failed!"<<endl;
return;
}
int iError_v = pthread_create(&pidv,NULL,GetValidLine,this);
if(iError_v)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetValidLine> is failed!"<<endl;
return;
}
int iError_n = pthread_create(&pidn,NULL,GetNoteLine,this);
if(iError_n)
{
cout<<"[CTestStaticCFile::CreateThread] Create pthread<GetNoteLine> is failed!"<<endl;
return;
}
int iError_rt = pthread_join(pidt,&it);
if(iError_rt)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidt> is failed!"<<endl;
return;
}
int iError_rb = pthread_join(pidb,&ib);
if(iError_rb)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidb> is failed!"<<endl;
return;
}
int iError_rv = pthread_join(pidv,&iv);
if(iError_rv)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidv> is failed!"<<endl;
return;
}
int iError_rn = pthread_join(pidn,&in);
if(iError_rn)
{
cout<<"[CTestStaticCFile::CreateThread] Jion pthread<pidn> is failed!"<<endl;
return;
}
_iTotalLine = (long)it;
_iBlankLine = (long)ib;
_iValidLine = (long)iv;
_iNoteLine = (long)in;
}
void *CTestStaticHtmlFile::GetTotalLine(void *pParam)
{
CTestStaticHtmlFile *pThis = (CTestStaticHtmlFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char cBuffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetTotalLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return NULL;
}
int iCount = 0;
while(!iStaticFile.eof() && iStaticFile.getline(cBuffer,MAX_NUM-1))
iCount++;
iStaticFile.close();
return (void *)iCount;
}
void *CTestStaticHtmlFile::GetBlankLine(void *pParam)
{
CTestStaticHtmlFile *pThis = (CTestStaticHtmlFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char cBuffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetBlankLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return 0;
}
int iCount = 0;
while(!iStaticFile.eof() && iStaticFile.getline(cBuffer,MAX_NUM-1))
{
string sStr(cBuffer);
CTestObjectDir::TrimString(sStr);
if(sStr.empty())
iCount++;
}
iStaticFile.close();
return (void *)(iCount);
}
void *CTestStaticHtmlFile::GetValidLine(void *pParam)
{
CTestStaticHtmlFile *pThis = (CTestStaticHtmlFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char cBuffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticHtmlFile::GetValidLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return (void *)0;
}
int iCount = 0;
bool flag = false;
int iCounter = 0;
while(!iStaticFile.eof() && iStaticFile.getline(cBuffer,MAX_NUM-1))
{
iCounter++;
string sStr(cBuffer);
CTestObjectDir::TrimString(sStr);
if(!sStr.empty())
{
int index_f = sStr.find("<!--");
if(0 == index_f)
{
flag = true;
}
else if(0 < index_f)
{
flag = true;
iCount++;
int index = sStr.find("-->");
if(0 < index)
flag = false;
continue;
}
if(flag)
{
int index_l = sStr.find("-->");
if(0 <= index_l)
{
if(index_l + 3 == sStr.length())
{
flag = false;
continue;
}
else
{
flag = false;
iCount++;
continue;
}
}
else
continue;
}
else
{
iCount++;
continue;
}
}
}
iStaticFile.close();
return (void *)iCount;
}
void *CTestStaticHtmlFile::GetNoteLine(void *pParam)
{
CTestStaticHtmlFile *pThis = (CTestStaticHtmlFile *)pParam;
if(NULL == pThis && pThis->GetFilePath().empty())
return NULL;
char buffer[MAX_NUM];
ifstream iStaticFile;
iStaticFile.open(pThis->GetFilePath().c_str());
if(!iStaticFile.is_open())
{
cout<<"[CTestStaticBase::GetNoteLine] Opening file ["<<pThis->GetFilePath()<<"] is failed!"<<endl;
return (void *)0;
}
int iCount = 0;
bool flag = false;
while(!iStaticFile.eof() && iStaticFile.getline(buffer,MAX_NUM-1))
{
string sStr(buffer);
CTestObjectDir::TrimString(sStr);
if(!sStr.empty())
{
int index_f = sStr.find("<!--");
if(0 <= index_f)
flag = true;
if(flag)
{
int index_l = sStr.find("-->");
if(0 <= index_l)
{
flag = false;
iCount++;
continue;
}
else
{
iCount++;
continue;
}
}
}
}
iStaticFile.close();
return (void *)iCount;
}
main.cpp
#include "Test4.h"
#include "TestStaticCFile.h"
#include "TestStaticPythonFile.h"
#include "TestStaticShellFile.h"
#include "TestStaticHtmlFile.h"
using namespace std;
void PrintResultC(const string& sFileName)
{
if(sFileName.empty())
return;
CTestStaticCFile *cHandle = new CTestStaticCFile(sFileName);
cHandle->InitStaticCFile();
cout<<"["<<sFileName<<"] Tatol num["<<cHandle->GetTotalNum()<<"] Blank num["<<cHandle->GetBlankNum()<<"] Valid num["
<<cHandle->GetValidNum()<<"] Note num["<<cHandle->GetNoteNum()<<"]"<<endl;
delete cHandle;
}
void PrintResultPython(const string& sFileName)
{
if(sFileName.empty())
return;
CTestStaticPythonFile *cHandle = new CTestStaticPythonFile(sFileName);
cHandle->InitStaticCFile();
cout<<"["<<sFileName<<"] Tatol num["<<cHandle->GetTotalNum()<<"] Blank num["<<cHandle->GetBlankNum()<<"] Valid num["
<<cHandle->GetValidNum()<<"] Note num["<<cHandle->GetNoteNum()<<"]"<<endl;
delete cHandle;
}
void PrintResultShell(const string& sFileName)
{
if(sFileName.empty())
return;
CTestStaticShellFile *cHandle = new CTestStaticShellFile(sFileName);
cHandle->InitStaticCFile();
cout<<"["<<sFileName<<"] Tatol num["<<cHandle->GetTotalNum()<<"] Blank num["<<cHandle->GetBlankNum()<<"] Valid num["
<<cHandle->GetValidNum()<<"] Note num["<<cHandle->GetNoteNum()<<"]"<<endl;
delete cHandle;
}
void PrintResultHtml(const string& sFileName)
{
if(sFileName.empty())
return;
CTestStaticHtmlFile *cHandle = new CTestStaticHtmlFile(sFileName);
cHandle->InitStaticCFile();
cout<<"["<<sFileName<<"] Tatol num["<<cHandle->GetTotalNum()<<"] Blank num["<<cHandle->GetBlankNum()<<"] Valid num["
<<cHandle->GetValidNum()<<"] Note num["<<cHandle->GetNoteNum()<<"]"<<endl;
delete cHandle;
}
void test4(string& str)
{
CTestObjectDir *TOD = new CTestObjectDir(str);
if(NULL == TOD)
{
cout<<"New TestObjectDir is failed!"<<endl;
return;
}
TOD->InitObjectDir();
map<string,string> mFileName = TOD->GetFileMap();
delete TOD;
map<string,string>::iterator iter;
for(iter = mFileName.begin(); iter != mFileName.end(); iter++)
{
string sFirst = iter->first;
string sSecond = iter->second;
if("C" == sSecond)
PrintResultC(sFirst);
else if("Python" == sSecond)
PrintResultPython(sFirst);
else if("Shell" == sSecond)
PrintResultShell(sFirst);
else if("Html" == sSecond)
PrintResultHtml(sFirst);
else
cout<<"Other file! "<<sFirst<<" "<<sSecond<<endl;
}
cout<<"Engineering has "<<mFileName.size()<<" files."<<endl;
}
int main()
{
try
{
char buffer[MAX_LEN];
loop:
cout<<"Please input the absolute path of the project directory : "<<endl;
cin.getline(buffer,MAX_LEN);
string str(buffer);
CTestObjectDir::TrimString(str);
if(str.empty())
{
cout<<"Please input the absolute path of the project directory again!"<<endl;
goto loop;
}
//string str("/mnt/hgfs/Ubuntu/Test/FLHS/makefile");
test4(str);
}
catch(...)
{
cout<<"[test4] has a error!"<<endl;
}
return 0;
}
Makefile:
CC = g++
FLAGS = -g
LIBS = -lpthread
OBJS = main.o Test4.o TestStaticCFile.o TestStaticPythonFile.o \
TestStaticShellFile.o TestStaticHtmlFile.o
main:$(OBJS)
$(CC) $(FLAGS) -o main $(OBJS) $(LIBS)
clean:
rm -f $(OBJS) main
其余几个模块(TestStaticPythonFile.cpp /TestStaticShellFile.h /TestStaticShellFile.cpp)与CTestStaticHtmlFile相似
希望大家多多提意见。。。