]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
Remove the XOpenIM test as lyxlookup.C has been buried.
[lyx.git] / src / Chktex.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *           Copyright 1995 Matthias Ettrich
6  *           Copyright 1995-2001 The LyX Team.
7  *
8  *           This file is Copyright 1997-1998
9  *           Asger Alstrup
10  *
11  * ======================================================
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "Chktex.h"
21 #include "LaTeX.h" // TeXErrors
22 #include "lyxlex.h"
23 #include "debug.h"
24 #include "gettext.h"
25
26 #include "support/FileInfo.h"
27 #include "support/filetools.h"
28 #include "support/systemcall.h"
29 #include "support/path.h"
30 #include "support/lstrings.h"
31
32 #include "BoostFormat.h"
33
34 #include <fstream>
35
36 using std::ifstream;
37 using std::getline;
38
39 /*
40  * CLASS Chktex
41  */
42
43 Chktex::Chktex(string const & chktex, string const & f, string const & p)
44                 : cmd(chktex), file(f), path(p)
45 {
46 }
47
48
49 int Chktex::run(TeXErrors &terr)
50 {
51         // run bibtex
52         string log = OnlyFilename(ChangeExtension(file, ".log"));
53         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
54         Systemcall one;
55         int result= one.startscript(Systemcall::Wait, tmp);
56         if (result == 0) {
57                 result = scanLogFile(terr);
58         } else {
59                 result = -1;
60         }
61         return result;
62 }
63
64
65 int Chktex::scanLogFile(TeXErrors & terr)
66 {
67         string token;
68         int retval = 0;
69
70         string const tmp = OnlyFilename(ChangeExtension(file, ".log"));
71
72 #if USE_BOOST_FORMAT
73         boost::format msg(_("ChkTeX warning id # %1$d"));
74 #else
75         string const msg(_("ChkTeX warning id # "));
76 #endif
77         ifstream ifs(tmp.c_str());
78         while (getline(ifs, token)) {
79                 string srcfile;
80                 string line;
81                 string pos;
82                 string warno;
83                 string warning;
84                 token = split(token, srcfile, ':');
85                 token = split(token, line, ':');
86                 token = split(token, pos, ':');
87                 token = split(token, warno, ':');
88                 token = split(token, warning, ':');
89
90                 int const lineno = lyx::atoi(line);
91
92 #if USE_BOOST_FORMAT
93                 msg % warno;
94                 terr.insertError(lineno, msg.str(), warning);
95                 msg.clear();
96 #else
97                 terr.insertError(lineno, msg + warno, warning);
98 #endif
99
100                 ++retval;
101         }
102         return retval;
103 }