1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich
6 * Copyright 1995-1999 The LyX Team.
8 * ======================================================
17 #pragma implementation
20 #include "support/filetools.h"
24 #include "support/FileInfo.h"
26 #include "support/lyxlib.h"
27 #include "support/syscall.h"
28 #include "support/syscontr.h"
29 #include "support/path.h"
30 #include "bufferlist.h"
31 #include "minibuffer.h"
34 extern BufferList bufferlist;
36 Literate::Literate(string const & latex, string const & f, string const & p,
38 string const & literate, string const & literate_f,
39 string const & build, string const & build_f)
40 : LaTeX (latex, f, p),
42 literate_cmd(literate), literate_filter(literate_f),
43 build_cmd(build), build_filter(build_f)
48 int Literate::weave(TeXErrors &terr, MiniBuffer *minib)
50 int scanres = Literate::NO_ERRORS;
55 // The class LaTeX does not know the temp path.
56 bufferlist.updateIncludedTeXfiles(GetCWD());
58 lyxerr[Debug::LATEX] << "Weaving document" << endl;
59 minib->Set(string(_("Weaving document")));
62 // Run the literate program to convert \literate_extension file to .tex file
64 tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
65 tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
66 ret1 = one.startscript(Systemcalls::System, tmp1);
67 ret2 = two.startscript(Systemcalls::System, tmp2);
68 lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
69 scanres = scanLiterateLogFile(terr);
70 if (scanres & Literate::ERRORS) return scanres; // return on literate error
72 return run(terr, minib);
76 int Literate::build(TeXErrors &terr, MiniBuffer *minib)
77 // We know that this function will only be run if the lyx buffer
80 int scanres = Literate::NO_ERRORS;
81 num_errors = 0; // just to make sure.
82 // DepTable head; // empty head // unused
83 // bool rerun = false; // rerun requested // unused
88 // The class LaTeX does not know the temp path.
89 bufferlist.updateIncludedTeXfiles(GetCWD());
91 lyxerr[Debug::LATEX] << "Building program" << endl;
92 minib->Set(string(_("Building program")));
95 // Run the build program
97 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
98 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
99 ret1 = one.startscript(Systemcalls::System, tmp1);
100 ret2 = two.startscript(Systemcalls::System, tmp2);
101 scanres = scanBuildLogFile(terr);
102 lyxerr[Debug::LATEX] << "Done." << endl;
108 int Literate::scanLiterateLogFile(TeXErrors &terr)
111 int retval = NO_ERRORS;
115 string tmp = litfile + ".log";
117 if (!lex.setFile(tmp)) {
118 // unable to open file
120 retval |= NO_LOGFILE;
126 token = lex.GetString();
127 else // blank line in the file being read
130 lyxerr[Debug::LATEX] << token << endl;
132 if (prefixIs(token, "Build Warning:")) {
133 // Here shall we handle different
135 retval |= LATEX_WARNING;
136 lyxerr[Debug::LATEX] << "Build Warning." << endl;
137 } else if (prefixIs(token, "! Build Error:")) {
138 // Here shall we handle different
140 retval |= LATEX_ERROR;
141 lyxerr[Debug::LATEX] << "Build Error." << endl;
142 // this is not correct yet
151 int Literate::scanBuildLogFile(TeXErrors &terr)
154 int retval = NO_ERRORS;
158 string tmp = litfile + ".log";
160 if (!lex.setFile(tmp)) {
161 // unable to open file
163 retval |= NO_LOGFILE;
169 token = lex.GetString();
170 else // blank line in the file being read
173 lyxerr[Debug::LATEX] << token << endl;
175 if (prefixIs(token, "Build Warning:")) {
176 // Here shall we handle different
178 retval |= LATEX_WARNING;
179 lyxerr[Debug::LATEX] << "Build Warning." << endl;
180 } else if (prefixIs(token, "! Build Error:")) {
181 // Here shall we handle different
183 retval |= LATEX_ERROR;
184 lyxerr[Debug::LATEX] << "Build Error." << endl;
185 // this is not correct yet