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/package.h"
21 #include "support/path.h"
22 #include "support/systemcall.h"
24 #include <boost/cregex.hpp>
32 using support::contains;
33 using support::getExtension;
34 using support::getFileContents;
35 using support::getVectorFromString;
36 using support::libFileSearch;
37 using support::onlyFilename;
38 using support::package;
40 using support::quoteName;
42 using support::Systemcall;
47 // build filelists of all availabe bst/cls/sty-files. done through
48 // kpsewhich and an external script, saved in *Files.lst
49 void rescanTexStyles()
51 // Run rescan in user lyx directory
52 Path p(package().user_support());
54 one.startscript(Systemcall::Wait,
56 quoteName(libFileSearch("scripts", "TeXFiles.sh")));
59 // quoteName(libFileSearch("scripts", "TeXFiles.py")));
65 // Run texhash in user lyx directory
66 Path p(package().user_support());
68 //path to texhash through system
70 one.startscript(Systemcall::Wait,"texhash");
74 void getTexFileList(string const & filename, std::vector<string> & list)
77 string const file = libFileSearch("", filename);
81 list = getVectorFromString(getFileContents(file), "\n");
83 // Normalise paths like /foo//bar ==> /foo/bar
84 boost::RegEx regex("/{2,}");
85 std::vector<string>::iterator it = list.begin();
86 std::vector<string>::iterator end = list.end();
87 for (; it != end; ++it) {
88 *it = regex.Merge((*it), "/");
91 // remove empty items and duplicates
92 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
93 eliminate_duplicates(list);
97 string const getListOfOptions(string const & classname, string const & type)
99 string const filename = getTexFileFromList(classname,type);
100 string optionList = string();
101 std::ifstream is(filename.c_str());
105 if (contains(s,"DeclareOption")) {
106 s = s.substr(s.find("DeclareOption"));
107 s = split(s,'{'); // cut front
108 s = token(s,'}',0); // cut end
109 optionList += (s + '\n');
116 string const getTexFileFromList(string const & file,
120 // do we need to add the suffix?
121 if (!(getExtension(file) == type))
124 lyxerr << "Searching for file " << file_ << endl;
128 lstfile = "clsFiles.lst";
129 else if (type == "sty")
130 lstfile = "styFiles.lst";
131 else if (type == "bst")
132 lstfile = "bstFiles.lst";
133 else if (type == "bib")
134 lstfile = "bibFiles.lst";
135 string const allClasses = getFileContents(libFileSearch(string(),
138 string classfile = token(allClasses, '\n', entries);
140 while ((!contains(classfile, file) ||
141 (onlyFilename(classfile) != file)) &&
143 classfile = token(allClasses, '\n', ++entries);
146 // now we have filename with full path
147 lyxerr << "with full path: " << classfile << endl;
152 } // namespace frontend