]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
fix a compiler warning regarding unused variable
[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::FileName;
31 using support::makeAbsPath;
32 using support::onlyFilename;
33 using support::split;
34 using support::Systemcall;
35
36 using std::getline;
37 using std::string;
38 using std::ifstream;
39
40
41 Chktex::Chktex(string const & chktex, string const & f, string const & p)
42                 : cmd(chktex), file(f), path(p)
43 {
44 }
45
46
47 int Chktex::run(TeXErrors &terr)
48 {
49         // run bibtex
50         string log = onlyFilename(changeExtension(file, ".log"));
51         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
52         Systemcall one;
53         int result = one.startscript(Systemcall::Wait, tmp);
54         if (result == 0) {
55                 result = scanLogFile(terr);
56         } else {
57                 result = -1;
58         }
59         return result;
60 }
61
62
63 int Chktex::scanLogFile(TeXErrors & terr)
64 {
65         int retval = 0;
66
67         // FIXME: Find out whether we can onlyFilename() is really needed,
68         // or whether makeAbsPath(onlyFilename()) is a noop here
69         FileName const tmp(makeAbsPath(onlyFilename(changeExtension(file, ".log"))));
70
71 #if USE_BOOST_FORMAT
72         boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
73 #else
74         docstring const msg(_("ChkTeX warning id # "));
75 #endif
76         docstring token;
77         // FIXME UNICODE
78         // We have no idea what the encoding of the error file is
79         idocfstream ifs(tmp.toFilesystemEncoding().c_str());
80         while (getline(ifs, token)) {
81                 docstring srcfile;
82                 docstring line;
83                 docstring pos;
84                 docstring warno;
85                 docstring warning;
86                 token = split(token, srcfile, ':');
87                 token = split(token, line, ':');
88                 token = split(token, pos, ':');
89                 token = split(token, warno, ':');
90                 token = split(token, warning, ':');
91
92                 int const lineno = convert<int>(line);
93
94 #if USE_BOOST_FORMAT
95                 msg % warno;
96                 terr.insertError(lineno, msg.str(), warning);
97                 msg.clear();
98 #else
99                 terr.insertError(lineno, msg + warno, warning);
100 #endif
101
102                 ++retval;
103         }
104         return retval;
105 }
106
107
108 } // namespace lyx