Cppcheck
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
settings.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2016 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "settings.h"
20 #include "preprocessor.h" // Preprocessor
21 #include "utils.h"
22 
23 #include <fstream>
24 #include <set>
25 
27 
29  : debug(false),
30  debugnormal(false),
31  debugwarnings(false),
32  dump(false),
33  exceptionHandling(false),
34  inconclusive(false),
35  jointSuppressionReport(false),
36  experimental(false),
37  quiet(false),
38  inlineSuppressions(false),
39  verbose(false),
40  force(false),
41  relativePaths(false),
42  xml(false), xml_version(1),
43  jobs(1),
44  loadAverage(0),
45  exitCode(0),
46  showtime(SHOWTIME_NONE),
47  preprocessOnly(false),
48  maxConfigs(12),
49  enforcedLang(None),
50  reportProgress(false),
51  checkConfiguration(false),
52  checkLibrary(false)
53 {
54 }
55 
56 namespace {
57  const std::set<std::string> id = make_container< std::set<std::string> > ()
58  << "warning"
59  << "style"
60  << "performance"
61  << "portability"
62  << "information"
63  << "missingInclude"
64  << "unusedFunction"
65 #ifdef CHECK_INTERNAL
66  << "internal"
67 #endif
68  ;
69 }
70 std::string Settings::addEnabled(const std::string &str)
71 {
72  // Enable parameters may be comma separated...
73  if (str.find(',') != std::string::npos) {
74  std::string::size_type prevPos = 0;
75  std::string::size_type pos = 0;
76  while ((pos = str.find(',', pos)) != std::string::npos) {
77  if (pos == prevPos)
78  return std::string("cppcheck: --enable parameter is empty");
79  const std::string errmsg(addEnabled(str.substr(prevPos, pos - prevPos)));
80  if (!errmsg.empty())
81  return errmsg;
82  ++pos;
83  prevPos = pos;
84  }
85  if (prevPos >= str.length())
86  return std::string("cppcheck: --enable parameter is empty");
87  return addEnabled(str.substr(prevPos));
88  }
89 
90  if (str == "all") {
91  std::set<std::string>::const_iterator it;
92  for (it = id.begin(); it != id.end(); ++it) {
93  if (*it == "internal")
94  continue;
95 
96  _enabled.insert(*it);
97  }
98  } else if (id.find(str) != id.end()) {
99  _enabled.insert(str);
100  if (str == "information") {
101  _enabled.insert("missingInclude");
102  }
103  } else {
104  if (str.empty())
105  return std::string("cppcheck: --enable parameter is empty");
106  else
107  return std::string("cppcheck: there is no --enable parameter with the name '" + str + "'");
108  }
109 
110  return std::string("");
111 }
112 
113 
114 bool Settings::append(const std::string &filename)
115 {
116  std::ifstream fin(filename.c_str());
117  if (!fin.is_open()) {
118  return false;
119  }
120  std::string line;
121  while (std::getline(fin, line)) {
122  _append += line + "\n";
123  }
125  return true;
126 }
127 
128 const std::string &Settings::append() const
129 {
130  return _append;
131 }
const std::string & append() const
get append code (–append)
Definition: settings.cpp:128
static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &_settings)
std::string _append
Code to append in the checks.
Definition: settings.h:48
Settings()
Definition: settings.cpp:28
static void preprocessWhitespaces(std::string &processedFile)
preprocess all whitespaces
std::set< std::string > _enabled
enable extra checks by id
Definition: settings.h:51
std::string addEnabled(const std::string &str)
Enable extra checks by id.
Definition: settings.cpp:70
static bool _terminated
terminate checking
Definition: settings.h:54