3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "tex_helpers.h"
18 #include "frontends/Alert.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "support/lyxalgo.h"
23 #include "support/os.h"
24 #include "support/package.h"
25 #include "support/path.h"
26 #include "support/systemcall.h"
28 #include <boost/cregex.hpp>
36 using support::bformat;
37 using support::contains;
38 using support::FileName;
39 using support::getExtension;
40 using support::getFileContents;
41 using support::getVectorFromString;
42 using support::libFileSearch;
43 using support::onlyFilename;
44 using support::package;
46 using support::quoteName;
48 using support::Systemcall;
53 void rescanTexStyles()
55 // Run rescan in user lyx directory
56 Path p(package().user_support());
57 FileName const command = libFileSearch("scripts", "TeXFiles.py");
59 int const status = one.startscript(Systemcall::Wait,
60 lyx::support::os::python() + ' ' +
61 quoteName(command.toFilesystemEncoding()));
65 Alert::error(_("Could not update TeX information"),
66 bformat(_("The script `%s' failed."), lyx::from_utf8(command.absFilename())));
72 // Run texhash in user lyx directory
73 Path p(package().user_support());
75 //path to texhash through system
77 one.startscript(Systemcall::Wait,"texhash");
81 void getTexFileList(string const & filename, std::vector<string> & list)
84 FileName const file = libFileSearch("", filename);
88 list = getVectorFromString(getFileContents(file), "\n");
90 // Normalise paths like /foo//bar ==> /foo/bar
91 boost::RegEx regex("/{2,}");
92 std::vector<string>::iterator it = list.begin();
93 std::vector<string>::iterator end = list.end();
94 for (; it != end; ++it) {
95 *it = regex.Merge((*it), "/");
98 // remove empty items and duplicates
99 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
100 eliminate_duplicates(list);
104 string const getListOfOptions(string const & classname, string const & type)
106 FileName const filename(getTexFileFromList(classname, type));
107 if (filename.empty())
109 string optionList = string();
110 std::ifstream is(filename.toFilesystemEncoding().c_str());
114 if (contains(s,"DeclareOption")) {
115 s = s.substr(s.find("DeclareOption"));
116 s = split(s,'{'); // cut front
117 s = token(s,'}',0); // cut end
118 optionList += (s + '\n');
125 string const getTexFileFromList(string const & file,
129 // do we need to add the suffix?
130 if (!(getExtension(file) == type))
133 lyxerr << "Searching for file " << file_ << endl;
137 lstfile = "clsFiles.lst";
138 else if (type == "sty")
139 lstfile = "styFiles.lst";
140 else if (type == "bst")
141 lstfile = "bstFiles.lst";
142 else if (type == "bib")
143 lstfile = "bibFiles.lst";
144 FileName const abslstfile = libFileSearch(string(), lstfile);
145 if (abslstfile.empty()) {
146 lyxerr << "File `'" << lstfile << "' not found." << endl;
149 string const allClasses = getFileContents(abslstfile);
151 string classfile = token(allClasses, '\n', entries);
153 while ((!contains(classfile, file) ||
154 (onlyFilename(classfile) != file)) &&
156 classfile = token(allClasses, '\n', ++entries);
159 // now we have filename with full path
160 lyxerr << "with full path: " << classfile << endl;
165 } // namespace frontend