X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeX.C;h=deaffae9ce38a8d3797dc60db20e55966f1d7e65;hb=1312eeaba533a3215595711985f0aec53a7d675d;hp=eb552063a915630e3f8ece988d6dce8bc7ba3314;hpb=e6d063c4317b298bd4f14a4b15f97d37f2291c17;p=lyx.git diff --git a/src/LaTeX.C b/src/LaTeX.C index eb552063a9..deaffae9ce 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -31,8 +31,10 @@ #include "bufferlist.h" #include "minibuffer.h" #include "gettext.h" +#include "lyx_gui_misc.h" using std::ifstream; +using std::getline; using std::endl; // TODO: in no particular order @@ -50,29 +52,6 @@ using std::endl; extern BufferList bufferlist; -struct texfile_struct { - LaTeX::TEX_FILES file; - char const * extension; -}; - -static -const texfile_struct all_files[] = { - { LaTeX::AUX, ".aux"}, - { LaTeX::BBL, ".bbl"}, - { LaTeX::DVI, ".dvi"}, - { LaTeX::GLO, ".glo"}, - { LaTeX::IDX, ".idx"}, - { LaTeX::IND, ".ind"}, - { LaTeX::LOF, ".lof"}, - { LaTeX::LOA, ".loa"}, - { LaTeX::LOG, ".log"}, - { LaTeX::LOT, ".lot"}, - { LaTeX::TOC, ".toc"}, - { LaTeX::LTX, ".ltx"}, - { LaTeX::TEX, ".tex"} -}; - - /* * CLASS TEXERRORS */ @@ -91,10 +70,10 @@ void TeXErrors::insertError(int line, string const & error_desc, LaTeX::LaTeX(string const & latex, string const & f, string const & p) : cmd(latex), file(f), path(p) { - tex_files = NO_FILES; - file_count = sizeof(all_files) / sizeof(texfile_struct); num_errors = 0; depfile = file + ".dep"; + if (prefixIs(cmd, "pdf")) // Do we use pdflatex ? + depfile += "-pdf"; } @@ -105,21 +84,23 @@ void LaTeX::deleteFilesOnError() const // What files do we have to delete? // This will at least make latex do all the runs - ::unlink(depfile.c_str()); + lyx::unlink(depfile); // but the reason for the error might be in a generated file... + string ofname = OnlyFilename(file); + // bibtex file - string bbl = ChangeExtension(file, ".bbl", true); - ::unlink(bbl.c_str()); + string bbl = ChangeExtension(ofname, ".bbl"); + lyx::unlink(bbl); // makeindex file - string ind = ChangeExtension(file, ".ind", true); - ::unlink(ind.c_str()); + string ind = ChangeExtension(ofname, ".ind"); + lyx::unlink(ind); // Also remove the aux file - string aux = ChangeExtension(file, ".aux", true); - ::unlink(aux.c_str()); + string aux = ChangeExtension(ofname, ".aux"); + lyx::unlink(aux); } @@ -138,7 +119,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) bool rerun = false; // rerun requested // The class LaTeX does not know the temp path. - bufferlist.updateIncludedTeXfiles(GetCWD()); + bufferlist.updateIncludedTeXfiles(lyx::getcwd()); //GetCWD()); // Never write the depfile if an error was encountered. @@ -172,8 +153,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) << "Dependency file has changed" << endl; lyxerr[Debug::LATEX] << "Run #" << count << endl; - minib->Set(string(_("LaTeX run number ")) + tostr(count)); - minib->Store(); + WriteStatus(minib, + string(_("LaTeX run number ")) + tostr(count)); this->operator()(); scanres = scanLogFile(terr); if (scanres & LaTeX::ERRORS) { @@ -197,8 +178,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) lyxerr[Debug::LATEX] << "Run #" << count << endl; head.insert(file, true); - minib->Set(string(_("LaTeX run number ")) + tostr(count)); - minib->Store(); + WriteStatus(minib, + string(_("LaTeX run number ")) + tostr(count)); this->operator()(); scanres = scanLogFile(terr); if (scanres & LaTeX::ERRORS) { @@ -210,7 +191,6 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) // update the dependencies. deplog(head); // reads the latex log - deptex(head); // checks for latex files head.update(); // 0.5 @@ -221,12 +201,11 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) // if needed. // run makeindex - if (head.haschanged(ChangeExtension(file, ".idx", true))) { + if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) { // no checks for now lyxerr[Debug::LATEX] << "Running MakeIndex." << endl; - minib->Set(_("Running MakeIndex.")); - minib->Store(); - rerun = runMakeIndex(ChangeExtension(file, ".idx", true)); + WriteStatus(minib, _("Running MakeIndex.")); + rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx"))); } // run bibtex @@ -238,9 +217,9 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) // tags is found -> run bibtex and set rerun = true; // no checks for now lyxerr[Debug::LATEX] << "Running BibTeX." << endl; - minib->Set(_("Running BibTeX.")); - minib->Store(); - rerun = runBibTeX(ChangeExtension(file, ".aux", true), head); + WriteStatus(minib, _("Running BibTeX.")); + rerun = runBibTeX(OnlyFilename(ChangeExtension(file, ".aux")), + head); } // 1 @@ -262,8 +241,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) << "Dep. file has changed or rerun requested" << endl; lyxerr[Debug::LATEX] << "Run #" << count << endl; - minib->Set(string(_("LaTeX run number ")) + tostr(count)); - minib->Store(); + WriteStatus(minib, + string(_("LaTeX run number ")) + tostr(count)); this->operator()(); scanres = scanLogFile(terr); if (scanres & LaTeX::ERRORS) { @@ -287,12 +266,11 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) // more after this. // run makeindex if the .idx has changed or was generated. - if (head.haschanged(ChangeExtension(file, ".idx", true))) { + if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) { // no checks for now lyxerr[Debug::LATEX] << "Running MakeIndex." << endl; - minib->Set(_("Running MakeIndex.")); - minib->Store(); - rerun = runMakeIndex(ChangeExtension(file, ".idx", true)); + WriteStatus(minib, _("Running MakeIndex.")); + rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx"))); } // 2 @@ -312,8 +290,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) rerun = false; ++count; lyxerr[Debug::LATEX] << "Run #" << count << endl; - minib->Set(string(_("LaTeX run number ")) + tostr(count)); - minib->Store(); + WriteStatus(minib, string(_("LaTeX run number ")) + tostr(count)); this->operator()(); scanres = scanLogFile(terr); if (scanres & LaTeX::ERRORS) { @@ -369,7 +346,7 @@ bool LaTeX::scanAux(DepTable & dep) if (dep.extchanged(".bib") || dep.extchanged(".bst")) return true; - string aux = ChangeExtension(file, ".aux", true); + string aux = OnlyFilename(ChangeExtension(file, ".aux")); ifstream ifs(aux.c_str()); string token; LRegex reg1("\\\\bibdata\\{([^}]+)\\}"); @@ -391,7 +368,7 @@ bool LaTeX::scanAux(DepTable & dep) } string full_l = findtexfile( - ChangeExtension(l, "bib", false), "bib"); + ChangeExtension(l, "bib"), "bib"); if (!full_l.empty()) { if (!dep.exist(full_l)) return true; @@ -405,7 +382,7 @@ bool LaTeX::scanAux(DepTable & dep) // pass it to the helper string full_l = findtexfile( - ChangeExtension(style, "bst", false), + ChangeExtension(style, "bst"), "bst"); if (!full_l.empty()) { if (!dep.exist(full_l)) @@ -449,7 +426,7 @@ bool LaTeX::runBibTeX(string const & f, DepTable & dep) } string full_l = findtexfile( - ChangeExtension(l, "bib", false), + ChangeExtension(l, "bib"), "bib"); lyxerr[Debug::LATEX] << "Bibtex database: `" << full_l << "'" << endl; @@ -467,7 +444,7 @@ bool LaTeX::runBibTeX(string const & f, DepTable & dep) // pass it to the helper string full_l = findtexfile( - ChangeExtension(style, "bst", false), + ChangeExtension(style, "bst"), "bst"); lyxerr[Debug::LATEX] << "Bibtex style: `" << full_l << "'" << endl; @@ -480,7 +457,7 @@ bool LaTeX::runBibTeX(string const & f, DepTable & dep) if (using_bibtex) { // run bibtex and string tmp = "bibtex "; - tmp += ChangeExtension(file, string(), true); + tmp += OnlyFilename(ChangeExtension(file, string())); Systemcalls one; one.startscript(Systemcalls::System, tmp); return true; @@ -495,7 +472,7 @@ int LaTeX::scanLogFile(TeXErrors & terr) int last_line = -1; int line_count = 1; int retval = NO_ERRORS; - string tmp = ChangeExtension(file, ".log", true); + string tmp = OnlyFilename(ChangeExtension(file, ".log")); lyxerr[Debug::LATEX] << "Log file: " << tmp << endl; ifstream ifs(tmp.c_str()); @@ -614,40 +591,61 @@ void LaTeX::deplog(DepTable & head) // files used by the LaTeX run. The files are then entered into the // dependency file. - string logfile = ChangeExtension(file, ".log", true); + string logfile = OnlyFilename(ChangeExtension(file, ".log")); + + LRegex reg1(")* *\\(([^ \\)]+).*"); + LRegex reg2("File: ([^ ]+).*"); + LRegex reg3("No file ([^ ]+)\\..*"); + LRegex reg4("\\\\openout[0-9]+.*=.*`([^ ]+)'\\..*"); + LRegex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$"); ifstream ifs(logfile.c_str()); while (ifs) { - // Now we read chars until we find a '(' - char c = 0; - while(ifs.get(c)) { - if (c == '(') break; - }; - if (!ifs) break; - - // We now have c == '(', we now read the the sequence of - // chars until reaching EOL, ' ' or ')' and put that - // into a string. + // Ok, the scanning of files here is not sufficient. + // Sometimes files are named by "File: xxx" only + // So I think we should use some regexps to find files instead. + // "(\([^ ]+\)" should match the "(file " variant + // "File: \([^ ]+\)" should match the "File: file" variant string foundfile; - while (ifs.get(c)) { - if (c == '\n' || c == ' ' || c == ')') - break; - foundfile += c; + string token; + getline(ifs, token); + if (token.empty()) continue; + + if (reg1.exact_match(token)) { + LRegex::SubMatches const & sub = reg1.exec(token); + foundfile = LSubstring(token, sub[1].first, + sub[1].second); + } else if (reg2.exact_match(token)) { + LRegex::SubMatches const & sub = reg2.exec(token); + foundfile = LSubstring(token, sub[1].first, + sub[1].second); + } else if (reg3.exact_match(token)) { + LRegex::SubMatches const & sub = reg3.exec(token); + foundfile = LSubstring(token, sub[1].first, + sub[1].second); + } else if (reg4.exact_match(token)) { + LRegex::SubMatches const & sub = reg4.exec(token); + foundfile = LSubstring(token, sub[1].first, + sub[1].second); + } else { + continue; } + lyxerr[Debug::DEPEND] << "Found file: " - << foundfile << endl; + << foundfile << endl; // Ok now we found a file. - // Now we should make sure that - // this is a file that we can - // access through the normal - // paths: + // Now we should make sure that this is a file that we can + // access through the normal paths. + // We will not try any fance search methods to + // find the file. + // (1) foundfile is an // absolute path and should // be inserted. if (AbsolutePath(foundfile)) { lyxerr[Debug::DEPEND] << "AbsolutePath file: " - << foundfile << endl; + << 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. @@ -658,23 +656,26 @@ void LaTeX::deplog(DepTable & head) // (2) foundfile is in the tmpdir // insert it into head if (FileInfo(OnlyFilename(foundfile)).exist()) { - if (suffixIs(foundfile, ".aux")) { - lyxerr[Debug::DEPEND] << "We don't want " - << OnlyFilename(foundfile) - << " in the dep file" - << endl; + if (unwanted.exact_match(foundfile)) { + lyxerr[Debug::DEPEND] + << "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::DEPEND] << "Tmpdir TeX file: " - << OnlyFilename(foundfile) - << endl; + lyxerr[Debug::DEPEND] + << "Tmpdir TeX file: " + << OnlyFilename(foundfile) + << endl; head.insert(foundfile, true); } else { - lyxerr[Debug::DEPEND] << "In tmpdir file:" - << OnlyFilename(foundfile) - << endl; + lyxerr[Debug::DEPEND] + << "In tmpdir file:" + << OnlyFilename(foundfile) + << endl; head.insert(OnlyFilename(foundfile)); } continue; @@ -684,21 +685,3 @@ void LaTeX::deplog(DepTable & head) << endl; } } - - -void LaTeX::deptex(DepTable & head) -{ - int except = AUX|LOG|DVI|BBL|IND|GLO; - 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::DEPEND] << "deptex: " << tmp << endl; - if (fi.newFile(tmp).exist()) - head.insert(tmp); - } - } -}