]> git.lyx.org Git - lyx.git/blob - src/Chktex.cpp
Rename the minted 'lang' external template option as 'language'
[lyx.git] / src / Chktex.cpp
1 /**
2  * \file Chktex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Chktex.h"
14
15 #include "LaTeX.h" // TeXErrors
16
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"
23
24 using namespace std;
25 using namespace lyx::support;
26
27 namespace lyx {
28
29
30 Chktex::Chktex(string const & chktex, string const & f, string const & p)
31                 : cmd(chktex), file(f), path(p)
32 {}
33
34
35 int Chktex::run(TeXErrors &terr)
36 {
37         // run bibtex
38         string log = onlyFileName(changeExtension(file, ".log"));
39         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
40         Systemcall one;
41         int result = one.startscript(Systemcall::Wait, tmp);
42         if (result == 0) {
43                 result = scanLogFile(terr);
44         } else {
45                 result = -1;
46         }
47         return result;
48 }
49
50
51 int Chktex::scanLogFile(TeXErrors & terr)
52 {
53         int retval = 0;
54
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"))));
58
59         docstring const msg(_("ChkTeX warning id # %1$s"));
60         docstring token;
61         // FIXME UNICODE
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)) {
65                 docstring srcfile;
66                 docstring line;
67                 docstring pos;
68                 docstring warno;
69                 docstring warning;
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, ':');
75
76                 int const lineno = convert<int>(line);
77
78                 terr.insertError(lineno, bformat(msg, warno), warning);
79
80                 ++retval;
81         }
82         return retval;
83 }
84
85
86 } // namespace lyx