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::getExtension;
39 using support::getFileContents;
40 using support::getVectorFromString;
41 using support::libFileSearch;
42 using support::onlyFilename;
43 using support::package;
45 using support::quoteName;
47 using support::Systemcall;
52 void rescanTexStyles()
54 // Run rescan in user lyx directory
55 Path p(package().user_support());
56 string const command = libFileSearch("scripts", "TeXFiles.py");
58 int const status = one.startscript(Systemcall::Wait,
59 lyx::support::os::python() + ' ' +
63 Alert::error(_("Could not update TeX information"),
64 bformat(_("The script `%s' failed."), command));
70 // Run texhash in user lyx directory
71 Path p(package().user_support());
73 //path to texhash through system
75 one.startscript(Systemcall::Wait,"texhash");
79 void getTexFileList(string const & filename, std::vector<string> & list)
82 string const file = libFileSearch("", filename);
86 list = getVectorFromString(getFileContents(file), "\n");
88 // Normalise paths like /foo//bar ==> /foo/bar
89 boost::RegEx regex("/{2,}");
90 std::vector<string>::iterator it = list.begin();
91 std::vector<string>::iterator end = list.end();
92 for (; it != end; ++it) {
93 *it = regex.Merge((*it), "/");
96 // remove empty items and duplicates
97 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
98 eliminate_duplicates(list);
102 string const getListOfOptions(string const & classname, string const & type)
104 string const filename = getTexFileFromList(classname,type);
105 string optionList = string();
106 std::ifstream is(filename.c_str());
110 if (contains(s,"DeclareOption")) {
111 s = s.substr(s.find("DeclareOption"));
112 s = split(s,'{'); // cut front
113 s = token(s,'}',0); // cut end
114 optionList += (s + '\n');
121 string const getTexFileFromList(string const & file,
125 // do we need to add the suffix?
126 if (!(getExtension(file) == type))
129 lyxerr << "Searching for file " << file_ << endl;
133 lstfile = "clsFiles.lst";
134 else if (type == "sty")
135 lstfile = "styFiles.lst";
136 else if (type == "bst")
137 lstfile = "bstFiles.lst";
138 else if (type == "bib")
139 lstfile = "bibFiles.lst";
140 string const allClasses = getFileContents(libFileSearch(string(),
143 string classfile = token(allClasses, '\n', entries);
145 while ((!contains(classfile, file) ||
146 (onlyFilename(classfile) != file)) &&
148 classfile = token(allClasses, '\n', ++entries);
151 // now we have filename with full path
152 lyxerr << "with full path: " << classfile << endl;
157 } // namespace frontend