From 43dd749cc6859fe1f35b65cc8980cd7b97728008 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 15 Apr 2010 22:45:38 +0200 Subject: [PATCH] Fix #1585 (--append doesn't work with TAB formating) --- lib/cppcheck.cpp | 8 ++++++-- lib/preprocessor.cpp | 12 +++++++++--- lib/preprocessor.h | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a7e2ae39b..adde9792f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -40,7 +40,7 @@ - rename "file" to "single" - synchronise map access in multithreaded mode or disable timing - add unit tests - - for --showtime + - for --showtime (needs input file) - for Timer* classes - move timer stuff to seperate source/header */ @@ -669,7 +669,11 @@ unsigned int CppCheck::check() if (_settings._errorsOnly == false && it != configurations.begin()) _errorLogger.reportOut(std::string("Checking ") + fname + ": " + cfg + std::string("...")); - checkFile(codeWithoutCfg + _settings.append(), _filenames[c].c_str()); + std::string appendCode = _settings.append(); + if( !appendCode.empty() ) + Preprocessor::preprocessWhitespaces(appendCode); + + checkFile(codeWithoutCfg + appendCode, _filenames[c].c_str()); ++checkCount; } } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 8c0ceb32a..304ebca57 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -568,10 +568,8 @@ std::string Preprocessor::replaceIfDefined(const std::string &str) return ret; } -void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list &resultConfigurations, const std::string &filename, const std::list &includePaths) +void Preprocessor::preprocessWhitespaces(std::string &processedFile) { - processedFile = read(srcCodeStream, filename, _settings); - // Replace all tabs with spaces.. std::replace(processedFile.begin(), processedFile.end(), '\t', ' '); @@ -581,6 +579,14 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe // Remove space characters that are after or before new line character processedFile = removeSpaceNearNL(processedFile); +} + +void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list &resultConfigurations, const std::string &filename, const std::list &includePaths) +{ + processedFile = read(srcCodeStream, filename, _settings); + + // normalize the whitespaces of the file + preprocessWhitespaces(processedFile); // Remove asm(...) removeAsm(processedFile); diff --git a/lib/preprocessor.h b/lib/preprocessor.h index d3e1e3fad..e180c7a22 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -91,6 +91,12 @@ public: */ static void simplifyCondition(const std::map &variables, std::string &condition, bool match); + /** + * preprocess all whitespaces + * @param processedFile The data to be processed + */ + static void preprocessWhitespaces(std::string &processedFile); + protected: /**