]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeX.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / LaTeX.C
index 6943eb4b9f2c27f4301031f866fe8465352cbefa..a63b5604d3f5c54de40b72347b59505542538a3d 100644 (file)
@@ -30,6 +30,7 @@
 #include "support/os.h"
 
 #include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
 #include <boost/regex.hpp>
 
 #include <fstream>
@@ -756,22 +757,33 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 
 namespace {
 
-bool insertIfExists(FileName const & absname, DepTable & head)
-{
-       bool exists;
+/**
+ * Wrapper around fs::exists that can handle invalid file names.
+ * In theory we could test with fs::native whether a filename is valid
+ * before calling fs::exists, but in practice it is unusable: On windows it
+ * does not allow spaces, and on unix it does not allow absolute file names.
+ * This function has the disadvantage that it catches also other errors than
+ * invalid names, but for dependency checking we can live with that.
+ */
+bool exists(FileName const & possible_name) {
        try {
-               fs::path const path = absname.toFilesystemEncoding();
-               exists = fs::exists(path) && !fs::is_directory(path);
+               return fs::exists(possible_name.toFilesystemEncoding());
        }
        catch (fs::filesystem_error const & fe) {
-               // This was probably no file at all.
                lyxerr[Debug::DEPEND] << "Got error `" << fe.what()
-                       << "' while checking whether file `" << absname
-                       << "' exists and is no directory." << endl;
+                       << "' while checking whether file `" << possible_name
+                       << "' exists." << endl;
+               return false;
        }
-       if (exists) {
-                       head.insert(absname, true);
-                       return true;
+}
+
+
+bool insertIfExists(FileName const & absname, DepTable & head)
+{
+       if (exists(absname) &&
+           !fs::is_directory(absname.toFilesystemEncoding())) {
+               head.insert(absname, true);
+               return true;
        }
        return false;
 }
@@ -804,6 +816,12 @@ bool handleFoundFile(string const & ff, DepTable & head)
                        // check for spaces
                        string strippedfile = foundfile;
                        while (contains(strippedfile, " ")) {
+                               // files with spaces are often enclosed in quotation
+                               // marks; those have to be removed
+                               string unquoted = subst(strippedfile, "\"", "");
+                               absname.set(unquoted);
+                               if (insertIfExists(absname, head))
+                                       return true;
                                // strip off part after last space and try again
                                string tmp = strippedfile;
                                string const stripoff =
@@ -820,20 +838,16 @@ bool handleFoundFile(string const & ff, DepTable & head)
 
        // check for spaces
        while (contains(foundfile, ' ')) {
-               bool exists;
-               try {
-                       exists = fs::exists(absname.toFilesystemEncoding());
-               }
-               catch (fs::filesystem_error const & fe) {
-                       // This was probably no file at all.
-                       lyxerr[Debug::DEPEND] << "Got error `" << fe.what()
-                               << "' while checking whether file `"
-                               << absname << "' exists." << endl;
-               }
-               if (exists)
+               if (exists(absname))
                        // everything o.k.
                        break;
                else {
+                       // files with spaces are often enclosed in quotation
+                       // marks; those have to be removed
+                       string unquoted = subst(foundfile, "\"", "");
+                       absname = makeAbsPath(unquoted);
+                       if (exists(absname))
+                               break;
                        // strip off part after last space and try again
                        string strippedfile;
                        string const stripoff =
@@ -846,18 +860,8 @@ bool handleFoundFile(string const & ff, DepTable & head)
 
        // (2) foundfile is in the tmpdir
        //     insert it into head
-       bool exists;
-       try {
-               fs::path const path = absname.toFilesystemEncoding();
-               exists = fs::exists(path) && !fs::is_directory(path);
-       }
-       catch (fs::filesystem_error const & fe) {
-               // This was probably no file at all.
-               lyxerr[Debug::DEPEND] << "Got error `" << fe.what()
-                       << "' while checking whether file `" << absname
-                       << "' exists and is no directory." << endl;
-       }
-       if (exists) {
+       if (exists(absname) &&
+           !fs::is_directory(absname.toFilesystemEncoding())) {
                static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
                if (regex_match(onlyfile, unwanted)) {
                        lyxerr[Debug::DEPEND]
@@ -979,9 +983,7 @@ void LaTeX::deplog(DepTable & head)
                        token = lastline + token;
                if (token.length() > 255) {
                        // string too long. Cut off.
-                       int r = token.length() - 250;
-                       string ntoken = token.substr(r, token.length());
-                       token = ntoken;
+                       token.erase(0, token.length() - 251);
                }
 
                smatch sub;