]> git.lyx.org Git - lyx.git/blob - src/LaTeX.C
remove some unneeded version of functions from lstrings,
[lyx.git] / src / LaTeX.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *           Copyright 1995 Matthias Ettrich
6  *           Copyright 1995-2001 The LyX Team.
7  *
8  *           This file is Copyright 1996-2001
9  *           Lars Gullik Bjønnes
10  *
11  * ======================================================
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "LaTeX.h"
21 #include "bufferlist.h"
22 #include "gettext.h"
23 #include "lyxfunc.h"
24 #include "debug.h"
25 #include "support/filetools.h"
26 #include "support/FileInfo.h"
27 #include "support/lstrings.h"
28 #include "support/lyxlib.h"
29 #include "support/systemcall.h"
30 #include "support/os.h"
31 #include "support/path.h"
32
33 #include <boost/regex.hpp>
34
35 #include <fstream>
36 #include <cstdio>  // sscanf
37
38 #ifndef CXX_GLOBAL_CSTD
39 using std::sscanf;
40 #endif
41
42 using std::ifstream;
43 using std::getline;
44 using std::endl;
45 using std::vector;
46 using std::set;
47 using boost::regex;
48 using boost::regex_match;
49 using boost::smatch;
50
51 // TODO: in no particular order
52 // - get rid of the extern BufferList and the call to
53 //   BufferList::updateIncludedTeXfiles, this should either
54 //   be done before calling LaTeX::funcs or in a completely
55 //   different way.
56 // - the bibtex command options should be supported.
57 // - the makeindex style files should be taken care of with
58 //   the dependency mechanism.
59 // - makeindex commandline options should be supported
60 // - somewhere support viewing of bibtex and makeindex log files.
61 // - we should perhaps also scan the bibtex log file
62 // - we should perhaps also scan the bibtex log file
63
64 extern BufferList bufferlist;
65
66 /*
67  * CLASS TEXERRORS
68  */
69
70 void TeXErrors::insertError(int line, string const & error_desc,
71                             string const & error_text)
72 {
73         Error newerr(line, error_desc, error_text);
74         errors.push_back(newerr);
75 }
76
77 /*
78  * CLASS LaTeX
79  */
80
81 LaTeX::LaTeX(string const & latex, string const & f, string const & p)
82                 : cmd(latex), file(f), path(p)
83 {
84         num_errors = 0;
85         depfile = file + ".dep";
86         if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
87                 depfile += "-pdf";
88                 output_file = ChangeExtension(file,".pdf");
89         } else {
90                 output_file = ChangeExtension(file,".dvi");
91         }
92 }
93
94
95 void LaTeX::deleteFilesOnError() const
96 {
97         // currently just a dummy function.
98
99         // What files do we have to delete?
100
101         // This will at least make latex do all the runs
102         lyx::unlink(depfile);
103
104         // but the reason for the error might be in a generated file...
105
106         string ofname = OnlyFilename(file);
107
108         // bibtex file
109         string bbl = ChangeExtension(ofname, ".bbl");
110         lyx::unlink(bbl);
111
112         // makeindex file
113         string ind = ChangeExtension(ofname, ".ind");
114         lyx::unlink(ind);
115
116         // Also remove the aux file
117         string aux = ChangeExtension(ofname, ".aux");
118         lyx::unlink(aux);
119 }
120
121
122 int LaTeX::run(TeXErrors & terr, LyXFunc * lfun)
123         // We know that this function will only be run if the lyx buffer
124         // has been changed. We also know that a newly written .tex file
125         // is always different from the previous one because of the date
126         // in it. However it seems safe to run latex (at least) on time each
127         // time the .tex file changes.
128 {
129         int scanres = NO_ERRORS;
130         unsigned int count = 0; // number of times run
131         num_errors = 0; // just to make sure.
132         const unsigned int MAX_RUN = 6;
133         DepTable head; // empty head
134         bool rerun = false; // rerun requested
135
136         // The class LaTeX does not know the temp path.
137         bufferlist.updateIncludedTeXfiles(lyx::getcwd()); //GetCWD());
138
139         // Never write the depfile if an error was encountered.
140
141         // 0
142         // first check if the file dependencies exist:
143         //     ->If it does exist
144         //             check if any of the files mentioned in it have
145         //             changed (done using a checksum).
146         //                 -> if changed:
147         //                        run latex once and
148         //                        remake the dependency file
149         //                 -> if not changed:
150         //                        just return there is nothing to do for us.
151         //     ->if it doesn't exist
152         //             make it and
153         //             run latex once (we need to run latex once anyway) and
154         //             remake the dependency file.
155         //
156
157         FileInfo fi(depfile);
158         bool had_depfile = fi.exist();
159         bool run_bibtex = false;
160         string aux_file = OnlyFilename(ChangeExtension(file, "aux"));
161
162         if (had_depfile) {
163                 lyxerr[Debug::DEPEND] << "Dependency file exists" << endl;
164                 // Read the dep file:
165                 head.read(depfile);
166                 // Update the checksums
167                 head.update();
168                 // Can't just check if anything has changed because it might have aborted
169                 // on error last time... in which cas we need to re-run latex
170                 // and collect the error messages (even if they are the same).
171                 if (!FileInfo(output_file).exist()) {
172                         lyxerr[Debug::DEPEND]
173                                 << "re-running LaTeX because output file doesn't exist." << endl;
174                 } else if (!head.sumchange()) {
175                         lyxerr[Debug::DEPEND] << "return no_change" << endl;
176                         return NO_CHANGE;
177                 } else {
178                         lyxerr[Debug::DEPEND]
179                                 << "Dependency file has changed" << endl;
180                 }
181
182                 if (head.extchanged(".bib") || head.extchanged(".bst"))
183                         run_bibtex = true;
184         } else
185                 lyxerr[Debug::DEPEND]
186                         << "Dependency file does not exist" << endl;
187
188         /// We scan the aux file even when had_depfile = false,
189         /// because we can run pdflatex on the file after running latex on it,
190         /// in which case we will not need to run bibtex again.
191         vector<Aux_Info> bibtex_info_old;
192         if (!run_bibtex)
193                 bibtex_info_old = scanAuxFiles(aux_file);
194
195         ++count;
196         lyxerr[Debug::LATEX] << "Run #" << count << endl;
197         if (lfun) {
198                 ostringstream str;
199                 str << _("LaTeX run number") << ' ' << count;
200                 lfun->dispatch(LFUN_MESSAGE, str.str().c_str(), false);
201         }
202
203         this->operator()();
204         scanres = scanLogFile(terr);
205         if (scanres & ERROR_RERUN) {
206                 lyxerr[Debug::LATEX] << "Rerunning LaTeX" << endl;
207                 this->operator()();
208                 scanres = scanLogFile(terr);
209         }
210
211         if (scanres & ERRORS) {
212                 deleteFilesOnError();
213                 return scanres; // return on error
214         }
215
216         vector<Aux_Info> const bibtex_info = scanAuxFiles(aux_file);
217         if (!run_bibtex && bibtex_info_old != bibtex_info)
218                 run_bibtex = true;
219
220         // update the dependencies.
221         deplog(head); // reads the latex log
222         head.update();
223
224         // 0.5
225         // At this point we must run external programs if needed.
226         // makeindex will be run if a .idx file changed or was generated.
227         // And if there were undefined citations or changes in references
228         // the .aux file is checked for signs of bibtex. Bibtex is then run
229         // if needed.
230
231         // run makeindex
232         if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) {
233                 // no checks for now
234                 lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
235                 if (lfun) {
236                         lfun->dispatch(LFUN_MESSAGE, _("Running MakeIndex."), false);
237                 }
238
239                 rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx")));
240         }
241
242         // run bibtex
243         // if (scanres & UNDEF_CIT || scanres & RERUN || run_bibtex)
244         if (scanres & UNDEF_CIT || run_bibtex) {
245                 // Here we must scan the .aux file and look for
246                 // "\bibdata" and/or "\bibstyle". If one of those
247                 // tags is found -> run bibtex and set rerun = true;
248                 // no checks for now
249                 lyxerr[Debug::LATEX] << "Running BibTeX." << endl;
250                 if (lfun) {
251                         lfun->dispatch(LFUN_MESSAGE, _("Running BibTeX."), false);
252                 }
253
254                 updateBibtexDependencies(head, bibtex_info);
255                 rerun |= runBibTeX(bibtex_info);
256         } else if (!had_depfile) {
257                 /// If we run pdflatex on the file after running latex on it,
258                 /// then we do not need to run bibtex, but we do need to
259                 /// insert the .bib and .bst files into the .dep-pdf file.
260                 updateBibtexDependencies(head, bibtex_info);
261         }
262
263         // 1
264         // we know on this point that latex has been run once (or we just
265         // returned) and the question now is to decide if we need to run
266         // it any more. This is done by asking if any of the files in the
267         // dependency file has changed. (remember that the checksum for
268         // a given file is reported to have changed if it just was created)
269         //     -> if changed or rerun == true:
270         //             run latex once more and
271         //             update the dependency structure
272         //     -> if not changed:
273         //             we does nothing at this point
274         //
275         if (rerun || head.sumchange()) {
276                 rerun = false;
277                 ++count;
278                 lyxerr[Debug::DEPEND]
279                         << "Dep. file has changed or rerun requested" << endl;
280                 lyxerr[Debug::LATEX]
281                         << "Run #" << count << endl;
282                 if (lfun) {
283                         ostringstream str;
284                         str << _("LaTeX run number") << ' ' << count;
285                         // check lyxstring string stream and gcc 3.1 before fixing
286                         lfun->dispatch(LFUN_MESSAGE, str.str().c_str(), false);
287                 }
288
289                 this->operator()();
290                 scanres = scanLogFile(terr);
291                 if (scanres & ERRORS) {
292                         deleteFilesOnError();
293                         return scanres; // return on error
294                 }
295
296                 // update the depedencies
297                 deplog(head); // reads the latex log
298                 head.update();
299         } else {
300                 lyxerr[Debug::DEPEND] << "Dep. file has NOT changed" << endl;
301         }
302
303         // 1.5
304         // The inclusion of files generated by external programs like
305         // makeindex or bibtex might have done changes to pagenumbereing,
306         // etc. And because of this we must run the external programs
307         // again to make sure everything is redone correctly.
308         // Also there should be no need to run the external programs any
309         // more after this.
310
311         // run makeindex if the <file>.idx has changed or was generated.
312         if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) {
313                 // no checks for now
314                 lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
315                 if (lfun) {
316                         lfun->dispatch(LFUN_MESSAGE, _("Running MakeIndex."), false);
317                 }
318
319                 rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx")));
320         }
321
322         // 2
323         // we will only run latex more if the log file asks for it.
324         // or if the sumchange() is true.
325         //     -> rerun asked for:
326         //             run latex and
327         //             remake the dependency file
328         //             goto 2 or return if max runs are reached.
329         //     -> rerun not asked for:
330         //             just return (fall out of bottom of func)
331         //
332         while ((head.sumchange() || rerun || (scanres & RERUN))
333                && count < MAX_RUN) {
334                 // Yes rerun until message goes away, or until
335                 // MAX_RUNS are reached.
336                 rerun = false;
337                 ++count;
338                 lyxerr[Debug::LATEX] << "Run #" << count << endl;
339                 if (lfun) {
340                         ostringstream str;
341                         str << _("LaTeX run number") << ' ' << count;
342                         lfun->dispatch(LFUN_MESSAGE, str.str().c_str(), false);
343                 }
344
345                 this->operator()();
346                 scanres = scanLogFile(terr);
347                 if (scanres & ERRORS) {
348                         deleteFilesOnError();
349                         return scanres; // return on error
350                 }
351
352                 // keep this updated
353                 head.update();
354         }
355
356         // Write the dependencies to file.
357         head.write(depfile);
358         lyxerr[Debug::LATEX] << "Done." << endl;
359         return scanres;
360 }
361
362
363 int LaTeX::operator()()
364 {
365 #ifndef __EMX__
366         string tmp = cmd + ' ' + QuoteName(file) + " > /dev/null";
367 #else // cmd.exe (OS/2) causes SYS0003 error at "/dev/null"
368         string tmp = cmd + ' ' + file + " > nul";
369 #endif
370         Systemcall one;
371         return one.startscript(Systemcall::Wait, tmp);
372 }
373
374
375 bool LaTeX::runMakeIndex(string const & f)
376 {
377         lyxerr[Debug::LATEX] << "idx file has been made,"
378                 " running makeindex on file "
379                              <<  f << endl;
380
381         // It should be possible to set the switches for makeindex
382         // sorting style and such. It would also be very convenient
383         // to be able to make style files from within LyX. This has
384         // to come for a later time.
385         string tmp = "makeindex -c -q ";
386         tmp += f;
387         Systemcall one;
388         one.startscript(Systemcall::Wait, tmp);
389         return true;
390 }
391
392
393 vector<Aux_Info> const
394 LaTeX::scanAuxFiles(string const & file)
395 {
396         vector<Aux_Info> result;
397
398         result.push_back(scanAuxFile(file));
399
400         for (int i = 1; i < 1000; ++i) {
401                 string file2 = ChangeExtension(file, "") + "." + tostr(i)
402                         + ".aux";
403                 FileInfo fi(file2);
404                 if (!fi.exist())
405                         break;
406                 result.push_back(scanAuxFile(file2));
407         }
408         return result;
409 }
410
411
412 Aux_Info const LaTeX::scanAuxFile(string const & file)
413 {
414         Aux_Info result;
415         result.aux_file = file;
416         scanAuxFile(file, result);
417         return result;
418 }
419
420
421 void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info)
422 {
423         lyxerr[Debug::LATEX] << "Scanning aux file: " << file << endl;
424
425         ifstream ifs(file.c_str());
426         string token;
427         regex reg1("\\\\citation\\{([^}]+)\\}");
428         regex reg2("\\\\bibdata\\{([^}]+)\\}");
429         regex reg3("\\\\bibstyle\\{([^}]+)\\}");
430         regex reg4("\\\\@input\\{([^}]+)\\}");
431
432         while (getline(ifs, token)) {
433                 token = strip(token, "\r");
434                 smatch sub;
435                 if (regex_match(token, sub, reg1)) {
436                         string data = sub[1];
437                         while (!data.empty()) {
438                                 string citation;
439                                 data = split(data, citation, ',');
440                                 lyxerr[Debug::LATEX] << "Citation: "
441                                                      << citation << endl;
442                                 aux_info.citations.insert(citation);
443                         }
444                 } else if (regex_match(token, sub, reg2)) {
445                         string data = sub[1];
446                         // data is now all the bib files separated by ','
447                         // get them one by one and pass them to the helper
448                         while (!data.empty()) {
449                                 string database;
450                                 data = split(data, database, ',');
451                                 database = ChangeExtension(database, "bib");
452                                 lyxerr[Debug::LATEX] << "Bibtex database: `"
453                                                      << database << "'" << endl;
454                                 aux_info.databases.insert(database);
455                         }
456                 } else if (regex_match(token, sub, reg3)) {
457                         string style = sub[1];
458                         // token is now the style file
459                         // pass it to the helper
460                         style = ChangeExtension(style, "bst");
461                         lyxerr[Debug::LATEX] << "Bibtex style: `"
462                                              << style << "'" << endl;
463                         aux_info.styles.insert(style);
464                 } else if (regex_match(token, sub, reg4)) {
465                         string file2 = sub[1];
466                         scanAuxFile(file2, aux_info);
467                 }
468         }
469 }
470
471
472 void LaTeX::updateBibtexDependencies(DepTable & dep,
473                                      vector<Aux_Info> const & bibtex_info)
474 {
475         // Since a run of Bibtex mandates more latex runs it is ok to
476         // remove all ".bib" and ".bst" files.
477         dep.remove_files_with_extension(".bib");
478         dep.remove_files_with_extension(".bst");
479         //string aux = OnlyFilename(ChangeExtension(file, ".aux"));
480
481         for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
482              it != bibtex_info.end(); ++it) {
483                 for (set<string>::const_iterator it2 = it->databases.begin();
484                      it2 != it->databases.end(); ++it2) {
485                         string file = findtexfile(*it2, "bib");
486                         if (!file.empty())
487                                 dep.insert(file, true);
488                 }
489
490                 for (set<string>::const_iterator it2 = it->styles.begin();
491                      it2 != it->styles.end(); ++it2) {
492                         string file = findtexfile(*it2, "bst");
493                         if (!file.empty())
494                                 dep.insert(file, true);
495                 }
496         }
497 }
498
499
500 bool LaTeX::runBibTeX(vector<Aux_Info> const & bibtex_info)
501 {
502         bool result = false;
503         for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
504              it != bibtex_info.end(); ++it) {
505                 if (it->databases.empty())
506                         continue;
507                 result = true;
508
509                 string tmp = "bibtex ";
510                 tmp += OnlyFilename(ChangeExtension(it->aux_file, string()));
511                 Systemcall one;
512                 one.startscript(Systemcall::Wait, tmp);
513         }
514         // Return whether bibtex was run
515         return result;
516 }
517
518
519 int LaTeX::scanLogFile(TeXErrors & terr)
520 {
521         int last_line = -1;
522         int line_count = 1;
523         int retval = NO_ERRORS;
524         string tmp = OnlyFilename(ChangeExtension(file, ".log"));
525         lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
526         ifstream ifs(tmp.c_str());
527
528         string token;
529         while (getline(ifs, token)) {
530                 lyxerr[Debug::LATEX] << "Log line: " << token << endl;
531
532                 if (token.empty())
533                         continue;
534
535                 if (prefixIs(token, "LaTeX Warning:")) {
536                         // Here shall we handle different
537                         // types of warnings
538                         retval |= LATEX_WARNING;
539                         lyxerr[Debug::LATEX] << "LaTeX Warning." << endl;
540                         if (contains(token, "Rerun to get cross-references")) {
541                                 retval |= RERUN;
542                                 lyxerr[Debug::LATEX]
543                                         << "We should rerun." << endl;
544                         } else if (contains(token, "Citation")
545                                    && contains(token, "on page")
546                                    && contains(token, "undefined")) {
547                                 retval |= UNDEF_CIT;
548                         }
549                 } else if (prefixIs(token, "Package")) {
550                         // Package warnings
551                         retval |= PACKAGE_WARNING;
552                         if (contains(token, "natbib Warning:")) {
553                                 // Natbib warnings
554                                 if (contains(token, "Citation")
555                                     && contains(token, "on page")
556                                     && contains(token, "undefined")) {
557                                         retval |= UNDEF_CIT;
558                                 }
559                         } else if (contains(token, "run BibTeX")) {
560                                 retval |= UNDEF_CIT;
561                         } else if (contains(token, "Rerun LaTeX") ||
562                                    contains(token, "Rerun to get")) {
563                                 // at least longtable.sty and bibtopic.sty
564                                 // might use this.
565                                 lyxerr[Debug::LATEX]
566                                         << "We should rerun." << endl;
567                                 retval |= RERUN;
568                         }
569                 } else if (prefixIs(token, "(")) {
570                         if (contains(token, "Rerun LaTeX") ||
571                             contains(token, "Rerun to get")) {
572                                 // Used by natbib
573                                 lyxerr[Debug::LATEX]
574                                         << "We should rerun." << endl;
575                                 retval |= RERUN;
576                         }
577                 } else if (prefixIs(token, "! ")) {
578                         // Ok, we have something that looks like a TeX Error
579                         // but what do we really have.
580
581                         // Just get the error description:
582                         string desc(token, 2);
583                         if (contains(token, "LaTeX Error:"))
584                                 retval |= LATEX_ERROR;
585                         // get the next line
586                         string tmp;
587                         int count = 0;
588                         do {
589                                 if (!getline(ifs, tmp))
590                                         break;
591                                 if (++count > 10)
592                                         break;
593                         } while (!prefixIs(tmp, "l."));
594                         if (prefixIs(tmp, "l.")) {
595                                 // we have a latex error
596                                 retval |=  TEX_ERROR;
597                                 if (contains(desc, "Package babel Error: You haven't defined the language"))
598                                         retval |= ERROR_RERUN;
599                                 // get the line number:
600                                 int line = 0;
601                                 sscanf(tmp.c_str(), "l.%d", &line);
602                                 // get the rest of the message:
603                                 string errstr(tmp, tmp.find(' '));
604                                 errstr += '\n';
605                                 getline(ifs, tmp);
606                                 while (!contains(errstr, "l.")
607                                        && !tmp.empty()
608                                        && !prefixIs(tmp, "! ")
609                                        && !contains(tmp, "(job aborted")) {
610                                         errstr += tmp;
611                                         errstr += "\n";
612                                         getline(ifs, tmp);
613                                 }
614                                 lyxerr[Debug::LATEX]
615                                         << "line: " << line << '\n'
616                                         << "Desc: " << desc << '\n'
617                                         << "Text: " << errstr << endl;
618                                 if (line == last_line)
619                                         ++line_count;
620                                 else {
621                                         line_count = 1;
622                                         last_line = line;
623                                 }
624                                 if (line_count <= 5) {
625                                         terr.insertError(line, desc, errstr);
626                                         ++num_errors;
627                                 }
628                         }
629                 } else {
630                         // information messages, TeX warnings and other
631                         // warnings we have not caught earlier.
632                         if (prefixIs(token, "Overfull ")) {
633                                 retval |= TEX_WARNING;
634                         } else if (prefixIs(token, "Underfull ")) {
635                                 retval |= TEX_WARNING;
636                         } else if (contains(token, "Rerun to get citations")) {
637                                 // Natbib seems to use this.
638                                 retval |= UNDEF_CIT;
639                         } else if (contains(token, "No pages of output")) {
640                                 // A dvi file was not created
641                                 retval |= NO_OUTPUT;
642                         } else if (contains(token, "That makes 100 errors")) {
643                                 // More than 100 errors were reprted
644                                 retval |= TOO_MANY_ERRORS;
645                         }
646                 }
647         }
648         lyxerr[Debug::LATEX] << "Log line: " << token << endl;
649         return retval;
650 }
651
652
653 void LaTeX::deplog(DepTable & head)
654 {
655         // This function reads the LaTeX log file end extracts all the external
656         // files used by the LaTeX run. The files are then entered into the
657         // dependency file.
658
659         string const logfile = OnlyFilename(ChangeExtension(file, ".log"));
660
661         regex reg1("\\)* *\\(([^ )]+).*");
662         regex reg2("File: ([^ ]+).*");
663         regex reg3("No file ([^ ]+)\\..*");
664         regex reg4("\\\\openout[0-9]+.*=.*`([^ ]+)'\\..*");
665         // If an index should be created, MikTex does not write a line like
666         //    \openout# = 'sample,idx'.
667         // but intstead only a line like this into the log:
668         //   Writing index file sample.idx
669         regex reg5("Writing index file ([^ ]+).*");
670         regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
671
672         ifstream ifs(logfile.c_str());
673         while (ifs) {
674                 // Ok, the scanning of files here is not sufficient.
675                 // Sometimes files are named by "File: xxx" only
676                 // So I think we should use some regexps to find files instead.
677                 // "(\([^ ]+\)"   should match the "(file " variant
678                 // "File: \([^ ]+\)" should match the "File: file" variant
679                 string foundfile;
680                 string token;
681                 getline(ifs, token);
682                 token = strip(token, "\r");
683                 if (token.empty()) continue;
684
685                 smatch sub;
686                 if (regex_match(token, sub, reg1)) {
687                         foundfile = sub[1];
688                 } else if (regex_match(token, sub, reg2)) {
689                         foundfile = sub[1];
690                 } else if (regex_match(token, sub, reg3)) {
691                         foundfile = sub[1];
692                 } else if (regex_match(token, sub, reg4)) {
693                         foundfile = sub[1];
694                 } else if (regex_match(token, sub, reg5)) {
695                         foundfile = sub[1];
696                 } else {
697                         continue;
698                 }
699
700                 // convert from native os path to unix path
701                 foundfile = os::internal_path(foundfile);
702
703                 lyxerr[Debug::DEPEND] << "Found file: "
704                                       << foundfile << endl;
705
706                 // Ok now we found a file.
707                 // Now we should make sure that this is a file that we can
708                 // access through the normal paths.
709                 // We will not try any fancy search methods to
710                 // find the file.
711
712                 // (1) foundfile is an
713                 //     absolute path and should
714                 //     be inserted.
715                 if (AbsolutePath(foundfile)) {
716                         lyxerr[Debug::DEPEND] << "AbsolutePath file: "
717                                               << foundfile << endl;
718                         // On initial insert we want to do the update at once
719                         // since this file can not be a file generated by
720                         // the latex run.
721                         if (FileInfo(foundfile).exist())
722                                 head.insert(foundfile, true);
723                 }
724
725                 // (2) foundfile is in the tmpdir
726                 //     insert it into head
727                 else if (FileInfo(OnlyFilename(foundfile)).exist()) {
728                         if (regex_match(foundfile, unwanted)) {
729                                 lyxerr[Debug::DEPEND]
730                                         << "We don't want "
731                                         << OnlyFilename(foundfile)
732                                         << " in the dep file"
733                                         << endl;
734                         } else if (suffixIs(foundfile, ".tex")) {
735                                 // This is a tex file generated by LyX
736                                 // and latex is not likely to change this
737                                 // during its runs.
738                                 lyxerr[Debug::DEPEND]
739                                         << "Tmpdir TeX file: "
740                                         << OnlyFilename(foundfile)
741                                         << endl;
742                                 head.insert(foundfile, true);
743                         } else {
744                                 lyxerr[Debug::DEPEND]
745                                         << "In tmpdir file:"
746                                         << OnlyFilename(foundfile)
747                                         << endl;
748                                 head.insert(OnlyFilename(foundfile));
749                         }
750                 } else
751                         lyxerr[Debug::DEPEND]
752                                 << "Not a file or we are unable to find it."
753                                 << endl;
754         }
755
756         // Make sure that the main .tex file is in the dependancy file.
757         head.insert(OnlyFilename(file), true);
758 }