X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fcontrollers%2Ftex_helpers.C;h=fbc78c2d78b1e023b9e8e120072aa9084662b282;hb=534095ce9e82d0b0f875540f7306ff218df3b5aa;hp=d542bbabca326d2f39b11de7988d13b64c3a8ccf;hpb=4c6e0fe4226ce3b55d13726977f1e579f17c2ad1;p=lyx.git diff --git a/src/frontends/controllers/tex_helpers.C b/src/frontends/controllers/tex_helpers.C index d542bbabca..fbc78c2d78 100644 --- a/src/frontends/controllers/tex_helpers.C +++ b/src/frontends/controllers/tex_helpers.C @@ -13,38 +13,64 @@ #include "tex_helpers.h" #include "debug.h" +#include "gettext.h" + +#include "frontends/Alert.h" #include "support/filetools.h" #include "support/lstrings.h" -#include "support/systemcall.h" -#include "support/path.h" #include "support/lyxalgo.h" -#include "support/path_defines.h" +#include "support/os.h" +#include "support/package.h" +#include "support/path.h" +#include "support/systemcall.h" #include #include -using namespace lyx::support; - +using std::string; using std::endl; +namespace lyx { + +using support::bformat; +using support::contains; +using support::FileName; +using support::getExtension; +using support::getFileContents; +using support::getVectorFromString; +using support::libFileSearch; +using support::onlyFilename; +using support::package; +using support::Path; +using support::quoteName; +using support::split; +using support::Systemcall; +using support::token; + +namespace frontend { -// build filelists of all availabe bst/cls/sty-files. done through -// kpsewhich and an external script, saved in *Files.lst void rescanTexStyles() { // Run rescan in user lyx directory - Path p(user_lyxdir()); + Path p(package().user_support()); + FileName const command = libFileSearch("scripts", "TeXFiles.py"); Systemcall one; - one.startscript(Systemcall::Wait, - LibFileSearch("scripts", "TeXFiles.sh")); + int const status = one.startscript(Systemcall::Wait, + lyx::support::os::python() + ' ' + + quoteName(command.toFilesystemEncoding())); + if (status == 0) + return; + // FIXME UNICODE + Alert::error(_("Could not update TeX information"), + bformat(_("The script `%s' failed."), lyx::from_utf8(command.absFilename()))); } void texhash() { // Run texhash in user lyx directory - Path p(user_lyxdir()); + Path p(package().user_support()); //path to texhash through system Systemcall one; @@ -55,29 +81,33 @@ void texhash() void getTexFileList(string const & filename, std::vector & list) { list.clear(); - string const file = LibFileSearch("", filename); + FileName const file = libFileSearch("", filename); if (file.empty()) return; - list = getVectorFromString(GetFileContents(file), "\n"); + list = getVectorFromString(getFileContents(file), "\n"); // Normalise paths like /foo//bar ==> /foo/bar boost::RegEx regex("/{2,}"); std::vector::iterator it = list.begin(); std::vector::iterator end = list.end(); for (; it != end; ++it) { - *it = STRCONV(regex.Merge(STRCONV((*it)), "/")); + *it = regex.Merge((*it), "/"); } - lyx::eliminate_duplicates(list); + // remove empty items and duplicates + list.erase(std::remove(list.begin(), list.end(), ""), list.end()); + eliminate_duplicates(list); } string const getListOfOptions(string const & classname, string const & type) { - string const filename = getTexFileFromList(classname,type); + FileName const filename(getTexFileFromList(classname, type)); + if (filename.empty()) + return string(); string optionList = string(); - std::ifstream is(filename.c_str()); + std::ifstream is(filename.toFilesystemEncoding().c_str()); while (is) { string s; is >> s; @@ -95,19 +125,33 @@ string const getListOfOptions(string const & classname, string const & type) string const getTexFileFromList(string const & file, string const & type) { - string const file_ = (type == "cls") ? file + ".cls" : file + ".sty"; - - lyxerr << "Search for classfile " << file_ << endl; - - string const lstfile = - ((type == "cls") ? "clsFiles.lst" : "styFiles.lst"); - string const allClasses = GetFileContents(LibFileSearch(string(), - lstfile)); + string file_ = file; + // do we need to add the suffix? + if (!(getExtension(file) == type)) + file_ += '.' + type; + + lyxerr << "Searching for file " << file_ << endl; + + string lstfile; + if (type == "cls") + lstfile = "clsFiles.lst"; + else if (type == "sty") + lstfile = "styFiles.lst"; + else if (type == "bst") + lstfile = "bstFiles.lst"; + else if (type == "bib") + lstfile = "bibFiles.lst"; + FileName const abslstfile = libFileSearch(string(), lstfile); + if (abslstfile.empty()) { + lyxerr << "File `'" << lstfile << "' not found." << endl; + return string(); + } + string const allClasses = getFileContents(abslstfile); int entries = 0; string classfile = token(allClasses, '\n', entries); int count = 0; while ((!contains(classfile, file) || - (OnlyFilename(classfile) != file)) && + (onlyFilename(classfile) != file)) && (++count < 1000)) { classfile = token(allClasses, '\n', ++entries); } @@ -117,3 +161,6 @@ string const getTexFileFromList(string const & file, return classfile; } + +} // namespace frontend +} // namespace lyx