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>
32 using support::contains;
33 using support::GetFileContents;
34 using support::getVectorFromString;
35 using support::LibFileSearch;
36 using support::OnlyFilename;
40 using support::Systemcall;
42 using support::user_lyxdir;
46 // build filelists of all availabe bst/cls/sty-files. done through
47 // kpsewhich and an external script, saved in *Files.lst
48 void rescanTexStyles()
50 // Run rescan in user lyx directory
51 Path p(user_lyxdir());
53 one.startscript(Systemcall::Wait,
54 LibFileSearch("scripts", "TeXFiles.sh"));
60 // Run texhash in user lyx directory
61 Path p(user_lyxdir());
63 //path to texhash through system
65 one.startscript(Systemcall::Wait,"texhash");
69 void getTexFileList(string const & filename, std::vector<string> & list)
72 string const file = LibFileSearch("", filename);
76 list = getVectorFromString(GetFileContents(file), "\n");
78 // Normalise paths like /foo//bar ==> /foo/bar
79 boost::RegEx regex("/{2,}");
80 std::vector<string>::iterator it = list.begin();
81 std::vector<string>::iterator end = list.end();
82 for (; it != end; ++it) {
83 *it = regex.Merge((*it), "/");
86 eliminate_duplicates(list);
90 string const getListOfOptions(string const & classname, string const & type)
92 string const filename = getTexFileFromList(classname,type);
93 string optionList = string();
94 std::ifstream is(filename.c_str());
98 if (contains(s,"DeclareOption")) {
99 s = s.substr(s.find("DeclareOption"));
100 s = split(s,'{'); // cut front
101 s = token(s,'}',0); // cut end
102 optionList += (s + '\n');
109 string const getTexFileFromList(string const & file,
112 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
114 lyxerr << "Search for classfile " << file_ << endl;
116 string const lstfile =
117 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
118 string const allClasses = GetFileContents(LibFileSearch(string(),
121 string classfile = token(allClasses, '\n', entries);
123 while ((!contains(classfile, file) ||
124 (OnlyFilename(classfile) != file)) &&
126 classfile = token(allClasses, '\n', ++entries);
129 // now we have filename with full path
130 lyxerr << "with full path: " << classfile << endl;
135 } // namespace frontend