1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* This file is Copyright 1997-1998
|
1999-09-27 18:44:28 +00:00
|
|
|
* Asger Alstrup
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
#include <fstream>
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cstdlib> // atoi
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Chktex.h"
|
|
|
|
#include "LaTeX.h" // TeXErrors
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyxlex.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/FileInfo.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/syscall.h"
|
|
|
|
#include "support/syscontr.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
#include "support/path.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
using std::ifstream;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* CLASS Chktex
|
|
|
|
*/
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
Chktex::Chktex(string const & chktex, string const & f, string const & p)
|
1999-09-27 18:44:28 +00:00
|
|
|
: cmd(chktex), file(f), path(p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Chktex::run(TeXErrors &terr)
|
|
|
|
{
|
|
|
|
// run bibtex
|
1999-10-02 16:21:10 +00:00
|
|
|
string log = ChangeExtension(file, ".log", true);
|
|
|
|
string tmp = cmd + " -q -v0 -b0 -x " + file + " -o " + log;
|
1999-09-27 18:44:28 +00:00
|
|
|
Systemcalls one;
|
1999-10-12 21:37:10 +00:00
|
|
|
int result= one.startscript(Systemcalls::System, tmp);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (result == 0) {
|
|
|
|
result = scanLogFile(terr);
|
|
|
|
} else {
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
int Chktex::scanLogFile(TeXErrors & terr)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string token;
|
1999-09-27 18:44:28 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = ChangeExtension(file, ".log", true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
ifstream ifs(tmp.c_str());
|
|
|
|
while (getline(ifs, token)) {
|
1999-10-02 16:21:10 +00:00
|
|
|
string srcfile, line, pos, warno, warning;
|
1999-11-04 01:40:20 +00:00
|
|
|
token = split(token, srcfile, ':');
|
|
|
|
token = split(token, line, ':');
|
|
|
|
token = split(token, pos, ':');
|
|
|
|
token = split(token, warno, ':');
|
|
|
|
token = split(token, warning, ':');
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
int lineno = atoi(line.c_str());
|
|
|
|
warno = _("ChkTeX warning id #") + warno;
|
|
|
|
terr.insertError(lineno, warno, warning);
|
1999-11-04 01:40:20 +00:00
|
|
|
++retval;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|