]> git.lyx.org Git - lyx.git/blob - src/Chktex.C
35c6ba5455104a9bcfebec568f80089860093ae5
[lyx.git] / src / Chktex.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor         
5  *           Copyright (C) 1995 Matthias Ettrich
6  *           Copyright (C) 1995-1998 The LyX Team.
7  *
8  *           This file is Copyright (C) 1997-1998
9  *           Asger Alstrup
10  *
11  *======================================================
12  */
13
14 #include <config.h>
15
16 #include <stdlib.h> // atoi
17
18 #ifdef __GNUG__
19 #pragma implementation
20 #endif
21
22 #include "Chktex.h"
23 #include "LaTeX.h" // TeXErrors
24 #include "filetools.h"
25 #include "lyxlex.h"
26 #include "FileInfo.h"
27 #include "error.h"
28 #include "syscall.h"
29 #include "syscontr.h"
30 #include "pathstack.h"
31 #include "gettext.h"
32
33 //      $Id: Chktex.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $    
34
35 #if !defined(lint) && !defined(WITH_WARNINGS)
36 static char vcid[] = "$Id: Chktex.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
37 #endif /* lint */
38
39
40 /*
41  * CLASS Chktex
42  */
43
44 Chktex::Chktex(LString const & chktex, LString const & f, LString const & p)
45                 : cmd(chktex), file(f), path(p)
46 {
47 }
48
49
50 int Chktex::run(TeXErrors &terr)
51 {
52         // run bibtex
53         LString log = ChangeExtension(file, ".log", true);
54         LString tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
55         Systemcalls one;
56         int result= one.Startscript(Systemcalls::System, tmp);
57         if (result == 0) {
58                 result = scanLogFile(terr);
59         } else {
60                 result = -1;
61         }
62         return result;
63 }
64
65
66 int Chktex::scanLogFile(TeXErrors &terr)
67 {
68         LString token;
69         int retval = 0;
70
71         LyXLex lex(NULL, 0);
72
73         LString tmp = ChangeExtension(file, ".log", true);
74
75         if (!lex.setFile(tmp)) {
76                 // Unable to open file. Return at once
77                 return -1;
78         }
79
80         while (lex.IsOK()) {
81                 if (lex.EatLine())
82                         token = lex.GetString();
83                 else // blank line in the file being read
84                         continue;
85
86                 LString srcfile, line, pos, warno, warning;
87                 token.split(srcfile, ':');
88                 token.split(line, ':');
89                 token.split(pos, ':');
90                 token.split(warno, ':');
91                 token.split(warning, ':');
92
93                 int lineno = atoi(line.c_str());
94                 warno = _("ChkTeX warning id #") + warno;
95                 terr.insertError(lineno, warno, warning);
96                 retval++;
97         }
98         return retval;
99 }