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/lyxalgo.h"
20 #include "support/package.h"
21 #include "support/path.h"
22 #include "support/systemcall.h"
24 #include <boost/cregex.hpp>
32 using support::contains;
33 using support::GetExtension;
34 using support::GetFileContents;
35 using support::getVectorFromString;
36 using support::LibFileSearch;
37 using support::OnlyFilename;
38 using support::package;
41 using support::Systemcall;
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(package().user_support());
53 one.startscript(Systemcall::Wait,
54 "sh " + LibFileSearch("scripts", "TeXFiles.sh"));
60 // Run texhash in user lyx directory
61 Path p(package().user_support());
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 // remove empty items and duplicates
87 list.erase(std::remove(list.begin(), list.end(), ""), list.end());
88 eliminate_duplicates(list);
92 string const getListOfOptions(string const & classname, string const & type)
94 string const filename = getTexFileFromList(classname,type);
95 string optionList = string();
96 std::ifstream is(filename.c_str());
100 if (contains(s,"DeclareOption")) {
101 s = s.substr(s.find("DeclareOption"));
102 s = split(s,'{'); // cut front
103 s = token(s,'}',0); // cut end
104 optionList += (s + '\n');
111 string const getTexFileFromList(string const & file,
115 // do we need to add the suffix?
116 if (!(GetExtension(file) == type))
119 lyxerr << "Searching for file " << file_ << endl;
123 lstfile = "clsFiles.lst";
124 else if (type == "sty")
125 lstfile = "styFiles.lst";
126 else if (type == "bst")
127 lstfile = "bstFiles.lst";
128 else if (type == "bib")
129 lstfile = "bibFiles.lst";
130 string const allClasses = GetFileContents(LibFileSearch(string(),
133 string classfile = token(allClasses, '\n', entries);
135 while ((!contains(classfile, file) ||
136 (OnlyFilename(classfile) != file)) &&
138 classfile = token(allClasses, '\n', ++entries);
141 // now we have filename with full path
142 lyxerr << "with full path: " << classfile << endl;
147 } // namespace frontend