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"
23 #include "support/debug.h"
24 #include "support/convert.h"
25 #include "support/FileName.h"
26 #include "support/filetools.h"
27 #include "support/gettext.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==(AuxInfo const & a, AuxInfo const & o)
80 return a.aux_file == o.aux_file
81 && a.citations == o.citations
82 && a.databases == o.databases
83 && a.styles == o.styles;
87 bool operator!=(AuxInfo const & a, AuxInfo 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<AuxInfo> 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<AuxInfo> 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 Index Processor."));
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, ".nlo", ".nls");
272 FileName const glofile(changeExtension(file.absFilename(), ".glo"));
273 if (head.haschanged(glofile))
274 rerun |= runMakeIndexNomencl(file, ".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, runparams);
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 do 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");
328 // Complex bibliography packages such as Biblatex require
329 // an additional bibtex cycle sometimes.
330 if (scanres & UNDEF_CIT) {
331 // Here we must scan the .aux file and look for
332 // "\bibdata" and/or "\bibstyle". If one of those
333 // tags is found -> run bibtex and set rerun = true;
335 LYXERR(Debug::LATEX, "Running BibTeX.");
336 message(_("Running BibTeX."));
337 updateBibtexDependencies(head, bibtex_info);
338 rerun |= runBibTeX(bibtex_info, runparams);
342 // The inclusion of files generated by external programs such as
343 // makeindex or bibtex might have done changes to pagenumbering,
344 // etc. And because of this we must run the external programs
345 // again to make sure everything is redone correctly.
346 // Also there should be no need to run the external programs any
349 // run makeindex if the <file>.idx has changed or was generated.
350 if (head.haschanged(idxfile)) {
352 LYXERR(Debug::LATEX, "Running MakeIndex.");
353 message(_("Running Index Processor."));
354 // onlyFilename() is needed for cygwin
355 rerun = runMakeIndex(onlyFilename(changeExtension(
356 file.absFilename(), ".idx")), runparams);
359 // I am not pretty sure if need this twice.
360 if (head.haschanged(nlofile))
361 rerun |= runMakeIndexNomencl(file, ".nlo", ".nls");
362 if (head.haschanged(glofile))
363 rerun |= runMakeIndexNomencl(file, ".glo", ".gls");
366 // we will only run latex more if the log file asks for it.
367 // or if the sumchange() is true.
368 // -> rerun asked for:
370 // remake the dependency file
371 // goto 2 or return if max runs are reached.
372 // -> rerun not asked for:
373 // just return (fall out of bottom of func)
375 while ((head.sumchange() || rerun || (scanres & RERUN))
376 && count < MAX_RUN) {
377 // Yes rerun until message goes away, or until
378 // MAX_RUNS are reached.
381 LYXERR(Debug::LATEX, "Run #" << count);
382 message(runMessage(count));
384 scanres = scanLogFile(terr);
385 if (scanres & ERRORS) {
386 deleteFilesOnError();
387 return scanres; // return on error
394 // Write the dependencies to file.
396 LYXERR(Debug::LATEX, "Done.");
401 int LaTeX::startscript()
403 // onlyFilename() is needed for cygwin
404 string tmp = cmd + ' '
405 + quoteName(onlyFilename(file.toFilesystemEncoding()))
406 + " > " + os::nulldev();
408 return one.startscript(Systemcall::Wait, tmp);
412 bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams,
413 string const & params)
415 string tmp = runparams.use_japanese ?
416 lyxrc.jindex_command : lyxrc.index_command;
419 "idx file has been made, running index processor ("
420 << tmp << ") on file " << f);
422 tmp = subst(tmp, "$$lang", runparams.document_language);
423 if (runparams.use_indices) {
424 tmp = lyxrc.splitindex_command + " -m " + quoteName(tmp);
426 "Multiple indices. Using splitindex command: " << tmp);
432 one.startscript(Systemcall::Wait, tmp);
437 bool LaTeX::runMakeIndexNomencl(FileName const & file,
438 string const & nlo, string const & nls)
440 LYXERR(Debug::LATEX, "Running MakeIndex for nomencl.");
441 message(_("Running MakeIndex for nomencl."));
442 string tmp = lyxrc.nomencl_command + ' ';
443 // onlyFilename() is needed for cygwin
444 tmp += quoteName(onlyFilename(changeExtension(file.absFilename(), nlo)));
446 + onlyFilename(changeExtension(file.toFilesystemEncoding(), nls));
448 one.startscript(Systemcall::Wait, tmp);
453 vector<AuxInfo> const
454 LaTeX::scanAuxFiles(FileName const & file)
456 vector<AuxInfo> result;
458 result.push_back(scanAuxFile(file));
460 string const basename = removeExtension(file.absFilename());
461 for (int i = 1; i < 1000; ++i) {
462 FileName const file2(basename
463 + '.' + convert<string>(i)
467 result.push_back(scanAuxFile(file2));
473 AuxInfo const LaTeX::scanAuxFile(FileName const & file)
476 result.aux_file = file;
477 scanAuxFile(file, result);
482 void LaTeX::scanAuxFile(FileName const & file, AuxInfo & aux_info)
484 LYXERR(Debug::LATEX, "Scanning aux file: " << file);
486 ifstream ifs(file.toFilesystemEncoding().c_str());
488 static regex const reg1("\\\\citation\\{([^}]+)\\}");
489 static regex const reg2("\\\\bibdata\\{([^}]+)\\}");
490 static regex const reg3("\\\\bibstyle\\{([^}]+)\\}");
491 static regex const reg4("\\\\@input\\{([^}]+)\\}");
493 while (getline(ifs, token)) {
494 token = rtrim(token, "\r");
496 // FIXME UNICODE: We assume that citation keys and filenames
497 // in the aux file are in the file system encoding.
498 token = to_utf8(from_filesystem8bit(token));
499 if (regex_match(token, sub, reg1)) {
500 string data = sub.str(1);
501 while (!data.empty()) {
503 data = split(data, citation, ',');
504 LYXERR(Debug::LATEX, "Citation: " << citation);
505 aux_info.citations.insert(citation);
507 } else if (regex_match(token, sub, reg2)) {
508 string data = sub.str(1);
509 // data is now all the bib files separated by ','
510 // get them one by one and pass them to the helper
511 while (!data.empty()) {
513 data = split(data, database, ',');
514 database = changeExtension(database, "bib");
515 LYXERR(Debug::LATEX, "BibTeX database: `" << database << '\'');
516 aux_info.databases.insert(database);
518 } else if (regex_match(token, sub, reg3)) {
519 string style = sub.str(1);
520 // token is now the style file
521 // pass it to the helper
522 style = changeExtension(style, "bst");
523 LYXERR(Debug::LATEX, "BibTeX style: `" << style << '\'');
524 aux_info.styles.insert(style);
525 } else if (regex_match(token, sub, reg4)) {
526 string const file2 = sub.str(1);
527 scanAuxFile(makeAbsPath(file2), aux_info);
533 void LaTeX::updateBibtexDependencies(DepTable & dep,
534 vector<AuxInfo> const & bibtex_info)
536 // Since a run of Bibtex mandates more latex runs it is ok to
537 // remove all ".bib" and ".bst" files.
538 dep.remove_files_with_extension(".bib");
539 dep.remove_files_with_extension(".bst");
540 //string aux = OnlyFilename(ChangeExtension(file, ".aux"));
542 for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
543 it != bibtex_info.end(); ++it) {
544 for (set<string>::const_iterator it2 = it->databases.begin();
545 it2 != it->databases.end(); ++it2) {
546 FileName const file = findtexfile(*it2, "bib");
548 dep.insert(file, true);
551 for (set<string>::const_iterator it2 = it->styles.begin();
552 it2 != it->styles.end(); ++it2) {
553 FileName const file = findtexfile(*it2, "bst");
555 dep.insert(file, true);
561 bool LaTeX::runBibTeX(vector<AuxInfo> const & bibtex_info,
562 OutputParams const & runparams)
565 for (vector<AuxInfo>::const_iterator it = bibtex_info.begin();
566 it != bibtex_info.end(); ++it) {
567 if (it->databases.empty())
571 string tmp = runparams.use_japanese ?
572 lyxrc.jbibtex_command : lyxrc.bibtex_command;
574 // onlyFilename() is needed for cygwin
575 tmp += quoteName(onlyFilename(removeExtension(
576 it->aux_file.absFilename())));
578 one.startscript(Systemcall::Wait, tmp);
580 // Return whether bibtex was run
585 int LaTeX::scanLogFile(TeXErrors & terr)
589 int retval = NO_ERRORS;
591 onlyFilename(changeExtension(file.absFilename(), ".log"));
592 LYXERR(Debug::LATEX, "Log file: " << tmp);
593 FileName const fn = FileName(makeAbsPath(tmp));
594 ifstream ifs(fn.toFilesystemEncoding().c_str());
595 bool fle_style = false;
596 static regex file_line_error(".+\\.\\D+:[0-9]+: (.+)");
599 while (getline(ifs, token)) {
600 // MikTeX sometimes inserts \0 in the log file. They can't be
601 // removed directly with the existing string utility
602 // functions, so convert them first to \r, and remove all
603 // \r's afterwards, since we need to remove them anyway.
604 token = subst(token, '\0', '\r');
605 token = subst(token, "\r", "");
608 LYXERR(Debug::LATEX, "Log line: " << token);
613 if (contains(token, "file:line:error style messages enabled"))
616 if (prefixIs(token, "LaTeX Warning:") ||
617 prefixIs(token, "! pdfTeX warning")) {
618 // Here shall we handle different
620 retval |= LATEX_WARNING;
621 LYXERR(Debug::LATEX, "LaTeX Warning.");
622 if (contains(token, "Rerun to get cross-references")) {
624 LYXERR(Debug::LATEX, "We should rerun.");
625 // package clefval needs 2 latex runs before bibtex
626 } else if (contains(token, "Value of")
627 && contains(token, "on page")
628 && contains(token, "undefined")) {
629 retval |= ERROR_RERUN;
630 LYXERR(Debug::LATEX, "Force rerun.");
631 } else if (contains(token, "Citation")
632 && contains(token, "on page")
633 && contains(token, "undefined")) {
636 } else if (prefixIs(token, "Package")) {
638 retval |= PACKAGE_WARNING;
639 if (contains(token, "natbib Warning:")) {
641 if (contains(token, "Citation")
642 && contains(token, "on page")
643 && contains(token, "undefined")) {
646 } else if (contains(token, "run BibTeX")) {
648 } else if (contains(token, "Rerun LaTeX") ||
649 contains(token, "Rerun to get")) {
650 // at least longtable.sty and bibtopic.sty
652 LYXERR(Debug::LATEX, "We should rerun.");
655 } else if (prefixIs(token, "LETTRE WARNING:")) {
656 if (contains(token, "veuillez recompiler")) {
658 LYXERR(Debug::LATEX, "We should rerun.");
661 } else if (token[0] == '(') {
662 if (contains(token, "Rerun LaTeX") ||
663 contains(token, "Rerun to get")) {
665 LYXERR(Debug::LATEX, "We should rerun.");
668 } else if (prefixIs(token, "! ")
669 || (fle_style && regex_match(token, sub, file_line_error))) {
670 // Ok, we have something that looks like a TeX Error
671 // but what do we really have.
673 // Just get the error description:
675 if (prefixIs(token, "! "))
676 desc = string(token, 2);
679 if (contains(token, "LaTeX Error:"))
680 retval |= LATEX_ERROR;
685 if (!getline(ifs, tmp))
689 } while (!prefixIs(tmp, "l."));
690 if (prefixIs(tmp, "l.")) {
691 // we have a latex error
694 "Package babel Error: You haven't defined the language") ||
696 "Package babel Error: You haven't loaded the option"))
697 retval |= ERROR_RERUN;
698 // get the line number:
700 sscanf(tmp.c_str(), "l.%d", &line);
701 // get the rest of the message:
702 string errstr(tmp, tmp.find(' '));
705 while (!contains(errstr, "l.")
707 && !prefixIs(tmp, "! ")
708 && !contains(tmp, "(job aborted")) {
713 LYXERR(Debug::LATEX, "line: " << line << '\n'
714 << "Desc: " << desc << '\n' << "Text: " << errstr);
715 if (line == last_line)
721 if (line_count <= 5) {
723 // We have no idea what the encoding of
725 // It seems that the output from the
726 // latex compiler itself is pure ASCII,
727 // but it can include bits from the
728 // document, so whatever encoding we
729 // assume here it can be wrong.
730 terr.insertError(line,
731 from_local8bit(desc),
732 from_local8bit(errstr));
737 // information messages, TeX warnings and other
738 // warnings we have not caught earlier.
739 if (prefixIs(token, "Overfull ")) {
740 retval |= TEX_WARNING;
741 } else if (prefixIs(token, "Underfull ")) {
742 retval |= TEX_WARNING;
743 } else if (contains(token, "Rerun to get citations")) {
744 // Natbib seems to use this.
746 } else if (contains(token, "No pages of output")) {
747 // A dvi file was not created
749 } else if (contains(token, "That makes 100 errors")) {
750 // More than 100 errors were reprted
751 retval |= TOO_MANY_ERRORS;
755 LYXERR(Debug::LATEX, "Log line: " << token);
762 bool insertIfExists(FileName const & absname, DepTable & head)
764 if (absname.exists() && !absname.isDirectory()) {
765 head.insert(absname, true);
772 bool handleFoundFile(string const & ff, DepTable & head)
774 // convert from native os path to unix path
775 string foundfile = os::internal_path(trim(ff));
777 LYXERR(Debug::DEPEND, "Found file: " << foundfile);
779 // Ok now we found a file.
780 // Now we should make sure that this is a file that we can
781 // access through the normal paths.
782 // We will not try any fancy search methods to
785 // (1) foundfile is an
786 // absolute path and should
788 FileName absname(foundfile);
789 if (absname.isAbsolute()) {
790 LYXERR(Debug::DEPEND, "AbsolutePath file: " << foundfile);
791 // On initial insert we want to do the update at once
792 // since this file cannot be a file generated by
794 if (!insertIfExists(absname, head)) {
796 string strippedfile = foundfile;
797 while (contains(strippedfile, " ")) {
798 // files with spaces are often enclosed in quotation
799 // marks; those have to be removed
800 string unquoted = subst(strippedfile, "\"", "");
801 absname.set(unquoted);
802 if (insertIfExists(absname, head))
804 // strip off part after last space and try again
805 string tmp = strippedfile;
806 string const stripoff =
807 rsplit(tmp, strippedfile, ' ');
808 absname.set(strippedfile);
809 if (insertIfExists(absname, head))
815 string onlyfile = onlyFilename(foundfile);
816 absname = makeAbsPath(onlyfile);
819 while (contains(foundfile, ' ')) {
820 if (absname.exists())
824 // files with spaces are often enclosed in quotation
825 // marks; those have to be removed
826 string unquoted = subst(foundfile, "\"", "");
827 absname = makeAbsPath(unquoted);
828 if (absname.exists())
830 // strip off part after last space and try again
832 string const stripoff =
833 rsplit(foundfile, strippedfile, ' ');
834 foundfile = strippedfile;
835 onlyfile = onlyFilename(strippedfile);
836 absname = makeAbsPath(onlyfile);
840 // (2) foundfile is in the tmpdir
841 // insert it into head
842 if (absname.exists() && !absname.isDirectory()) {
843 // FIXME: This regex contained glo, but glo is used by the old
844 // version of nomencl.sty. Do we need to put it back?
845 static regex const unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
846 if (regex_match(onlyfile, unwanted)) {
847 LYXERR(Debug::DEPEND, "We don't want " << onlyfile
848 << " in the dep file");
849 } else if (suffixIs(onlyfile, ".tex")) {
850 // This is a tex file generated by LyX
851 // and latex is not likely to change this
853 LYXERR(Debug::DEPEND, "Tmpdir TeX file: " << onlyfile);
854 head.insert(absname, true);
856 LYXERR(Debug::DEPEND, "In tmpdir file:" << onlyfile);
857 head.insert(absname);
861 LYXERR(Debug::DEPEND, "Not a file or we are unable to find it.");
867 bool checkLineBreak(string const & ff, DepTable & head)
869 if (!contains(ff, '.'))
872 // if we have a dot, we let handleFoundFile decide
873 return handleFoundFile(ff, head);
879 void LaTeX::deplog(DepTable & head)
881 // This function reads the LaTeX log file end extracts all the
882 // external files used by the LaTeX run. The files are then
883 // entered into the dependency file.
885 string const logfile =
886 onlyFilename(changeExtension(file.absFilename(), ".log"));
888 static regex const reg1("File: (.+).*");
889 static regex const reg2("No file (.+)(.).*");
890 static regex const reg3("\\\\openout[0-9]+.*=.*`(.+)(..).*");
891 // If an index should be created, MikTex does not write a line like
892 // \openout# = 'sample.idx'.
893 // but instead only a line like this into the log:
894 // Writing index file sample.idx
895 static regex const reg4("Writing index file (.+).*");
896 // files also can be enclosed in <...>
897 static regex const reg5("<([^>]+)(.).*");
898 static regex const regoldnomencl("Writing glossary file (.+).*");
899 static regex const regnomencl("Writing nomenclature file (.+).*");
900 // If a toc should be created, MikTex does not write a line like
901 // \openout# = `sample.toc'.
902 // but only a line like this into the log:
904 // This line is also written by tetex.
905 // This line is not present if no toc should be created.
906 static regex const miktexTocReg("\\\\tf@toc=\\\\write.*");
907 static regex const reg6(".*\\([^)]+.*");
909 FileName const fn = makeAbsPath(logfile);
910 ifstream ifs(fn.toFilesystemEncoding().c_str());
913 // Ok, the scanning of files here is not sufficient.
914 // Sometimes files are named by "File: xxx" only
915 // So I think we should use some regexps to find files instead.
916 // Note: all file names and paths might contains spaces.
917 bool found_file = false;
920 // MikTeX sometimes inserts \0 in the log file. They can't be
921 // removed directly with the existing string utility
922 // functions, so convert them first to \r, and remove all
923 // \r's afterwards, since we need to remove them anyway.
924 token = subst(token, '\0', '\r');
925 token = subst(token, "\r", "");
926 if (token.empty() || token == ")") {
931 // Sometimes, filenames are broken across lines.
932 // We care for that and save suspicious lines.
933 // Here we exclude some cases where we are sure
934 // that there is no continued filename
935 if (!lastline.empty()) {
936 static regex const package_info("Package \\w+ Info: .*");
937 static regex const package_warning("Package \\w+ Warning: .*");
938 if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
939 || prefixIs(token, "Package:")
940 || prefixIs(token, "Language:")
941 || prefixIs(token, "LaTeX Info:")
942 || prefixIs(token, "LaTeX Font Info:")
943 || prefixIs(token, "\\openout[")
944 || prefixIs(token, "))")
945 || regex_match(token, package_info)
946 || regex_match(token, package_warning))
950 if (!lastline.empty())
951 // probably a continued filename from last line
952 token = lastline + token;
953 if (token.length() > 255) {
954 // string too long. Cut off.
955 token.erase(0, token.length() - 251);
960 // FIXME UNICODE: We assume that the file names in the log
961 // file are in the file system encoding.
962 token = to_utf8(from_filesystem8bit(token));
964 // (1) "File: file.ext"
965 if (regex_match(token, sub, reg1)) {
967 found_file = checkLineBreak(sub.str(1), head);
969 if (suffixIs(token, ")"))
970 // no line break for sure
971 // pretend we've been succesfully searching
973 // (2) "No file file.ext"
974 } else if (regex_match(token, sub, reg2)) {
975 // file names must contains a dot, line ends with dot
976 if (contains(sub.str(1), '.') && sub.str(2) == ".")
977 found_file = handleFoundFile(sub.str(1), head);
979 // we suspect a line break
981 // (3) "\openout<nr> = `file.ext'."
982 } else if (regex_match(token, sub, reg3)) {
983 // search for closing '. at the end of the line
984 if (sub.str(2) == "\'.")
985 found_file = handleFoundFile(sub.str(1), head);
987 // probable line break
989 // (4) "Writing index file file.ext"
990 } else if (regex_match(token, sub, reg4))
992 found_file = checkLineBreak(sub.str(1), head);
994 else if (regex_match(token, sub, reg5)) {
995 // search for closing '>' and dot ('*.*>') at the eol
996 if (contains(sub.str(1), '.') && sub.str(2) == ">")
997 found_file = handleFoundFile(sub.str(1), head);
999 // probable line break
1001 // (6) "Writing nomenclature file file.ext"
1002 } else if (regex_match(token, sub, regnomencl) ||
1003 regex_match(token, sub, regoldnomencl))
1005 found_file = checkLineBreak(sub.str(1), head);
1006 // (7) "\tf@toc=\write<nr>" (for MikTeX)
1007 else if (regex_match(token, sub, miktexTocReg))
1008 found_file = handleFoundFile(onlyFilename(changeExtension(
1009 file.absFilename(), ".toc")), head);
1011 // not found, but we won't check further
1012 // pretend we've been succesfully searching
1016 // note that we can have several of these on one line
1017 // this must be queried separated, because of
1018 // cases such as "File: file.ext (type eps)"
1019 // where "File: file.ext" would be skipped
1020 if (regex_match(token, sub, reg6)) {
1021 // search for strings in (...)
1022 static regex reg6_1("\\(([^()]+)(.).*");
1024 string::const_iterator first = token.begin();
1025 string::const_iterator end = token.end();
1027 while (regex_search(first, end, what, reg6_1)) {
1028 // if we have a dot, try to handle as file
1029 if (contains(what.str(1), '.')) {
1030 first = what[0].second;
1031 if (what.str(2) == ")") {
1032 handleFoundFile(what.str(1), head);
1033 // since we had a closing bracket,
1034 // do not investigate further
1037 // if we have no closing bracket,
1038 // try to handle as file nevertheless
1039 found_file = handleFoundFile(
1040 what.str(1) + what.str(2), head);
1042 // if we do not have a dot, check if the line has
1043 // a closing bracket (else, we suspect a line break)
1044 else if (what.str(2) != ")") {
1045 first = what[0].second;
1048 // we have a closing bracket, so the content
1049 // is not a file name.
1050 // no need to investigate further
1051 // pretend we've been succesfully searching
1052 first = what[0].second;
1059 // probable linebreak:
1063 // no linebreak: reset
1064 lastline = string();
1067 // Make sure that the main .tex file is in the dependency file.
1068 head.insert(file, true);