2008-12-18 22:28:57 +01:00
|
|
|
/*
|
2009-01-21 21:04:20 +01:00
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2008-12-18 22:28:57 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-18 22:28:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CPPCHECKEXECUTOR_H
|
|
|
|
#define CPPCHECKEXECUTOR_H
|
|
|
|
|
2023-11-02 17:42:41 +01:00
|
|
|
#include "config.h"
|
2023-11-03 23:24:04 +01:00
|
|
|
#include "filesettings.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
|
2015-11-25 22:37:38 +01:00
|
|
|
#include <cstdio>
|
2023-11-03 23:24:04 +01:00
|
|
|
#include <list>
|
2011-10-09 20:14:44 +02:00
|
|
|
#include <string>
|
2023-11-07 21:21:24 +01:00
|
|
|
#include <utility>
|
2022-01-27 19:03:20 +01:00
|
|
|
#include <vector>
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2010-08-31 20:32:26 +02:00
|
|
|
class CppCheck;
|
2017-05-27 04:33:47 +02:00
|
|
|
class Settings;
|
2023-11-16 10:35:43 +01:00
|
|
|
class ErrorLogger;
|
2024-01-04 21:32:21 +01:00
|
|
|
class Suppressions;
|
2010-08-31 20:32:26 +02:00
|
|
|
|
2008-12-18 22:28:57 +01:00
|
|
|
/**
|
|
|
|
* This class works as an example of how CppCheck can be used in external
|
|
|
|
* programs without very little knowledge of the internal parts of the
|
|
|
|
* program itself. If you wish to use cppcheck e.g. as a part of IDE,
|
|
|
|
* just rewrite this class for your needs and possibly use other methods
|
|
|
|
* from CppCheck class instead the ones used here.
|
|
|
|
*/
|
2023-11-16 10:35:43 +01:00
|
|
|
class CppCheckExecutor {
|
2008-12-18 22:28:57 +01:00
|
|
|
public:
|
2023-08-18 11:55:23 +02:00
|
|
|
friend class TestSuppressions;
|
|
|
|
|
2008-12-18 22:28:57 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2023-08-08 11:05:02 +02:00
|
|
|
CppCheckExecutor() = default;
|
2021-10-28 16:33:15 +02:00
|
|
|
CppCheckExecutor(const CppCheckExecutor &) = delete;
|
2024-01-05 11:12:30 +01:00
|
|
|
CppCheckExecutor& operator=(const CppCheckExecutor&) = delete;
|
2008-12-18 22:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the checking.
|
|
|
|
*
|
|
|
|
* @param argc from main()
|
|
|
|
* @param argv from main()
|
2009-03-06 01:03:31 +01:00
|
|
|
* @return EXIT_FAILURE if arguments are invalid or no input files
|
|
|
|
* were found.
|
|
|
|
* If errors are found and --error-exitcode is used,
|
|
|
|
* given value is returned instead of default 0.
|
|
|
|
* If no errors are found, 0 is returned.
|
2008-12-18 22:28:57 +01:00
|
|
|
*/
|
2012-02-24 20:45:56 +01:00
|
|
|
int check(int argc, const char* const argv[]);
|
2008-12-18 22:28:57 +01:00
|
|
|
|
2014-05-25 08:47:37 +02:00
|
|
|
/**
|
2020-12-27 09:15:59 +01:00
|
|
|
* @param exceptionOutput Output file
|
2014-05-25 08:47:37 +02:00
|
|
|
*/
|
2019-07-15 18:11:11 +02:00
|
|
|
static void setExceptionOutput(FILE* exceptionOutput);
|
2014-05-25 08:47:37 +02:00
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @return file name to be used for output from exception handler. Has to be either "stdout" or "stderr".
|
|
|
|
*/
|
2015-11-25 22:37:38 +01:00
|
|
|
static FILE* getExceptionOutput();
|
2014-05-25 08:47:37 +02:00
|
|
|
|
2023-11-04 13:33:10 +01:00
|
|
|
private:
|
|
|
|
|
2020-05-19 16:04:25 +02:00
|
|
|
/**
|
2023-09-20 10:40:57 +02:00
|
|
|
* Execute a shell command and read the output from it. Returns exitcode of the executed command,.
|
2020-05-19 16:04:25 +02:00
|
|
|
*/
|
2023-09-20 10:40:57 +02:00
|
|
|
static int executeCommand(std::string exe, std::vector<std::string> args, std::string redirect, std::string &output_);
|
2020-05-19 16:04:25 +02:00
|
|
|
|
2023-11-16 10:35:43 +01:00
|
|
|
protected:
|
2009-02-09 21:51:04 +01:00
|
|
|
|
2024-01-04 21:32:21 +01:00
|
|
|
static bool reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
|
2023-08-18 11:55:23 +02:00
|
|
|
|
2014-03-16 12:04:13 +01:00
|
|
|
/**
|
|
|
|
* Wrapper around check_internal
|
|
|
|
* - installs optional platform dependent signal handling
|
|
|
|
*
|
2018-12-21 21:23:03 +01:00
|
|
|
* @param cppcheck cppcheck instance
|
2014-03-16 12:04:13 +01:00
|
|
|
**/
|
2022-03-21 18:35:53 +01:00
|
|
|
int check_wrapper(CppCheck& cppcheck);
|
2014-03-16 12:04:13 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* Starts the checking.
|
|
|
|
*
|
|
|
|
* @param cppcheck cppcheck instance
|
|
|
|
* @return EXIT_FAILURE if arguments are invalid or no input files
|
|
|
|
* were found.
|
|
|
|
* If errors are found and --error-exitcode is used,
|
|
|
|
* given value is returned instead of default 0.
|
|
|
|
* If no errors are found, 0 is returned.
|
|
|
|
*/
|
2023-11-25 22:07:49 +01:00
|
|
|
int check_internal(CppCheck& cppcheck) const;
|
2014-10-17 17:16:34 +02:00
|
|
|
|
2012-05-14 20:46:23 +02:00
|
|
|
/**
|
|
|
|
* Filename associated with size of file
|
|
|
|
*/
|
2023-11-07 21:21:24 +01:00
|
|
|
std::list<std::pair<std::string, std::size_t>> mFiles;
|
2012-05-14 20:46:23 +02:00
|
|
|
|
2023-11-03 23:24:04 +01:00
|
|
|
std::list<FileSettings> mFileSettings;
|
|
|
|
|
2023-10-21 09:12:59 +02:00
|
|
|
#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
|
2014-05-25 08:47:37 +02:00
|
|
|
/**
|
|
|
|
* Output file name for exception handler
|
|
|
|
*/
|
2019-07-15 18:11:11 +02:00
|
|
|
static FILE* mExceptionOutput;
|
2023-10-21 09:12:59 +02:00
|
|
|
#endif
|
2014-05-25 08:47:37 +02:00
|
|
|
|
2023-11-16 10:35:43 +01:00
|
|
|
class StdLogger;
|
|
|
|
StdLogger* mStdLogger{};
|
2008-12-18 22:28:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CPPCHECKEXECUTOR_H
|