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 * ======================================================
14 #pragma implementation
17 #include "support/filetools.h"
20 #include "support/FileInfo.h"
22 #include "support/lyxlib.h"
23 #include "support/syscall.h"
24 #include "support/syscontr.h"
25 #include "support/path.h"
26 #include "bufferlist.h"
27 #include "minibuffer.h"
30 extern BufferList bufferlist;
32 Literate::Literate(string const & latex, string const & f, string const & p,
34 string const & literate, string const & literate_f,
35 string const & build, string const & build_f)
38 literate_cmd(literate), literate_filter(literate_f),
39 build_cmd(build), build_filter(build_f)
43 int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
45 int scanres = Literate::NO_ERRORS;
50 // The class LaTeX does not know the temp path.
51 bufferlist.updateIncludedTeXfiles(GetCWD());
53 lyxerr[Debug::LATEX] << "Weaving document" << endl;
54 minib->Set(string(_("Weaving document")));
57 // Run the literate program to convert \literate_extension file to .tex file
59 tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
60 tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
61 ret1 = one.startscript(Systemcalls::System, tmp1);
62 ret2 = two.startscript(Systemcalls::System, tmp2);
63 lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
64 scanres = scanLiterateLogFile();
65 if (scanres & Literate::ERRORS) return scanres; // return on literate error
66 return run(terr, minib);
70 int Literate::build(TeXErrors & terr, MiniBuffer * minib)
71 // We know that this function will only be run if the lyx buffer
74 int scanres = Literate::NO_ERRORS;
75 num_errors = 0; // just to make sure.
80 // The class LaTeX does not know the temp path.
81 bufferlist.updateIncludedTeXfiles(GetCWD());
83 lyxerr[Debug::LATEX] << "Building program" << endl;
84 minib->Set(string(_("Building program")));
87 // Run the build program
89 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
90 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
91 ret1 = one.startscript(Systemcalls::System, tmp1);
92 ret2 = two.startscript(Systemcalls::System, tmp2);
93 scanres = scanBuildLogFile();
94 lyxerr[Debug::LATEX] << "Done." << endl;
100 int Literate::scanLiterateLogFile()
103 int retval = NO_ERRORS;
105 string tmp = litfile + ".log";
107 ifstream ifs(tmp.c_str());
108 while (getline(ifs, token)) {
109 lyxerr[Debug::LATEX] << token << endl;
111 if (prefixIs(token, "Build Warning:")) {
112 // Here shall we handle different
114 retval |= LATEX_WARNING;
115 lyxerr[Debug::LATEX] << "Build Warning." << endl;
116 } else if (prefixIs(token, "! Build Error:")) {
117 // Here shall we handle different
119 retval |= LATEX_ERROR;
120 lyxerr[Debug::LATEX] << "Build Error." << endl;
121 // this is not correct yet
129 int Literate::scanBuildLogFile()
132 int retval = NO_ERRORS;
134 string tmp = litfile + ".log";
136 ifstream ifs(tmp.c_str());
137 while (getline(ifs, token)) {
138 lyxerr[Debug::LATEX] << token << endl;
140 if (prefixIs(token, "Build Warning:")) {
141 // Here shall we handle different
143 retval |= LATEX_WARNING;
144 lyxerr[Debug::LATEX] << "Build Warning." << endl;
145 } else if (prefixIs(token, "! Build Error:")) {
146 // Here shall we handle different
148 retval |= LATEX_ERROR;
149 lyxerr[Debug::LATEX] << "Build Error." << endl;
150 // this is not correct yet