]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
dc94696ace1b5a8317eee8d9a2b7a3c89ef74575
[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-1999 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 <cstdlib> // atoi
17
18 #ifdef __GNUG__
19 #pragma implementation
20 #endif
21
22 #include "Chktex.h"
23 #include "LaTeX.h" // TeXErrors
24 #include "support/filetools.h"
25 #include "lyxlex.h"
26 #include "support/FileInfo.h"
27 #include "debug.h"
28 #include "support/syscall.h"
29 #include "support/syscontr.h"
30 #include "support/path.h"
31 #include "gettext.h"
32
33 /*
34  * CLASS Chktex
35  */
36
37 Chktex::Chktex(string const & chktex, string const & f, string const & p)
38                 : cmd(chktex), file(f), path(p)
39 {
40 }
41
42
43 int Chktex::run(TeXErrors &terr)
44 {
45         // run bibtex
46         string log = ChangeExtension(file, ".log", true);
47         string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
48         Systemcalls one;
49         int result= one.startscript(Systemcalls::System, tmp);
50         if (result == 0) {
51                 result = scanLogFile(terr);
52         } else {
53                 result = -1;
54         }
55         return result;
56 }
57
58
59 int Chktex::scanLogFile(TeXErrors &terr)
60 {
61         string token;
62         int retval = 0;
63
64         LyXLex lex(0, 0);
65
66         string tmp = ChangeExtension(file, ".log", true);
67
68         if (!lex.setFile(tmp)) {
69                 // Unable to open file. Return at once
70                 return -1;
71         }
72
73         while (lex.IsOK()) {
74                 if (lex.EatLine())
75                         token = lex.GetString();
76                 else // blank line in the file being read
77                         continue;
78
79                 string srcfile, line, pos, warno, warning;
80                 token=split(token, srcfile, ':');
81                 token=split(token, line, ':');
82                 token=split(token, pos, ':');
83                 token=split(token, warno, ':');
84                 token=split(token, warning, ':');
85
86                 int lineno = atoi(line.c_str());
87                 warno = _("ChkTeX warning id #") + warno;
88                 terr.insertError(lineno, warno, warning);
89                 retval++;
90         }
91         return retval;
92 }