This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / Chktex.C
blobf4f9cf22da5b0052fce3e303fbd216030be4aad4
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  */
14 #include <config.h>
16 #include <cstdlib> // atoi
18 #ifdef __GNUG__
19 #pragma implementation
20 #endif
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"
34  * CLASS Chktex
35  */
37 Chktex::Chktex(string const & chktex, string const & f, string const & p)
38                 : cmd(chktex), file(f), path(p)
43 int Chktex::run(TeXErrors &terr)
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;
59 int Chktex::scanLogFile(TeXErrors &terr)
61         string token;
62         int retval = 0;
64         string tmp = ChangeExtension(file, ".log", true);
66         ifstream ifs(tmp.c_str());
67         while (getline(ifs, token)) {
68                 string srcfile, line, pos, warno, warning;
69                 token = split(token, srcfile, ':');
70                 token = split(token, line, ':');
71                 token = split(token, pos, ':');
72                 token = split(token, warno, ':');
73                 token = split(token, warning, ':');
75                 int lineno = atoi(line.c_str());
76                 warno = _("ChkTeX warning id #") + warno;
77                 terr.insertError(lineno, warno, warning);
78                 ++retval;
79         }
80         return retval;