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.
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>
27 using namespace lyx::support;
32 Chktex::Chktex(string const & chktex, string const & f, string const & p)
33 : cmd(chktex), file(f), path(p)
37 int Chktex::run(TeXErrors &terr)
40 string log = onlyFileName(changeExtension(file, ".log"));
41 string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
43 int result = one.startscript(Systemcall::Wait, tmp);
45 result = scanLogFile(terr);
53 int Chktex::scanLogFile(TeXErrors & terr)
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"))));
62 boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
64 docstring const msg(_("ChkTeX warning id # "));
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)) {
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, ':');
82 int const lineno = convert<int>(line);
86 terr.insertError(lineno, msg.str(), warning);
89 terr.insertError(lineno, msg + warno, warning);