]> git.lyx.org Git - lyx.git/blob - src/Chktex.cpp
avoid float-conversion warning and simplify size computation
[lyx.git] / src / Chktex.cpp
1 /**
2  * \file Chktex.cpp
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
15 #include "LaTeX.h" // TeXErrors
16
17 #include "support/convert.h"
18 #include "support/docstream.h"
19 #include "support/filetools.h"
20 #include "support/gettext.h"
21 #include "support/lstrings.h"
22 #include "support/Systemcall.h"
23
24 #include <boost/format.hpp>
25
26 using namespace std;
27 using namespace lyx::support;
28
29 namespace lyx {
30
31
32 Chktex::Chktex(string const & chktex, string const & f, string const & p)
33                 : cmd(chktex), file(f), path(p)
34 {}
35
36
37 int Chktex::run(TeXErrors &terr)
38 {
39         // run bibtex
40         string log = onlyFileName(changeExtension(file, ".log"));
41         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
42         Systemcall one;
43         int result = one.startscript(Systemcall::Wait, tmp);
44         if (result == 0) {
45                 result = scanLogFile(terr);
46         } else {
47                 result = -1;
48         }
49         return result;
50 }
51
52
53 int Chktex::scanLogFile(TeXErrors & terr)
54 {
55         int retval = 0;
56
57         // FIXME: Find out whether onlyFileName() is really needed,
58         // or whether makeAbsPath(onlyFileName()) is a noop here
59         FileName const tmp(makeAbsPath(onlyFileName(changeExtension(file, ".log"))));
60
61 #if USE_BOOST_FORMAT
62         boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
63 #else
64         docstring const msg(_("ChkTeX warning id # "));
65 #endif
66         docstring token;
67         // FIXME UNICODE
68         // We have no idea what the encoding of the error file is
69         ifdocstream ifs(tmp.toFilesystemEncoding().c_str());
70         while (getline(ifs, token)) {
71                 docstring srcfile;
72                 docstring line;
73                 docstring pos;
74                 docstring warno;
75                 docstring warning;
76                 token = split(token, srcfile, ':');
77                 token = split(token, line, ':');
78                 token = split(token, pos, ':');
79                 token = split(token, warno, ':');
80                 token = split(token, warning, ':');
81
82                 int const lineno = convert<int>(line);
83
84 #if USE_BOOST_FORMAT
85                 msg % warno;
86                 terr.insertError(lineno, msg.str(), warning);
87                 msg.clear();
88 #else
89                 terr.insertError(lineno, msg + warno, warning);
90 #endif
91
92                 ++retval;
93         }
94         return retval;
95 }
96
97
98 } // namespace lyx