X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeX.C;h=b1758d2749634a7e49bd69b3d7dbd7da588a73d2;hb=a858be7332e331e0244e4dba7b0931b6072ffd3d;hp=69ce0b6dc73b38ddefba1925d604fcadbaa4c3e3;hpb=27de1486ca34aaad446adb798d71a77d6f6304da;p=lyx.git diff --git a/src/LaTeX.C b/src/LaTeX.C index 69ce0b6dc7..b1758d2749 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -2,43 +2,37 @@ * ====================================================== * * 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 -#include -#include +#include +#include #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 { @@ -65,10 +59,10 @@ const texfile_struct all_files[] = { // 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]; @@ -78,7 +72,7 @@ LString readLine(FILE *file) i++; } while (!feof(file) && s[i-1] != '\n' && i<510); s[i] = '\0'; - LString tmp; + string tmp; if (i == 1 && feof(file)) ; else @@ -108,38 +102,38 @@ TeXErrors::~TeXErrors() 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); @@ -149,13 +143,13 @@ void TeXErrors::scanError(LyXLex &lex) } 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) { @@ -168,7 +162,7 @@ bool TeXErrors::getFirstError(int *line, LString *text) } -bool TeXErrors::getNextError(int *line, LString *text) +bool TeXErrors::getNextError(int *line, string *text) { if (next_error) { *line = next_error->error_in_line; @@ -180,8 +174,8 @@ bool TeXErrors::getNextError(int *line, LString *text) } -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) { @@ -196,17 +190,14 @@ void TeXErrors::insertError(int line, LString const &error_desc, 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); } @@ -220,17 +211,17 @@ void TeXErrors::printWarnings() 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; } @@ -238,7 +229,7 @@ void TeXErrors::printStatus() * 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; @@ -289,28 +280,27 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib) // 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); @@ -362,11 +352,11 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib) // 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); @@ -375,7 +365,7 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib) 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 @@ -409,8 +399,9 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib) // 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); @@ -421,7 +412,7 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib) // Write the dependencies to file. head.write(depfile); - lyxerr.debug("Done.", Error::LATEX); + lyxerr[Debug::LATEX] << "Done." << endl; return scanres; } @@ -429,37 +420,37 @@ int LaTeX::run(TeXErrors &terr, MiniBuffer *minib) 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 @@ -472,12 +463,12 @@ bool LaTeX::runBibTeX(LString const &file) 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; } @@ -489,94 +480,94 @@ bool LaTeX::runBibTeX(LString const &file) 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"; @@ -590,17 +581,17 @@ int LaTeX::scanLogFile(TeXErrors &terr) } 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; } @@ -616,7 +607,7 @@ void LaTeX::deplog(DepTable & head) // 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 @@ -634,7 +625,7 @@ void LaTeX::deplog(DepTable & head) // 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); @@ -642,9 +633,8 @@ void LaTeX::deplog(DepTable & head) } 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 @@ -654,9 +644,8 @@ void LaTeX::deplog(DepTable & head) // 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. @@ -667,23 +656,23 @@ void LaTeX::deplog(DepTable & head) // (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; @@ -693,24 +682,21 @@ void LaTeX::deplog(DepTable & head) // 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; } } @@ -718,14 +704,14 @@ void LaTeX::deplog(DepTable & head) 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); }