1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
1999-11-24 22:14:46 +00:00
|
|
|
#include <fstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LaTeX.h"
|
|
|
|
#include "Literate.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/FileInfo.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/syscall.h"
|
|
|
|
#include "support/syscontr.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
#include "support/path.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "bufferlist.h"
|
|
|
|
#include "minibuffer.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
using std::ifstream;
|
2000-05-04 10:57:00 +00:00
|
|
|
using std::getline;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
Literate::Literate(string const & latex, string const & f, string const & p,
|
|
|
|
string const & l,
|
|
|
|
string const & literate, string const & literate_f,
|
|
|
|
string const & build, string const & build_f)
|
1999-11-04 01:40:20 +00:00
|
|
|
: LaTeX(latex, f, p),
|
1999-09-27 18:44:28 +00:00
|
|
|
litfile(l),
|
|
|
|
literate_cmd(literate), literate_filter(literate_f),
|
|
|
|
build_cmd(build), build_filter(build_f)
|
1999-11-04 01:40:20 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
int scanres = Literate::NO_ERRORS;
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp1, tmp2;
|
1999-09-27 18:44:28 +00:00
|
|
|
int ret1, ret2;
|
|
|
|
Systemcalls one, two;
|
|
|
|
|
|
|
|
// The class LaTeX does not know the temp path.
|
|
|
|
bufferlist.updateIncludedTeXfiles(GetCWD());
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Weaving document" << endl;
|
1999-10-02 16:21:10 +00:00
|
|
|
minib->Set(string(_("Weaving document")));
|
1999-09-27 18:44:28 +00:00
|
|
|
minib->Store();
|
|
|
|
|
|
|
|
// Run the literate program to convert \literate_extension file to .tex file
|
|
|
|
//
|
|
|
|
tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
|
|
|
|
tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
|
1999-10-12 21:37:10 +00:00
|
|
|
ret1 = one.startscript(Systemcalls::System, tmp1);
|
|
|
|
ret2 = two.startscript(Systemcalls::System, tmp2);
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
|
1999-11-04 01:40:20 +00:00
|
|
|
scanres = scanLiterateLogFile();
|
1999-09-27 18:44:28 +00:00
|
|
|
if (scanres & Literate::ERRORS) return scanres; // return on literate error
|
|
|
|
return run(terr, minib);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib)
|
1999-09-27 18:44:28 +00:00
|
|
|
// We know that this function will only be run if the lyx buffer
|
|
|
|
// has been changed.
|
|
|
|
{
|
|
|
|
int scanres = Literate::NO_ERRORS;
|
|
|
|
num_errors = 0; // just to make sure.
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp1, tmp2;
|
1999-09-27 18:44:28 +00:00
|
|
|
int ret1, ret2;
|
|
|
|
Systemcalls one, two;
|
|
|
|
|
|
|
|
// The class LaTeX does not know the temp path.
|
|
|
|
bufferlist.updateIncludedTeXfiles(GetCWD());
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Building program" << endl;
|
1999-10-02 16:21:10 +00:00
|
|
|
minib->Set(string(_("Building program")));
|
1999-09-27 18:44:28 +00:00
|
|
|
minib->Store();
|
|
|
|
|
|
|
|
// Run the build program
|
|
|
|
//
|
|
|
|
tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
|
|
|
|
tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
|
1999-10-12 21:37:10 +00:00
|
|
|
ret1 = one.startscript(Systemcalls::System, tmp1);
|
|
|
|
ret2 = two.startscript(Systemcalls::System, tmp2);
|
1999-11-04 01:40:20 +00:00
|
|
|
scanres = scanBuildLogFile();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Done." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
return scanres;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int Literate::scanLiterateLogFile()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string token;
|
1999-09-27 18:44:28 +00:00
|
|
|
int retval = NO_ERRORS;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = litfile + ".log";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
ifstream ifs(tmp.c_str());
|
|
|
|
while (getline(ifs, token)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << token << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
if (prefixIs(token, "Build Warning:")) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Here shall we handle different
|
|
|
|
// types of warnings
|
|
|
|
retval |= LATEX_WARNING;
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Build Warning." << endl;
|
1999-10-02 16:21:10 +00:00
|
|
|
} else if (prefixIs(token, "! Build Error:")) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Here shall we handle different
|
|
|
|
// types of errors
|
|
|
|
retval |= LATEX_ERROR;
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Build Error." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// this is not correct yet
|
2000-01-24 18:34:46 +00:00
|
|
|
++num_errors;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int Literate::scanBuildLogFile()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string token;
|
1999-09-27 18:44:28 +00:00
|
|
|
int retval = NO_ERRORS;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = litfile + ".log";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
ifstream ifs(tmp.c_str());
|
|
|
|
while (getline(ifs, token)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << token << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
if (prefixIs(token, "Build Warning:")) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Here shall we handle different
|
|
|
|
// types of warnings
|
|
|
|
retval |= LATEX_WARNING;
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Build Warning." << endl;
|
1999-10-02 16:21:10 +00:00
|
|
|
} else if (prefixIs(token, "! Build Error:")) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Here shall we handle different
|
|
|
|
// types of errors
|
|
|
|
retval |= LATEX_ERROR;
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Build Error." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// this is not correct yet
|
2000-01-24 18:34:46 +00:00
|
|
|
++num_errors;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|