This commit was manufactured by cvs2svn to create tag 'lyx-1_3_7'.
[lyx.git] / src / frontends / controllers / tex_helpers.C
blobd6c629995fbf9ebf05fa94831864daadb6bbc5ad
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 Voss
7  *
8  * Full author contact details are available in file CREDITS
9  */
11 #include <config.h>
13 #include "tex_helpers.h"
15 #include "debug.h"
16 #include "gettext.h"
18 #include "support/filetools.h"
19 #include "support/lstrings.h"
20 #include "support/lyxalgo.h"
21 #include "support/package.h"
22 #include "support/path.h"
23 #include "support/systemcall.h"
25 #include <vector>
26 #include <fstream>
27 #include <algorithm>
29 using std::vector;
30 using std::endl;
31 using std::sort;
32 using std::unique;
35 namespace {
37 vector<string> listWithoutPath(vector<string> & dbase)
39         vector<string>::iterator it = dbase.begin();
40         vector<string>::iterator end = dbase.end();
41         for (; it != end; ++it)
42                 *it = OnlyFilename(*it);
43         return dbase;
46 } // namespace anon
48 // build filelists of all availabe bst/cls/sty-files. done through
49 // kpsewhich and an external script, saved in *Files.lst
50 void rescanTexStyles()
52         // Run rescan in user lyx directory
53         Path p(lyx::package().user_support());
54         Systemcall one;
55         one.startscript(Systemcall::Wait,
56                         "sh " +
57                         QuoteName(LibFileSearch("scripts", "TeXFiles.sh")));
61 void texhash()
63         // Run texhash in user lyx directory
64         Path p(lyx::package().user_support());
66         //path to texhash through system
67         Systemcall one;
68         one.startscript(Systemcall::Wait,"texhash");
72 string const getTexFileList(string const & filename, bool withFullPath)
74         string const file = LibFileSearch("", filename);
75         if (file.empty())
76                 return string();
78         vector<string> dbase =
79                 getVectorFromString(GetFileContents(file), "\n");
81         lyx::eliminate_duplicates(dbase);
82         string const str_out = withFullPath ?
83                 getStringFromVector(dbase, "\n") :
84                 getStringFromVector(listWithoutPath(dbase), "\n");
85         return str_out;
89 string const getListOfOptions(string const & classname, string const & type)
91         string const filename = getTexFileFromList(classname,type);
92         string optionList = string();
93         std::ifstream is(filename.c_str());
94         while (is) {
95             string s;
96             is >> s;
97             if (contains(s,"DeclareOption")) {
98                 s = s.substr(s.find("DeclareOption"));
99                 s = split(s,'{');               // cut front
100                 s = token(s,'}',0);             // cut end
101                 optionList += (s + '\n');
102             }
103         }
104         return optionList;
108 string const getTexFileFromList(string const & file,
109                             string const & type)
111         string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
113         lyxerr << "Search for classfile " << file_ << endl;
115         string const lstfile =
116                 ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
117         string const allClasses = GetFileContents(LibFileSearch(string(),
118                                                                 lstfile));
119         int entries = 0;
120         string classfile = token(allClasses, '\n', entries);
121         int count = 0;
122         while ((!contains(classfile, file) ||
123                 (OnlyFilename(classfile) != file)) &&
124                 (++count < 1000)) {
125                 classfile = token(allClasses, '\n', ++entries);
126         }
128         // now we have filename with full path
129         lyxerr << "with full path: " << classfile << endl;
131         return classfile;