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 "support/filetools.h"
19 #include "support/lstrings.h"
20 #include "support/systemcall.h"
21 #include "support/path.h"
22 #include "support/lyxalgo.h"
24 #include <boost/cregex.hpp>
29 using namespace lyx::support;
36 extern string user_lyxdir; // home of *Files.lst
39 // build filelists of all availabe bst/cls/sty-files. done through
40 // kpsewhich and an external script, saved in *Files.lst
41 void rescanTexStyles()
43 // Run rescan in user lyx directory
46 one.startscript(Systemcall::Wait,
47 LibFileSearch("scripts", "TeXFiles.sh"));
53 // Run texhash in user lyx directory
56 //path to texhash through system
58 one.startscript(Systemcall::Wait,"texhash");
62 void getTexFileList(string const & filename, std::vector<string> & list)
65 string const file = LibFileSearch("", filename);
69 list = getVectorFromString(GetFileContents(file), "\n");
71 // Normalise paths like /foo//bar ==> /foo/bar
72 boost::RegEx regex("/{2,}");
73 std::vector<string>::iterator it = list.begin();
74 std::vector<string>::iterator end = list.end();
75 for (; it != end; ++it) {
76 *it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
79 lyx::eliminate_duplicates(list);
83 string const getListOfOptions(string const & classname, string const & type)
85 string const filename = getTexFileFromList(classname,type);
86 string optionList = string();
87 std::ifstream is(filename.c_str());
91 if (contains(s,"DeclareOption")) {
92 s = s.substr(s.find("DeclareOption"));
93 s = split(s,'{'); // cut front
94 s = token(s,'}',0); // cut end
95 optionList += (s + '\n');
102 string const getTexFileFromList(string const & file,
105 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
107 lyxerr << "Search for classfile " << file_ << endl;
109 string const lstfile =
110 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
111 string const allClasses = GetFileContents(LibFileSearch(string(),
114 string classfile = token(allClasses, '\n', entries);
116 while ((!contains(classfile, file) ||
117 (OnlyFilename(classfile) != file)) &&
119 classfile = token(allClasses, '\n', ++entries);
122 // now we have filename with full path
123 lyxerr << "with full path: " << classfile << endl;