From 566e74fae0a99f5814c99f35019b4aa42af3d10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 14 Sep 2020 15:43:43 +0200 Subject: [PATCH] bump simplecpp (fix hang when systemheader includes itself) --- externals/simplecpp/simplecpp.cpp | 57 +++++++++++++------------------ 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 61cc1d38e..52ba3ea6f 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -2363,30 +2363,30 @@ static std::string _openHeader(std::ifstream &f, const std::string &path) #endif } +static std::string getRelativeFileName(const std::string &sourcefile, const std::string &header) +{ + if (sourcefile.find_first_of("\\/") != std::string::npos) + return simplecpp::simplifyPath(sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header); + return simplecpp::simplifyPath(header); +} + static std::string openHeaderRelative(std::ifstream &f, const std::string &sourcefile, const std::string &header) { - if (sourcefile.find_first_of("\\/") != std::string::npos) { - const std::string s = sourcefile.substr(0, sourcefile.find_last_of("\\/") + 1U) + header; - std::string simplePath = _openHeader(f, s); - if (!simplePath.empty()) - return simplePath; - } else { - std::string simplePath = _openHeader(f, header); - if (!simplePath.empty()) - return simplePath; - } - return ""; + return _openHeader(f, getRelativeFileName(sourcefile, header)); +} + +static std::string getIncludePathFileName(const std::string &includePath, const std::string &header) +{ + std::string path = includePath; + if (!path.empty() && path[path.size()-1U]!='/' && path[path.size()-1U]!='\\') + path += '/'; + return path + header; } static std::string openHeaderIncludePath(std::ifstream &f, const simplecpp::DUI &dui, const std::string &header) { for (std::list::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { - std::string s = *it; - if (!s.empty() && s[s.size()-1U]!='/' && s[s.size()-1U]!='\\') - s += '/'; - s += header; - - std::string simplePath = _openHeader(f, s); + std::string simplePath = _openHeader(f, getIncludePathFileName(*it, header)); if (!simplePath.empty()) return simplePath; } @@ -2418,28 +2418,19 @@ static std::string getFileName(const std::map::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { - std::string s = *it; - if (!s.empty() && s[s.size()-1U]!='/' && s[s.size()-1U]!='\\') - s += '/'; - s += header; - s = simplecpp::simplifyPath(s); + std::string s = simplecpp::simplifyPath(getIncludePathFileName(*it, header)); if (filedata.find(s) != filedata.end()) return s; } + if (filedata.find(relativeFilename) != filedata.end()) + return relativeFilename; + return ""; }