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
11 * \author Jürgen Spitzmüller
13 * Full author contact details are available in file CREDITS.
18 #include "BufferList.h"
20 #include "support/gettext.h"
22 #include "support/debug.h"
25 #include "support/convert.h"
26 #include "support/FileName.h"
27 #include "support/filetools.h"
28 #include "support/lstrings.h"
29 #include "support/Systemcall.h"
30 #include "support/os.h"
32 #include <boost/regex.hpp>
40 using namespace lyx::support;
44 namespace os = support::os;
46 // TODO: in no particular order
47 // - get rid of the call to
48 // BufferList::updateIncludedTeXfiles, this should either
49 // be done before calling LaTeX::funcs or in a completely
51 // - the makeindex style files should be taken care of with
52 // the dependency mechanism.
53 // - makeindex commandline options should be supported
54 // - somewhere support viewing of bibtex and makeindex log files.
55 // - we should perhaps also scan the bibtex log file
59 docstring runMessage(unsigned int count)
61 return bformat(_("Waiting for LaTeX run number %1$d"), count);
70 void TeXErrors::insertError(int line, docstring const & error_desc,
71 docstring const & error_text)
73 Error newerr(line, error_desc, error_text);
74 errors.push_back(newerr);
78 bool operator==(Aux_Info const & a, Aux_Info const & o)
80 return a.aux_file == o.aux_file &&
81 a.citations == o.citations &&
82 a.databases == o.databases &&
87 bool operator!=(Aux_Info const & a, Aux_Info const & o)
97 LaTeX::LaTeX(string const & latex, OutputParams const & rp,
99 : cmd(latex), file(f), runparams(rp)
102 if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
103 depfile = FileName(file.absFilename() + ".dep-pdf");
105 FileName(changeExtension(file.absFilename(), ".pdf"));
107 depfile = FileName(file.absFilename() + ".dep");
109 FileName(changeExtension(file.absFilename(), ".dvi"));
114 void LaTeX::deleteFilesOnError() const
116 // currently just a dummy function.
118 // What files do we have to delete?
120 // This will at least make latex do all the runs
121 depfile.removeFile();
123 // but the reason for the error might be in a generated file...
126 FileName const bbl(changeExtension(file.absFilename(), ".bbl"));
130 FileName const ind(changeExtension(file.absFilename(), ".ind"));
134 FileName const nls(changeExtension(file.absFilename(), ".nls"));
137 // nomencl file (old version of the package)
138 FileName const gls(changeExtension(file.absFilename(), ".gls"));
141 // Also remove the aux file
142 FileName const aux(changeExtension(file.absFilename(), ".aux"));
147 int LaTeX::run(TeXErrors & terr)
148 // We know that this function will only be run if the lyx buffer
149 // has been changed. We also know that a newly written .tex file
150 // is always different from the previous one because of the date
151 // in it. However it seems safe to run latex (at least) on time
152 // each time the .tex file changes.
154 int scanres = NO_ERRORS;
155 unsigned int count = 0; // number of times run
156 num_errors = 0; // just to make sure.
157 unsigned int const MAX_RUN = 6;
158 DepTable head; // empty head
159 bool rerun = false; // rerun requested
161 // The class LaTeX does not know the temp path.
162 theBufferList().updateIncludedTeXfiles(FileName::getcwd().absFilename(),
165 // Never write the depfile if an error was encountered.
168 // first check if the file dependencies exist:
169 // ->If it does exist
170 // check if any of the files mentioned in it have
171 // changed (done using a checksum).
173 // run latex once and
174 // remake the dependency file
175 // -> if not changed:
176 // just return there is nothing to do for us.
177 // ->if it doesn't exist
179 // run latex once (we need to run latex once anyway) and
180 // remake the dependency file.
183 bool had_depfile = depfile.exists();
184 bool run_bibtex = false;
185 FileName const aux_file(changeExtension(file.absFilename(), "aux"));
188 LYXERR(Debug::DEPEND, "Dependency file exists");
189 // Read the dep file:
190 had_depfile = head.read(depfile);
194 // Update the checksums
196 // Can't just check if anything has changed because it might
197 // have aborted on error last time... in which cas we need
198 // to re-run latex and collect the error messages
199 // (even if they are the same).
200 if (!output_file.exists()) {
201 LYXERR(Debug::DEPEND,
202 "re-running LaTeX because output file doesn't exist.");
203 } else if (!head.sumchange()) {
204 LYXERR(Debug::DEPEND, "return no_change");
207 LYXERR(Debug::DEPEND, "Dependency file has changed");
210 if (head.extchanged(".bib") || head.extchanged(".bst"))
213 LYXERR(Debug::DEPEND,
214 "Dependency file does not exist, or has wrong format");
216 /// We scan the aux file even when had_depfile = false,
217 /// because we can run pdflatex on the file after running latex on it,
218 /// in which case we will not need to run bibtex again.
219 vector<Aux_Info> bibtex_info_old;
221 bibtex_info_old = scanAuxFiles(aux_file);
224 LYXERR(Debug::LATEX, "Run #" << count);
225 message(runMessage(count));
228 scanres = scanLogFile(terr);
229 if (scanres & ERROR_RERUN) {
230 LYXERR(Debug::LATEX, "Rerunning LaTeX");
232 scanres = scanLogFile(terr);
235 if (scanres & ERRORS) {
236 deleteFilesOnError();
237 return scanres; // return on error
240 vector<Aux_Info> const bibtex_info = scanAuxFiles(aux_file);
241 if (!run_bibtex && bibtex_info_old != bibtex_info)
244 // update the dependencies.
245 deplog(head); // reads the latex log
249 // At this point we must run external programs if needed.
250 // makeindex will be run if a .idx file changed or was generated.
251 // And if there were undefined citations or changes in references
252 // the .aux file is checked for signs of bibtex. Bibtex is then run
255 // memoir (at least) writes an empty *idx file in the first place.
256 // A second latex run is needed.
257 FileName const idxfile(changeExtension(file.absFilename(), ".idx"));
258 rerun = idxfile.exists() && idxfile.isFileEmpty();
261 if (head.haschanged(idxfile)) {
263 LYXERR(Debug::LATEX, "Running MakeIndex.");
264 message(_("Running MakeIndex."));
265 // onlyFilename() is needed for cygwin
266 rerun |= runMakeIndex(onlyFilename(idxfile.absFilename()),
269 FileName const nlofile(changeExtension(file.absFilename(), ".nlo"));
270 if (head.haschanged(nlofile))
271 rerun |= runMakeIndexNomencl(file, runparams, ".nlo", ".nls");
272 FileName const glofile(changeExtension(file.absFilename(), ".glo"));
273 if (head.haschanged(glofile))
274 rerun |= runMakeIndexNomencl(file, runparams, ".glo", ".gls");
277 // if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
278 if (scanres & UNDEF_CIT || run_bibtex) {
279 // Here we must scan the .aux file and look for
280 // "\bibdata" and/or "\bibstyle". If one of those
281 // tags is found -> run bibtex and set rerun = true;
283 LYXERR(Debug::LATEX, "Running BibTeX.");
284 message(_("Running BibTeX."));
285 updateBibtexDependencies(head, bibtex_info);
286 rerun |= runBibTeX(bibtex_info);
287 } else if (!had_depfile) {
288 /// If we run pdflatex on the file after running latex on it,
289 /// then we do not need to run bibtex, but we do need to
290 /// insert the .bib and .bst files into the .dep-pdf file.
291 updateBibtexDependencies(head, bibtex_info);
295 // we know on this point that latex has been run once (or we just
296 // returned) and the question now is to decide if we need to run
297 // it any more. This is done by asking if any of the files in the
298 // dependency file has changed. (remember that the checksum for
299 // a given file is reported to have changed if it just was created)
300 // -> if changed or rerun == true:
301 // run latex once more and
302 // update the dependency structure
303 // -> if not changed:
304 // we does nothing at this point
306 if (rerun || head.sumchange()) {
309 LYXERR(Debug::DEPEND, "Dep. file has changed or rerun requested");
310 LYXERR(Debug::LATEX, "Run #" << count);
311 message(runMessage(count));
313 scanres = scanLogFile(terr);
314 if (scanres & ERRORS) {
315 deleteFilesOnError();
316 return scanres; // return on error
319 // update the depedencies
320 deplog(head); // reads the latex log
323 LYXERR(Debug::DEPEND, "Dep. file has NOT changed");
327 // The inclusion of files generated by external programs like
328 // makeindex or bibtex might have done changes to pagenumbering,
329 // etc. And because of this we must run the external programs
330 // again to make sure everything is redone correctly.
331 // Also there should be no need to run the external programs any
334 // run makeindex if the <file>.idx has changed or was generated.
335 if (head.haschanged(idxfile)) {
337 LYXERR(Debug::LATEX, "Running MakeIndex.");
338 message(_("Running MakeIndex."));
339 // onlyFilename() is needed for cygwin
340 rerun = runMakeIndex(onlyFilename(changeExtension(
341 file.absFilename(), ".idx")), runparams);
344 // I am not pretty sure if need this twice.
345 if (head.haschanged(nlofile))
346 rerun |= runMakeIndexNomencl(file, runparams, ".nlo", ".nls");
347 if (head.haschanged(glofile))
348 rerun |= runMakeIndexNomencl(file, runparams, ".glo", ".gls");
351 // we will only run latex more if the log file asks for it.
352 // or if the sumchange() is true.
353 // -> rerun asked for:
355 // remake the dependency file
356 // goto 2 or return if max runs are reached.
357 // -> rerun not asked for:
358 // just return (fall out of bottom of func)
360 while ((head.sumchange() || rerun || (scanres & RERUN))
361 && count < MAX_RUN) {
362 // Yes rerun until message goes away, or until
363 // MAX_RUNS are reached.
366 LYXERR(Debug::LATEX, "Run #" << count);
367 message(runMessage(count));
369 scanres = scanLogFile(terr);
370 if (scanres & ERRORS) {
371 deleteFilesOnError();
372 return scanres; // return on error
379 // Write the dependencies to file.
381 LYXERR(Debug::LATEX, "Done.");
386 int LaTeX::startscript()
388 // onlyFilename() is needed for cygwin
389 string tmp = cmd + ' '
390 + quoteName(onlyFilename(file.toFilesystemEncoding()))
391 + " > " + os::nulldev();
393 return one.startscript(Systemcall::Wait, tmp);
397 bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams,
398 string const & params)
401 "idx file has been made, running makeindex on file " << f);
402 string tmp = lyxrc.index_command + ' ';
404 tmp = subst(tmp, "$$lang", runparams.document_language);
408 one.startscript(Systemcall::Wait, tmp);
413 bool LaTeX::runMakeIndexNomencl(FileName const & file,
414 OutputParams const & runparams,
415 string const & nlo, string const & nls)
417 LYXERR(Debug::LATEX, "Running MakeIndex for nomencl.");
418 message(_("Running MakeIndex for nomencl."));
419 // onlyFilename() is needed for cygwin
420 string const nomenclstr = " -s nomencl.ist -o "
421 + onlyFilename(changeExtension(file.toFilesystemEncoding(), nls));
423 onlyFilename(changeExtension(file.absFilename(), nlo)),
424 runparams, nomenclstr);
428 vector<Aux_Info> const
429 LaTeX::scanAuxFiles(FileName const & file)
431 vector<Aux_Info> result;
433 result.push_back(scanAuxFile(file));
435 string const basename = removeExtension(file.absFilename());
436 for (int i = 1; i < 1000; ++i) {
437 FileName const file2(basename
438 + '.' + convert<string>(i)
442 result.push_back(scanAuxFile(file2));
448 Aux_Info const LaTeX::scanAuxFile(FileName const & file)
451 result.aux_file = file;
452 scanAuxFile(file, result);
457 void LaTeX::scanAuxFile(FileName const & file, Aux_Info & aux_info)
459 LYXERR(Debug::LATEX, "Scanning aux file: " << file);
461 ifstream ifs(file.toFilesystemEncoding().c_str());
463 static regex const reg1("\\\\citation\\{([^}]+)\\}");
464 static regex const reg2("\\\\bibdata\\{([^}]+)\\}");
465 static regex const reg3("\\\\bibstyle\\{([^}]+)\\}");
466 static regex const reg4("\\\\@input\\{([^}]+)\\}");
468 while (getline(ifs, token)) {
469 token = rtrim(token, "\r");
471 // FIXME UNICODE: We assume that citation keys and filenames
472 // in the aux file are in the file system encoding.
473 token = to_utf8(from_filesystem8bit(token));
474 if (regex_match(token, sub, reg1)) {
475 string data = sub.str(1);
476 while (!data.empty()) {
478 data = split(data, citation, ',');
479 LYXERR(Debug::LATEX, "Citation: " << citation);
480 aux_info.citations.insert(citation);
482 } else if (regex_match(token, sub, reg2)) {
483 string data = sub.str(1);
484 // data is now all the bib files separated by ','
485 // get them one by one and pass them to the helper
486 while (!data.empty()) {
488 data = split(data, database, ',');
489 database = changeExtension(database, "bib");
490 LYXERR(Debug::LATEX, "BibTeX database: `" << database << '\'');
491 aux_info.databases.insert(database);
493 } else if (regex_match(token, sub, reg3)) {
494 string style = sub.str(1);
495 // token is now the style file
496 // pass it to the helper
497 style = changeExtension(style, "bst");
498 LYXERR(Debug::LATEX, "BibTeX style: `" << style << '\'');
499 aux_info.styles.insert(style);
500 } else if (regex_match(token, sub, reg4)) {
501 string const file2 = sub.str(1);
502 scanAuxFile(makeAbsPath(file2), aux_info);
508 void LaTeX::updateBibtexDependencies(DepTable & dep,
509 vector<Aux_Info> const & bibtex_info)
511 // Since a run of Bibtex mandates more latex runs it is ok to
512 // remove all ".bib" and ".bst" files.
513 dep.remove_files_with_extension(".bib");
514 dep.remove_files_with_extension(".bst");
515 //string aux = OnlyFilename(ChangeExtension(file, ".aux"));
517 for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
518 it != bibtex_info.end(); ++it) {
519 for (set<string>::const_iterator it2 = it->databases.begin();
520 it2 != it->databases.end(); ++it2) {
521 FileName const file = findtexfile(*it2, "bib");
523 dep.insert(file, true);
526 for (set<string>::const_iterator it2 = it->styles.begin();
527 it2 != it->styles.end(); ++it2) {
528 FileName const file = findtexfile(*it2, "bst");
530 dep.insert(file, true);
536 bool LaTeX::runBibTeX(vector<Aux_Info> const & bibtex_info)
539 for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
540 it != bibtex_info.end(); ++it) {
541 if (it->databases.empty())
545 string tmp = lyxrc.bibtex_command + " ";
546 // onlyFilename() is needed for cygwin
547 tmp += quoteName(onlyFilename(removeExtension(
548 it->aux_file.absFilename())));
550 one.startscript(Systemcall::Wait, tmp);
552 // Return whether bibtex was run
557 int LaTeX::scanLogFile(TeXErrors & terr)
561 int retval = NO_ERRORS;
563 onlyFilename(changeExtension(file.absFilename(), ".log"));
564 LYXERR(Debug::LATEX, "Log file: " << tmp);
565 FileName const fn = FileName(makeAbsPath(tmp));
566 ifstream ifs(fn.toFilesystemEncoding().c_str());
567 bool fle_style = false;
568 static regex file_line_error(".+\\.\\D+:[0-9]+: (.+)");
571 while (getline(ifs, token)) {
572 // MikTeX sometimes inserts \0 in the log file. They can't be
573 // removed directly with the existing string utility
574 // functions, so convert them first to \r, and remove all
575 // \r's afterwards, since we need to remove them anyway.
576 token = subst(token, '\0', '\r');
577 token = subst(token, "\r", "");
580 LYXERR(Debug::LATEX, "Log line: " << token);
585 if (contains(token, "file:line:error style messages enabled"))
588 if (prefixIs(token, "LaTeX Warning:") ||
589 prefixIs(token, "! pdfTeX warning")) {
590 // Here shall we handle different
592 retval |= LATEX_WARNING;
593 LYXERR(Debug::LATEX, "LaTeX Warning.");
594 if (contains(token, "Rerun to get cross-references")) {
596 LYXERR(Debug::LATEX, "We should rerun.");
597 } else if (contains(token, "Citation")
598 && contains(token, "on page")
599 && contains(token, "undefined")) {
602 } else if (prefixIs(token, "Package")) {
604 retval |= PACKAGE_WARNING;
605 if (contains(token, "natbib Warning:")) {
607 if (contains(token, "Citation")
608 && contains(token, "on page")
609 && contains(token, "undefined")) {
612 } else if (contains(token, "run BibTeX")) {
614 } else if (contains(token, "Rerun LaTeX") ||
615 contains(token, "Rerun to get")) {
616 // at least longtable.sty and bibtopic.sty
618 LYXERR(Debug::LATEX, "We should rerun.");
621 } else if (token[0] == '(') {
622 if (contains(token, "Rerun LaTeX") ||
623 contains(token, "Rerun to get")) {
625 LYXERR(Debug::LATEX, "We should rerun.");
628 } else if (prefixIs(token, "! ") ||
629 fle_style && regex_match(token, sub, file_line_error)) {
630 // Ok, we have something that looks like a TeX Error
631 // but what do we really have.
633 // Just get the error description:
635 if (prefixIs(token, "! "))
636 desc = string(token, 2);
639 if (contains(token, "LaTeX Error:"))
640 retval |= LATEX_ERROR;
645 if (!getline(ifs, tmp))
649 } while (!prefixIs(tmp, "l."));
650 if (prefixIs(tmp, "l.")) {
651 // we have a latex error
654 "Package babel Error: You haven't defined the language") ||
656 "Package babel Error: You haven't loaded the option"))
657 retval |= ERROR_RERUN;
658 // get the line number:
660 sscanf(tmp.c_str(), "l.%d", &line);
661 // get the rest of the message:
662 string errstr(tmp, tmp.find(' '));
665 while (!contains(errstr, "l.")
667 && !prefixIs(tmp, "! ")
668 && !contains(tmp, "(job aborted")) {
673 LYXERR(Debug::LATEX, "line: " << line << '\n'
674 << "Desc: " << desc << '\n' << "Text: " << errstr);
675 if (line == last_line)
681 if (line_count <= 5) {
683 // We have no idea what the encoding of
685 // It seems that the output from the
686 // latex compiler itself is pure ASCII,
687 // but it can include bits from the
688 // document, so whatever encoding we
689 // assume here it can be wrong.
690 terr.insertError(line,
691 from_local8bit(desc),
692 from_local8bit(errstr));
697 // information messages, TeX warnings and other
698 // warnings we have not caught earlier.
699 if (prefixIs(token, "Overfull ")) {
700 retval |= TEX_WARNING;
701 } else if (prefixIs(token, "Underfull ")) {
702 retval |= TEX_WARNING;
703 } else if (contains(token, "Rerun to get citations")) {
704 // Natbib seems to use this.
706 } else if (contains(token, "No pages of output")) {
707 // A dvi file was not created
709 } else if (contains(token, "That makes 100 errors")) {
710 // More than 100 errors were reprted
711 retval |= TOO_MANY_ERRORS;
715 LYXERR(Debug::LATEX, "Log line: " << token);
722 bool insertIfExists(FileName const & absname, DepTable & head)
724 if (absname.exists() && !absname.isDirectory()) {
725 head.insert(absname, true);
732 bool handleFoundFile(string const & ff, DepTable & head)
734 // convert from native os path to unix path
735 string foundfile = os::internal_path(trim(ff));
737 LYXERR(Debug::DEPEND, "Found file: " << foundfile);
739 // Ok now we found a file.
740 // Now we should make sure that this is a file that we can
741 // access through the normal paths.
742 // We will not try any fancy search methods to
745 // (1) foundfile is an
746 // absolute path and should
748 FileName absname(foundfile);
749 if (absname.isAbsolute()) {
750 LYXERR(Debug::DEPEND, "AbsolutePath file: " << foundfile);
751 // On initial insert we want to do the update at once
752 // since this file cannot be a file generated by
754 if (!insertIfExists(absname, head)) {
756 string strippedfile = foundfile;
757 while (contains(strippedfile, " ")) {
758 // files with spaces are often enclosed in quotation
759 // marks; those have to be removed
760 string unquoted = subst(strippedfile, "\"", "");
761 absname.set(unquoted);
762 if (insertIfExists(absname, head))
764 // strip off part after last space and try again
765 string tmp = strippedfile;
766 string const stripoff =
767 rsplit(tmp, strippedfile, ' ');
768 absname.set(strippedfile);
769 if (insertIfExists(absname, head))
775 string onlyfile = onlyFilename(foundfile);
776 absname = makeAbsPath(onlyfile);
779 while (contains(foundfile, ' ')) {
780 if (absname.exists())
784 // files with spaces are often enclosed in quotation
785 // marks; those have to be removed
786 string unquoted = subst(foundfile, "\"", "");
787 absname = makeAbsPath(unquoted);
788 if (absname.exists())
790 // strip off part after last space and try again
792 string const stripoff =
793 rsplit(foundfile, strippedfile, ' ');
794 foundfile = strippedfile;
795 onlyfile = onlyFilename(strippedfile);
796 absname = makeAbsPath(onlyfile);
800 // (2) foundfile is in the tmpdir
801 // insert it into head
802 if (absname.exists() && !absname.isDirectory()) {
803 // FIXME: This regex contained glo, but glo is used by the old
804 // version of nomencl.sty. Do we need to put it back?
805 static regex const unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
806 if (regex_match(onlyfile, unwanted)) {
807 LYXERR(Debug::DEPEND, "We don't want " << onlyfile
808 << " in the dep file");
809 } else if (suffixIs(onlyfile, ".tex")) {
810 // This is a tex file generated by LyX
811 // and latex is not likely to change this
813 LYXERR(Debug::DEPEND, "Tmpdir TeX file: " << onlyfile);
814 head.insert(absname, true);
816 LYXERR(Debug::DEPEND, "In tmpdir file:" << onlyfile);
817 head.insert(absname);
821 LYXERR(Debug::DEPEND, "Not a file or we are unable to find it.");
827 bool checkLineBreak(string const & ff, DepTable & head)
829 if (!contains(ff, '.'))
832 // if we have a dot, we let handleFoundFile decide
833 return handleFoundFile(ff, head);
839 void LaTeX::deplog(DepTable & head)
841 // This function reads the LaTeX log file end extracts all the
842 // external files used by the LaTeX run. The files are then
843 // entered into the dependency file.
845 string const logfile =
846 onlyFilename(changeExtension(file.absFilename(), ".log"));
848 static regex const reg1("File: (.+).*");
849 static regex const reg2("No file (.+)(.).*");
850 static regex const reg3("\\\\openout[0-9]+.*=.*`(.+)(..).*");
851 // If an index should be created, MikTex does not write a line like
852 // \openout# = 'sample.idx'.
853 // but instead only a line like this into the log:
854 // Writing index file sample.idx
855 static regex const reg4("Writing index file (.+).*");
856 // files also can be enclosed in <...>
857 static regex const reg5("<([^>]+)(.).*");
858 static regex const regoldnomencl("Writing glossary file (.+).*");
859 static regex const regnomencl("Writing nomenclature file (.+).*");
860 // If a toc should be created, MikTex does not write a line like
861 // \openout# = `sample.toc'.
862 // but only a line like this into the log:
864 // This line is also written by tetex.
865 // This line is not present if no toc should be created.
866 static regex const miktexTocReg("\\\\tf@toc=\\\\write.*");
867 static regex const reg6(".*\\([^)]+.*");
869 FileName const fn = makeAbsPath(logfile);
870 ifstream ifs(fn.toFilesystemEncoding().c_str());
873 // Ok, the scanning of files here is not sufficient.
874 // Sometimes files are named by "File: xxx" only
875 // So I think we should use some regexps to find files instead.
876 // Note: all file names and paths might contains spaces.
877 bool found_file = false;
880 // MikTeX sometimes inserts \0 in the log file. They can't be
881 // removed directly with the existing string utility
882 // functions, so convert them first to \r, and remove all
883 // \r's afterwards, since we need to remove them anyway.
884 token = subst(token, '\0', '\r');
885 token = subst(token, "\r", "");
886 if (token.empty() || token == ")") {
891 // Sometimes, filenames are broken across lines.
892 // We care for that and save suspicious lines.
893 // Here we exclude some cases where we are sure
894 // that there is no continued filename
895 if (!lastline.empty()) {
896 static regex const package_info("Package \\w+ Info: .*");
897 static regex const package_warning("Package \\w+ Warning: .*");
898 if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
899 || prefixIs(token, "Package:")
900 || prefixIs(token, "Language:")
901 || prefixIs(token, "LaTeX Info:")
902 || prefixIs(token, "LaTeX Font Info:")
903 || prefixIs(token, "\\openout[")
904 || prefixIs(token, "))")
905 || regex_match(token, package_info)
906 || regex_match(token, package_warning))
910 if (!lastline.empty())
911 // probably a continued filename from last line
912 token = lastline + token;
913 if (token.length() > 255) {
914 // string too long. Cut off.
915 token.erase(0, token.length() - 251);
920 // FIXME UNICODE: We assume that the file names in the log
921 // file are in the file system encoding.
922 token = to_utf8(from_filesystem8bit(token));
924 // (1) "File: file.ext"
925 if (regex_match(token, sub, reg1)) {
927 found_file = checkLineBreak(sub.str(1), head);
929 if (suffixIs(token, ")"))
930 // no line break for sure
931 // pretend we've been succesfully searching
933 // (2) "No file file.ext"
934 } else if (regex_match(token, sub, reg2)) {
935 // file names must contains a dot, line ends with dot
936 if (contains(sub.str(1), '.') && sub.str(2) == ".")
937 found_file = handleFoundFile(sub.str(1), head);
939 // we suspect a line break
941 // (3) "\openout<nr> = `file.ext'."
942 } else if (regex_match(token, sub, reg3)) {
943 // search for closing '. at the end of the line
944 if (sub.str(2) == "\'.")
945 found_file = handleFoundFile(sub.str(1), head);
947 // probable line break
949 // (4) "Writing index file file.ext"
950 } else if (regex_match(token, sub, reg4))
952 found_file = checkLineBreak(sub.str(1), head);
954 else if (regex_match(token, sub, reg5)) {
955 // search for closing '>' and dot ('*.*>') at the eol
956 if (contains(sub.str(1), '.') && sub.str(2) == ">")
957 found_file = handleFoundFile(sub.str(1), head);
959 // probable line break
961 // (6) "Writing nomenclature file file.ext"
962 } else if (regex_match(token, sub, regnomencl) ||
963 regex_match(token, sub, regoldnomencl))
965 found_file = checkLineBreak(sub.str(1), head);
966 // (7) "\tf@toc=\write<nr>" (for MikTeX)
967 else if (regex_match(token, sub, miktexTocReg))
968 found_file = handleFoundFile(onlyFilename(changeExtension(
969 file.absFilename(), ".toc")), head);
971 // not found, but we won't check further
972 // pretend we've been succesfully searching
976 // note that we can have several of these on one line
977 // this must be queried separated, because of
978 // cases such as "File: file.ext (type eps)"
979 // where "File: file.ext" would be skipped
980 if (regex_match(token, sub, reg6)) {
981 // search for strings in (...)
982 static regex reg6_1("\\(([^()]+)(.).*");
984 string::const_iterator first = token.begin();
985 string::const_iterator end = token.end();
987 while (regex_search(first, end, what, reg6_1)) {
988 // if we have a dot, try to handle as file
989 if (contains(what.str(1), '.')) {
990 first = what[0].second;
991 if (what.str(2) == ")") {
992 handleFoundFile(what.str(1), head);
993 // since we had a closing bracket,
994 // do not investigate further
997 // if we have no closing bracket,
998 // try to handle as file nevertheless
999 found_file = handleFoundFile(
1000 what.str(1) + what.str(2), head);
1002 // if we do not have a dot, check if the line has
1003 // a closing bracket (else, we suspect a line break)
1004 else if (what.str(2) != ")") {
1005 first = what[0].second;
1008 // we have a closing bracket, so the content
1009 // is not a file name.
1010 // no need to investigate further
1011 // pretend we've been succesfully searching
1012 first = what[0].second;
1019 // probable linebreak:
1023 // no linebreak: reset
1024 lastline = string();
1027 // Make sure that the main .tex file is in the dependency file.
1028 head.insert(file, true);