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);
42 // ChkTeX (as of v. 1.7.7) has the following return values:
43 // 0 = EXIT_SUCCESS : program ran successfully, nothing to report
44 // 1 = EXIT_FAILURE : program ran unsucessfully
45 // 2 = EXIT_WARNINGS : program ran successfully, only warnings to report
46 // 3 = EXIT_ERRORS : program ran successfully, errors to report
47 // We only check for EXIT_FAILURE here, since older versions of ChkTeX
48 // returned 0 also in case 2 and 3.
49 if (result == EXIT_FAILURE)
52 result = scanLogFile(terr);
57 int Chktex::scanLogFile(TeXErrors & terr)
61 // FIXME: Find out whether onlyFileName() is really needed,
62 // or whether makeAbsPath(onlyFileName()) is a noop here
63 FileName const tmp(makeAbsPath(onlyFileName(changeExtension(file, ".log"))));
65 docstring const msg(_("ChkTeX warning id # %1$s"));
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);
84 terr.insertError(lineno, bformat(msg, warno), warning);