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"
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)
42 literate_cmd(literate), literate_filter(literate_f),
43 build_cmd(build), build_filter(build_f)
47 int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
49 int scanres = Literate::NO_ERRORS;
54 // The class LaTeX does not know the temp path.
55 bufferlist.updateIncludedTeXfiles(GetCWD());
57 lyxerr[Debug::LATEX] << "Weaving document" << endl;
58 minib->Set(string(_("Weaving document")));
61 // Run the literate program to convert \literate_extension file to .tex file
63 tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
64 tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
65 ret1 = one.startscript(Systemcalls::System, tmp1);
66 ret2 = two.startscript(Systemcalls::System, tmp2);
67 lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
68 scanres = scanLiterateLogFile();
69 if (scanres & Literate::ERRORS) return scanres; // return on literate error
70 return run(terr, minib);
74 int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib)
75 // We know that this function will only be run if the lyx buffer
78 int scanres = Literate::NO_ERRORS;
79 num_errors = 0; // just to make sure.
84 // The class LaTeX does not know the temp path.
85 bufferlist.updateIncludedTeXfiles(GetCWD());
87 lyxerr[Debug::LATEX] << "Building program" << endl;
88 minib->Set(string(_("Building program")));
91 // Run the build program
93 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
94 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
95 ret1 = one.startscript(Systemcalls::System, tmp1);
96 ret2 = two.startscript(Systemcalls::System, tmp2);
97 scanres = scanBuildLogFile();
98 lyxerr[Debug::LATEX] << "Done." << endl;
104 int Literate::scanLiterateLogFile()
107 int retval = NO_ERRORS;
109 string tmp = litfile + ".log";
111 ifstream ifs(tmp.c_str());
112 while (getline(ifs, token)) {
113 lyxerr[Debug::LATEX] << token << endl;
115 if (prefixIs(token, "Build Warning:")) {
116 // Here shall we handle different
118 retval |= LATEX_WARNING;
119 lyxerr[Debug::LATEX] << "Build Warning." << endl;
120 } else if (prefixIs(token, "! Build Error:")) {
121 // Here shall we handle different
123 retval |= LATEX_ERROR;
124 lyxerr[Debug::LATEX] << "Build Error." << endl;
125 // this is not correct yet
133 int Literate::scanBuildLogFile()
136 int retval = NO_ERRORS;
138 string tmp = litfile + ".log";
140 ifstream ifs(tmp.c_str());
141 while (getline(ifs, token)) {
142 lyxerr[Debug::LATEX] << token << endl;
144 if (prefixIs(token, "Build Warning:")) {
145 // Here shall we handle different
147 retval |= LATEX_WARNING;
148 lyxerr[Debug::LATEX] << "Build Warning." << endl;
149 } else if (prefixIs(token, "! Build Error:")) {
150 // Here shall we handle different
152 retval |= LATEX_ERROR;
153 lyxerr[Debug::LATEX] << "Build Error." << endl;
154 // this is not correct yet