* ======================================================
*
* LyX, The Document Processor
- * Copyright (C) 1995 Matthias Ettrich
- * Copyright (C) 1995-1999 The LyX Team.
+ * Copyright 1995 Matthias Ettrich
+ * Copyright 1995-1999 The LyX Team.
*
- * This file is Copyright (C) 1996-1999
+ * This file is Copyright 1996-1999
* Lars Gullik Bjønnes
*
- *======================================================
+ * ======================================================
*/
#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
#ifdef __GNUG__
#pragma implementation
#endif
-#include "filetools.h"
+#include "support/filetools.h"
#include "LaTeX.h"
#include "lyxlex.h"
-#include "FileInfo.h"
-#include "error.h"
-#include "lyxlib.h"
-#include "syscall.h"
-#include "syscontr.h"
-#include "pathstack.h"
+#include "support/FileInfo.h"
+#include "debug.h"
+#include "support/lyxlib.h"
+#include "support/syscall.h"
+#include "support/syscontr.h"
+#include "support/path.h"
#include "bufferlist.h"
#include "minibuffer.h"
#include "gettext.h"
-// $Id: LaTeX.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $
-
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: LaTeX.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
-#endif /* lint */
-
extern BufferList bufferlist;
struct texfile_struct {
// This should perhaps be placed in LyXLex
static
-LString readLine(FILE *file)
+string readLine(FILE *file)
{
if (feof(file))
- return LString();
+ return string();
int i = 0;
char s[512];
i++;
} while (!feof(file) && s[i-1] != '\n' && i<510);
s[i] = '\0';
- LString tmp;
+ string tmp;
if (i == 1 && feof(file))
;
else
void TeXErrors::scanError(LyXLex &lex)
{
- LString token = lex.GetString();
+ string token = lex.GetString();
// Sometimes the error string goes over more than one
// line, and we need to get them all.
- LString errstr;
- LString tmp = readLine(lex.getFile()).frontStrip();
+ string errstr;
+ string tmp = frontStrip(readLine(lex.getFile()));
if (tmp == "\n" || tmp.empty()) {
- tmp = readLine(lex.getFile()).frontStrip();
- if (tmp.contains("See the LaTeX manual")) {
+ tmp = frontStrip(readLine(lex.getFile()));
+ if (contains(tmp, "See the LaTeX manual")) {
do {
tmp = readLine(lex.getFile());
- } while (!tmp.empty() && !tmp.contains("..."));
+ } while (!tmp.empty() && !contains(tmp, "..."));
}
- tmp = readLine(lex.getFile()).frontStrip();
+ tmp = frontStrip(readLine(lex.getFile()));
}
- while ((tmp != "\n" || !errstr.contains("l."))
- && !tmp.prefixIs("! ")
- && !tmp.contains("(job aborted")
+ while ((tmp != "\n" || !contains(errstr, "l."))
+ && !prefixIs(tmp, "! ")
+ && !contains(tmp, "(job aborted")
&& !tmp.empty()) {
errstr += tmp;
- tmp = readLine(lex.getFile()).frontStrip();
+ tmp = frontStrip(readLine(lex.getFile()));
}
- lyxerr.debug("tmp: " + errstr);
+ lyxerr.debug() << "tmp: " << errstr << endl;
int line = 0;
// unfortunately the error line is not always given
// by "l.###" in the beginning of the error string
// therefore we must search for "l.###" in the error
// msg.
- if (errstr.contains("l.")) {
+ if (contains(errstr, "l.")) {
// We make a const copy to make [] fast. (Asger)
- LString const es = errstr;
- for (int i = 2; i < es.length(); i++) {
+ string const es(errstr);
+ for (string::size_type i = 2; i < es.length(); ++i) {
if (es[i-2] == 'l' && es[i-1] == '.' &&
(es[i] >= '0' && es[i]<= '9')) {
line = atoi(es.c_str() + i);
}
insertError(line, token, errstr);
- if (tmp.prefixIs("! ")) {
+ if (prefixIs(tmp, "! ")) {
scanError(lex);
}
}
-bool TeXErrors::getFirstError(int *line, LString *text)
+bool TeXErrors::getFirstError(int *line, string *text)
{
next_error = errors;
if (next_error) {
}
-bool TeXErrors::getNextError(int *line, LString *text)
+bool TeXErrors::getNextError(int *line, string *text)
{
if (next_error) {
*line = next_error->error_in_line;
}
-void TeXErrors::insertError(int line, LString const &error_desc,
- LString const &error_text)
+void TeXErrors::insertError(int line, string const &error_desc,
+ string const &error_text)
{
Error *newerr = new Error(line, error_desc, error_text);
if (errors) {
void TeXErrors::printErrors()
{
- lyxerr.print("Printing errors.");
+ lyxerr << "Printing errors." << endl;
if (errors) {
Error *tmperr = errors;
do {
- lyxerr.print(LString("Error in line ")
- + tmperr->error_in_line
- + ": " + tmperr->error_desc
- + '\n' + tmperr->error_text);
- //%d: %s\n%s\n", tmperr->error_in_line,
- // tmperr->error_desc.c_str(),
- // tmperr->error_text.c_str());
+ lyxerr << "Error in line "
+ << tmperr->error_in_line
+ << ": " << tmperr->error_desc
+ << '\n' << tmperr->error_text << endl;
tmperr = tmperr->next_error;
} while (tmperr);
}
void TeXErrors::printStatus()
{
- lyxerr.print("Error struct:");
- lyxerr.print(LString(" status: ") + int(status));
- lyxerr.print(LString(" no err: ") + int(number_of_errors));
- if (status == LaTeX::NO_ERRORS) lyxerr.print("NO_ERRORS");
- if (status & LaTeX::NO_LOGFILE) lyxerr.print("NO_LOGFILE");
- if (status & LaTeX::NO_OUTPUT) lyxerr.print("NO_OUTPUT");
- if (status & LaTeX::UNDEF_REF) lyxerr. print("UNDEF_REF");
- if (status & LaTeX::RERUN) lyxerr. print("RERUN");
- if (status & LaTeX::TEX_ERROR) lyxerr.print("TEX_ERROR");
- if (status & LaTeX::TEX_WARNING) lyxerr.print("TEX_WARNING");
- if (status & LaTeX::NO_FILE) lyxerr.print("NO_FILE");
+ lyxerr << "Error struct:"
+ << "\n status: " << status
+ << "\n no err: " << number_of_errors << endl;
+ if (status == LaTeX::NO_ERRORS) lyxerr << "NO_ERRORS" << endl;
+ if (status & LaTeX::NO_LOGFILE) lyxerr << "NO_LOGFILE" << endl;
+ if (status & LaTeX::NO_OUTPUT) lyxerr << "NO_OUTPUT" << endl;
+ if (status & LaTeX::UNDEF_REF) lyxerr << "UNDEF_REF" << endl;
+ if (status & LaTeX::RERUN) lyxerr << "RERUN" << endl;
+ if (status & LaTeX::TEX_ERROR) lyxerr << "TEX_ERROR" << endl;
+ if (status & LaTeX::TEX_WARNING) lyxerr << "TEX_WARNING" << endl;
+ if (status & LaTeX::NO_FILE) lyxerr << "NO_FILE" << endl;
}
* CLASS LaTeX
*/
-LaTeX::LaTeX(LString const & latex, LString const & f, LString const & p)
+LaTeX::LaTeX(string const & latex, string const & f, string const & p)
: cmd(latex), file(f), path(p)
{
tex_files = NO_FILES;
// Update the checksums
head.update();
- lyxerr.debug("Dependency file exists", Error::LATEX);
+ lyxerr[Debug::LATEX] << "Dependency file exists" << endl;
if (head.sumchange()) {
- lyxerr.debug("Dependency file has changed",
- Error::LATEX);
- lyxerr.debug(LString(_("Run #")) + int(++count),
- Error::LATEX);
- minib->Set(LString(_("LaTeX run number ")) + int(count));
+ ++count;
+ 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
} else {
- lyxerr.debug("return no_change", Error::LATEX);
+ lyxerr[Debug::LATEX] << "return no_change" << endl;
return LaTeX::NO_CHANGE;
}
} else {
- lyxerr.debug("Dependency file does not exist",
- Error::LATEX);
- lyxerr.debug(LString(_("Run #")) + int(++count),
- Error::LATEX);
+ ++count;
+ lyxerr[Debug::LATEX] << "Dependency file does not exist\n"
+ << "Run #" << count << endl;
head.insert(file, true);
- minib->Set(LString(_("LaTeX run number ")) + int(count));
+ minib->Set(string(_("LaTeX run number ")) + tostr(count));
minib->Store();
this->operator()();
scanres = scanLogFile(terr);
//
if (rerun || head.sumchange()) {
rerun = false;
- lyxerr.debug("Dep. file has changed or rerun requested",
- Error::LATEX);
- lyxerr.debug(LString("Run #") + int(++count),
- Error::LATEX);
- minib->Set(LString(_("LaTeX run number ")) + int(count));
+ ++count;
+ 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);
deplog(head); // reads the latex log
head.update();
} else {
- lyxerr.debug("Dep. file has NOT changed", Error::LATEX);
+ lyxerr[Debug::LATEX] << "Dep. file has NOT changed" << endl;
}
// 1.5
// Yes rerun until message goes away, or until
// MAX_RUNS are reached.
rerun = false;
- lyxerr.debug(LString(_("Run #")) + int(++count), Error::LATEX);
- minib->Set(LString(_("LaTeX run number ")) + int(count));
+ ++count;
+ lyxerr[Debug::LATEX] << "Run #" << count << endl;
+ minib->Set(string(_("LaTeX run number ")) + tostr(count));
minib->Store();
this->operator()();
scanres = scanLogFile(terr);
// Write the dependencies to file.
head.write(depfile);
- lyxerr.debug("Done.", Error::LATEX);
+ lyxerr[Debug::LATEX] << "Done." << endl;
return scanres;
}
int LaTeX::operator()()
{
#ifndef __EMX__
- LString tmp = cmd + ' ' + file + " > /dev/null";
+ string tmp = cmd + ' ' + file + " > /dev/null";
#else // cmd.exe (OS/2) causes SYS0003 error at "/dev/null"
- LString tmp = cmd + ' ' + file + " > nul";
+ string tmp = cmd + ' ' + file + " > nul";
#endif
Systemcalls one;
- return one.Startscript(Systemcalls::System, tmp);
+ return one.startscript(Systemcalls::System, tmp);
}
-bool LaTeX::runMakeIndex(LString const &file)
+bool LaTeX::runMakeIndex(string const &file)
{
- lyxerr.debug("idx file has been made,"
- " running makeindex on file "
- + file, Error::LATEX);
+ lyxerr[Debug::LATEX] << "idx file has been made,"
+ " running makeindex on file "
+ << file << endl;
// It should be possible to set the switches for makeindex
// sorting style and such. It would also be very convenient
// to be able to make style files from within LyX. This has
// to come for a later time. (0.13 perhaps?)
- LString tmp = "makeindex -c -q ";
+ string tmp = "makeindex -c -q ";
tmp += file;
Systemcalls one;
- one.Startscript(Systemcalls::System, tmp);
+ one.startscript(Systemcalls::System, tmp);
return true;
}
-bool LaTeX::runBibTeX(LString const &file)
+bool LaTeX::runBibTeX(string const &file)
{
- LyXLex lex(NULL, 0);
- LString token;
+ LyXLex lex(0, 0);
+ string token;
if (!lex.setFile(file)) {
// unable to open .aux file
// return at once
else // blank line in the file being read
continue;
- if (token.contains("\\bibdata{")) {
+ if (contains(token, "\\bibdata{")) {
// run bibtex and
- LString tmp="bibtex ";
- tmp += ChangeExtension(file, LString(), true);
+ string tmp="bibtex ";
+ tmp += ChangeExtension(file, string(), true);
Systemcalls one;
- one.Startscript(Systemcalls::System, tmp);
+ one.startscript(Systemcalls::System, tmp);
return true;
}
int LaTeX::scanLogFile(TeXErrors &terr)
{
- LString token;
int retval = NO_ERRORS;
+ string tmp = ChangeExtension(file, ".log", true);
- LyXLex lex(NULL, 0);
-
- LString tmp = ChangeExtension(file, ".log", true);
-
+ LyXLex lex(0, 0);
if (!lex.setFile(tmp)) {
// unable to open file
// return at once
retval |= NO_LOGFILE;
return retval;
}
-
+
+ string token;
while (lex.IsOK()) {
if (lex.EatLine())
token = lex.GetString();
else // blank line in the file being read
continue;
- lyxerr.debug(token, Error::LATEX);
+ lyxerr[Debug::LATEX] << token << endl;
- if (token.prefixIs("LaTeX Warning:")) {
+ if (prefixIs(token, "LaTeX Warning:")) {
// Here shall we handle different
// types of warnings
retval |= LATEX_WARNING;
- lyxerr.debug("LaTeX Warning.", Error::LATEX);
- if (token.contains("Rerun to get cross-references")) {
+ lyxerr[Debug::LATEX] << "LaTeX Warning." << endl;
+ if (contains(token, "Rerun to get cross-references")) {
retval |= RERUN;
- lyxerr.debug("We should rerun.", Error::LATEX);
- } else if (token.contains("Citation")
- && token.contains("on page")
- && token.contains("undefined")) {
+ lyxerr[Debug::LATEX]
+ << "We should rerun." << endl;
+ } else if (contains(token, "Citation")
+ && contains(token, "on page")
+ && contains(token, "undefined")) {
retval |= UNDEF_CIT;
}
- } else if (token.prefixIs("Package")) {
+ } else if (prefixIs(token, "Package")) {
// Package warnings
retval |= PACKAGE_WARNING;
- if (token.contains("natbib Warning:")) {
+ if (contains(token, "natbib Warning:")) {
// Natbib warnings
- if (token.contains("Citation")
- && token.contains("on page")
- && token.contains("undefined")) {
+ if (contains(token, "Citation")
+ && contains(token, "on page")
+ && contains(token, "undefined")) {
retval |= UNDEF_CIT;
}
- } else if (token.contains("Rerun LaTeX.")) {
+ } else if (contains(token, "Rerun LaTeX.")) {
// at least longtable.sty might use this.
retval |= RERUN;
}
- } else if (token.prefixIs("! LaTeX Error:")) {
+ } else if (prefixIs(token, "! LaTeX Error:")) {
// Here shall we handle different
// types of errors
retval |= LATEX_ERROR;
- lyxerr.debug("LaTeX Error.", Error::LATEX);
+ lyxerr[Debug::LATEX] << "LaTeX Error." << endl;
// this is not correct yet
terr.scanError(lex);
num_errors++;
- } else if (token.prefixIs("! ")) {
+ } else if (prefixIs(token, "! ")) {
// Ok, we have something that looks like a TeX Error
// but what do we really have.
// Just get the error description:
- LString desc(token);
- desc.substring(2, desc.length() - 1);
+ string desc(token);
+ desc.erase(0, 2);
- if (desc.contains("Undefined control sequence")) {
+ if (contains(desc, "Undefined control sequence")) {
retval |= TEX_ERROR;
- lyxerr.debug("TeX Error.", Error::LATEX);
+ lyxerr[Debug::LATEX] << "TeX Error." << endl;
terr.scanError(lex);
num_errors++;
} else {
// get the next line
lex.next();
- LString tmp = lex.GetString();
- if (tmp.prefixIs("l.")) {
+ string tmp = lex.GetString();
+ if (prefixIs(tmp, "l.")) {
// we have a latex error
retval |= TEX_ERROR;
- lyxerr.debug("TeX Error.", Error::LATEX);
+ lyxerr[Debug::LATEX]
+ <<"TeX Error." << endl;
// get the line number:
int line = 0;
sscanf(tmp.c_str(), "l.%d", &line);
// get the rest of the message:
- LString errstr;
+ string errstr;
lex.EatLine();
tmp = lex.GetString();
- while ((tmp != "\n" || !errstr.contains("l."))
- && !tmp.prefixIs("! ")
- && !tmp.contains("(job aborted")
+ while ((tmp != "\n" || !contains(errstr, "l."))
+ && !prefixIs(tmp, "! ")
+ && !contains(tmp, "(job aborted")
&& !tmp.empty()) {
errstr += tmp;
errstr += "\n";
} else {
// information messages, TeX warnings and other
// warnings we have not caught earlier.
- if (token.prefixIs("Overfull ")) {
+ if (prefixIs(token, "Overfull ")) {
retval |= TEX_WARNING;
- } else if (token.prefixIs("Underfull ")) {
+ } else if (prefixIs(token, "Underfull ")) {
retval |= TEX_WARNING;
- } else if (token.contains("Rerun to get citations")) {
+ } else if (contains(token, "Rerun to get citations")) {
// Natbib seems to use this.
retval |= RERUN;
- } else if (token.contains("No pages of output")) {
+ } else if (contains(token, "No pages of output")) {
// A dvi file was not created
retval |= NO_OUTPUT;
- } else if (token.contains("That makes 100 errors")) {
+ } else if (contains(token, "That makes 100 errors")) {
// More than 100 errors were reprted
retval |= TOO_MANY_ERRORS;
}
// files used by the LaTeX run. The files are then entered into the
// dependency file.
- LString logfile = ChangeExtension(file, ".log", true);
+ string logfile = ChangeExtension(file, ".log", true);
FilePtr in(logfile, FilePtr::read);
bool not_eof = true;
if (in()) while (not_eof) { // We were able to open the file
// We now have c == '(', we now read the the sequence of
// chars until reaching EOL, or ' ' and put that into a string.
- LString foundfile;
+ string foundfile;
c = fgetc(in());
while (c != '\n' && c != ' ' && c != ')') {
foundfile += char(c);
}
if (foundfile.empty()) continue;
- lyxerr.debug("Found file: "
- + foundfile,
- Error::LATEX);
+ lyxerr[Debug::LATEX] << "Found file: "
+ << foundfile << endl;
// Ok now we found a file.
// Now we should make sure that
// this is a file that we can
// absolute path and should
// be inserted.
if (AbsolutePath(foundfile)) {
- lyxerr.debug("AbsolutePath file: "
- + foundfile,
- Error::LATEX);
+ lyxerr[Debug::LATEX] << "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
// the latex run.
// (2) foundfile is in the tmpdir
// insert it into head
if (FileInfo(OnlyFilename(foundfile)).exist()) {
- if (foundfile.suffixIs(".aux")) {
- lyxerr.debug("We don't want "
- + OnlyFilename(foundfile)
- + " in the dep file",
- Error::LATEX);
- } else if (foundfile.suffixIs(".tex")) {
+ if (suffixIs(foundfile, ".aux")) {
+ lyxerr[Debug::LATEX] << "We don't want "
+ << OnlyFilename(foundfile)
+ << " in the dep file"
+ << endl;
+ } else if (suffixIs(foundfile, ".tex")) {
// This is a tex file generated by LyX
// and latex is not likely to change this
// during its runs.
- lyxerr.debug("Tmpdir TeX file: "
- + OnlyFilename(foundfile),
- Error::LATEX);
+ lyxerr[Debug::LATEX] << "Tmpdir TeX file: "
+ << OnlyFilename(foundfile)
+ << endl;
head.insert(foundfile, true);
} else {
- lyxerr.debug("In tmpdir file:"
- + OnlyFilename(foundfile),
- Error::LATEX);
+ lyxerr[Debug::LATEX] << "In tmpdir file:"
+ << OnlyFilename(foundfile)
+ << endl;
head.insert(OnlyFilename(foundfile));
}
continue;
// found in the same dir
// as the .lyx file and
// should be inserted.
- PathPush(path);
+ Path p(path);
if (FileInfo(foundfile).exist()) {
- lyxerr.print("LyX Strange: this should actually never"
- " happen anymore, this it should be"
- " handled by the Absolute check.");
- lyxerr.debug("Same Directory file: "
- + foundfile,
- Error::LATEX);
+ lyxerr << "LyX Strange: this should actually never"
+ " happen anymore, this it should be"
+ " handled by the Absolute check."
+ << endl;
+ lyxerr[Debug::LATEX] << "Same Directory file: "
+ << foundfile << endl;
head.insert(foundfile);
- PathPop();
continue;
}
- PathPop();
- lyxerr.debug("Not a file or we are unable to find it.",
- Error::LATEX);
-
-
+ lyxerr[Debug::LATEX]
+ << "Not a file or we are unable to find it."
+ << endl;
}
}
void LaTeX::deptex(DepTable &head)
{
int except = AUX|LOG|DVI|BBL|IND|GLO;
- LString tmp;
+ string tmp;
FileInfo fi;
for (int i = 0; i < file_count; i++) {
if (!(all_files[i].file & except)) {
tmp = ChangeExtension(file,
all_files[i].extension,
true);
- lyxerr.debug("deptex: " + tmp, Error::LATEX);
+ lyxerr[Debug::LATEX] << "deptex: " << tmp << endl;
if (fi.newFile(tmp).exist())
head.insert(tmp);
}