3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
12 * Full author contact details are available in file CREDITS.
17 #include "bufferlist.h"
24 #include "support/filetools.h"
25 #include "support/convert.h"
26 #include "support/lstrings.h"
27 #include "support/lyxlib.h"
28 #include "support/systemcall.h"
29 #include "support/os.h"
31 #include <boost/filesystem/operations.hpp>
32 #include <boost/regex.hpp>
39 using support::absolutePath;
40 using support::bformat;
41 using support::changeExtension;
42 using support::contains;
43 using support::FileName;
44 using support::findtexfile;
45 using support::getcwd;
46 using support::makeAbsPath;
47 using support::onlyFilename;
48 using support::prefixIs;
49 using support::quoteName;
50 using support::removeExtension;
52 using support::rsplit;
55 using support::suffixIs;
56 using support::Systemcall;
57 using support::unlink;
60 namespace os = support::os;
61 namespace fs = boost::filesystem;
67 #ifndef CXX_GLOBAL_CSTD
78 // TODO: in no particular order
79 // - get rid of the call to
80 // BufferList::updateIncludedTeXfiles, this should either
81 // be done before calling LaTeX::funcs or in a completely
83 // - the makeindex style files should be taken care of with
84 // the dependency mechanism.
85 // - makeindex commandline options should be supported
86 // - somewhere support viewing of bibtex and makeindex log files.
87 // - we should perhaps also scan the bibtex log file
91 docstring runMessage(unsigned int count)
93 return bformat(_("Waiting for LaTeX run number %1$d"), count);
102 void TeXErrors::insertError(int line, docstring const & error_desc,
103 docstring const & error_text)
105 Error newerr(line, error_desc, error_text);
106 errors.push_back(newerr);
110 bool operator==(Aux_Info const & a, Aux_Info const & o)
112 return a.aux_file == o.aux_file &&
113 a.citations == o.citations &&
114 a.databases == o.databases &&
115 a.styles == o.styles;
119 bool operator!=(Aux_Info const & a, Aux_Info const & o)
129 LaTeX::LaTeX(string const & latex, OutputParams const & rp,
131 : cmd(latex), file(f), runparams(rp)
134 if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
135 depfile = FileName(file.absFilename() + ".dep-pdf");
136 output_file = FileName(changeExtension(file.absFilename(), ".pdf"));
138 depfile = FileName(file.absFilename() + ".dep");
139 output_file = FileName(changeExtension(file.absFilename(), ".dvi"));
144 void LaTeX::deleteFilesOnError() const
146 // currently just a dummy function.
148 // What files do we have to delete?
150 // This will at least make latex do all the runs
153 // but the reason for the error might be in a generated file...
156 FileName const bbl(changeExtension(file.absFilename(), ".bbl"));
160 FileName const ind(changeExtension(file.absFilename(), ".ind"));
164 FileName const nls(changeExtension(file.absFilename(), ".nls"));
167 // Also remove the aux file
168 FileName const aux(changeExtension(file.absFilename(), ".aux"));
173 int LaTeX::run(TeXErrors & terr)
174 // We know that this function will only be run if the lyx buffer
175 // has been changed. We also know that a newly written .tex file
176 // is always different from the previous one because of the date
177 // in it. However it seems safe to run latex (at least) on time each
178 // time the .tex file changes.
180 int scanres = NO_ERRORS;
181 unsigned int count = 0; // number of times run
182 num_errors = 0; // just to make sure.
183 unsigned int const MAX_RUN = 6;
184 DepTable head; // empty head
185 bool rerun = false; // rerun requested
187 // The class LaTeX does not know the temp path.
188 theBufferList().updateIncludedTeXfiles(getcwd().absFilename(), runparams);
190 // Never write the depfile if an error was encountered.
193 // first check if the file dependencies exist:
194 // ->If it does exist
195 // check if any of the files mentioned in it have
196 // changed (done using a checksum).
198 // run latex once and
199 // remake the dependency file
200 // -> if not changed:
201 // just return there is nothing to do for us.
202 // ->if it doesn't exist
204 // run latex once (we need to run latex once anyway) and
205 // remake the dependency file.
208 bool had_depfile = fs::exists(depfile.toFilesystemEncoding());
209 bool run_bibtex = false;
210 FileName const aux_file(changeExtension(file.absFilename(), "aux"));
213 lyxerr[Debug::DEPEND] << "Dependency file exists" << endl;
214 // Read the dep file:
215 had_depfile = head.read(depfile);
219 // Update the checksums
221 // Can't just check if anything has changed because it might have aborted
222 // on error last time... in which cas we need to re-run latex
223 // and collect the error messages (even if they are the same).
224 if (!fs::exists(output_file.toFilesystemEncoding())) {
225 lyxerr[Debug::DEPEND]
226 << "re-running LaTeX because output file doesn't exist." << endl;
227 } else if (!head.sumchange()) {
228 lyxerr[Debug::DEPEND] << "return no_change" << endl;
231 lyxerr[Debug::DEPEND]
232 << "Dependency file has changed" << endl;
235 if (head.extchanged(".bib") || head.extchanged(".bst"))
238 lyxerr[Debug::DEPEND]
239 << "Dependency file does not exist, or has wrong format" << endl;
241 /// We scan the aux file even when had_depfile = false,
242 /// because we can run pdflatex on the file after running latex on it,
243 /// in which case we will not need to run bibtex again.
244 vector<Aux_Info> bibtex_info_old;
246 bibtex_info_old = scanAuxFiles(aux_file);
249 lyxerr[Debug::LATEX] << "Run #" << count << endl;
250 message(runMessage(count));
253 scanres = scanLogFile(terr);
254 if (scanres & ERROR_RERUN) {
255 lyxerr[Debug::LATEX] << "Rerunning LaTeX" << endl;
257 scanres = scanLogFile(terr);
260 if (scanres & ERRORS) {
261 deleteFilesOnError();
262 return scanres; // return on error
265 vector<Aux_Info> const bibtex_info = scanAuxFiles(aux_file);
266 if (!run_bibtex && bibtex_info_old != bibtex_info)
269 // update the dependencies.
270 deplog(head); // reads the latex log
274 // At this point we must run external programs if needed.
275 // makeindex will be run if a .idx file changed or was generated.
276 // And if there were undefined citations or changes in references
277 // the .aux file is checked for signs of bibtex. Bibtex is then run
280 // memoir (at least) writes an empty *idx file in the first place.
281 // A second latex run is needed.
282 FileName const idxfile(changeExtension(file.absFilename(), ".idx"));
283 rerun = fs::exists(idxfile.toFilesystemEncoding()) &&
284 fs::is_empty(idxfile.toFilesystemEncoding());
287 if (head.haschanged(idxfile)) {
289 lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
290 message(_("Running MakeIndex."));
291 // onlyFilename() is needed for cygwin
292 rerun |= runMakeIndex(onlyFilename(idxfile.absFilename()), runparams);
294 if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
295 lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
296 message(_("Running MakeIndex for nomencl."));
297 // onlyFilename() is needed for cygwin
298 string const nomenclstr = " -s nomencl.ist -o " + onlyFilename(changeExtension(file.toFilesystemEncoding(), ".nls"));
299 rerun |= runMakeIndex(onlyFilename(changeExtension(file.absFilename(), ".nlo")), runparams, nomenclstr);
303 // if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
304 if (scanres & UNDEF_CIT || run_bibtex) {
305 // Here we must scan the .aux file and look for
306 // "\bibdata" and/or "\bibstyle". If one of those
307 // tags is found -> run bibtex and set rerun = true;
309 lyxerr[Debug::LATEX] << "Running BibTeX." << endl;
310 message(_("Running BibTeX."));
311 updateBibtexDependencies(head, bibtex_info);
312 rerun |= runBibTeX(bibtex_info);
313 } else if (!had_depfile) {
314 /// If we run pdflatex on the file after running latex on it,
315 /// then we do not need to run bibtex, but we do need to
316 /// insert the .bib and .bst files into the .dep-pdf file.
317 updateBibtexDependencies(head, bibtex_info);
321 // we know on this point that latex has been run once (or we just
322 // returned) and the question now is to decide if we need to run
323 // it any more. This is done by asking if any of the files in the
324 // dependency file has changed. (remember that the checksum for
325 // a given file is reported to have changed if it just was created)
326 // -> if changed or rerun == true:
327 // run latex once more and
328 // update the dependency structure
329 // -> if not changed:
330 // we does nothing at this point
332 if (rerun || head.sumchange()) {
335 lyxerr[Debug::DEPEND]
336 << "Dep. file has changed or rerun requested" << endl;
338 << "Run #" << count << endl;
339 message(runMessage(count));
341 scanres = scanLogFile(terr);
342 if (scanres & ERRORS) {
343 deleteFilesOnError();
344 return scanres; // return on error
347 // update the depedencies
348 deplog(head); // reads the latex log
351 lyxerr[Debug::DEPEND] << "Dep. file has NOT changed" << endl;
355 // The inclusion of files generated by external programs like
356 // makeindex or bibtex might have done changes to pagenumbering,
357 // etc. And because of this we must run the external programs
358 // again to make sure everything is redone correctly.
359 // Also there should be no need to run the external programs any
362 // run makeindex if the <file>.idx has changed or was generated.
363 if (head.haschanged(FileName(changeExtension(file.absFilename(), ".idx")))) {
365 lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
366 message(_("Running MakeIndex."));
367 // onlyFilename() is needed for cygwin
368 rerun = runMakeIndex(onlyFilename(changeExtension(file.absFilename(), ".idx")), runparams);
371 // I am not pretty sure if need this twice.
372 if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
373 lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
374 message(_("Running MakeIndex for nomencl."));
375 // onlyFilename() is needed for cygwin
376 string nomenclstr = " -s nomencl.ist -o " + onlyFilename(changeExtension(file.toFilesystemEncoding(), ".nls"));
377 rerun |= runMakeIndex(onlyFilename(changeExtension(file.absFilename(), ".nlo")), runparams, nomenclstr);
381 // we will only run latex more if the log file asks for it.
382 // or if the sumchange() is true.
383 // -> rerun asked for:
385 // remake the dependency file
386 // goto 2 or return if max runs are reached.
387 // -> rerun not asked for:
388 // just return (fall out of bottom of func)
390 while ((head.sumchange() || rerun || (scanres & RERUN))
391 && count < MAX_RUN) {
392 // Yes rerun until message goes away, or until
393 // MAX_RUNS are reached.
396 lyxerr[Debug::LATEX] << "Run #" << count << endl;
397 message(runMessage(count));
399 scanres = scanLogFile(terr);
400 if (scanres & ERRORS) {
401 deleteFilesOnError();
402 return scanres; // return on error
409 // Write the dependencies to file.
411 lyxerr[Debug::LATEX] << "Done." << endl;
416 int LaTeX::startscript()
418 // onlyFilename() is needed for cygwin
419 string tmp = cmd + ' ' + quoteName(onlyFilename(file.toFilesystemEncoding())) + " > " + os::nulldev();
421 return one.startscript(Systemcall::Wait, tmp);
425 bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams,
426 string const & params)
429 << "idx file has been made, running makeindex on file "
431 string tmp = lyxrc.index_command + ' ';
433 tmp = subst(tmp, "$$lang", runparams.document_language);
437 one.startscript(Systemcall::Wait, tmp);
442 vector<Aux_Info> const
443 LaTeX::scanAuxFiles(FileName const & file)
445 vector<Aux_Info> result;
447 result.push_back(scanAuxFile(file));
449 string const basename = removeExtension(file.absFilename());
450 for (int i = 1; i < 1000; ++i) {
451 FileName const file2(basename
452 + '.' + convert<string>(i)
454 if (!fs::exists(file2.toFilesystemEncoding()))
456 result.push_back(scanAuxFile(file2));
462 Aux_Info const LaTeX::scanAuxFile(FileName const & file)
465 result.aux_file = file;
466 scanAuxFile(file, result);
471 void LaTeX::scanAuxFile(FileName const & file, Aux_Info & aux_info)
473 lyxerr[Debug::LATEX] << "Scanning aux file: " << file << endl;
475 ifstream ifs(file.toFilesystemEncoding().c_str());
477 static regex const reg1("\\\\citation\\{([^}]+)\\}");
478 static regex const reg2("\\\\bibdata\\{([^}]+)\\}");
479 static regex const reg3("\\\\bibstyle\\{([^}]+)\\}");
480 static regex const reg4("\\\\@input\\{([^}]+)\\}");
482 while (getline(ifs, token)) {
483 token = rtrim(token, "\r");
485 // FIXME UNICODE: We assume that citation keys and filenames
486 // in the aux file are in the file system encoding.
487 token = to_utf8(from_filesystem8bit(token));
488 if (regex_match(token, sub, reg1)) {
489 string data = sub.str(1);
490 while (!data.empty()) {
492 data = split(data, citation, ',');
493 lyxerr[Debug::LATEX] << "Citation: "
495 aux_info.citations.insert(citation);
497 } else if (regex_match(token, sub, reg2)) {
498 string data = sub.str(1);
499 // data is now all the bib files separated by ','
500 // get them one by one and pass them to the helper
501 while (!data.empty()) {
503 data = split(data, database, ',');
504 database = changeExtension(database, "bib");
505 lyxerr[Debug::LATEX] << "BibTeX database: `"
506 << database << '\'' << endl;
507 aux_info.databases.insert(database);
509 } else if (regex_match(token, sub, reg3)) {
510 string style = sub.str(1);
511 // token is now the style file
512 // pass it to the helper
513 style = changeExtension(style, "bst");
514 lyxerr[Debug::LATEX] << "BibTeX style: `"
515 << style << '\'' << endl;
516 aux_info.styles.insert(style);
517 } else if (regex_match(token, sub, reg4)) {
518 string const file2 = sub.str(1);
519 scanAuxFile(makeAbsPath(file2), aux_info);
525 void LaTeX::updateBibtexDependencies(DepTable & dep,
526 vector<Aux_Info> const & bibtex_info)
528 // Since a run of Bibtex mandates more latex runs it is ok to
529 // remove all ".bib" and ".bst" files.
530 dep.remove_files_with_extension(".bib");
531 dep.remove_files_with_extension(".bst");
532 //string aux = OnlyFilename(ChangeExtension(file, ".aux"));
534 for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
535 it != bibtex_info.end(); ++it) {
536 for (set<string>::const_iterator it2 = it->databases.begin();
537 it2 != it->databases.end(); ++it2) {
538 FileName const file = findtexfile(*it2, "bib");
540 dep.insert(file, true);
543 for (set<string>::const_iterator it2 = it->styles.begin();
544 it2 != it->styles.end(); ++it2) {
545 FileName const file = findtexfile(*it2, "bst");
547 dep.insert(file, true);
553 bool LaTeX::runBibTeX(vector<Aux_Info> const & bibtex_info)
556 for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
557 it != bibtex_info.end(); ++it) {
558 if (it->databases.empty())
562 string tmp = lyxrc.bibtex_command + " ";
563 // onlyFilename() is needed for cygwin
564 tmp += quoteName(onlyFilename(removeExtension(it->aux_file.absFilename())));
566 one.startscript(Systemcall::Wait, tmp);
568 // Return whether bibtex was run
573 int LaTeX::scanLogFile(TeXErrors & terr)
577 int retval = NO_ERRORS;
578 string tmp = onlyFilename(changeExtension(file.absFilename(), ".log"));
579 lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
580 FileName const fn = FileName(makeAbsPath(tmp));
581 ifstream ifs(fn.toFilesystemEncoding().c_str());
584 while (getline(ifs, token)) {
585 // MikTeX sometimes inserts \0 in the log file. They can't be
586 // removed directly with the existing string utility
587 // functions, so convert them first to \r, and remove all
588 // \r's afterwards, since we need to remove them anyway.
589 token = subst(token, '\0', '\r');
590 token = subst(token, "\r", "");
592 lyxerr[Debug::LATEX] << "Log line: " << token << endl;
597 if (prefixIs(token, "LaTeX Warning:") ||
598 prefixIs(token, "! pdfTeX warning")) {
599 // Here shall we handle different
601 retval |= LATEX_WARNING;
602 lyxerr[Debug::LATEX] << "LaTeX Warning." << endl;
603 if (contains(token, "Rerun to get cross-references")) {
606 << "We should rerun." << endl;
607 } else if (contains(token, "Citation")
608 && contains(token, "on page")
609 && contains(token, "undefined")) {
612 } else if (prefixIs(token, "Package")) {
614 retval |= PACKAGE_WARNING;
615 if (contains(token, "natbib Warning:")) {
617 if (contains(token, "Citation")
618 && contains(token, "on page")
619 && contains(token, "undefined")) {
622 } else if (contains(token, "run BibTeX")) {
624 } else if (contains(token, "Rerun LaTeX") ||
625 contains(token, "Rerun to get")) {
626 // at least longtable.sty and bibtopic.sty
629 << "We should rerun." << endl;
632 } else if (token[0] == '(') {
633 if (contains(token, "Rerun LaTeX") ||
634 contains(token, "Rerun to get")) {
637 << "We should rerun." << endl;
640 } else if (prefixIs(token, "! ")) {
641 // Ok, we have something that looks like a TeX Error
642 // but what do we really have.
644 // Just get the error description:
645 string desc(token, 2);
646 if (contains(token, "LaTeX Error:"))
647 retval |= LATEX_ERROR;
652 if (!getline(ifs, tmp))
656 } while (!prefixIs(tmp, "l."));
657 if (prefixIs(tmp, "l.")) {
658 // we have a latex error
660 if (contains(desc, "Package babel Error: You haven't defined the language"))
661 retval |= ERROR_RERUN;
662 // get the line number:
664 sscanf(tmp.c_str(), "l.%d", &line);
665 // get the rest of the message:
666 string errstr(tmp, tmp.find(' '));
669 while (!contains(errstr, "l.")
671 && !prefixIs(tmp, "! ")
672 && !contains(tmp, "(job aborted")) {
678 << "line: " << line << '\n'
679 << "Desc: " << desc << '\n'
680 << "Text: " << errstr << endl;
681 if (line == last_line)
687 if (line_count <= 5) {
689 // We have no idea what the encoding of
691 // It seems that the output from the
692 // latex compiler itself is pure ASCII,
693 // but it can include bits from the
694 // document, so whatever encoding we
695 // assume here it can be wrong.
696 terr.insertError(line, from_local8bit(desc), from_local8bit(errstr));
701 // information messages, TeX warnings and other
702 // warnings we have not caught earlier.
703 if (prefixIs(token, "Overfull ")) {
704 retval |= TEX_WARNING;
705 } else if (prefixIs(token, "Underfull ")) {
706 retval |= TEX_WARNING;
707 } else if (contains(token, "Rerun to get citations")) {
708 // Natbib seems to use this.
710 } else if (contains(token, "No pages of output")) {
711 // A dvi file was not created
713 } else if (contains(token, "That makes 100 errors")) {
714 // More than 100 errors were reprted
715 retval |= TOO_MANY_ERRORS;
719 lyxerr[Debug::LATEX] << "Log line: " << token << endl;
726 bool handleFoundFile(string const & ff, DepTable & head)
728 // convert from native os path to unix path
729 string foundfile = os::internal_path(trim(ff));
731 lyxerr[Debug::DEPEND] << "Found file: " << foundfile << endl;
733 // Ok now we found a file.
734 // Now we should make sure that this is a file that we can
735 // access through the normal paths.
736 // We will not try any fancy search methods to
739 // (1) foundfile is an
740 // absolute path and should
742 if (absolutePath(foundfile)) {
743 lyxerr[Debug::DEPEND] << "AbsolutePath file: "
744 << foundfile << endl;
745 // On initial insert we want to do the update at once
746 // since this file cannot be a file generated by
748 FileName absname(foundfile);
749 if (fs::exists(absname.toFilesystemEncoding()) &&
750 !fs::is_directory(absname.toFilesystemEncoding())) {
751 head.insert(absname, true);
755 string strippedfile = foundfile;
756 while (contains(strippedfile, " ")) {
757 // strip off part after last space and try again
758 string tmp = strippedfile;
759 string const stripoff =
760 rsplit(tmp, strippedfile, ' ');
761 absname.set(strippedfile);
762 if (fs::exists(absname.toFilesystemEncoding()) &&
763 !fs::is_directory(absname.toFilesystemEncoding())) {
764 head.insert(absname, true);
771 string onlyfile = onlyFilename(foundfile);
772 FileName absname(makeAbsPath(onlyfile));
775 while (contains(foundfile, " ")) {
776 if (fs::exists(absname.toFilesystemEncoding()))
780 // strip off part after last space and try again
782 string const stripoff = rsplit(foundfile, strippedfile, ' ');
783 foundfile = strippedfile;
784 onlyfile = onlyFilename(strippedfile);
785 absname = makeAbsPath(onlyfile);
789 // (2) foundfile is in the tmpdir
790 // insert it into head
791 if (fs::exists(absname.toFilesystemEncoding())) {
792 static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
793 if (regex_match(onlyfile, unwanted)) {
794 lyxerr[Debug::DEPEND]
797 << " in the dep file"
799 } else if (suffixIs(onlyfile, ".tex")) {
800 // This is a tex file generated by LyX
801 // and latex is not likely to change this
803 lyxerr[Debug::DEPEND]
804 << "Tmpdir TeX file: "
807 head.insert(absname, true);
809 lyxerr[Debug::DEPEND]
813 head.insert(absname);
817 lyxerr[Debug::DEPEND]
818 << "Not a file or we are unable to find it."
825 bool checkLineBreak(string const & ff, DepTable & head)
827 if (contains(ff, '.'))
828 // if we have a dot, we let handleFoundFile decide
829 return handleFoundFile(ff, head);
831 // else, we suspect a line break
838 void LaTeX::deplog(DepTable & head)
840 // This function reads the LaTeX log file end extracts all the external
841 // files used by the LaTeX run. The files are then entered into the
844 string const logfile = onlyFilename(changeExtension(file.absFilename(), ".log"));
846 static regex reg1("File: (.+).*");
847 static regex reg2("No file (.+)(.).*");
848 static regex reg3("\\\\openout[0-9]+.*=.*`(.+)(..).*");
849 // If an index should be created, MikTex does not write a line like
850 // \openout# = 'sample.idx'.
851 // but instead only a line like this into the log:
852 // Writing index file sample.idx
853 static regex reg4("Writing index file (.+).*");
854 // files also can be enclosed in <...>
855 static regex reg5("<([^>]+)(.).*");
856 static regex regnomencl("Writing nomenclature file (.+).*");
857 // If a toc should be created, MikTex does not write a line like
858 // \openout# = `sample.toc'.
859 // but only a line like this into the log:
861 // This line is also written by tetex.
862 // This line is not present if no toc should be created.
863 static regex miktexTocReg("\\\\tf@toc=\\\\write.*");
864 static regex reg6(".*\\([^)]+.*");
866 FileName const fn(makeAbsPath(logfile));
867 ifstream ifs(fn.toFilesystemEncoding().c_str());
870 // Ok, the scanning of files here is not sufficient.
871 // Sometimes files are named by "File: xxx" only
872 // So I think we should use some regexps to find files instead.
873 // Note: all file names and paths might contains spaces.
875 bool found_file = false;
878 // MikTeX sometimes inserts \0 in the log file. They can't be
879 // removed directly with the existing string utility
880 // functions, so convert them first to \r, and remove all
881 // \r's afterwards, since we need to remove them anyway.
882 token = subst(token, '\0', '\r');
883 token = subst(token, "\r", "");
884 if (token.empty() || token == ")") {
889 // Sometimes, filenames are broken across lines.
890 // We care for that and save suspicious lines.
891 // Here we exclude some cases where we are sure
892 // that there is no continued filename
893 if (!lastline.empty()) {
894 static regex package_info("Package \\w+ Info: .*");
895 static regex package_warning("Package \\w+ Warning: .*");
896 if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
897 || prefixIs(token, "Package:")
898 || prefixIs(token, "Language:")
899 || prefixIs(token, "LaTeX Info:")
900 || prefixIs(token, "LaTeX Font Info:")
901 || prefixIs(token, "\\openout[")
902 || prefixIs(token, "))")
903 || regex_match(token, package_info)
904 || regex_match(token, package_warning))
908 if (!lastline.empty())
909 // probably a continued filename from last line
910 token = lastline + token;
914 // FIXME UNICODE: We assume that the file names in the log
915 // file are in the file system encoding.
916 token = to_utf8(from_filesystem8bit(token));
918 // (1) "File: file.ext"
919 if (regex_match(token, sub, reg1)) {
921 found_file = checkLineBreak(sub.str(1), head);
923 if (suffixIs(token, ")"))
924 // no line break for sure
925 // pretend we've been succesfully searching
927 // (2) "No file file.ext"
928 } else if (regex_match(token, sub, reg2)) {
929 // file names must contains a dot, line ends with dot
930 if (contains(sub.str(1), '.') && sub.str(2) == ".")
931 found_file = handleFoundFile(sub.str(1), head);
933 // we suspect a line break
935 // (3) "\openout<nr> = `file.ext'."
936 } else if (regex_match(token, sub, reg3)) {
937 // search for closing '. at the end of the line
938 if (sub.str(2) == "\'.")
939 found_file = handleFoundFile(sub.str(1), head);
941 // probable line break
943 // (4) "Writing index file file.ext"
944 } else if (regex_match(token, sub, reg4))
946 found_file = checkLineBreak(sub.str(1), head);
948 else if (regex_match(token, sub, reg5)) {
949 // search for closing '>' and dot ('*.*>') at the eol
950 if (contains(sub.str(1), '.') && sub.str(2) == ">")
951 found_file = handleFoundFile(sub.str(1), head);
953 // probable line break
955 // (6) "Writing nomenclature file file.ext"
956 } else if (regex_match(token, sub, regnomencl))
958 found_file = checkLineBreak(sub.str(1), head);
959 // (7) "\tf@toc=\write<nr>" (for MikTeX)
960 else if (regex_match(token, sub, miktexTocReg))
961 found_file = handleFoundFile(onlyFilename(changeExtension(
962 file.absFilename(), ".toc")), head);
964 // not found, but we won't check further
965 // pretend we've been succesfully searching
969 // note that we can have several of these on one line
970 // this must be queried separated, because of
971 // cases such as "File: file.ext (type eps)"
972 // where "File: file.ext" would be skipped
973 if (regex_match(token, sub, reg6)) {
974 // search for strings in (...)
975 static regex reg6_1("\\(([^()]+)(.).*");
977 string::const_iterator first = token.begin();
978 string::const_iterator end = token.end();
980 while (regex_search(first, end, what, reg6_1)) {
981 // if we have a dot, try to handle as file
982 if (contains(what.str(1), '.')) {
983 first = what[0].second;
984 if (what.str(2) == ")") {
985 handleFoundFile(what.str(1), head);
986 // since we had a closing bracket,
987 // do not investigate further
990 // if we have no closing bracket,
991 // try to handle as file nevertheless
992 found_file = handleFoundFile(
993 what.str(1) + what.str(2), head);
995 // if we do not have a dot, check if the line has
996 // a closing bracket (else, we suspect a line break)
997 else if (what.str(2) != ")") {
998 first = what[0].second;
1001 // we have a closing bracket, so the content
1002 // is not a file name.
1003 // no need to investigate further
1004 // pretend we've been succesfully searching
1005 first = what[0].second;
1012 // probable linebreak:
1016 // no linebreak: reset
1017 lastline = string();
1020 // Make sure that the main .tex file is in the dependency file.
1021 head.insert(file, true);