]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
fix the smallcaps drawing, move xfont metrics functions out from LyXFont, move non...
[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-2000 The LyX Team.
7  *
8  *           This file is Copyright 1997-1998
9  *           Asger Alstrup
10  *
11  * ====================================================== 
12  */
13
14 #include <config.h>
15
16 #include <fstream>
17 #include <cstdlib> // atoi
18
19 #ifdef __GNUG__
20 #pragma implementation
21 #endif
22
23 #include "Chktex.h"
24 #include "LaTeX.h" // TeXErrors
25 #include "support/filetools.h"
26 #include "lyxlex.h"
27 #include "support/FileInfo.h"
28 #include "debug.h"
29 #include "support/syscall.h"
30 #include "support/syscontr.h"
31 #include "support/path.h"
32 #include "gettext.h"
33
34 using std::ifstream;
35
36 /*
37  * CLASS Chktex
38  */
39
40 Chktex::Chktex(string const & chktex, string const & f, string const & p)
41                 : cmd(chktex), file(f), path(p)
42 {
43 }
44
45
46 int Chktex::run(TeXErrors &terr)
47 {
48         // run bibtex
49         string log = ChangeExtension(file, ".log", true);
50         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
51         Systemcalls one;
52         int result= one.startscript(Systemcalls::System, tmp);
53         if (result == 0) {
54                 result = scanLogFile(terr);
55         } else {
56                 result = -1;
57         }
58         return result;
59 }
60
61
62 int Chktex::scanLogFile(TeXErrors & terr)
63 {
64         string token;
65         int retval = 0;
66
67         string tmp = ChangeExtension(file, ".log", true);
68
69         ifstream ifs(tmp.c_str());
70         while (getline(ifs, token)) {
71                 string srcfile, line, pos, warno, warning;
72                 token = split(token, srcfile, ':');
73                 token = split(token, line, ':');
74                 token = split(token, pos, ':');
75                 token = split(token, warno, ':');
76                 token = split(token, warning, ':');
77
78                 int lineno = atoi(line.c_str());
79                 warno = _("ChkTeX warning id #") + warno;
80                 terr.insertError(lineno, warno, warning);
81                 ++retval;
82         }
83         return retval;
84 }