Visitar URL original
Fixed #83 Header not found, absolute path · x29a/simplecpp@c21b2a0 · GitHub
Skip to content

Commit c21b2a0

Browse files
committed
Fixed cppcheck-opensource#83 Header not found, absolute path
1 parent 047e4e7 commit c21b2a0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,8 +1719,19 @@ namespace simplecpp {
17191719
return f;
17201720
return ostr.str();
17211721
}
1722+
1723+
bool isAbsolutePath(const std::string &path) {
1724+
if (path.length() >= 3 && path[0] > 0 && std::isalpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
1725+
return true;
1726+
return path.length() > 1U && (path[0] == '/' || path[0] == '/');
1727+
}
1728+
17221729
#else
17231730
#define realFilename(f) f
1731+
1732+
bool isAbsolutePath(const std::string &path) {
1733+
return path.length() > 1U && path[0] == '/';
1734+
}
17241735
#endif
17251736

17261737
/**
@@ -1856,6 +1867,11 @@ static const simplecpp::Token *gotoNextLine(const simplecpp::Token *tok)
18561867

18571868
static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader)
18581869
{
1870+
if (simplecpp::isAbsolutePath(header)) {
1871+
f.open(header.c_str());
1872+
return f.is_open() ? simplecpp::simplifyPath(header) : "";
1873+
}
1874+
18591875
if (!systemheader) {
18601876
if (sourcefile.find_first_of("\\/") != std::string::npos) {
18611877
const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header;
@@ -1884,6 +1900,10 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
18841900

18851901
static std::string getFileName(const std::map<std::string, simplecpp::TokenList *> &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)
18861902
{
1903+
if (simplecpp::isAbsolutePath(header)) {
1904+
return (filedata.find(header) != filedata.end()) ? simplecpp::simplifyPath(header) : "";
1905+
}
1906+
18871907
if (!systemheader) {
18881908
if (sourcefile.find_first_of("\\/") != std::string::npos) {
18891909
const std::string s(simplecpp::simplifyPath(sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header));

0 commit comments

Comments
 (0)