tools: updated the code style
This commit is contained in:
parent
8c71c4194f
commit
5b86188c45
154
tools/dmake.cpp
154
tools/dmake.cpp
|
@ -10,104 +10,104 @@
|
|||
|
||||
std::string objfile(std::string cppfile)
|
||||
{
|
||||
cppfile.erase( cppfile.rfind(".") );
|
||||
return cppfile + ".o";
|
||||
cppfile.erase(cppfile.rfind("."));
|
||||
return cppfile + ".o";
|
||||
}
|
||||
|
||||
void getDeps(const std::string &filename, std::vector<std::string> &depfiles)
|
||||
{
|
||||
std::ifstream f( filename.c_str() );
|
||||
if ( ! f.is_open() )
|
||||
return;
|
||||
std::ifstream f(filename.c_str());
|
||||
if (! f.is_open())
|
||||
return;
|
||||
|
||||
std::string path( filename );
|
||||
if ( path.find("/") != std::string::npos )
|
||||
path.erase( 1 + path.rfind("/") );
|
||||
std::string path(filename);
|
||||
if (path.find("/") != std::string::npos)
|
||||
path.erase(1 + path.rfind("/"));
|
||||
|
||||
std::string line;
|
||||
while ( std::getline(f, line) )
|
||||
{
|
||||
std::string::size_type pos1 = line.find("#include \"");
|
||||
if ( pos1 == std::string::npos )
|
||||
continue;
|
||||
pos1 += 10;
|
||||
std::string line;
|
||||
while (std::getline(f, line))
|
||||
{
|
||||
std::string::size_type pos1 = line.find("#include \"");
|
||||
if (pos1 == std::string::npos)
|
||||
continue;
|
||||
pos1 += 10;
|
||||
|
||||
std::string::size_type pos2 = line.find("\"", pos1);
|
||||
std::string hfile( path + line.substr(pos1, pos2-pos1) );
|
||||
if ( hfile.find("/../") != std::string::npos ) // TODO: Ugly fix
|
||||
hfile.erase( 0, 4+hfile.find("/../") );
|
||||
if (std::find(depfiles.begin(), depfiles.end(), hfile) != depfiles.end())
|
||||
continue;
|
||||
depfiles.push_back( hfile );
|
||||
getDeps(hfile, depfiles);
|
||||
}
|
||||
std::string::size_type pos2 = line.find("\"", pos1);
|
||||
std::string hfile(path + line.substr(pos1, pos2 - pos1));
|
||||
if (hfile.find("/../") != std::string::npos) // TODO: Ugly fix
|
||||
hfile.erase(0, 4 + hfile.find("/../"));
|
||||
if (std::find(depfiles.begin(), depfiles.end(), hfile) != depfiles.end())
|
||||
continue;
|
||||
depfiles.push_back(hfile);
|
||||
getDeps(hfile, depfiles);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Get files..
|
||||
std::vector<std::string> srcfiles;
|
||||
FileLister::RecursiveAddFiles( srcfiles, "src/", true );
|
||||
std::vector<std::string> testfiles;
|
||||
FileLister::RecursiveAddFiles( testfiles, "test/", true );
|
||||
// Get files..
|
||||
std::vector<std::string> srcfiles;
|
||||
FileLister::RecursiveAddFiles(srcfiles, "src/", true);
|
||||
std::vector<std::string> testfiles;
|
||||
FileLister::RecursiveAddFiles(testfiles, "test/", true);
|
||||
|
||||
std::ofstream fout("Makefile");
|
||||
std::ofstream fout("Makefile");
|
||||
|
||||
fout << "CXXFLAGS=-Wall -pedantic -g\n\n";
|
||||
fout << "CXXFLAGS=-Wall -pedantic -g\n\n";
|
||||
|
||||
fout << "\n###### Object Files\n\n";
|
||||
fout << "OBJECTS = " << objfile(srcfiles[0]);
|
||||
for ( unsigned int i = 1; i < srcfiles.size(); ++i )
|
||||
fout << " \\" << std::endl << std::string(14,' ') << objfile(srcfiles[i]);
|
||||
fout << "\n\n";
|
||||
fout << "TESTOBJ = " << objfile(testfiles[0]);
|
||||
for ( unsigned int i = 1; i < testfiles.size(); ++i )
|
||||
fout << " \\" << std::endl << std::string(14,' ') << objfile(testfiles[i]);
|
||||
for ( unsigned int i = 0; i < srcfiles.size(); ++i )
|
||||
{
|
||||
if ( srcfiles[i] != "src/main.cpp" )
|
||||
fout << " \\" << std::endl << std::string(14,' ') << objfile(srcfiles[i]);
|
||||
}
|
||||
fout << "\n\n";
|
||||
fout << "\n###### Object Files\n\n";
|
||||
fout << "OBJECTS = " << objfile(srcfiles[0]);
|
||||
for (unsigned int i = 1; i < srcfiles.size(); ++i)
|
||||
fout << " \\" << std::endl << std::string(14, ' ') << objfile(srcfiles[i]);
|
||||
fout << "\n\n";
|
||||
fout << "TESTOBJ = " << objfile(testfiles[0]);
|
||||
for (unsigned int i = 1; i < testfiles.size(); ++i)
|
||||
fout << " \\" << std::endl << std::string(14, ' ') << objfile(testfiles[i]);
|
||||
for (unsigned int i = 0; i < srcfiles.size(); ++i)
|
||||
{
|
||||
if (srcfiles[i] != "src/main.cpp")
|
||||
fout << " \\" << std::endl << std::string(14, ' ') << objfile(srcfiles[i]);
|
||||
}
|
||||
fout << "\n\n";
|
||||
|
||||
|
||||
fout << "\n###### Targets\n\n";
|
||||
fout << "cppcheck:\t$(OBJECTS)\n";
|
||||
fout << "\tg++ $(CXXFLAGS) -o cppcheck $(OBJECTS)\n\n";
|
||||
fout << "testrunner:\t$(TESTOBJ)\n";
|
||||
fout << "\tg++ $(CXXFLAGS) -o testrunner $(TESTOBJ)\n\n";
|
||||
fout << "all:\tcppcheck\ttestrunner\n\n";
|
||||
fout << "test:\ttestrunner\n\n";
|
||||
fout << "clean:\n";
|
||||
fout << "\trm -f src/*.o test/*.o testrunner cppcheck\n\n";
|
||||
fout << "install:\tcppcheck\n";
|
||||
fout << "\tinstall -d ${BIN}\n";
|
||||
fout << "\tinstall cppcheck ${BIN}\n\n";
|
||||
fout << "\n###### Targets\n\n";
|
||||
fout << "cppcheck:\t$(OBJECTS)\n";
|
||||
fout << "\tg++ $(CXXFLAGS) -o cppcheck $(OBJECTS)\n\n";
|
||||
fout << "testrunner:\t$(TESTOBJ)\n";
|
||||
fout << "\tg++ $(CXXFLAGS) -o testrunner $(TESTOBJ)\n\n";
|
||||
fout << "all:\tcppcheck\ttestrunner\n\n";
|
||||
fout << "test:\ttestrunner\n\n";
|
||||
fout << "clean:\n";
|
||||
fout << "\trm -f src/*.o test/*.o testrunner cppcheck\n\n";
|
||||
fout << "install:\tcppcheck\n";
|
||||
fout << "\tinstall -d ${BIN}\n";
|
||||
fout << "\tinstall cppcheck ${BIN}\n\n";
|
||||
|
||||
fout << "\n###### Build\n\n";
|
||||
fout << "\n###### Build\n\n";
|
||||
|
||||
for ( unsigned int i = 0; i < srcfiles.size(); ++i )
|
||||
{
|
||||
fout << objfile(srcfiles[i]) << ": " << srcfiles[i];
|
||||
std::vector<std::string> depfiles;
|
||||
getDeps( srcfiles[i], depfiles );
|
||||
for ( unsigned int dep = 0; dep < depfiles.size(); ++dep )
|
||||
fout << " " << depfiles[dep];
|
||||
fout << "\n\tg++ $(CXXFLAGS) -c -o " << objfile(srcfiles[i]) << " " << srcfiles[i] << "\n\n";
|
||||
}
|
||||
for (unsigned int i = 0; i < srcfiles.size(); ++i)
|
||||
{
|
||||
fout << objfile(srcfiles[i]) << ": " << srcfiles[i];
|
||||
std::vector<std::string> depfiles;
|
||||
getDeps(srcfiles[i], depfiles);
|
||||
for (unsigned int dep = 0; dep < depfiles.size(); ++dep)
|
||||
fout << " " << depfiles[dep];
|
||||
fout << "\n\tg++ $(CXXFLAGS) -c -o " << objfile(srcfiles[i]) << " " << srcfiles[i] << "\n\n";
|
||||
}
|
||||
|
||||
for ( unsigned int i = 0; i < testfiles.size(); ++i )
|
||||
{
|
||||
fout << objfile(testfiles[i]) << ": " << testfiles[i];
|
||||
std::vector<std::string> depfiles;
|
||||
getDeps( testfiles[i], depfiles );
|
||||
for ( unsigned int dep = 0; dep < depfiles.size(); ++dep )
|
||||
fout << " " << depfiles[dep];
|
||||
fout << "\n\tg++ $(CXXFLAGS) -c -o " << objfile(testfiles[i]) << " " << testfiles[i] << "\n\n";
|
||||
}
|
||||
for (unsigned int i = 0; i < testfiles.size(); ++i)
|
||||
{
|
||||
fout << objfile(testfiles[i]) << ": " << testfiles[i];
|
||||
std::vector<std::string> depfiles;
|
||||
getDeps(testfiles[i], depfiles);
|
||||
for (unsigned int dep = 0; dep < depfiles.size(); ++dep)
|
||||
fout << " " << depfiles[dep];
|
||||
fout << "\n\tg++ $(CXXFLAGS) -c -o " << objfile(testfiles[i]) << " " << testfiles[i] << "\n\n";
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,20 +21,20 @@ public:
|
|||
|
||||
std::string msg(bool code) const
|
||||
{
|
||||
const char *str = code ? "\"" : "";
|
||||
std::string ret( str + _msg + str );
|
||||
if (! _par1.empty())
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = ret.find("%1", pos)) != std::string::npos)
|
||||
{
|
||||
ret.erase(pos, 2);
|
||||
if ( code )
|
||||
ret.insert(pos, "\" + " + _par1 + " + \"");
|
||||
else
|
||||
ret.insert(pos, _par1);
|
||||
}
|
||||
}
|
||||
const char *str = code ? "\"" : "";
|
||||
std::string ret(str + _msg + str);
|
||||
if (! _par1.empty())
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = ret.find("%1", pos)) != std::string::npos)
|
||||
{
|
||||
ret.erase(pos, 2);
|
||||
if (code)
|
||||
ret.insert(pos, "\" + " + _par1 + " + \"");
|
||||
else
|
||||
ret.insert(pos, _par1);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -65,13 +65,13 @@ public:
|
|||
ostr << "; }" << std::endl;
|
||||
}
|
||||
|
||||
void generateDoc(std::ostream &ostr, unsigned int i) const
|
||||
{
|
||||
if ( _settings == i )
|
||||
{
|
||||
ostr << " " << msg(false) << std::endl;
|
||||
}
|
||||
}
|
||||
void generateDoc(std::ostream &ostr, unsigned int i) const
|
||||
{
|
||||
if (_settings == i)
|
||||
{
|
||||
ostr << " " << msg(false) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -85,21 +85,21 @@ int main()
|
|||
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));
|
||||
|
||||
// Generate code..
|
||||
std::cout << "Generate code.." << std::endl;
|
||||
std::cout << "Generate code.." << std::endl;
|
||||
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
|
||||
it->generateCode(std::cout);
|
||||
std::cout << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Generate documentation..
|
||||
std::cout << "Generate doc.." << std::endl;
|
||||
for ( unsigned int i = 0; i < 4; ++i )
|
||||
{
|
||||
const char *suite[4] = { "standard", "all", "style", "all + style" };
|
||||
std::cout << " =" << suite[i] << "=" << std::endl;
|
||||
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
|
||||
it->generateDoc(std::cout, i);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// Generate documentation..
|
||||
std::cout << "Generate doc.." << std::endl;
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
{
|
||||
const char *suite[4] = { "standard", "all", "style", "all + style" };
|
||||
std::cout << " =" << suite[i] << "=" << std::endl;
|
||||
for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)
|
||||
it->generateDoc(std::cout, i);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue