2003-08-23 00:17:00 +00:00
|
|
|
/**
|
|
|
|
* \file Chktex.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Asger Alstrup
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Chktex.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
#include "LaTeX.h" // TeXErrors
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
#include "support/convert.h"
|
2006-11-12 10:58:00 +00:00
|
|
|
#include "support/docstream.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
#include "support/filetools.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-09-04 01:44:16 +00:00
|
|
|
#include "support/systemcall.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
2004-01-06 19:32:05 +00:00
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::changeExtension;
|
2006-11-29 21:47:37 +00:00
|
|
|
using support::FileName;
|
|
|
|
using support::makeAbsPath;
|
2006-10-21 00:16:43 +00:00
|
|
|
using support::onlyFilename;
|
|
|
|
using support::split;
|
|
|
|
using support::Systemcall;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
using std::getline;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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
|
2006-04-08 22:31:11 +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;
|
2003-06-30 15:06:30 +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
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
// FIXME: Find out whether onlyFilename() is really needed,
|
2006-11-29 21:47:37 +00:00
|
|
|
// or whether makeAbsPath(onlyFilename()) is a noop here
|
|
|
|
FileName const tmp(makeAbsPath(onlyFilename(changeExtension(file, ".log"))));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
2006-11-12 10:58:00 +00:00
|
|
|
boost::basic_format<char_type> msg(_("ChkTeX warning id # %1$d"));
|
2002-11-24 15:20:31 +00:00
|
|
|
#else
|
2006-11-12 10:58:00 +00:00
|
|
|
docstring const msg(_("ChkTeX warning id # "));
|
2002-11-24 15:20:31 +00:00
|
|
|
#endif
|
2006-11-12 10:58:00 +00:00
|
|
|
docstring token;
|
|
|
|
// FIXME UNICODE
|
|
|
|
// We have no idea what the encoding of the error file is
|
2006-11-29 21:47:37 +00:00
|
|
|
idocfstream ifs(tmp.toFilesystemEncoding().c_str());
|
1999-11-04 01:40:20 +00:00
|
|
|
while (getline(ifs, token)) {
|
2006-11-12 10:58:00 +00:00
|
|
|
docstring srcfile;
|
|
|
|
docstring line;
|
|
|
|
docstring pos;
|
|
|
|
docstring warno;
|
|
|
|
docstring 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
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
int const lineno = convert<int>(line);
|
2002-11-24 15:20:31 +00:00
|
|
|
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
msg % warno;
|
2003-09-15 11:00:00 +00:00
|
|
|
terr.insertError(lineno, msg.str(), warning);
|
2002-11-24 15:20:31 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|