diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-06-02 12:11:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-06-02 12:11:13 +0300 |
commit | a942b438a5742d87f84f5f09711abde3daebea1e (patch) | |
tree | 9a592d10db61f5a8686b1cda134990072fd62868 | |
parent | 70d884a705e5f116e9f3f04315cebebfefc96957 (diff) | |
download | mplint-a942b438a5742d87f84f5f09711abde3daebea1e.tar.gz mplint-a942b438a5742d87f84f5f09711abde3daebea1e.tar.bz2 mplint-a942b438a5742d87f84f5f09711abde3daebea1e.tar.xz mplint-a942b438a5742d87f84f5f09711abde3daebea1e.zip |
Add src dir detection.
-rw-r--r-- | src/lintmanager.cpp | 19 | ||||
-rw-r--r-- | src/lintmanager.h | 4 | ||||
-rw-r--r-- | src/rulebase.h | 4 |
3 files changed, 26 insertions, 1 deletions
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 <dirent.h> #include <fstream> @@ -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<RuleBase*>::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<RuleBase*> &rules); + void updateRules(); + private: std::vector<RuleBase*> mRules; @@ -65,6 +67,8 @@ class LintManager final std::vector<std::string> 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; }; |