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.
16 #include "LaTeX.h" // TeXErrors
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"
24 #include <boost/format.hpp>
29 using support::changeExtension;
30 using support::onlyFilename;
32 using support::Systemcall;
39 Chktex::Chktex(string const & chktex, string const & f, string const & p)
40 : cmd(chktex), file(f), path(p)
45 int Chktex::run(TeXErrors &terr)
48 string log = onlyFilename(changeExtension(file, ".log"));
49 string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
51 int result = one.startscript(Systemcall::Wait, tmp);
53 result = scanLogFile(terr);
61 int Chktex::scanLogFile(TeXErrors & terr)
65 string const tmp = onlyFilename(changeExtension(file, ".log"));
68 boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
70 docstring const msg(_("ChkTeX warning id # "));
74 // We have no idea what the encoding of the error file is
75 idocfstream ifs(tmp.c_str());
76 while (getline(ifs, token)) {
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, ':');
88 int const lineno = convert<int>(line);
92 terr.insertError(lineno, msg.str(), warning);
95 terr.insertError(lineno, msg + warno, warning);