]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
include shuffling and a mathed compile fix
[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/syscall.h"
29 #include "support/syscontr.h"
30 #include "support/path.h"
31 #include "support/lstrings.h"
32
33 #include <fstream>
34
35 using std::ifstream;
36 using std::getline;
37
38 /*
39  * CLASS Chktex
40  */
41
42 Chktex::Chktex(string const & chktex, string const & f, string const & p)
43                 : cmd(chktex), file(f), path(p)
44 {
45 }
46
47
48 int Chktex::run(TeXErrors &terr)
49 {
50         // run bibtex
51         string log = OnlyFilename(ChangeExtension(file, ".log"));
52         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
53         Systemcalls one;
54         int result= one.startscript(Systemcalls::System, tmp);
55         if (result == 0) {
56                 result = scanLogFile(terr);
57         } else {
58                 result = -1;
59         }
60         return result;
61 }
62
63
64 int Chktex::scanLogFile(TeXErrors & terr)
65 {
66         string token;
67         int retval = 0;
68
69         string tmp = OnlyFilename(ChangeExtension(file, ".log"));
70
71         ifstream ifs(tmp.c_str());
72         while (getline(ifs, token)) {
73                 string srcfile;
74                 string line;
75                 string pos;
76                 string warno;
77                 string warning;
78                 token = split(token, srcfile, ':');
79                 token = split(token, line, ':');
80                 token = split(token, pos, ':');
81                 token = split(token, warno, ':');
82                 token = split(token, warning, ':');
83
84                 int lineno = lyx::atoi(line);
85                 warno = _("ChkTeX warning id #") + warno;
86                 terr.insertError(lineno, warno, warning);
87                 ++retval;
88         }
89         return retval;
90 }