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 lyx::support::contains;
28 using lyx::support::GetFileContents;
29 using lyx::support::getVectorFromString;
30 using lyx::support::LibFileSearch;
31 using lyx::support::OnlyFilename;
32 using lyx::support::Path;
33 using lyx::support::Path;
34 using lyx::support::split;
35 using lyx::support::Systemcall;
36 using lyx::support::token;
37 using lyx::support::user_lyxdir;
42 // build filelists of all availabe bst/cls/sty-files. done through
43 // kpsewhich and an external script, saved in *Files.lst
44 void rescanTexStyles()
46 // Run rescan in user lyx directory
47 Path p(user_lyxdir());
49 one.startscript(Systemcall::Wait,
50 LibFileSearch("scripts", "TeXFiles.sh"));
56 // Run texhash in user lyx directory
57 Path p(user_lyxdir());
59 //path to texhash through system
61 one.startscript(Systemcall::Wait,"texhash");
65 void getTexFileList(string const & filename, std::vector<string> & list)
68 string const file = LibFileSearch("", filename);
72 list = getVectorFromString(GetFileContents(file), "\n");
74 // Normalise paths like /foo//bar ==> /foo/bar
75 boost::RegEx regex("/{2,}");
76 std::vector<string>::iterator it = list.begin();
77 std::vector<string>::iterator end = list.end();
78 for (; it != end; ++it) {
79 *it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
82 lyx::eliminate_duplicates(list);
86 string const getListOfOptions(string const & classname, string const & type)
88 string const filename = getTexFileFromList(classname,type);
89 string optionList = string();
90 std::ifstream is(filename.c_str());
94 if (contains(s,"DeclareOption")) {
95 s = s.substr(s.find("DeclareOption"));
96 s = split(s,'{'); // cut front
97 s = token(s,'}',0); // cut end
98 optionList += (s + '\n');
105 string const getTexFileFromList(string const & file,
108 string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
110 lyxerr << "Search for classfile " << file_ << endl;
112 string const lstfile =
113 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
114 string const allClasses = GetFileContents(LibFileSearch(string(),
117 string classfile = token(allClasses, '\n', entries);
119 while ((!contains(classfile, file) ||
120 (OnlyFilename(classfile) != file)) &&
122 classfile = token(allClasses, '\n', ++entries);
125 // now we have filename with full path
126 lyxerr << "with full path: " << classfile << endl;