lyx_mirror/src/Literate.C
Jürgen Vigna d02a3f2679 Small fixes notified by Angus and patch from Kayan!
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@878 a592a061-630c-0410-9148-cb99ea01b6c8
2000-07-12 13:24:24 +00:00

108 lines
3.3 KiB
C

/* This file is part of
* ======================================================
*
* LyX, The Document Processor
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2000 The LyX Team.
*
* ======================================================
*/
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include <fstream>
#include "support/filetools.h"
#include "LaTeX.h"
#include "Literate.h"
#include "support/FileInfo.h"
#include "debug.h"
#include "support/lyxlib.h"
#include "support/syscall.h"
#include "support/syscontr.h"
#include "support/path.h"
#include "bufferlist.h"
#include "minibuffer.h"
#include "gettext.h"
using std::ifstream;
using std::getline;
using std::endl;
extern BufferList bufferlist;
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)
: 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;
string tmp1, tmp2;
int ret1, ret2;
Systemcalls one, two;
string logfile = OnlyFilename(ChangeExtension(file, ".log"));
// The class LaTeX does not know the temp path.
bufferlist.updateIncludedTeXfiles(GetCWD());
lyxerr[Debug::LATEX] << "Weaving document" << endl;
minib->Set(string(_("Weaving document")));
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" + " > " + logfile;
ret1 = one.startscript(Systemcalls::System, tmp1);
ret2 = two.startscript(Systemcalls::System, tmp2);
lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
scanres = scanLogFile(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.
string tmp1, tmp2;
int ret1, ret2;
Systemcalls one, two;
string logfile = OnlyFilename(ChangeExtension(file, ".log"));
// The class LaTeX does not know the temp path.
bufferlist.updateIncludedTeXfiles(GetCWD());
lyxerr[Debug::LATEX] << "Building program" << endl;
minib->Set(string(_("Building program")));
minib->Store();
// Run the build program
//
tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
tmp2 = build_filter + " < " + litfile + ".out" + " > " + logfile;
ret1 = one.startscript(Systemcalls::System, tmp1);
ret2 = two.startscript(Systemcalls::System, tmp2);
scanres = scanLogFile(terr);
lyxerr[Debug::LATEX] << "Done." << endl;
return scanres;
}