diff options
author | Norbert Preining <preining@logic.at> | 2019-12-10 06:22:32 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2019-12-10 06:22:32 +0000 |
commit | 2bc8de74125743b8e3fb84e02f33c65bf9959e82 (patch) | |
tree | cb9ec3e069054ad5a2463a83e7013ae97c9701ef /Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp | |
parent | 7f85e4a77221267523ef1738a61320991bdbc000 (diff) |
dvisvgm 2.8.2 (from Martin Gieseking)
git-svn-id: svn://tug.org/texlive/trunk@53077 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp index dfd60412cb8..e867f648a76 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FileFinder.cpp @@ -46,6 +46,7 @@ std::string FileFinder::_argv0; std::string FileFinder::_progname; +std::string FileFinder::_pathbuf; bool FileFinder::_enableMktex = false; @@ -109,12 +110,11 @@ const char* FileFinder::findFile (const std::string &fname, const char *ftype) c if (fname.empty()) return nullptr; - static std::string buf; // try to lookup the file in the additionally specified directories for (const std::string &dir : _additionalDirs) { - buf = dir + "/" + fname; - if (FileSystem::exists(buf)) - return buf.c_str(); + _pathbuf = dir+"/"+fname; + if (FileSystem::exists(_pathbuf)) + return _pathbuf.c_str(); } std::string ext; if (ftype) @@ -126,21 +126,18 @@ const char* FileFinder::findFile (const std::string &fname, const char *ftype) c ext = fname.substr(pos+1); } +#ifdef _WIN32 + if (ext == "dll" || ext == "exe") + return lookupExecutable(fname); #ifdef MIKTEX - if (ext == "dll" || ext == "exe") { - // lookup dll and exe files in the MiKTeX bin directory first - buf = _miktex->getBinDir() + "/" + fname; - if (FileSystem::exists(buf)) - return buf.c_str(); - } else if (ext == "cmap") { // The MiKTeX SDK doesn't support the lookup of files without suffix (yet), thus // it's not possible to find cmap files which usually don't have a suffix. In order // to work around this, we try to lookup the files by calling kpsewhich. Process process("kpsewhich", "-format=cmap "+fname); - process.run(&buf); - buf = util::trim(buf); - return buf.empty() ? nullptr : buf.c_str(); + process.run(&_pathbuf); + _pathbuf = util::trim(_pathbuf); + return _pathbuf.empty() ? nullptr : _pathbuf.c_str(); } try { return _miktex->findFile(fname.c_str()); @@ -148,17 +145,9 @@ const char* FileFinder::findFile (const std::string &fname, const char *ftype) c catch (const MessageException &e) { return nullptr; } -#else -#ifdef TEXLIVEWIN32 - if (ext == "exe") { - // lookup exe files in directory where dvisvgm is located - if (const char *path = kpse_var_value("SELFAUTOLOC")) { - buf = std::string(path) + "/" + fname; - return FileSystem::exists(buf) ? buf.c_str() : nullptr; - } - return nullptr; - } -#endif +#endif // MIKTEX +#endif // _WIN32 +#ifndef MIKTEX static std::map<std::string, kpse_file_format_type> types = { {"tfm", kpse_tfm_format}, {"pfb", kpse_type1_format}, @@ -188,12 +177,12 @@ const char* FileFinder::findFile (const std::string &fname, const char *ftype) c // In the current version of libkpathsea, each call of kpse_find_file produces // a memory leak since the path buffer is not freed. I don't think we can do // anything against it here... - buf = path; + _pathbuf = path; std::free(path); - return buf.c_str(); + return _pathbuf.c_str(); } return nullptr; -#endif +#endif // !MIKTEX } @@ -264,3 +253,35 @@ const char* FileFinder::lookup (const std::string &fname, const char *ftype, boo return path; return nullptr; } + + +/** Looks up the location of an executable file. + * @param[in] fname name of file to look up + * @param[in] addSuffix if true, ".exe" is appended to the given filename (Windows only) + * @return absolute path of file or nullptr if not found */ +const char* FileFinder::lookupExecutable (const std::string &fname, bool addSuffix) const { +#ifdef MIKTEX + _pathbuf = _miktex->getBinDir() + "/" + fname; + if (addSuffix) + _pathbuf += ".exe"; + if (FileSystem::exists(_pathbuf)) + return _pathbuf.c_str(); + try { + return _miktex->findFile(fname.c_str()); + } + catch (...) { + } +#else + // lookup executables in directory where dvisvgm is located + if (const char *path = kpse_var_value("SELFAUTOLOC")) { + _pathbuf = std::string(path) + "/" + fname; +#ifdef _WIN32 + if (addSuffix) + _pathbuf += ".exe"; +#endif + if (FileSystem::exists(_pathbuf)) + return _pathbuf.c_str(); + } +#endif // !MIKTEX + return nullptr; +} |