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
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 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-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"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
using std::ifstream;
|
2000-05-04 10:57:00 +00:00
|
|
|
using std::getline;
|
1999-11-24 22:14:46 +00:00
|
|
|
|
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
|
2000-05-11 16:12:46 +00:00
|
|
|
string log = OnlyFilename(ChangeExtension(file, ".log"));
|
1999-10-02 16:21:10 +00:00
|
|
|
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;
|
|
|
|
|
2000-05-11 16:12:46 +00:00
|
|
|
string tmp = OnlyFilename(ChangeExtension(file, ".log"));
|
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)) {
|
2001-06-14 17:58:49 +00:00
|
|
|
string srcfile;
|
|
|
|
string line;
|
|
|
|
string pos;
|
|
|
|
string warno;
|
|
|
|
string 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
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
int lineno = lyx::atoi(line);
|
1999-09-27 18:44:28 +00:00
|
|
|
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;
|
|
|
|
}
|