From 597a37cc32fde7ddae82aa0ddcc64049f7d4f3e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 22 Oct 2011 21:24:23 +0200 Subject: [PATCH 1/2] #3244 'Get include pathes from file' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Günther Makulik --- cli/cmdlineparser.cpp | 32 ++++++++++++++++++++++++++++++++ test/testcmdlineparser.cpp | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index ff5ddfd6a..378e9ac8c 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -63,6 +63,33 @@ static void AddFilesToList(const std::string& FileList, std::vector } } +static void AddInclPathsToList(const std::string& FileList, std::list& PathNames) +{ + // to keep things initially simple, if the file can't be opened, just be + // silent and move on + // ideas : we could also require this should be an xml file, with the filenames + // specified in an xml structure + // we could elaborate this then, to also include the I-paths, ... + // basically for everything that makes the command line very long + // xml is a bonus then, since we can easily extend it + // we need a good parser then -> suggestion : TinyXml + // drawback : creates a dependency + 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 +357,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) { diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 70906b33c..a06a2e730 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -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"}; From efede199a50ae54cce045343852a4cbc98161dbd Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 23 Oct 2011 01:13:18 +0200 Subject: [PATCH 2/2] Removed comment lines suggesting to go for XML configuration --- cli/cmdlineparser.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 378e9ac8c..126246cbf 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -67,13 +67,6 @@ static void AddInclPathsToList(const std::string& FileList, std::list suggestion : TinyXml - // drawback : creates a dependency std::ifstream Files(FileList.c_str()); if (Files) {