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 namespace lyx::support;
35 // build filelists of all availabe bst/cls/sty-files. done through
36 // kpsewhich and an external script, saved in *Files.lst
37 void rescanTexStyles()
39 // Run rescan in user lyx directory
40 Path p(user_lyxdir());
42 one.startscript(Systemcall::Wait,
43 LibFileSearch("scripts", "TeXFiles.sh"));
49 // Run texhash in user lyx directory
50 Path p(user_lyxdir());
52 //path to texhash through system
54 one.startscript(Systemcall::Wait,"texhash");
58 void getTexFileList(string const & filename, std::vector<string> & list)
61 string const file = LibFileSearch("", filename);
65 list = getVectorFromString(GetFileContents(file), "\n");
67 // Normalise paths like /foo//bar ==> /foo/bar
68 boost::RegEx regex("/{2,}");
69 std::vector<string>::iterator it = list.begin();
70 std::vector<string>::iterator end = list.end();
71 for (; it != end; ++it) {
72 *it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
75 lyx::eliminate_duplicates(list);
79 string const getListOfOptions(string const & classname, string const & type)
81 string const filename = getTexFileFromList(classname,type);
82 string optionList = string();
83 std::ifstream is(filename.c_str());
87 if (contains(s,"DeclareOption")) {
88 s = s.substr(s.find("DeclareOption"));
89 s = split(s,'{'); // cut front
90 s = token(s,'}',0); // cut end
91 optionList += (s + '\n');
98 string const getTexFileFromList(string const & file,
101 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
103 lyxerr << "Search for classfile " << file_ << endl;
105 string const lstfile =
106 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
107 string const allClasses = GetFileContents(LibFileSearch(string(),
110 string classfile = token(allClasses, '\n', entries);
112 while ((!contains(classfile, file) ||
113 (OnlyFilename(classfile) != file)) &&
115 classfile = token(allClasses, '\n', ++entries);
118 // now we have filename with full path
119 lyxerr << "with full path: " << classfile << endl;