]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/tex_helpers.C
more unicode filenames
[lyx.git] / src / frontends / controllers / tex_helpers.C
index e2aa2d5bb933f59f38787df72e3612522ae3de71..fbc78c2d78b1e023b9e8e120072aa9084662b282 100644 (file)
 #include "tex_helpers.h"
 
 #include "debug.h"
+#include "gettext.h"
+
+#include "frontends/Alert.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
+#include "support/os.h"
 #include "support/package.h"
 #include "support/path.h"
 #include "support/systemcall.h"
@@ -29,31 +33,37 @@ using std::endl;
 
 namespace lyx {
 
+using support::bformat;
 using support::contains;
-using support::GetExtension;
-using support::GetFileContents;
+using support::FileName;
+using support::getExtension;
+using support::getFileContents;
 using support::getVectorFromString;
-using support::LibFileSearch;
-using support::OnlyFilename;
+using support::libFileSearch;
+using support::onlyFilename;
 using support::package;
 using support::Path;
-using support::QuoteName;
+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(package().user_support());
+       FileName const command = libFileSearch("scripts", "TeXFiles.py");
        Systemcall one;
-       one.startscript(Systemcall::Wait,
-                       "sh " +
-                       QuoteName(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())));
 }
 
 
@@ -71,11 +81,11 @@ void texhash()
 void getTexFileList(string const & filename, std::vector<string> & 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,}");
@@ -93,9 +103,11 @@ void getTexFileList(string const & filename, std::vector<string> & 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;
@@ -115,7 +127,7 @@ string const getTexFileFromList(string const & file,
 {
        string file_ = file;
        // do we need to add the suffix?
-       if (!(GetExtension(file) == type))
+       if (!(getExtension(file) == type))
                file_ += '.' + type;
 
        lyxerr << "Searching for file " << file_ << endl;
@@ -129,13 +141,17 @@ string const getTexFileFromList(string const & file,
                lstfile = "bstFiles.lst";
        else if (type == "bib")
                lstfile = "bibFiles.lst";
-       string const allClasses = GetFileContents(LibFileSearch(string(),
-                                                               lstfile));
+       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);
        }