diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index f488c8164..59a71d5e7 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -114,6 +114,10 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) else if (strcmp(argv[i], "--unused-functions") == 0) _settings._unusedFunctions = true; + // Append userdefined code to checked source code + else if (strncmp(argv[i], "--append=", 9) == 0) + _settings.append(9 + argv[i]); + #ifdef __GNUC__ // show timing information.. else if (strcmp(argv[i], "--showtime") == 0) @@ -294,15 +298,18 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[]) oss << "Cppcheck - A tool for static C/C++ code analysis\n" "\n" "Syntax:\n" - " cppcheck [--all] [--auto-dealloc file.lst] [--error-exitcode=[n]] [--force]\n" - " [--help] [-Idir] [-j [jobs]] [--quiet] [--style] [--unused-functions]\n" - " [--verbose] [--version] [--xml] [file or path1] [file or path] ...\n" + " cppcheck [--all] [--append=file] [--auto-dealloc file.lst]\n" + " [--error-exitcode=[n]] [--force] [--help] [-Idir] [-j [jobs]]\n" + " [--quiet] [--style] [--unused-functions] [--verbose] [--version]\n" + " [--xml] [file or path1] [file or path] ...\n" "\n" "If path is given instead of filename, *.cpp, *.cxx, *.cc, *.c++ and *.c files\n" "are checked recursively from given directory.\n\n" "Options:\n" " -a, --all Make the checking more sensitive. More bugs are\n" " detected, but there are also more false positives\n" + " --append=file This allows you to provide information about\n" + " functions by providing an implementation for these.\n" " --auto-dealloc file Suppress warnings about classes that have automatic\n" " deallocation.\n" " The classnames must be provided in plain text - one\n" @@ -413,7 +420,7 @@ unsigned int CppCheck::check() if (_settings._errorsOnly == false && it != configurations.begin()) _errorLogger->reportOut(std::string("Checking ") + fname + ": " + cfg + std::string("...")); - checkFile(codeWithoutCfg, _filenames[c].c_str()); + checkFile(codeWithoutCfg + _settings.append(), _filenames[c].c_str()); ++checkCount; } } diff --git a/src/settings.cpp b/src/settings.cpp index 310876330..d74c7bbe4 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -19,6 +19,7 @@ #include "settings.h" #include +#include Settings::Settings() { @@ -35,6 +36,7 @@ Settings::Settings() #ifdef __GNUC__ _showtime = false; #endif + _append = ""; } Settings::~Settings() @@ -67,3 +69,19 @@ bool Settings::isAutoDealloc(const char classname[]) const return (std::find(_autoDealloc.begin(), _autoDealloc.end(), classname) != _autoDealloc.end()); } + +void Settings::append(const std::string &filename) +{ + _append = "\n"; + std::ifstream fin(filename.c_str()); + std::string line; + while (std::getline(fin, line)) + { + _append += line + "\n"; + } +} + +std::string Settings::append() const +{ + return _append; +} diff --git a/src/settings.h b/src/settings.h index 57acb255f..2ca5f6062 100644 --- a/src/settings.h +++ b/src/settings.h @@ -38,6 +38,9 @@ private: /** classes that are automaticly deallocated */ std::list _autoDealloc; + /** Code to append in the checks */ + std::string _append; + public: Settings(); virtual ~Settings(); @@ -86,6 +89,12 @@ public: /** is a class automaticly deallocated? */ bool isAutoDealloc(const char classname[]) const; + + /** assign append code */ + void append(const std::string &filename); + + /** get append code */ + std::string append() const; }; /// @}