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"
35 extern BufferList bufferlist;
37 Literate::Literate(string const & latex, string const & f, string const & p,
39 string const & literate, string const & literate_f,
40 string const & build, string const & build_f)
43 literate_cmd(literate), literate_filter(literate_f),
44 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();
70 if (scanres & Literate::ERRORS) return scanres; // return on literate error
71 return run(terr, minib);
75 int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib)
76 // We know that this function will only be run if the lyx buffer
79 int scanres = Literate::NO_ERRORS;
80 num_errors = 0; // just to make sure.
85 // The class LaTeX does not know the temp path.
86 bufferlist.updateIncludedTeXfiles(GetCWD());
88 lyxerr[Debug::LATEX] << "Building program" << endl;
89 minib->Set(string(_("Building program")));
92 // Run the build program
94 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
95 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
96 ret1 = one.startscript(Systemcalls::System, tmp1);
97 ret2 = two.startscript(Systemcalls::System, tmp2);
98 scanres = scanBuildLogFile();
99 lyxerr[Debug::LATEX] << "Done." << endl;
105 int Literate::scanLiterateLogFile()
108 int retval = NO_ERRORS;
110 string tmp = litfile + ".log";
112 ifstream ifs(tmp.c_str());
113 while (getline(ifs, token)) {
114 lyxerr[Debug::LATEX] << token << endl;
116 if (prefixIs(token, "Build Warning:")) {
117 // Here shall we handle different
119 retval |= LATEX_WARNING;
120 lyxerr[Debug::LATEX] << "Build Warning." << endl;
121 } else if (prefixIs(token, "! Build Error:")) {
122 // Here shall we handle different
124 retval |= LATEX_ERROR;
125 lyxerr[Debug::LATEX] << "Build Error." << endl;
126 // this is not correct yet
134 int Literate::scanBuildLogFile()
137 int retval = NO_ERRORS;
139 string tmp = litfile + ".log";
141 ifstream ifs(tmp.c_str());
142 while (getline(ifs, token)) {
143 lyxerr[Debug::LATEX] << token << endl;
145 if (prefixIs(token, "Build Warning:")) {
146 // Here shall we handle different
148 retval |= LATEX_WARNING;
149 lyxerr[Debug::LATEX] << "Build Warning." << endl;
150 } else if (prefixIs(token, "! Build Error:")) {
151 // Here shall we handle different
153 retval |= LATEX_ERROR;
154 lyxerr[Debug::LATEX] << "Build Error." << endl;
155 // this is not correct yet