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")));
62 // Run texhash in user lyx directory
63 Path p(package().user_support());
65 //path to texhash through system
67 one.startscript(Systemcall::Wait,"texhash");
71 void getTexFileList(string const & filename, std::vector<string> & list)
74 string const file = libFileSearch("", filename);
78 list = getVectorFromString(getFileContents(file), "\n");
80 // Normalise paths like /foo//bar ==> /foo/bar
81 boost::RegEx regex("/{2,}");
82 std::vector<string>::iterator it = list.begin();
83 std::vector<string>::iterator end = list.end();
84 for (; it != end; ++it) {
85 *it = regex.Merge((*it), "/");
88 // remove empty items and duplicates
89 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
90 eliminate_duplicates(list);
94 string const getListOfOptions(string const & classname, string const & type)
96 string const filename = getTexFileFromList(classname,type);
97 string optionList = string();
98 std::ifstream is(filename.c_str());
102 if (contains(s,"DeclareOption")) {
103 s = s.substr(s.find("DeclareOption"));
104 s = split(s,'{'); // cut front
105 s = token(s,'}',0); // cut end
106 optionList += (s + '\n');
113 string const getTexFileFromList(string const & file,
117 // do we need to add the suffix?
118 if (!(getExtension(file) == type))
121 lyxerr << "Searching for file " << file_ << endl;
125 lstfile = "clsFiles.lst";
126 else if (type == "sty")
127 lstfile = "styFiles.lst";
128 else if (type == "bst")
129 lstfile = "bstFiles.lst";
130 else if (type == "bib")
131 lstfile = "bibFiles.lst";
132 string const allClasses = getFileContents(libFileSearch(string(),
135 string classfile = token(allClasses, '\n', entries);
137 while ((!contains(classfile, file) ||
138 (onlyFilename(classfile) != file)) &&
140 classfile = token(allClasses, '\n', ++entries);
143 // now we have filename with full path
144 lyxerr << "with full path: " << classfile << endl;
149 } // namespace frontend