1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich
6 * Copyright 1995-2000 The LyX Team.
8 * ======================================================
14 #pragma implementation
18 #include "support/filetools.h"
21 #include "support/FileInfo.h"
23 #include "support/lyxlib.h"
24 #include "support/syscall.h"
25 #include "support/syscontr.h"
26 #include "support/path.h"
27 #include "bufferlist.h"
28 #include "minibuffer.h"
33 extern BufferList bufferlist;
35 Literate::Literate(string const & latex, string const & f, string const & p,
37 string const & literate, string const & literate_f,
38 string const & build, string const & build_f)
41 literate_cmd(literate), literate_filter(literate_f),
42 build_cmd(build), build_filter(build_f)
46 int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
48 int scanres = Literate::NO_ERRORS;
53 // The class LaTeX does not know the temp path.
54 bufferlist.updateIncludedTeXfiles(GetCWD());
56 lyxerr[Debug::LATEX] << "Weaving document" << endl;
57 minib->Set(string(_("Weaving document")));
60 // Run the literate program to convert \literate_extension file to .tex file
62 tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
63 tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
64 ret1 = one.startscript(Systemcalls::System, tmp1);
65 ret2 = two.startscript(Systemcalls::System, tmp2);
66 lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
67 scanres = scanLiterateLogFile();
68 if (scanres & Literate::ERRORS) return scanres; // return on literate error
69 return run(terr, minib);
73 int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib)
74 // We know that this function will only be run if the lyx buffer
77 int scanres = Literate::NO_ERRORS;
78 num_errors = 0; // just to make sure.
83 // The class LaTeX does not know the temp path.
84 bufferlist.updateIncludedTeXfiles(GetCWD());
86 lyxerr[Debug::LATEX] << "Building program" << endl;
87 minib->Set(string(_("Building program")));
90 // Run the build program
92 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
93 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
94 ret1 = one.startscript(Systemcalls::System, tmp1);
95 ret2 = two.startscript(Systemcalls::System, tmp2);
96 scanres = scanBuildLogFile();
97 lyxerr[Debug::LATEX] << "Done." << endl;
103 int Literate::scanLiterateLogFile()
106 int retval = NO_ERRORS;
108 string tmp = litfile + ".log";
110 ifstream ifs(tmp.c_str());
111 while (getline(ifs, token)) {
112 lyxerr[Debug::LATEX] << token << endl;
114 if (prefixIs(token, "Build Warning:")) {
115 // Here shall we handle different
117 retval |= LATEX_WARNING;
118 lyxerr[Debug::LATEX] << "Build Warning." << endl;
119 } else if (prefixIs(token, "! Build Error:")) {
120 // Here shall we handle different
122 retval |= LATEX_ERROR;
123 lyxerr[Debug::LATEX] << "Build Error." << endl;
124 // this is not correct yet
132 int Literate::scanBuildLogFile()
135 int retval = NO_ERRORS;
137 string tmp = litfile + ".log";
139 ifstream ifs(tmp.c_str());
140 while (getline(ifs, token)) {
141 lyxerr[Debug::LATEX] << token << endl;
143 if (prefixIs(token, "Build Warning:")) {
144 // Here shall we handle different
146 retval |= LATEX_WARNING;
147 lyxerr[Debug::LATEX] << "Build Warning." << endl;
148 } else if (prefixIs(token, "! Build Error:")) {
149 // Here shall we handle different
151 retval |= LATEX_ERROR;
152 lyxerr[Debug::LATEX] << "Build Error." << endl;
153 // this is not correct yet