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