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;
32 // build filelists of all availabe bst/cls/sty-files. done through
33 // kpsewhich and an external script, saved in *Files.lst
34 void rescanTexStyles()
36 // Run rescan in user lyx directory
37 Path p(user_lyxdir());
39 one.startscript(Systemcall::Wait,
40 LibFileSearch("scripts", "TeXFiles.sh"));
46 // Run texhash in user lyx directory
47 Path p(user_lyxdir());
49 //path to texhash through system
51 one.startscript(Systemcall::Wait,"texhash");
55 void getTexFileList(string const & filename, std::vector<string> & list)
58 string const file = LibFileSearch("", filename);
62 list = getVectorFromString(GetFileContents(file), "\n");
64 // Normalise paths like /foo//bar ==> /foo/bar
65 boost::RegEx regex("/{2,}");
66 std::vector<string>::iterator it = list.begin();
67 std::vector<string>::iterator end = list.end();
68 for (; it != end; ++it) {
69 *it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
72 lyx::eliminate_duplicates(list);
76 string const getListOfOptions(string const & classname, string const & type)
78 string const filename = getTexFileFromList(classname,type);
79 string optionList = string();
80 std::ifstream is(filename.c_str());
84 if (contains(s,"DeclareOption")) {
85 s = s.substr(s.find("DeclareOption"));
86 s = split(s,'{'); // cut front
87 s = token(s,'}',0); // cut end
88 optionList += (s + '\n');
95 string const getTexFileFromList(string const & file,
98 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
100 lyxerr << "Search for classfile " << file_ << endl;
102 string const lstfile =
103 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
104 string const allClasses = GetFileContents(LibFileSearch(string(),
107 string classfile = token(allClasses, '\n', entries);
109 while ((!contains(classfile, file) ||
110 (OnlyFilename(classfile) != file)) &&
112 classfile = token(allClasses, '\n', ++entries);
115 // now we have filename with full path
116 lyxerr << "with full path: " << classfile << endl;