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"
23 #include "support/path_defines.h"
25 #include <boost/cregex.hpp>
30 using namespace lyx::support;
38 // build filelists of all availabe bst/cls/sty-files. done through
39 // kpsewhich and an external script, saved in *Files.lst
40 void rescanTexStyles()
42 // Run rescan in user lyx directory
43 Path p(user_lyxdir());
45 one.startscript(Systemcall::Wait,
46 LibFileSearch("scripts", "TeXFiles.sh"));
52 // Run texhash in user lyx directory
53 Path p(user_lyxdir());
55 //path to texhash through system
57 one.startscript(Systemcall::Wait,"texhash");
61 void getTexFileList(string const & filename, std::vector<string> & list)
64 string const file = LibFileSearch("", filename);
68 list = getVectorFromString(GetFileContents(file), "\n");
70 // Normalise paths like /foo//bar ==> /foo/bar
71 boost::RegEx regex("/{2,}");
72 std::vector<string>::iterator it = list.begin();
73 std::vector<string>::iterator end = list.end();
74 for (; it != end; ++it) {
75 *it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
78 lyx::eliminate_duplicates(list);
82 string const getListOfOptions(string const & classname, string const & type)
84 string const filename = getTexFileFromList(classname,type);
85 string optionList = string();
86 std::ifstream is(filename.c_str());
90 if (contains(s,"DeclareOption")) {
91 s = s.substr(s.find("DeclareOption"));
92 s = split(s,'{'); // cut front
93 s = token(s,'}',0); // cut end
94 optionList += (s + '\n');
101 string const getTexFileFromList(string const & file,
104 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
106 lyxerr << "Search for classfile " << file_ << endl;
108 string const lstfile =
109 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
110 string const allClasses = GetFileContents(LibFileSearch(string(),
113 string classfile = token(allClasses, '\n', entries);
115 while ((!contains(classfile, file) ||
116 (OnlyFilename(classfile) != file)) &&
118 classfile = token(allClasses, '\n', ++entries);
121 // now we have filename with full path
122 lyxerr << "with full path: " << classfile << endl;