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() + ' ' +
64 Alert::error(_("Could not update TeX information"),
65 bformat(_("The script `%s' failed."), lyx::from_utf8(command)));
71 // Run texhash in user lyx directory
72 Path p(package().user_support());
74 //path to texhash through system
76 one.startscript(Systemcall::Wait,"texhash");
80 void getTexFileList(string const & filename, std::vector<string> & list)
83 string const file = libFileSearch("", filename);
87 list = getVectorFromString(getFileContents(file), "\n");
89 // Normalise paths like /foo//bar ==> /foo/bar
90 boost::RegEx regex("/{2,}");
91 std::vector<string>::iterator it = list.begin();
92 std::vector<string>::iterator end = list.end();
93 for (; it != end; ++it) {
94 *it = regex.Merge((*it), "/");
97 // remove empty items and duplicates
98 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
99 eliminate_duplicates(list);
103 string const getListOfOptions(string const & classname, string const & type)
105 string const filename = getTexFileFromList(classname,type);
106 string optionList = string();
107 std::ifstream is(filename.c_str());
111 if (contains(s,"DeclareOption")) {
112 s = s.substr(s.find("DeclareOption"));
113 s = split(s,'{'); // cut front
114 s = token(s,'}',0); // cut end
115 optionList += (s + '\n');
122 string const getTexFileFromList(string const & file,
126 // do we need to add the suffix?
127 if (!(getExtension(file) == type))
130 lyxerr << "Searching for file " << file_ << endl;
134 lstfile = "clsFiles.lst";
135 else if (type == "sty")
136 lstfile = "styFiles.lst";
137 else if (type == "bst")
138 lstfile = "bstFiles.lst";
139 else if (type == "bib")
140 lstfile = "bibFiles.lst";
141 string const allClasses = getFileContents(libFileSearch(string(),
144 string classfile = token(allClasses, '\n', entries);
146 while ((!contains(classfile, file) ||
147 (onlyFilename(classfile) != file)) &&
149 classfile = token(allClasses, '\n', ++entries);
152 // now we have filename with full path
153 lyxerr << "with full path: " << classfile << endl;
158 } // namespace frontend