1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright (C) 1995 Matthias Ettrich
6 * Copyright (C) 1995-1998 The LyX Team.
8 * This file is Copyright (C) 1996-1998
11 *======================================================
20 #pragma implementation
23 #include "filetools.h"
32 #include "pathstack.h"
33 #include "bufferlist.h"
34 #include "minibuffer.h"
37 // $Id: Literate.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $
39 #if !defined(lint) && !defined(WITH_WARNINGS)
40 static char vcid[] = "$Id: Literate.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
43 extern BufferList bufferlist;
45 Literate::Literate(LString const & latex, LString const & f, LString const & p,
47 LString const & literate, LString const & literate_f,
48 LString const & build, LString const & build_f)
49 : LaTeX (latex, f, p),
51 literate_cmd(literate), literate_filter(literate_f),
52 build_cmd(build), build_filter(build_f)
57 int Literate::weave(TeXErrors &terr, MiniBuffer *minib)
59 int scanres = Literate::NO_ERRORS;
64 // The class LaTeX does not know the temp path.
65 bufferlist.updateIncludedTeXfiles(GetCWD());
67 lyxerr.debug(LString(_("Weaving document")),
69 minib->Set(LString(_("Weaving document")));
72 // Run the literate program to convert \literate_extension file to .tex file
74 tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
75 tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
76 ret1 = one.Startscript(Systemcalls::System, tmp1);
77 ret2 = two.Startscript(Systemcalls::System, tmp2);
78 lyxerr.debug(LString(_("LITERATE")) + " {" + tmp1 + "} {" + tmp2 + "}");
79 scanres = scanLiterateLogFile(terr);
80 if (scanres & Literate::ERRORS) return scanres; // return on literate error
82 return run(terr, minib);
86 int Literate::build(TeXErrors &terr, MiniBuffer *minib)
87 // We know that this function will only be run if the lyx buffer
90 int scanres = Literate::NO_ERRORS;
91 num_errors = 0; // just to make sure.
92 // DepTable head; // empty head // unused
93 // bool rerun = false; // rerun requested // unused
98 // The class LaTeX does not know the temp path.
99 bufferlist.updateIncludedTeXfiles(GetCWD());
101 lyxerr.debug(LString(_("Building program")),
103 minib->Set(LString(_("Building program")));
106 // Run the build program
108 tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
109 tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
110 ret1 = one.Startscript(Systemcalls::System, tmp1);
111 ret2 = two.Startscript(Systemcalls::System, tmp2);
112 scanres = scanBuildLogFile(terr);
113 lyxerr.debug("Done.", Error::LATEX);
119 int Literate::scanLiterateLogFile(TeXErrors &terr)
122 int retval = NO_ERRORS;
126 LString tmp = litfile + ".log";
128 if (!lex.setFile(tmp)) {
129 // unable to open file
131 retval |= NO_LOGFILE;
137 token = lex.GetString();
138 else // blank line in the file being read
141 lyxerr.debug(token, Error::LATEX);
143 if (token.prefixIs("Build Warning:")) {
144 // Here shall we handle different
146 retval |= LATEX_WARNING;
147 lyxerr.debug("Build Warning.", Error::LATEX);
148 } else if (token.prefixIs("! Build Error:")) {
149 // Here shall we handle different
151 retval |= LATEX_ERROR;
152 lyxerr.debug("Build Error.", Error::LATEX);
153 // this is not correct yet
162 int Literate::scanBuildLogFile(TeXErrors &terr)
165 int retval = NO_ERRORS;
169 LString tmp = litfile + ".log";
171 if (!lex.setFile(tmp)) {
172 // unable to open file
174 retval |= NO_LOGFILE;
180 token = lex.GetString();
181 else // blank line in the file being read
184 lyxerr.debug(token, Error::LATEX);
186 if (token.prefixIs("Build Warning:")) {
187 // Here shall we handle different
189 retval |= LATEX_WARNING;
190 lyxerr.debug("Build Warning.", Error::LATEX);
191 } else if (token.prefixIs("! Build Error:")) {
192 // Here shall we handle different
194 retval |= LATEX_ERROR;
195 lyxerr.debug("Build Error.", Error::LATEX);
196 // this is not correct yet