]> git.lyx.org Git - lyx.git/blob - src/Literate.C
make text private in LyXParagraph some changes to import ascii file
[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
33 extern BufferList bufferlist;
34
35 Literate::Literate(string const & latex, string const & f, string const & p, 
36                    string const & l, 
37                    string const & literate, string const & literate_f, 
38                    string const & build, string const & build_f)
39                    : LaTeX(latex, f, p),
40                      litfile(l),
41                      literate_cmd(literate), literate_filter(literate_f), 
42                      build_cmd(build), build_filter(build_f)
43 {}
44
45
46 int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
47 {
48         int scanres = Literate::NO_ERRORS;
49         string tmp1, tmp2;
50         int ret1, ret2;
51         Systemcalls one, two;
52
53         // The class LaTeX does not know the temp path.
54         bufferlist.updateIncludedTeXfiles(GetCWD());
55         
56         lyxerr[Debug::LATEX] << "Weaving document" << endl;
57         minib->Set(string(_("Weaving document")));
58         minib->Store();
59
60         // Run the literate program to convert \literate_extension file to .tex file
61         //
62         tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
63         tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
64         ret1 = one.startscript(Systemcalls::System, tmp1);
65         ret2 = two.startscript(Systemcalls::System, tmp2);
66         lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
67         scanres = scanLiterateLogFile();
68         if (scanres & Literate::ERRORS) return scanres; // return on literate error
69         return run(terr, minib);
70 }
71
72
73 int Literate::build(TeXErrors & /*terr*/, MiniBuffer * minib)
74         // We know that this function will only be run if the lyx buffer
75         // has been changed. 
76 {
77         int scanres = Literate::NO_ERRORS;
78         num_errors = 0; // just to make sure.
79         string tmp1, tmp2;
80         int ret1, ret2;
81         Systemcalls one, two;
82         
83         // The class LaTeX does not know the temp path.
84         bufferlist.updateIncludedTeXfiles(GetCWD());
85         
86         lyxerr[Debug::LATEX] << "Building program" << endl;
87         minib->Set(string(_("Building program")));
88         minib->Store();
89
90         // Run the build program
91         //
92         tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
93         tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
94         ret1 = one.startscript(Systemcalls::System, tmp1);
95         ret2 = two.startscript(Systemcalls::System, tmp2);
96         scanres = scanBuildLogFile();
97         lyxerr[Debug::LATEX] << "Done." << endl;
98
99         return scanres;
100 }
101
102
103 int Literate::scanLiterateLogFile()
104 {
105         string token;
106         int retval = NO_ERRORS;
107         
108         string tmp = litfile + ".log";
109         
110         ifstream ifs(tmp.c_str());
111         while (getline(ifs, token)) {
112                 lyxerr[Debug::LATEX] << token << endl;
113                 
114                 if (prefixIs(token, "Build Warning:")) {
115                         // Here shall we handle different
116                         // types of warnings
117                         retval |= LATEX_WARNING;
118                         lyxerr[Debug::LATEX] << "Build Warning." << endl;
119                 } else if (prefixIs(token, "! Build Error:")) {
120                         // Here shall we handle different
121                         // types of errors
122                         retval |= LATEX_ERROR;
123                         lyxerr[Debug::LATEX] << "Build Error." << endl;
124                         // this is not correct yet
125                         ++num_errors;
126                 }
127         }       
128         return retval;
129 }
130
131
132 int Literate::scanBuildLogFile()
133 {
134         string token;
135         int retval = NO_ERRORS;
136  
137         string tmp = litfile + ".log";
138         
139         ifstream ifs(tmp.c_str());
140         while (getline(ifs, token)) {
141                 lyxerr[Debug::LATEX] << token << endl;
142                 
143                 if (prefixIs(token, "Build Warning:")) {
144                         // Here shall we handle different
145                         // types of warnings
146                         retval |= LATEX_WARNING;
147                         lyxerr[Debug::LATEX] << "Build Warning." << endl;
148                 } else if (prefixIs(token, "! Build Error:")) {
149                         // Here shall we handle different
150                         // types of errors
151                         retval |= LATEX_ERROR;
152                         lyxerr[Debug::LATEX] << "Build Error." << endl;
153                         // this is not correct yet
154                         ++num_errors;
155                 }
156         }       
157         return retval;
158 }