Refactorized cmdlineparser.cpp:

- Added const char* overload for PrintMessage()
- Call Path::removeQuotationMarks() before any other path formatting functions
- Fixed --help output on terminal outputs with 80 columns
- Hide -l option on systems where it does not do anything
- Added pre-check for "-" at the beginning to distinguish between options and files early
This commit is contained in:
PKEuS 2015-11-20 12:01:04 +01:00
parent 00bdc89f98
commit 6235515889
2 changed files with 548 additions and 537 deletions

View File

@ -24,6 +24,7 @@
#include "settings.h"
#include "timer.h"
#include "check.h"
#include "threadexecutor.h" // Threading model
#include <algorithm>
#include <iostream>
@ -67,8 +68,8 @@ static void AddInclPathsToList(const std::string& FileList, std::list<std::strin
std::string PathName;
while (std::getline(Files, PathName)) { // next line
if (!PathName.empty()) {
PathName = Path::fromNativeSeparators(PathName);
PathName = Path::removeQuotationMarks(PathName);
PathName = Path::fromNativeSeparators(PathName);
// If path doesn't end with / or \, add it
if (PathName.back() != '/')
@ -101,12 +102,18 @@ void CmdLineParser::PrintMessage(const std::string &message)
std::cout << message << std::endl;
}
void CmdLineParser::PrintMessage(const char* message)
{
std::cout << message << std::endl;
}
bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
{
bool def = false;
bool maxconfigs = false;
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (std::strcmp(argv[i], "--version") == 0) {
_showVersion = true;
_exitAfterPrint = true;
@ -138,7 +145,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->exceptionHandling = true;
else if (std::strncmp(argv[i], "--exception-handling=", 21) == 0) {
_settings->exceptionHandling = true;
const std::string exceptionOutfilename=&(argv[i][21]);
const std::string exceptionOutfilename = &(argv[i][21]);
CppCheckExecutor::setExceptionOutput(exceptionOutfilename);
}
@ -399,8 +406,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
else {
path = 2 + argv[i];
}
path = Path::fromNativeSeparators(path);
path = Path::removeQuotationMarks(path);
path = Path::fromNativeSeparators(path);
// If path doesn't end with / or \, add it
if (path.back() != '/')
@ -451,9 +458,9 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
}
if (!path.empty()) {
path = Path::removeQuotationMarks(path);
path = Path::fromNativeSeparators(path);
path = Path::simplifyPath(path);
path = Path::removeQuotationMarks(path);
if (FileLister::isDirectory(path)) {
// If directory name doesn't end with / or \, add it
@ -710,17 +717,18 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
break;
}
else if (argv[i][0] == '-') {
else {
std::string message("cppcheck: error: unrecognized command line option: \"");
message += argv[i];
message += "\".";
PrintMessage(message);
return false;
}
}
else {
std::string path = Path::fromNativeSeparators(argv[i]);
path = Path::removeQuotationMarks(path);
std::string path = Path::removeQuotationMarks(argv[i]);
path = Path::fromNativeSeparators(path);
_pathnames.push_back(path);
}
}
@ -779,10 +787,10 @@ void CmdLineParser::PrintHelp()
" --check-library Show information messages when library files have\n"
" incomplete info.\n"
" --config-exclude=<dir>\n"
" Path (prefix) to be excluded from configuration checking.\n"
" Preprocessor configurations defined in headers (but not sources)\n"
" matching the prefix will not be considered for evaluation\n"
" of configuration alternatives\n"
" Path (prefix) to be excluded from configuration\n"
" checking. Preprocessor configurations defined in\n"
" headers (but not sources) matching the prefix will not\n"
" be considered for evaluation.\n"
" --config-excludes-file=<file>\n"
" A file that contains a list of config-excludes\n"
" --dump Dump xml data for each translation unit. The dump\n"
@ -865,10 +873,12 @@ void CmdLineParser::PrintHelp()
" --inline-suppr Enable inline suppressions. Use them by placing one or\n"
" more comments, like: '// cppcheck-suppress warningId'\n"
" on the lines before the warning to suppress.\n"
" -j <jobs> Start [jobs] threads to do the checking simultaneously.\n"
" -l <load> Specifies that no new threads should be started if there\n"
" are other threads running and the load average is at least\n"
" load (ignored on non UNIX-like systems)\n"
" -j <jobs> Start <jobs> threads to do the checking simultaneously.\n"
#ifdef THREADING_MODEL_FORK
" -l <load> Specifies that no new threads should be started if\n"
" there are other threads running and the load average is\n"
" at least <load>.\n"
#endif
" --language=<language>, -x <language>\n"
" Forces cppcheck to check all files as the given\n"
" language. Valid values are: c, c++\n"
@ -914,7 +924,7 @@ void CmdLineParser::PrintHelp()
#ifdef HAVE_RULES
" --rule=<rule> Match regular expression.\n"
" --rule-file=<file> Use given rule file. For more information, see: \n"
" https://sourceforge.net/projects/cppcheck/files/Articles/\n"
" http://sourceforge.net/projects/cppcheck/files/Articles/\n"
#endif
" --std=<id> Set standard.\n"
" The available options are:\n"

View File

@ -104,6 +104,7 @@ protected:
* Print message (to console?).
*/
static void PrintMessage(const std::string &message);
static void PrintMessage(const char* message);
private:
std::vector<std::string> _pathnames;