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