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/systemcall.h"
20 #include "support/path.h"
21 #include "support/lyxalgo.h"
22 #include "support/path_defines.h"
24 #include <boost/cregex.hpp>
27 using lyx::support::contains;
28 using lyx::support::GetFileContents;
29 using lyx::support::getVectorFromString;
30 using lyx::support::LibFileSearch;
31 using lyx::support::OnlyFilename;
32 using lyx::support::Path;
33 using lyx::support::Path;
34 using lyx::support::split;
35 using lyx::support::Systemcall;
36 using lyx::support::token;
37 using lyx::support::user_lyxdir;
43 // build filelists of all availabe bst/cls/sty-files. done through
44 // kpsewhich and an external script, saved in *Files.lst
45 void rescanTexStyles()
47 // Run rescan in user lyx directory
48 Path p(user_lyxdir());
50 one.startscript(Systemcall::Wait,
51 LibFileSearch("scripts", "TeXFiles.sh"));
57 // Run texhash in user lyx directory
58 Path p(user_lyxdir());
60 //path to texhash through system
62 one.startscript(Systemcall::Wait,"texhash");
66 void getTexFileList(string const & filename, std::vector<string> & list)
69 string const file = LibFileSearch("", filename);
73 list = getVectorFromString(GetFileContents(file), "\n");
75 // Normalise paths like /foo//bar ==> /foo/bar
76 boost::RegEx regex("/{2,}");
77 std::vector<string>::iterator it = list.begin();
78 std::vector<string>::iterator end = list.end();
79 for (; it != end; ++it) {
80 *it = regex.Merge((*it), "/");
83 lyx::eliminate_duplicates(list);
87 string const getListOfOptions(string const & classname, string const & type)
89 string const filename = getTexFileFromList(classname,type);
90 string optionList = string();
91 std::ifstream is(filename.c_str());
95 if (contains(s,"DeclareOption")) {
96 s = s.substr(s.find("DeclareOption"));
97 s = split(s,'{'); // cut front
98 s = token(s,'}',0); // cut end
99 optionList += (s + '\n');
106 string const getTexFileFromList(string const & file,
109 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
111 lyxerr << "Search for classfile " << file_ << endl;
113 string const lstfile =
114 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
115 string const allClasses = GetFileContents(LibFileSearch(string(),
118 string classfile = token(allClasses, '\n', entries);
120 while ((!contains(classfile, file) ||
121 (OnlyFilename(classfile) != file)) &&
123 classfile = token(allClasses, '\n', ++entries);
126 // now we have filename with full path
127 lyxerr << "with full path: " << classfile << endl;