Merge pull request #43 from makulik/master

#3244 'Get include pathes from file'
This commit is contained in:
Daniel Marjamäki 2011-10-23 01:04:31 -07:00
commit a381581a8b
2 changed files with 36 additions and 0 deletions

View File

@ -63,6 +63,26 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
}
}
static void AddInclPathsToList(const std::string& FileList, std::list<std::string>& PathNames)
{
// to keep things initially simple, if the file can't be opened, just be
// silent and move on
std::ifstream Files(FileList.c_str());
if (Files)
{
std::string PathName;
while (std::getline(Files, PathName)) // next line
{
if (!PathName.empty())
{
PathName = Path::fromNativeSeparators(PathName);
PathName = Path::removeQuotationMarks(PathName);
PathNames.push_back(PathName);
}
}
}
}
CmdLineParser::CmdLineParser(Settings *settings)
: _settings(settings)
, _showHelp(false)
@ -330,6 +350,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->_includePaths.push_back(path);
}
else if (strncmp(argv[i], "--includes-file=", 16) == 0)
{
// open this file and read every input file (1 file name per line)
AddInclPathsToList(16 + argv[i], _settings->_includePaths);
}
// file list specified
else if (strncmp(argv[i], "--file-list=", 12) == 0) {

View File

@ -56,6 +56,7 @@ private:
TEST_CASE(includesbackslash);
TEST_CASE(includesnospace);
TEST_CASE(includes2);
TEST_CASE(includesFile);
TEST_CASE(enabledAll);
TEST_CASE(enabledStyle);
TEST_CASE(enabledPerformance);
@ -365,6 +366,16 @@ private:
ASSERT_EQUALS("framework/", settings._includePaths.front());
}
void includesFile()
{
// TODO: Fails since cannot open the file
REDIRECT;
const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
}
void enabledAll() {
REDIRECT;
const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"};