]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
Move #include "lyxlib.h" out of Path.h, move ctor, dtor out of line.
[lyx.git] / src / Chktex.C
1 /**
2  * \file Chktex.C
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 #include "LaTeX.h" // TeXErrors
15 #include "lyxlex.h"
16 #include "debug.h"
17 #include "gettext.h"
18
19 #include "support/FileInfo.h"
20 #include "support/filetools.h"
21 #include "support/lstrings.h"
22 #include "support/lyxlib.h"
23 #include "support/path.h"
24 #include "support/systemcall.h"
25
26 #include "support/BoostFormat.h"
27
28 #include <fstream>
29
30 using namespace lyx::support;
31
32 using std::ifstream;
33 using std::getline;
34
35
36 Chktex::Chktex(string const & chktex, string const & f, string const & p)
37                 : cmd(chktex), file(f), path(p)
38 {
39 }
40
41
42 int Chktex::run(TeXErrors &terr)
43 {
44         // run bibtex
45         string log = OnlyFilename(ChangeExtension(file, ".log"));
46         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
47         Systemcall one;
48         int result = one.startscript(Systemcall::Wait, tmp);
49         if (result == 0) {
50                 result = scanLogFile(terr);
51         } else {
52                 result = -1;
53         }
54         return result;
55 }
56
57
58 int Chktex::scanLogFile(TeXErrors & terr)
59 {
60         string token;
61         int retval = 0;
62
63         string const tmp = OnlyFilename(ChangeExtension(file, ".log"));
64
65 #if USE_BOOST_FORMAT
66         boost::format msg(STRCONV(_("ChkTeX warning id # %1$d")));
67 #else
68         string const msg(_("ChkTeX warning id # "));
69 #endif
70         ifstream ifs(tmp.c_str());
71         while (getline(ifs, token)) {
72                 string srcfile;
73                 string line;
74                 string pos;
75                 string warno;
76                 string warning;
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, ':');
82
83                 int const lineno = atoi(line);
84
85 #if USE_BOOST_FORMAT
86                 msg % warno;
87                 terr.insertError(lineno, STRCONV(msg.str()), warning);
88                 msg.clear();
89 #else
90                 terr.insertError(lineno, msg + warno, warning);
91 #endif
92
93                 ++retval;
94         }
95         return retval;
96 }