From 240ba0118aa9f394545f8b487198d036b1fd0c2a Mon Sep 17 00:00:00 2001 From: Joshua Beck Date: Mon, 26 Sep 2011 04:04:16 -0500 Subject: [PATCH 1/3] Added support for reading file lists from stdin --- cli/cmdlineparser.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 034b61046..264ad7424 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -45,11 +45,21 @@ static void AddFilesToList(const std::string& FileList, std::vector // 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()); + std::istream *Files; + std::ifstream Infile; + if (FileList.compare("-") == 0) // read from stdin + { + Files = &std::cin; + } + else + { + Infile.open(FileList.c_str()); + Files = &Infile; + } if (Files) { std::string FileName; - while (std::getline(Files, FileName)) // next line + while (std::getline(*Files, FileName)) // next line { if (!FileName.empty()) { From 87cff36f9db60cdbb026ecbac7956a1e1925ee7e Mon Sep 17 00:00:00 2001 From: Joshua Beck Date: Mon, 26 Sep 2011 20:43:39 -0500 Subject: [PATCH 2/3] Updated manual and added test for reading file list from stdin. --- man/cppcheck.1.xml | 2 +- test/testcmdlineparser.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml index 88536f431..a8e3f2fd4 100644 --- a/man/cppcheck.1.xml +++ b/man/cppcheck.1.xml @@ -225,7 +225,7 @@ Example: -DDEBUG=1 -D__cplusplus - Specify the files to check in a text file. One filename per line. + Specify the files to check in a text file. One filename per line. When file is -, the file list will be read from standard input. diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index b85e00e2a..af59fb011 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -71,6 +71,7 @@ private: TEST_CASE(exitcodeSuppressions); TEST_CASE(exitcodeSuppressionsNoFile); TEST_CASE(fileList); // TODO: Create and test real file listing file + TEST_CASE(fileListStdin); TEST_CASE(inlineSuppr); TEST_CASE(jobs); TEST_CASE(jobsMissingCount); @@ -530,6 +531,16 @@ private: CmdLineParser parser(&settings); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv)); } + + void fileListStdin() + { + // TODO: Give it some stdin to read from + REDIRECT; + const char *argv[] = {"cppcheck", "--file-list", "-", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv)); + } void inlineSuppr() { From 9583394eba5c5681273207027957b131248e01d9 Mon Sep 17 00:00:00 2001 From: Joshua Beck Date: Tue, 27 Sep 2011 01:02:58 -0500 Subject: [PATCH 3/3] Fix test and add info to -h output. --- cli/cmdlineparser.cpp | 3 ++- test/testcmdlineparser.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 264ad7424..941c7dd9b 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -730,7 +730,8 @@ void CmdLineParser::PrintHelp() " Used when certain messages should be displayed but\n" " should not cause a non-zero exitcode.\n" " --file-list= Specify the files to check in a text file. Add one\n" - " filename per line.\n" + " filename per line. When file is -, the file list will\n" + " be read from standard input.\n" " -f, --force Force checking of all configurations in files that have\n" " \"too many\" configurations.\n" " -h, --help Print this help.\n" diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index af59fb011..aacae87e6 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -534,12 +534,13 @@ private: void fileListStdin() { - // TODO: Give it some stdin to read from + // TODO: Give it some stdin to read from, fails because the list of + // files in stdin (_pathnames) is empty REDIRECT; - const char *argv[] = {"cppcheck", "--file-list", "-", "file.cpp"}; + const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"}; Settings settings; CmdLineParser parser(&settings); - TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv)); + TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv)); } void inlineSuppr()