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/filetools.h"
20 #include "support/lstrings.h"
21 #include "support/systemcall.h"
23 #include <boost/format.hpp>
30 using support::changeExtension;
31 using support::onlyFilename;
33 using support::Systemcall;
40 Chktex::Chktex(string const & chktex, string const & f, string const & p)
41 : cmd(chktex), file(f), path(p)
46 int Chktex::run(TeXErrors &terr)
49 string log = onlyFilename(changeExtension(file, ".log"));
50 string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
52 int result = one.startscript(Systemcall::Wait, tmp);
54 result = scanLogFile(terr);
62 int Chktex::scanLogFile(TeXErrors & terr)
67 string const tmp = onlyFilename(changeExtension(file, ".log"));
70 boost::format msg(to_utf8(_("ChkTeX warning id # %1$d")));
72 string const msg(to_utf8(_("ChkTeX warning id # ")));
74 ifstream ifs(tmp.c_str());
75 while (getline(ifs, token)) {
81 token = split(token, srcfile, ':');
82 token = split(token, line, ':');
83 token = split(token, pos, ':');
84 token = split(token, warno, ':');
85 token = split(token, warning, ':');
87 int const lineno = convert<int>(line);
91 terr.insertError(lineno, msg.str(), warning);
94 terr.insertError(lineno, msg + warno, warning);