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
)
38 int Chktex::run(TeXErrors
&terr
)
41 string log
= onlyFilename(changeExtension(file
, ".log"));
42 string tmp
= cmd
+ " -q -v0 -b0 -x " + file
+ " -o " + log
;
44 int result
= one
.startscript(Systemcall::Wait
, tmp
);
46 result
= scanLogFile(terr
);
54 int Chktex::scanLogFile(TeXErrors
& terr
)
58 // FIXME: Find out whether onlyFilename() is really needed,
59 // or whether makeAbsPath(onlyFilename()) is a noop here
60 FileName
const tmp(makeAbsPath(onlyFilename(changeExtension(file
, ".log"))));
63 boost::basic_format
<char_type
> msg(_("ChkTeX warning id # %1$d"));
65 docstring
const msg(_("ChkTeX warning id # "));
69 // We have no idea what the encoding of the error file is
70 ifdocstream
ifs(tmp
.toFilesystemEncoding().c_str());
71 while (getline(ifs
, token
)) {
77 token
= split(token
, srcfile
, ':');
78 token
= split(token
, line
, ':');
79 token
= split(token
, pos
, ':');
80 token
= split(token
, warno
, ':');
81 token
= split(token
, warning
, ':');
83 int const lineno
= convert
<int>(line
);
87 terr
.insertError(lineno
, msg
.str(), warning
);
90 terr
.insertError(lineno
, msg
+ warno
, warning
);