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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
string getExtension(string path)
{
int i=path.length();
for(; path[i]!='\\'; i--)
{
if(path[i]=='.')
{
// we have reached the '.', meaning that from here to
// the null terminator is the extension.
string ext;
while(path[i])
{
ext+=path[i++];
}
return ext;
}
}
return ("");
}
string getExtension(char* path)
{
string pth=path;
return getExtension(pth);
}
string allowedFiles[8]={".c", ".cpp", ".cc", ".h", ".hpp", ".hh", ".asm", ".inc"};
void processContents(directory d)
{
/*** processes d.contents to remove all files which
are not of type .c, .cpp, .cc, .h, .hpp, .hh, .asm, .inc , etc
***/
srcparse parser;
bool deleteFile=FALSE;
if(!d.listcontents())
{
cout << "error : d.listcontents in processContents()" << endl;
return;
}
for(list<file>::iterator it=d.contents.begin(); it!=d.contents.end(); ++it)
{
/* here we run thru all of them and check if they are of type ? in the
table. if not, we delete them */
for(int i=0; i<8; i++)
{
if(!strcmpi(getExtension(it->getpath()).c_str(), allowedFiles[i].c_str()))
{
// the file matches one of the ones allowed.
deleteFile=false;
break;
}
if(strcmpi(getExtension(it->getpath()).c_str(), allowedFiles[i].c_str()))
deleteFile=true;
}
if(deleteFile)
{
cout << "removing file from list :" << it->getpath() << endl;
d.contents.remove(*it);
it=d.contents.begin();
}
}
cout << "file list:" << endl;
for(list<file>::iterator it=d.contents.begin();it!=d.contents.end(); ++it)
cout << it->getpath() << endl;
srcparse::stats stats{0, 0, 0};
srcparse::stats tmp{0, 0, 0};
for(list<file>::iterator it=d.contents.begin();it!=d.contents.end(); ++it)
{
tmp=parser.parse((char*)it->load());
stats.chartotal+=tmp.chartotal;
stats.linetotal+=tmp.linetotal;
stats.linecode+=tmp.linecode;
}
cout << stats.linecode;
}
|