2002-06-20 20:41:00 +00:00
|
|
|
/**
|
|
|
|
* \file tex_helpers.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-20 20:41:00 +00:00
|
|
|
*
|
2002-10-21 17:38:09 +00:00
|
|
|
* \author Herbert Voss
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-06-20 20:41:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-06-21 16:35:29 +00:00
|
|
|
#include "tex_helpers.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
2002-06-20 20:41:00 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/systemcall.h"
|
|
|
|
#include "support/path.h"
|
|
|
|
#include "support/lyxalgo.h"
|
2003-07-27 22:13:29 +00:00
|
|
|
#include "support/path_defines.h"
|
2002-06-20 20:41:00 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
#include <boost/cregex.hpp>
|
2002-06-21 16:35:29 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <fstream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2002-06-20 20:41:00 +00:00
|
|
|
using std::vector;
|
2002-06-21 16:35:29 +00:00
|
|
|
using std::endl;
|
2002-06-20 20:41:00 +00:00
|
|
|
using std::sort;
|
|
|
|
using std::unique;
|
|
|
|
|
|
|
|
|
|
|
|
// build filelists of all availabe bst/cls/sty-files. done through
|
|
|
|
// kpsewhich and an external script, saved in *Files.lst
|
|
|
|
void rescanTexStyles()
|
|
|
|
{
|
|
|
|
// Run rescan in user lyx directory
|
2003-07-27 22:13:29 +00:00
|
|
|
Path p(user_lyxdir());
|
2002-06-20 20:41:00 +00:00
|
|
|
Systemcall one;
|
|
|
|
one.startscript(Systemcall::Wait,
|
|
|
|
LibFileSearch("scripts", "TeXFiles.sh"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void texhash()
|
|
|
|
{
|
|
|
|
// Run texhash in user lyx directory
|
2003-07-27 22:13:29 +00:00
|
|
|
Path p(user_lyxdir());
|
2002-06-20 20:41:00 +00:00
|
|
|
|
|
|
|
//path to texhash through system
|
|
|
|
Systemcall one;
|
2002-10-21 17:38:09 +00:00
|
|
|
one.startscript(Systemcall::Wait,"texhash");
|
2002-06-20 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
void getTexFileList(string const & filename, std::vector<string> & list)
|
2002-06-20 20:41:00 +00:00
|
|
|
{
|
2003-06-20 14:03:49 +00:00
|
|
|
list.clear();
|
2002-06-20 23:35:10 +00:00
|
|
|
string const file = LibFileSearch("", filename);
|
|
|
|
if (file.empty())
|
2003-06-20 14:03:49 +00:00
|
|
|
return;
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
list = getVectorFromString(GetFileContents(file), "\n");
|
2002-06-20 23:35:10 +00:00
|
|
|
|
2003-06-20 14:03:49 +00:00
|
|
|
// Normalise paths like /foo//bar ==> /foo/bar
|
|
|
|
boost::RegEx regex("/{2,}");
|
|
|
|
std::vector<string>::iterator it = list.begin();
|
|
|
|
std::vector<string>::iterator end = list.end();
|
|
|
|
for (; it != end; ++it) {
|
2003-06-30 23:56:22 +00:00
|
|
|
*it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
|
2003-02-14 13:52:32 +00:00
|
|
|
}
|
2003-06-20 14:03:49 +00:00
|
|
|
|
|
|
|
lyx::eliminate_duplicates(list);
|
2002-06-20 20:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
string const getListOfOptions(string const & classname, string const & type)
|
2002-06-20 20:41:00 +00:00
|
|
|
{
|
|
|
|
string const filename = getTexFileFromList(classname,type);
|
|
|
|
string optionList = string();
|
|
|
|
std::ifstream is(filename.c_str());
|
|
|
|
while (is) {
|
2003-06-30 15:06:30 +00:00
|
|
|
string s;
|
|
|
|
is >> s;
|
|
|
|
if (contains(s,"DeclareOption")) {
|
|
|
|
s = s.substr(s.find("DeclareOption"));
|
|
|
|
s = split(s,'{'); // cut front
|
|
|
|
s = token(s,'}',0); // cut end
|
|
|
|
optionList += (s + '\n');
|
|
|
|
}
|
2002-06-20 20:41:00 +00:00
|
|
|
}
|
|
|
|
return optionList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
string const getTexFileFromList(string const & file,
|
2002-06-20 20:41:00 +00:00
|
|
|
string const & type)
|
|
|
|
{
|
|
|
|
string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2002-06-20 20:41:00 +00:00
|
|
|
lyxerr << "Search for classfile " << file_ << endl;
|
2002-10-21 17:38:09 +00:00
|
|
|
|
|
|
|
string const lstfile =
|
|
|
|
((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
|
|
|
|
string const allClasses = GetFileContents(LibFileSearch(string(),
|
|
|
|
lstfile));
|
2002-06-20 20:41:00 +00:00
|
|
|
int entries = 0;
|
|
|
|
string classfile = token(allClasses, '\n', entries);
|
|
|
|
int count = 0;
|
2002-10-21 17:38:09 +00:00
|
|
|
while ((!contains(classfile, file) ||
|
2002-06-20 20:41:00 +00:00
|
|
|
(OnlyFilename(classfile) != file)) &&
|
|
|
|
(++count < 1000)) {
|
|
|
|
classfile = token(allClasses, '\n', ++entries);
|
|
|
|
}
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2002-06-20 20:41:00 +00:00
|
|
|
// now we have filename with full path
|
|
|
|
lyxerr << "with full path: " << classfile << endl;
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2002-06-20 20:41:00 +00:00
|
|
|
return classfile;
|
|
|
|
}
|