]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
hopefully fix tex2lyx linking.
[lyx.git] / src / Chktex.C
1 /**
2  * \file Chktex.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Chktex.h"
14 #include "gettext.h"
15
16 #include "LaTeX.h" // TeXErrors
17
18 #include "support/convert.h"
19 #include "support/docstream.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "support/systemcall.h"
23
24 #include <boost/format.hpp>
25
26
27 namespace lyx {
28
29 using support::changeExtension;
30 using support::onlyFilename;
31 using support::split;
32 using support::Systemcall;
33
34 using std::getline;
35 using std::string;
36 using std::ifstream;
37
38
39 Chktex::Chktex(string const & chktex, string const & f, string const & p)
40                 : cmd(chktex), file(f), path(p)
41 {
42 }
43
44
45 int Chktex::run(TeXErrors &terr)
46 {
47         // run bibtex
48         string log = onlyFilename(changeExtension(file, ".log"));
49         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
50         Systemcall one;
51         int result = one.startscript(Systemcall::Wait, tmp);
52         if (result == 0) {
53                 result = scanLogFile(terr);
54         } else {
55                 result = -1;
56         }
57         return result;
58 }
59
60
61 int Chktex::scanLogFile(TeXErrors & terr)
62 {
63         int retval = 0;
64
65         string const tmp = onlyFilename(changeExtension(file, ".log"));
66
67 #if USE_BOOST_FORMAT
68         boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
69 #else
70         docstring const msg(_("ChkTeX warning id # "));
71 #endif
72         docstring token;
73         // FIXME UNICODE
74         // We have no idea what the encoding of the error file is
75         idocfstream ifs(tmp.c_str());
76         while (getline(ifs, token)) {
77                 docstring srcfile;
78                 docstring line;
79                 docstring pos;
80                 docstring warno;
81                 docstring warning;
82                 token = split(token, srcfile, ':');
83                 token = split(token, line, ':');
84                 token = split(token, pos, ':');
85                 token = split(token, warno, ':');
86                 token = split(token, warning, ':');
87
88                 int const lineno = convert<int>(line);
89
90 #if USE_BOOST_FORMAT
91                 msg % warno;
92                 terr.insertError(lineno, msg.str(), warning);
93                 msg.clear();
94 #else
95                 terr.insertError(lineno, msg + warno, warning);
96 #endif
97
98                 ++retval;
99         }
100         return retval;
101 }
102
103
104 } // namespace lyx