]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/tex_helpers.C
Removed all redundant using directives from the source.
[lyx.git] / src / frontends / controllers / tex_helpers.C
1 /**
2  * \file tex_helpers.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Herbert Voß
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "tex_helpers.h"
14
15 #include "debug.h"
16
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"
23
24 #include <boost/cregex.hpp>
25 #include <fstream>
26
27 using namespace lyx::support;
28
29 using std::endl;
30
31
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()
35 {
36         // Run rescan in user lyx directory
37         Path p(user_lyxdir());
38         Systemcall one;
39         one.startscript(Systemcall::Wait,
40                         LibFileSearch("scripts", "TeXFiles.sh"));
41 }
42
43
44 void texhash()
45 {
46         // Run texhash in user lyx directory
47         Path p(user_lyxdir());
48
49         //path to texhash through system
50         Systemcall one;
51         one.startscript(Systemcall::Wait,"texhash");
52 }
53
54
55 void getTexFileList(string const & filename, std::vector<string> & list)
56 {
57         list.clear();
58         string const file = LibFileSearch("", filename);
59         if (file.empty())
60                 return;
61
62         list = getVectorFromString(GetFileContents(file), "\n");
63
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)), "/"));
70         }
71
72         lyx::eliminate_duplicates(list);
73 }
74
75
76 string const getListOfOptions(string const & classname, string const & type)
77 {
78         string const filename = getTexFileFromList(classname,type);
79         string optionList = string();
80         std::ifstream is(filename.c_str());
81         while (is) {
82                 string s;
83                 is >> s;
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');
89                 }
90         }
91         return optionList;
92 }
93
94
95 string const getTexFileFromList(string const & file,
96                             string const & type)
97 {
98         string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
99
100         lyxerr << "Search for classfile " << file_ << endl;
101
102         string const lstfile =
103                 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
104         string const allClasses = GetFileContents(LibFileSearch(string(),
105                                                                 lstfile));
106         int entries = 0;
107         string classfile = token(allClasses, '\n', entries);
108         int count = 0;
109         while ((!contains(classfile, file) ||
110                 (OnlyFilename(classfile) != file)) &&
111                 (++count < 1000)) {
112                 classfile = token(allClasses, '\n', ++entries);
113         }
114
115         // now we have filename with full path
116         lyxerr << "with full path: " << classfile << endl;
117
118         return classfile;
119 }