1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
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"
|
|
|
|
#include "lyxlex.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/FileInfo.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "error.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/syscall.h"
|
|
|
|
#include "support/syscontr.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "pathstack.h"
|
|
|
|
#include "bufferlist.h"
|
|
|
|
#include "minibuffer.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
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-09-27 18:44:28 +00:00
|
|
|
: LaTeX (latex, f, p),
|
|
|
|
litfile(l),
|
|
|
|
literate_cmd(literate), literate_filter(literate_f),
|
|
|
|
build_cmd(build), build_filter(build_f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Literate::weave(TeXErrors &terr, MiniBuffer *minib)
|
|
|
|
{
|
|
|
|
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-02 16:21:10 +00:00
|
|
|
lyxerr.debug(string(_("Weaving document")),
|
1999-09-27 18:44:28 +00:00
|
|
|
Error::LATEX);
|
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";
|
|
|
|
ret1 = one.Startscript(Systemcalls::System, tmp1);
|
|
|
|
ret2 = two.Startscript(Systemcalls::System, tmp2);
|
1999-10-02 16:21:10 +00:00
|
|
|
lyxerr.debug(string(_("LITERATE")) + " {" + tmp1 + "} {" + tmp2 + "}");
|
1999-09-27 18:44:28 +00:00
|
|
|
scanres = scanLiterateLogFile(terr);
|
|
|
|
if (scanres & Literate::ERRORS) return scanres; // return on literate error
|
|
|
|
|
|
|
|
return run(terr, minib);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Literate::build(TeXErrors &terr, MiniBuffer *minib)
|
|
|
|
// 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.
|
|
|
|
// DepTable head; // empty head // unused
|
|
|
|
// bool rerun = false; // rerun requested // unused
|
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-02 16:21:10 +00:00
|
|
|
lyxerr.debug(string(_("Building program")),
|
1999-09-27 18:44:28 +00:00
|
|
|
Error::LATEX);
|
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";
|
|
|
|
ret1 = one.Startscript(Systemcalls::System, tmp1);
|
|
|
|
ret2 = two.Startscript(Systemcalls::System, tmp2);
|
|
|
|
scanres = scanBuildLogFile(terr);
|
|
|
|
lyxerr.debug("Done.", Error::LATEX);
|
|
|
|
|
|
|
|
return scanres;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Literate::scanLiterateLogFile(TeXErrors &terr)
|
|
|
|
{
|
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
|
|
|
LyXLex lex(0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = litfile + ".log";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!lex.setFile(tmp)) {
|
|
|
|
// unable to open file
|
|
|
|
// return at once
|
|
|
|
retval |= NO_LOGFILE;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
if (lex.EatLine())
|
|
|
|
token = lex.GetString();
|
|
|
|
else // blank line in the file being read
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lyxerr.debug(token, Error::LATEX);
|
|
|
|
|
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;
|
|
|
|
lyxerr.debug("Build Warning.", Error::LATEX);
|
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;
|
|
|
|
lyxerr.debug("Build Error.", Error::LATEX);
|
|
|
|
// this is not correct yet
|
|
|
|
terr.scanError(lex);
|
|
|
|
num_errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Literate::scanBuildLogFile(TeXErrors &terr)
|
|
|
|
{
|
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
|
|
|
LyXLex lex(0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = litfile + ".log";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!lex.setFile(tmp)) {
|
|
|
|
// unable to open file
|
|
|
|
// return at once
|
|
|
|
retval |= NO_LOGFILE;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
if (lex.EatLine())
|
|
|
|
token = lex.GetString();
|
|
|
|
else // blank line in the file being read
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lyxerr.debug(token, Error::LATEX);
|
|
|
|
|
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;
|
|
|
|
lyxerr.debug("Build Warning.", Error::LATEX);
|
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;
|
|
|
|
lyxerr.debug("Build Error.", Error::LATEX);
|
|
|
|
// this is not correct yet
|
|
|
|
terr.scanError(lex);
|
|
|
|
num_errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|