]> git.lyx.org Git - lyx.git/blob - src/Literate.C
small changes to ButtonController usage
[lyx.git] / src / Literate.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor         
5  *           Copyright 1995 Matthias Ettrich
6  *           Copyright 1995-2000 The LyX Team.
7  *
8  * ====================================================== 
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16 #include <fstream>
17
18 #include "support/filetools.h"
19 #include "LaTeX.h"
20 #include "Literate.h"
21 #include "support/FileInfo.h"
22 #include "debug.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"
29 #include "gettext.h"
30
31 using std::ifstream;
32 using std::getline;
33 using std::endl;
34
35 extern BufferList bufferlist;
36
37 Literate::Literate(string const & latex, string const & f, string const & p, 
38                    string const & l, 
39                    string const & literate, string const & literate_f, 
40                    string const & build, string const & build_f)
41                    : LaTeX(latex, f, p),
42                      litfile(l),
43                      literate_cmd(literate), literate_filter(literate_f), 
44                      build_cmd(build), build_filter(build_f)
45 {}
46
47
48 int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
49 {
50         int scanres = Literate::NO_ERRORS;
51         string tmp1, tmp2;
52         int ret1, ret2;
53         Systemcalls one, two;
54         string logfile = OnlyFilename(ChangeExtension(file, ".log"));
55
56         // The class LaTeX does not know the temp path.
57         bufferlist.updateIncludedTeXfiles(GetCWD());
58         
59         lyxerr[Debug::LATEX] << "Weaving document" << endl;
60         minib->Set(string(_("Weaving document")));
61         minib->Store();
62
63         // Run the literate program to convert \literate_extension file to .tex file
64         //
65         tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
66         tmp2 = literate_filter + " < " + litfile + ".out" + " > " + logfile;
67         ret1 = one.startscript(Systemcalls::System, tmp1);
68         ret2 = two.startscript(Systemcalls::System, tmp2);
69         lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
70
71         scanres = scanLogFile(terr);
72         if (scanres & Literate::ERRORS) return scanres; // return on literate error
73         return run(terr, minib);
74 }
75
76
77 int Literate::build(TeXErrors & terr, MiniBuffer * minib)
78         // We know that this function will only be run if the lyx buffer
79         // has been changed. 
80 {
81         int scanres = Literate::NO_ERRORS;
82         num_errors = 0; // just to make sure.
83         string tmp1, tmp2;
84         int ret1, ret2;
85         Systemcalls one, two;
86         string logfile = OnlyFilename(ChangeExtension(file, ".log"));
87
88         
89         // The class LaTeX does not know the temp path.
90         bufferlist.updateIncludedTeXfiles(GetCWD());
91         
92         lyxerr[Debug::LATEX] << "Building program" << endl;
93         minib->Set(string(_("Building program")));
94         minib->Store();
95
96         // Run the build program
97         //
98         tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
99         tmp2 = build_filter + " < " + litfile + ".out" + " > " + logfile;
100         ret1 = one.startscript(Systemcalls::System, tmp1);
101         ret2 = two.startscript(Systemcalls::System, tmp2);
102
103         scanres = scanLogFile(terr);
104         lyxerr[Debug::LATEX] << "Done." << endl;
105
106         return scanres;
107 }