diff --git a/src/sfizz/parser/Parser.cpp b/src/sfizz/parser/Parser.cpp index 13572cea..f54398ac 100644 --- a/src/sfizz/parser/Parser.cpp +++ b/src/sfizz/parser/Parser.cpp @@ -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; } diff --git a/src/sfizz/parser/Parser.h b/src/sfizz/parser/Parser.h index 17f88709..5ab1d75b 100644 --- a/src/sfizz/parser/Parser.h +++ b/src/sfizz/parser/Parser.h @@ -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 IncludeFileSet; typedef absl::flat_hash_map DefinitionSet;