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