1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +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
|
|
|
|
*
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Chktex.h"
|
|
|
|
#include "LaTeX.h" // TeXErrors
|
|
|
|
#include "lyxlex.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include "support/FileInfo.h"
|
|
|
|
#include "support/filetools.h"
|
2002-02-18 19:13:48 +00:00
|
|
|
#include "support/systemcall.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"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
2002-11-21 18:33:09 +00:00
|
|
|
#include "BoostFormat.h"
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
#include <fstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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;
|
2002-03-21 17:27:08 +00:00
|
|
|
Systemcall one;
|
2002-02-18 19:13:48 +00:00
|
|
|
int result= one.startscript(Systemcall::Wait, 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;
|
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
string const tmp = OnlyFilename(ChangeExtension(file, ".log"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
boost::format msg(_("ChkTeX warning id # %1$d"));
|
|
|
|
#else
|
|
|
|
string const msg(_("ChkTeX warning id # "));
|
|
|
|
#endif
|
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
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
int const lineno = lyx::atoi(line);
|
|
|
|
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
msg % warno;
|
|
|
|
terr.insertError(lineno, msg.str(), warning);
|
|
|
|
msg.clear();
|
|
|
|
#else
|
|
|
|
terr.insertError(lineno, msg + warno, warning);
|
|
|
|
#endif
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
++retval;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|