diff --git a/main.cpp b/main.cpp index 2237927..7b3f3dc 100644 --- a/main.cpp +++ b/main.cpp @@ -189,22 +189,32 @@ InputExtractor::List InputExtractor::Include(Path::Path path) { cout << path << "done" << endl; } +Path::Path fixFilename(const Path::Path &file, const Path::Path &root) { + Path::Path temp(file); + + // try to make path absolute + if (Path::isRelative(temp)) { + // add current file's path + temp = Path::Join(root, temp); + } + if (Path::isRelative(temp)) { + // add process working directory + temp = Path::Join(fs::cwd(), temp); + } + + return Path::Clean(temp); +} + + InputExtractor::List InputExtractor::operator()(const Path::Path &file, const MemoryString &str){ List result; CommandList IncludeCommands; + IncludeCommands["input"] = [&file, this](List &l, std::string a) { if (a.empty()) return; if (Path::Extension(a) != ".tex") a += ".tex"; - // try to make path absolute - if (Path::isRelative(a)) { - // add current file's path - a = Path::Join(file, a); - } - if (Path::isRelative(a)) { - // add process working directory - a = Path::Join(fs::cwd(), a); - } + a = fixFilename(a, file); l.push_back(a); // try to extract all inputs of that file @@ -214,7 +224,7 @@ InputExtractor::List InputExtractor::operator()(const Path::Path &file, const Me }; IncludeCommands["include"] = IncludeCommands["input"]; - IncludeCommands["lstinputlisting"] = [](List &l, std::string a){ l.push_back(a); }; + IncludeCommands["lstinputlisting"] = [file](List &l, std::string a){ l.push_back(fixFilename(a, file)); }; MemoryString::const_iterator current = str.begin();