]> git.lyx.org Git - lyx.git/blob - src/Literate.C
white-space changes, removed definitions.h several enum changes because of this,...
[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-1999 The LyX Team.
7  *
8  * ====================================================== 
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "support/filetools.h"
18 #include "LaTeX.h"
19 #include "Literate.h"
20 #include "support/FileInfo.h"
21 #include "debug.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"
28 #include "gettext.h"
29
30 extern BufferList bufferlist;
31
32 Literate::Literate(string const & latex, string const & f, string const & p, 
33                    string const & l, 
34                    string const & literate, string const & literate_f, 
35                    string const & build, string const & build_f)
36                    : LaTeX(latex, f, p),
37                      litfile(l),
38                      literate_cmd(literate), literate_filter(literate_f), 
39                      build_cmd(build), build_filter(build_f)
40 {}
41
42
43 int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
44 {
45         int scanres = Literate::NO_ERRORS;
46         string tmp1, tmp2;
47         int ret1, ret2;
48         Systemcalls one, two;
49
50         // The class LaTeX does not know the temp path.
51         bufferlist.updateIncludedTeXfiles(GetCWD());
52         
53         lyxerr[Debug::LATEX] << "Weaving document" << endl;
54         minib->Set(string(_("Weaving document")));
55         minib->Store();
56
57         // Run the literate program to convert \literate_extension file to .tex file
58         //
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);
67 }
68
69
70 int Literate::build(TeXErrors & terr, MiniBuffer * minib)
71         // We know that this function will only be run if the lyx buffer
72         // has been changed. 
73 {
74         int scanres = Literate::NO_ERRORS;
75         num_errors = 0; // just to make sure.
76         string tmp1, tmp2;
77         int ret1, ret2;
78         Systemcalls one, two;
79         
80         // The class LaTeX does not know the temp path.
81         bufferlist.updateIncludedTeXfiles(GetCWD());
82         
83         lyxerr[Debug::LATEX] << "Building program" << endl;
84         minib->Set(string(_("Building program")));
85         minib->Store();
86
87         // Run the build program
88         //
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;
95
96         return scanres;
97 }
98
99
100 int Literate::scanLiterateLogFile()
101 {
102         string token;
103         int retval = NO_ERRORS;
104         
105         string tmp = litfile + ".log";
106         
107         ifstream ifs(tmp.c_str());
108         while (getline(ifs, token)) {
109                 lyxerr[Debug::LATEX] << token << endl;
110                 
111                 if (prefixIs(token, "Build Warning:")) {
112                         // Here shall we handle different
113                         // types of warnings
114                         retval |= LATEX_WARNING;
115                         lyxerr[Debug::LATEX] << "Build Warning." << endl;
116                 } else if (prefixIs(token, "! Build Error:")) {
117                         // Here shall we handle different
118                         // types of errors
119                         retval |= LATEX_ERROR;
120                         lyxerr[Debug::LATEX] << "Build Error." << endl;
121                         // this is not correct yet
122                         num_errors++;
123                 }
124         }       
125         return retval;
126 }
127
128
129 int Literate::scanBuildLogFile()
130 {
131         string token;
132         int retval = NO_ERRORS;
133  
134         string tmp = litfile + ".log";
135         
136         ifstream ifs(tmp.c_str());
137         while (getline(ifs, token)) {
138                 lyxerr[Debug::LATEX] << token << endl;
139                 
140                 if (prefixIs(token, "Build Warning:")) {
141                         // Here shall we handle different
142                         // types of warnings
143                         retval |= LATEX_WARNING;
144                         lyxerr[Debug::LATEX] << "Build Warning." << endl;
145                 } else if (prefixIs(token, "! Build Error:")) {
146                         // Here shall we handle different
147                         // types of errors
148                         retval |= LATEX_ERROR;
149                         lyxerr[Debug::LATEX] << "Build Error." << endl;
150                         // this is not correct yet
151                         num_errors++;
152                 }
153         }       
154         return retval;
155 }