]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeX.C
More fixes to insettabular/text (and some missing features added).
[lyx.git] / src / LaTeX.C
index 310cc49ec383241bc8f5f228b648d320b9977787..2485f03371fc263a38fe8bbc372d006009952a70 100644 (file)
@@ -31,6 +31,7 @@
 #include "bufferlist.h"
 #include "minibuffer.h"
 #include "gettext.h"
+#include "lyx_gui_misc.h"
 
 using std::ifstream;
 using std::getline;
@@ -51,29 +52,6 @@ using std::endl;
 
 extern BufferList bufferlist;
 
-struct texfile_struct {
-       LaTeX::TEX_FILES file;
-       char const * extension;
-};
-
-static
-const texfile_struct all_files[] = {
-       { LaTeX::AUX, ".aux"},
-       { LaTeX::BBL, ".bbl"},
-       { LaTeX::DVI, ".dvi"},
-       { LaTeX::GLO, ".glo"},
-       { LaTeX::IDX, ".idx"},
-       { LaTeX::IND, ".ind"},
-       { LaTeX::LOF, ".lof"},
-       { LaTeX::LOA, ".loa"},
-       { LaTeX::LOG, ".log"},
-       { LaTeX::LOT, ".lot"},
-       { LaTeX::TOC, ".toc"},
-       { LaTeX::LTX, ".ltx"},
-       { LaTeX::TEX, ".tex"}
-};
-
-
 /*
  * CLASS TEXERRORS
  */
@@ -92,10 +70,10 @@ void TeXErrors::insertError(int line, string const & error_desc,
 LaTeX::LaTeX(string const & latex, string const & f, string const & p)
                : cmd(latex), file(f), path(p)
 {
-       tex_files = NO_FILES;
-       file_count = sizeof(all_files) / sizeof(texfile_struct);
        num_errors = 0;
        depfile = file + ".dep";
+       if (prefixIs(cmd, "pdf")) // Do we use pdflatex ?
+               depfile += "-pdf";
 }
 
 
@@ -106,7 +84,7 @@ void LaTeX::deleteFilesOnError() const
        // What files do we have to delete?
 
        // This will at least make latex do all the runs
-       ::unlink(depfile.c_str());
+       lyx::unlink(depfile);
 
        // but the reason for the error might be in a generated file...
 
@@ -114,15 +92,15 @@ void LaTeX::deleteFilesOnError() const
 
        // bibtex file
        string bbl = ChangeExtension(ofname, ".bbl");
-       ::unlink(bbl.c_str());
+       lyx::unlink(bbl);
 
        // makeindex file
        string ind = ChangeExtension(ofname, ".ind");
-       ::unlink(ind.c_str());
+       lyx::unlink(ind);
        
        // Also remove the aux file
        string aux = ChangeExtension(ofname, ".aux");
-       ::unlink(aux.c_str());
+       lyx::unlink(aux);
 }
 
 
@@ -141,7 +119,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
        bool rerun = false; // rerun requested
        
        // The class LaTeX does not know the temp path.
-       bufferlist.updateIncludedTeXfiles(GetCWD());
+       bufferlist.updateIncludedTeXfiles(lyx::getcwd()); //GetCWD());
        
        // Never write the depfile if an error was encountered.
        
@@ -175,8 +153,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
                                << "Dependency file has changed" << endl;
                        lyxerr[Debug::LATEX]
                                << "Run #" << count << endl; 
-                       minib->Set(string(_("LaTeX run number ")) + tostr(count));
-                       minib->Store();
+                       WriteStatus(minib,
+                                   string(_("LaTeX run number ")) + tostr(count));
                        this->operator()();
                        scanres = scanLogFile(terr);
                        if (scanres & LaTeX::ERRORS) {
@@ -200,8 +178,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
                lyxerr[Debug::LATEX]
                        << "Run #" << count << endl;
                head.insert(file, true);
-               minib->Set(string(_("LaTeX run number ")) + tostr(count));
-               minib->Store();
+               WriteStatus(minib,
+                           string(_("LaTeX run number ")) + tostr(count));
                this->operator()();
                scanres = scanLogFile(terr);
                if (scanres & LaTeX::ERRORS) {
@@ -213,7 +191,6 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
 
        // update the dependencies.
        deplog(head); // reads the latex log
-       deptex(head); // checks for latex files
        head.update();
 
        // 0.5
@@ -227,8 +204,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
        if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) {
                // no checks for now
                lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
-               minib->Set(_("Running MakeIndex."));
-               minib->Store();
+               WriteStatus(minib, _("Running MakeIndex."));
                rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx")));
        }
 
@@ -241,8 +217,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
                // tags is found -> run bibtex and set rerun = true;
                // no checks for now
                lyxerr[Debug::LATEX] << "Running BibTeX." << endl;
-               minib->Set(_("Running BibTeX."));
-               minib->Store();
+               WriteStatus(minib, _("Running BibTeX."));
                rerun = runBibTeX(OnlyFilename(ChangeExtension(file, ".aux")), 
                                  head);
        }
@@ -266,8 +241,8 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
                        << "Dep. file has changed or rerun requested" << endl;
                lyxerr[Debug::LATEX]
                        << "Run #" << count << endl;
-               minib->Set(string(_("LaTeX run number ")) + tostr(count));
-               minib->Store();
+               WriteStatus(minib,
+                           string(_("LaTeX run number ")) + tostr(count));
                this->operator()();
                scanres = scanLogFile(terr);
                if (scanres & LaTeX::ERRORS) {
@@ -294,8 +269,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
        if (head.haschanged(OnlyFilename(ChangeExtension(file, ".idx")))) {
                // no checks for now
                lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
-               minib->Set(_("Running MakeIndex."));
-               minib->Store();
+               WriteStatus(minib, _("Running MakeIndex."));
                rerun = runMakeIndex(OnlyFilename(ChangeExtension(file, ".idx")));
        }
        
@@ -316,8 +290,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib)
                rerun = false;
                ++count;
                lyxerr[Debug::LATEX] << "Run #" << count << endl;
-               minib->Set(string(_("LaTeX run number ")) + tostr(count));
-               minib->Store();
+               WriteStatus(minib, string(_("LaTeX run number ")) + tostr(count));
                this->operator()();
                scanres = scanLogFile(terr);
                if (scanres & LaTeX::ERRORS) {
@@ -619,40 +592,61 @@ void LaTeX::deplog(DepTable & head)
        // dependency file.
 
        string logfile = OnlyFilename(ChangeExtension(file, ".log"));
+
+       LRegex reg1(")* *\\(([^ \\)]+).*");
+       LRegex reg2("File: ([^ ]+).*");
+       LRegex reg3("No file ([^ ]+)\\..*");
+       LRegex reg4("\\\\openout[0-9]+.*=.*`([^ ]+)'\\..*");
+       LRegex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
        
        ifstream ifs(logfile.c_str());
        while (ifs) {
-               // Now we read chars until we find a '('
-               char c = 0;
-               while(ifs.get(c)) {
-                       if (c == '(') break;
-               };
-               if (!ifs) break;
-               
-               // We now have c == '(', we now read the the sequence of
-               // chars until reaching EOL, ' ' or ')' and put that
-               // into a string.
+               // Ok, the scanning of files here is not sufficient.
+               // Sometimes files are named by "File: xxx" only
+               // So I think we should use some regexps to find files instead.
+               // "(\([^ ]+\)"   should match the "(file " variant
+               // "File: \([^ ]+\)" should match the "File: file" variant
                string foundfile;
-               while (ifs.get(c)) {
-                       if (c == '\n' || c == ' ' || c == ')')
-                               break;
-                       foundfile += c;
+               string token;
+               getline(ifs, token);
+               if (token.empty()) continue;
+               
+               if (reg1.exact_match(token)) {
+                       LRegex::SubMatches const & sub = reg1.exec(token);
+                       foundfile = LSubstring(token, sub[1].first,
+                                              sub[1].second);
+               } else if (reg2.exact_match(token)) {
+                       LRegex::SubMatches const & sub = reg2.exec(token);
+                       foundfile = LSubstring(token, sub[1].first,
+                                              sub[1].second);
+               } else if (reg3.exact_match(token)) {
+                       LRegex::SubMatches const & sub = reg3.exec(token);
+                       foundfile = LSubstring(token, sub[1].first,
+                                              sub[1].second);
+               } else if (reg4.exact_match(token)) {
+                       LRegex::SubMatches const & sub = reg4.exec(token);
+                       foundfile = LSubstring(token, sub[1].first,
+                                              sub[1].second);
+               } else {
+                       continue;
                }
+
                lyxerr[Debug::DEPEND] << "Found file: " 
-                                    << foundfile << endl;
+                                     << foundfile << endl;
                
                // Ok now we found a file.
-               // Now we should make sure that
-               // this is a file that we can
-               // access through the normal
-               // paths:
+               // Now we should make sure that this is a file that we can
+               // access through the normal paths.
+               // We will not try any fancy search methods to
+               // find the file.
+               
                // (1) foundfile is an
                //     absolute path and should
                //     be inserted.
                if (AbsolutePath(foundfile)) {
                        lyxerr[Debug::DEPEND] << "AbsolutePath file: " 
-                                            << foundfile << endl;
-                       // On inital insert we want to do the update at once
+                                             << foundfile << endl;
+                       // On initial insert we want to do the update at once
                        // since this file can not be a file generated by
                        // the latex run.
                        head.insert(foundfile, true);
@@ -662,23 +656,26 @@ void LaTeX::deplog(DepTable & head)
                // (2) foundfile is in the tmpdir
                //     insert it into head
                if (FileInfo(OnlyFilename(foundfile)).exist()) {
-                       if (suffixIs(foundfile, ".aux")) {
-                               lyxerr[Debug::DEPEND] << "We don't want "
-                                                    << OnlyFilename(foundfile)
-                                                    << " in the dep file"
-                                                    << endl;
+                       if (unwanted.exact_match(foundfile)) {
+                               lyxerr[Debug::DEPEND]
+                                       << "We don't want "
+                                       << OnlyFilename(foundfile)
+                                       << " in the dep file"
+                                       << endl;
                        } else if (suffixIs(foundfile, ".tex")) {
                                // This is a tex file generated by LyX
                                // and latex is not likely to change this
                                // during its runs.
-                               lyxerr[Debug::DEPEND] << "Tmpdir TeX file: "
-                                                    << OnlyFilename(foundfile)
-                                                    << endl;
+                               lyxerr[Debug::DEPEND]
+                                       << "Tmpdir TeX file: "
+                                       << OnlyFilename(foundfile)
+                                       << endl;
                                head.insert(foundfile, true);
                        } else {
-                               lyxerr[Debug::DEPEND] << "In tmpdir file:"
-                                                    << OnlyFilename(foundfile)
-                                                    << endl;
+                               lyxerr[Debug::DEPEND]
+                                       << "In tmpdir file:"
+                                       << OnlyFilename(foundfile)
+                                       << endl;
                                head.insert(OnlyFilename(foundfile));
                        }
                        continue;
@@ -688,20 +685,3 @@ void LaTeX::deplog(DepTable & head)
                        << endl;
        }
 }
-
-
-void LaTeX::deptex(DepTable & head)
-{
-       int except = AUX|LOG|DVI|BBL|IND|GLO; 
-       string tmp;
-       FileInfo fi;
-       for (int i = 0; i < file_count; ++i) {
-               if (!(all_files[i].file & except)) {
-                       tmp = OnlyFilename(ChangeExtension(file,
-                                                          all_files[i].extension));
-                       lyxerr[Debug::DEPEND] << "deptex: " << tmp << endl;
-                       if (fi.newFile(tmp).exist())
-                               head.insert(tmp);
-               }
-       }
-}