*
* LyX, The Document Processor
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-1999 The LyX Team.
+ * Copyright 1995-2000 The LyX Team.
*
- * This file is Copyright 1996-1999
+ * This file is Copyright 1996-2000
* Lars Gullik Bjønnes
*
* ======================================================
#include "gettext.h"
using std::ifstream;
+using std::getline;
+using std::endl;
// TODO: in no particular order
// - get rid of the extern BufferList and the call to
struct texfile_struct {
LaTeX::TEX_FILES file;
- char const *extension;
+ char const * extension;
};
static
}
+void LaTeX::deleteFilesOnError() const
+{
+ // currently just a dummy function.
+
+ // What files do we have to delete?
+
+ // This will at least make latex do all the runs
+ ::unlink(depfile.c_str());
+
+ // but the reason for the error might be in a generated file...
+
+ // bibtex file
+ string bbl = ChangeExtension(file, ".bbl", true);
+ ::unlink(bbl.c_str());
+
+ // makeindex file
+ string ind = ChangeExtension(file, ".ind", true);
+ ::unlink(ind.c_str());
+
+ // Also remove the aux file
+ string aux = ChangeExtension(file, ".aux", true);
+ ::unlink(aux.c_str());
+}
+
+
int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
// We know that this function will only be run if the lyx buffer
// has been changed. We also know that a newly written .tex file
// Update the checksums
head.update();
- lyxerr[Debug::LATEX] << "Dependency file exists" << endl;
+ lyxerr[Debug::DEPEND] << "Dependency file exists" << endl;
if (head.sumchange()) {
++count;
+ lyxerr[Debug::DEPEND]
+ << "Dependency file has changed" << endl;
lyxerr[Debug::LATEX]
- << "Dependency file has changed\n"
<< "Run #" << count << endl;
minib->Set(string(_("LaTeX run number ")) + tostr(count));
minib->Store();
this->operator()();
scanres = scanLogFile(terr);
- if (scanres & LaTeX::ERRORS) return scanres; // return on error
+ if (scanres & LaTeX::ERRORS) {
+ deleteFilesOnError();
+ return scanres; // return on error
+ }
+
run_bibtex = scanAux(head);
if (run_bibtex)
- lyxerr << "Bibtex demands rerun" << endl;
+ lyxerr[Debug::DEPEND]
+ << "Bibtex demands rerun" << endl;
} else {
- lyxerr[Debug::LATEX] << "return no_change" << endl;
+ lyxerr[Debug::DEPEND] << "return no_change" << endl;
return LaTeX::NO_CHANGE;
}
} else {
++count;
- lyxerr[Debug::LATEX] << "Dependency file does not exist\n"
- << "Run #" << count << endl;
+ lyxerr[Debug::DEPEND]
+ << "Dependency file does not exist" << endl;
+
+ lyxerr[Debug::LATEX]
+ << "Run #" << count << endl;
head.insert(file, true);
minib->Set(string(_("LaTeX run number ")) + tostr(count));
minib->Store();
this->operator()();
scanres = scanLogFile(terr);
- if (scanres & LaTeX::ERRORS) return scanres; // return on error
+ if (scanres & LaTeX::ERRORS) {
+ deleteFilesOnError();
+ return scanres; // return on error
+ }
+
}
// update the dependencies.
if (rerun || head.sumchange()) {
rerun = false;
++count;
+ lyxerr[Debug::DEPEND]
+ << "Dep. file has changed or rerun requested" << endl;
lyxerr[Debug::LATEX]
- << "Dep. file has changed or rerun requested\n"
<< "Run #" << count << endl;
minib->Set(string(_("LaTeX run number ")) + tostr(count));
minib->Store();
this->operator()();
scanres = scanLogFile(terr);
- if (scanres & LaTeX::ERRORS) return scanres; // return on error
+ if (scanres & LaTeX::ERRORS) {
+ deleteFilesOnError();
+ return scanres; // return on error
+ }
+
// update the depedencies
deplog(head); // reads the latex log
head.update();
} else {
- lyxerr[Debug::LATEX] << "Dep. file has NOT changed" << endl;
+ lyxerr[Debug::DEPEND] << "Dep. file has NOT changed" << endl;
}
// 1.5
minib->Store();
this->operator()();
scanres = scanLogFile(terr);
- if (scanres & LaTeX::ERRORS) return scanres; // return on error
+ if (scanres & LaTeX::ERRORS) {
+ deleteFilesOnError();
+ return scanres; // return on error
+ }
+
// keep this updated
head.update();
}
int LaTeX::operator()()
{
#ifndef __EMX__
- string tmp = cmd + ' ' + file + " > /dev/null";
+ string tmp = cmd + ' ' + QuoteName(file) + " > /dev/null";
#else // cmd.exe (OS/2) causes SYS0003 error at "/dev/null"
string tmp = cmd + ' ' + file + " > nul";
#endif
int LaTeX::scanLogFile(TeXErrors & terr)
{
+ int last_line = -1;
+ int line_count = 1;
int retval = NO_ERRORS;
string tmp = ChangeExtension(file, ".log", true);
lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
retval |= LATEX_ERROR;
// get the next line
string tmp;
- getline(ifs, tmp);
+ int count = 0;
+ do {
+ if (!getline(ifs, tmp))
+ break;
+ if (++count > 10)
+ break;
+ } while (!prefixIs(tmp, "l."));
if (prefixIs(tmp, "l.")) {
// we have a latex error
retval |= TEX_ERROR;
<< "line: " << line << '\n'
<< "Desc: " << desc << '\n'
<< "Text: " << errstr << endl;
- terr.insertError(line, desc, errstr);
- ++num_errors;
+ if (line == last_line)
+ ++line_count;
+ else {
+ line_count = 1;
+ last_line = line;
+ }
+ if (line_count <= 5) {
+ terr.insertError(line, desc, errstr);
+ ++num_errors;
+ }
}
} else {
// information messages, TeX warnings and other
break;
foundfile += c;
}
- lyxerr[Debug::LATEX] << "Found file: "
+ lyxerr[Debug::DEPEND] << "Found file: "
<< foundfile << endl;
// Ok now we found a file.
// absolute path and should
// be inserted.
if (AbsolutePath(foundfile)) {
- lyxerr[Debug::LATEX] << "AbsolutePath file: "
+ lyxerr[Debug::DEPEND] << "AbsolutePath file: "
<< foundfile << endl;
// On inital insert we want to do the update at once
// since this file can not be a file generated by
// insert it into head
if (FileInfo(OnlyFilename(foundfile)).exist()) {
if (suffixIs(foundfile, ".aux")) {
- lyxerr[Debug::LATEX] << "We don't want "
+ lyxerr[Debug::DEPEND] << "We don't want "
<< OnlyFilename(foundfile)
<< " in the dep file"
<< endl;
// This is a tex file generated by LyX
// and latex is not likely to change this
// during its runs.
- lyxerr[Debug::LATEX] << "Tmpdir TeX file: "
+ lyxerr[Debug::DEPEND] << "Tmpdir TeX file: "
<< OnlyFilename(foundfile)
<< endl;
head.insert(foundfile, true);
} else {
- lyxerr[Debug::LATEX] << "In tmpdir file:"
+ lyxerr[Debug::DEPEND] << "In tmpdir file:"
<< OnlyFilename(foundfile)
<< endl;
head.insert(OnlyFilename(foundfile));
}
continue;
}
- lyxerr[Debug::LATEX]
+ lyxerr[Debug::DEPEND]
<< "Not a file or we are unable to find it."
<< endl;
}
tmp = ChangeExtension(file,
all_files[i].extension,
true);
- lyxerr[Debug::LATEX] << "deptex: " << tmp << endl;
+ lyxerr[Debug::DEPEND] << "deptex: " << tmp << endl;
if (fi.newFile(tmp).exist())
head.insert(tmp);
}
}
}
-