]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/tex_helpers.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / tex_helpers.C
index 383464b96be295b4c956f901cee0c55eb76c7f2e..e2aa2d5bb933f59f38787df72e3612522ae3de71 100644 (file)
 
 #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/package.h"
+#include "support/path.h"
+#include "support/systemcall.h"
 
 #include <boost/cregex.hpp>
 #include <fstream>
@@ -30,16 +30,17 @@ using std::endl;
 namespace lyx {
 
 using support::contains;
+using support::GetExtension;
 using support::GetFileContents;
 using support::getVectorFromString;
 using support::LibFileSearch;
 using support::OnlyFilename;
+using support::package;
 using support::Path;
-using support::Path;
+using support::QuoteName;
 using support::split;
 using support::Systemcall;
 using support::token;
-using support::user_lyxdir;
 
 namespace frontend {
 
@@ -48,17 +49,18 @@ namespace frontend {
 void rescanTexStyles()
 {
        // Run rescan in user lyx directory
-       Path p(user_lyxdir());
+       Path p(package().user_support());
        Systemcall one;
        one.startscript(Systemcall::Wait,
-                       LibFileSearch("scripts", "TeXFiles.sh"));
+                       "sh " +
+                       QuoteName(LibFileSearch("scripts", "TeXFiles.sh")));
 }
 
 
 void texhash()
 {
        // Run texhash in user lyx directory
-       Path p(user_lyxdir());
+       Path p(package().user_support());
 
        //path to texhash through system
        Systemcall one;
@@ -83,6 +85,8 @@ void getTexFileList(string const & filename, std::vector<string> & list)
                *it = regex.Merge((*it), "/");
        }
 
+       // remove empty items and duplicates
+       list.erase(std::remove(list.begin(), list.end(), ""), list.end());
        eliminate_duplicates(list);
 }
 
@@ -109,12 +113,22 @@ 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 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";
        string const allClasses = GetFileContents(LibFileSearch(string(),
                                                                lstfile));
        int entries = 0;