Not so soon, I guess, since that FIXME was from r6305.
[lyx.git] / src / Chktex.cpp
blob8683203d3b040b959aaf11244972a9932066a991
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.
6 * \author Asger Alstrup
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "Chktex.h"
15 #include "LaTeX.h" // TeXErrors
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"
24 #include <boost/format.hpp>
26 using namespace std;
27 using namespace lyx::support;
29 namespace lyx {
32 Chktex::Chktex(string const & chktex, string const & f, string const & p)
33 : cmd(chktex), file(f), path(p)
38 int Chktex::run(TeXErrors &terr)
40 // run bibtex
41 string log = onlyFilename(changeExtension(file, ".log"));
42 string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
43 Systemcall one;
44 int result = one.startscript(Systemcall::Wait, tmp);
45 if (result == 0) {
46 result = scanLogFile(terr);
47 } else {
48 result = -1;
50 return result;
54 int Chktex::scanLogFile(TeXErrors & terr)
56 int retval = 0;
58 // FIXME: Find out whether onlyFilename() is really needed,
59 // or whether makeAbsPath(onlyFilename()) is a noop here
60 FileName const tmp(makeAbsPath(onlyFilename(changeExtension(file, ".log"))));
62 #if USE_BOOST_FORMAT
63 boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
64 #else
65 docstring const msg(_("ChkTeX warning id # "));
66 #endif
67 docstring token;
68 // FIXME UNICODE
69 // We have no idea what the encoding of the error file is
70 ifdocstream ifs(tmp.toFilesystemEncoding().c_str());
71 while (getline(ifs, token)) {
72 docstring srcfile;
73 docstring line;
74 docstring pos;
75 docstring warno;
76 docstring warning;
77 token = split(token, srcfile, ':');
78 token = split(token, line, ':');
79 token = split(token, pos, ':');
80 token = split(token, warno, ':');
81 token = split(token, warning, ':');
83 int const lineno = convert<int>(line);
85 #if USE_BOOST_FORMAT
86 msg % warno;
87 terr.insertError(lineno, msg.str(), warning);
88 msg.clear();
89 #else
90 terr.insertError(lineno, msg + warno, warning);
91 #endif
93 ++retval;
95 return retval;
99 } // namespace lyx