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"
25 using namespace lyx::support;
30 Chktex::Chktex(string const & chktex, string const & f, string const & p)
31 : cmd(chktex), file(f), path(p)
35 int Chktex::run(TeXErrors &terr)
38 string log = onlyFileName(changeExtension(file, ".log"));
39 string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
41 int result = one.startscript(Systemcall::Wait, tmp);
43 result = scanLogFile(terr);
51 int Chktex::scanLogFile(TeXErrors & terr)
55 // FIXME: Find out whether onlyFileName() is really needed,
56 // or whether makeAbsPath(onlyFileName()) is a noop here
57 FileName const tmp(makeAbsPath(onlyFileName(changeExtension(file, ".log"))));
59 docstring const msg(_("ChkTeX warning id # %1$s"));
62 // We have no idea what the encoding of the error file is
63 ifdocstream ifs(tmp.toFilesystemEncoding().c_str());
64 while (getline(ifs, token)) {
70 token = split(token, srcfile, ':');
71 token = split(token, line, ':');
72 token = split(token, pos, ':');
73 token = split(token, warno, ':');
74 token = split(token, warning, ':');
76 int const lineno = convert<int>(line);
78 terr.insertError(lineno, bformat(msg, warno), warning);