From a942b438a5742d87f84f5f09711abde3daebea1e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 2 Jun 2014 12:11:13 +0300 Subject: Add src dir detection. --- src/lintmanager.cpp | 19 ++++++++++++++++++- src/lintmanager.h | 4 ++++ src/rulebase.h | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lintmanager.cpp b/src/lintmanager.cpp index bba2926..f595a38 100644 --- a/src/lintmanager.cpp +++ b/src/lintmanager.cpp @@ -21,6 +21,7 @@ #include "lintmanager.h" #include "rulebase.h" +#include "stringutils.h" #include #include @@ -32,15 +33,31 @@ LintManager lint; -LintManager::LintManager() +LintManager::LintManager() : + mFileName(), + mRootPath() { } void LintManager::run(std::string path) { + mRootPath = path; + size_t idx = path.rfind("src/"); + if (idx != std::string::npos) + mRootPath = mRootPath.substr(0, idx); + if (!strEndWith(mRootPath, "/")) + mRootPath.append("/"); + + updateRules(); enumFiles(path); } +void LintManager::updateRules() +{ + FOR_EACH (std::vector::iterator, it, mRules) + (*it)->setRootDir(mRootPath); +} + void LintManager::addRule(RuleBase *const rule) { mRules.push_back(rule); diff --git a/src/lintmanager.h b/src/lintmanager.h index 7992971..237e937 100644 --- a/src/lintmanager.h +++ b/src/lintmanager.h @@ -57,6 +57,8 @@ class LintManager final void deleteFrom(RuleBase *const rule, std::vector &rules); + void updateRules(); + private: std::vector mRules; @@ -65,6 +67,8 @@ class LintManager final std::vector mFileData; std::string mFileName; + + std::string mRootPath; }; extern LintManager lint; diff --git a/src/rulebase.h b/src/rulebase.h index 1d237ee..4421291 100644 --- a/src/rulebase.h +++ b/src/rulebase.h @@ -66,6 +66,9 @@ class RuleBase bool getFlag() const A_WARN_UNUSED { return flag; } + void setRootDir(const std::string &dir) + { rootDir = dir; } + void terminateRule(); protected: @@ -81,6 +84,7 @@ class RuleBase std::string file; std::string ruleName; + std::string rootDir; int line; bool flag; }; -- cgit v1.2.3-70-g09d2