Add an originalDirectory setter and change the logic for parseFile

This commit is contained in:
Paul Ferrand 2020-03-28 00:45:59 +01:00
parent 42234da650
commit 25fa15acbe
2 changed files with 15 additions and 3 deletions

View file

@ -39,6 +39,14 @@ void Parser::parseFile(const fs::path& path)
if (_listener)
_listener->onParseBegin();
if (path.empty())
return;
if (path.is_relative())
setOriginalDirectory(originalDirectory() / path);
else
setOriginalDirectory(path.parent_path());
includeNewFile(path);
processTopLevel();
flushCurrentHeader();
@ -62,14 +70,17 @@ void Parser::parseString(absl::string_view sfzView)
_listener->onParseEnd();
}
void Parser::setOriginalDirectory(const fs::path& originalDirectory) noexcept
{
_originalDirectory = originalDirectory;
}
void Parser::includeNewFile(const fs::path& path)
{
fs::path fullPath =
(path.empty() || path.is_absolute()) ? path : _originalDirectory / path;
if (_pathsIncluded.empty())
_originalDirectory = fullPath.parent_path();
else if (_pathsIncluded.find(fullPath.string()) != _pathsIncluded.end()) {
if (_pathsIncluded.find(fullPath.string()) != _pathsIncluded.end()) {
if (_recursiveIncludeGuardEnabled)
return;
}

View file

@ -35,6 +35,7 @@ public:
void setMaximumIncludeDepth(size_t depth) { _maxIncludeDepth = depth; }
const fs::path& originalDirectory() const noexcept { return _originalDirectory; }
void setOriginalDirectory(const fs::path& originalDirectory) noexcept;
typedef absl::flat_hash_set<std::string> IncludeFileSet;
typedef absl::flat_hash_map<std::string, std::string> DefinitionSet;