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"
17 #include "support/filetools.h"
18 #include "support/lstrings.h"
19 #include "support/lyxalgo.h"
20 #include "support/os.h"
21 #include "support/package.h"
22 #include "support/path.h"
23 #include "support/systemcall.h"
25 #include <boost/cregex.hpp>
33 using support::contains;
34 using support::getExtension;
35 using support::getFileContents;
36 using support::getVectorFromString;
37 using support::libFileSearch;
38 using support::onlyFilename;
39 using support::package;
41 using support::quoteName;
43 using support::Systemcall;
48 // build filelists of all availabe bst/cls/sty-files. done through
49 // kpsewhich and an external script, saved in *Files.lst
50 void rescanTexStyles()
52 // Run rescan in user lyx directory
53 Path p(package().user_support());
55 one.startscript(Systemcall::Wait,
56 lyx::support::os::python() + ' ' +
57 quoteName(libFileSearch("scripts", "TeXFiles.py")));
63 // Run texhash in user lyx directory
64 Path p(package().user_support());
66 //path to texhash through system
68 one.startscript(Systemcall::Wait,"texhash");
72 void getTexFileList(string const & filename, std::vector<string> & list)
75 string const file = libFileSearch("", filename);
79 list = getVectorFromString(getFileContents(file), "\n");
81 // Normalise paths like /foo//bar ==> /foo/bar
82 boost::RegEx regex("/{2,}");
83 std::vector<string>::iterator it = list.begin();
84 std::vector<string>::iterator end = list.end();
85 for (; it != end; ++it) {
86 *it = regex.Merge((*it), "/");
89 // remove empty items and duplicates
90 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
91 eliminate_duplicates(list);
95 string const getListOfOptions(string const & classname, string const & type)
97 string const filename = getTexFileFromList(classname,type);
98 string optionList = string();
99 std::ifstream is(filename.c_str());
103 if (contains(s,"DeclareOption")) {
104 s = s.substr(s.find("DeclareOption"));
105 s = split(s,'{'); // cut front
106 s = token(s,'}',0); // cut end
107 optionList += (s + '\n');
114 string const getTexFileFromList(string const & file,
118 // do we need to add the suffix?
119 if (!(getExtension(file) == type))
122 lyxerr << "Searching for file " << file_ << endl;
126 lstfile = "clsFiles.lst";
127 else if (type == "sty")
128 lstfile = "styFiles.lst";
129 else if (type == "bst")
130 lstfile = "bstFiles.lst";
131 else if (type == "bib")
132 lstfile = "bibFiles.lst";
133 string const allClasses = getFileContents(libFileSearch(string(),
136 string classfile = token(allClasses, '\n', entries);
138 while ((!contains(classfile, file) ||
139 (onlyFilename(classfile) != file)) &&
141 classfile = token(allClasses, '\n', ++entries);
144 // now we have filename with full path
145 lyxerr << "with full path: " << classfile << endl;
150 } // namespace frontend