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 "pathstack.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(string(_("Weaving document")),
60 minib->Set(string(_("Weaving document")));
63 // Run the literate program to convert \literate_extension file to .tex file
65 tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
66 tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
67 ret1 = one.Startscript(Systemcalls::System, tmp1);
68 ret2 = two.Startscript(Systemcalls::System, tmp2);
69 lyxerr.debug(string(_("LITERATE")) + " {" + tmp1 + "} {" + tmp2 + "}");
70 scanres = scanLiterateLogFile(terr);
71 if (scanres & Literate::ERRORS) return scanres; // return on literate error
73 return run(terr, minib);
77 int Literate::build(TeXErrors &terr, MiniBuffer *minib)
78 // We know that this function will only be run if the lyx buffer
81 int scanres = Literate::NO_ERRORS;
82 num_errors = 0; // just to make sure.
83 // DepTable head; // empty head // unused
84 // bool rerun = false; // rerun requested // unused
89 // The class LaTeX does not know the temp path.
90 bufferlist.updateIncludedTeXfiles(GetCWD());
92 lyxerr.debug(string(_("Building program")),
94 minib->Set(string(_("Building program")));
97 // Run the build program
99 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
100 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
101 ret1 = one.Startscript(Systemcalls::System, tmp1);
102 ret2 = two.Startscript(Systemcalls::System, tmp2);
103 scanres = scanBuildLogFile(terr);
104 lyxerr.debug("Done.", Error::LATEX);
110 int Literate::scanLiterateLogFile(TeXErrors &terr)
113 int retval = NO_ERRORS;
117 string tmp = litfile + ".log";
119 if (!lex.setFile(tmp)) {
120 // unable to open file
122 retval |= NO_LOGFILE;
128 token = lex.GetString();
129 else // blank line in the file being read
132 lyxerr.debug(token, Error::LATEX);
134 if (prefixIs(token, "Build Warning:")) {
135 // Here shall we handle different
137 retval |= LATEX_WARNING;
138 lyxerr.debug("Build Warning.", Error::LATEX);
139 } else if (prefixIs(token, "! Build Error:")) {
140 // Here shall we handle different
142 retval |= LATEX_ERROR;
143 lyxerr.debug("Build Error.", Error::LATEX);
144 // this is not correct yet
153 int Literate::scanBuildLogFile(TeXErrors &terr)
156 int retval = NO_ERRORS;
160 string tmp = litfile + ".log";
162 if (!lex.setFile(tmp)) {
163 // unable to open file
165 retval |= NO_LOGFILE;
171 token = lex.GetString();
172 else // blank line in the file being read
175 lyxerr.debug(token, Error::LATEX);
177 if (prefixIs(token, "Build Warning:")) {
178 // Here shall we handle different
180 retval |= LATEX_WARNING;
181 lyxerr.debug("Build Warning.", Error::LATEX);
182 } else if (prefixIs(token, "! Build Error:")) {
183 // Here shall we handle different
185 retval |= LATEX_ERROR;
186 lyxerr.debug("Build Error.", Error::LATEX);
187 // this is not correct yet