]> git.lyx.org Git - features.git/commitdiff
Fix tex2lyx path handling for relative file names
authorGeorg Baum <baum@lyx.org>
Sun, 30 Sep 2012 13:03:07 +0000 (15:03 +0200)
committerGeorg Baum <baum@lyx.org>
Sun, 30 Sep 2012 13:06:18 +0000 (15:06 +0200)
The input and output file names of tex2lyx may be relative. In this case,
getMasterFilePath() and getParentFilePath() return relative paths as well.
Now the file name translation logic for all kinds of included files can
cope with that.

src/tex2lyx/text.cpp

index b3604b77f5146fa19d9e078247d6ae434e2df606..53836804b276aaad5fff8175f8c21e76ecb91a98 100644 (file)
@@ -1839,8 +1839,10 @@ void fix_relative_filename(string & name)
        if (FileName::isAbsolute(name))
                return;
 
-       name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFileName()),
-                                  from_utf8(getParentFilePath())));
+       string const absMaster = makeAbsPath(getMasterFilePath()).absFileName();
+       string const absParent = makeAbsPath(getParentFilePath()).absFileName();
+       string const abs = makeAbsPath(name, absMaster).absFileName();
+       name = to_utf8(makeRelPath(from_utf8(abs), from_utf8(absParent)));
 }
 
 
@@ -2531,7 +2533,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                                skip_braces(p);
                                                p.get_token();
                                                string name = normalize_filename(p.verbatim_item());
-                                               string const path = getMasterFilePath();
+                                               string const path = makeAbsPath(getMasterFilePath()).absFileName();
                                                // We want to preserve relative / absolute filenames,
                                                // therefore path is only used for testing
                                                // The file extension is in every case ".tex".
@@ -2758,7 +2760,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                opts["clip"] = string();
                        string name = normalize_filename(p.verbatim_item());
 
-                       string const path = getMasterFilePath();
+                       string const path = makeAbsPath(getMasterFilePath()).absFileName();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
                        if (!makeAbsPath(name, path).exists()) {
@@ -3723,7 +3725,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                name += p.get_token().asInput();
                        context.check_layout(os);
                        string filename(normalize_filename(p.getArg('{', '}')));
-                       string const path = getMasterFilePath();
+                       string const path = makeAbsPath(getMasterFilePath()).absFileName();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
                        if ((t.cs() == "include" || t.cs() == "input") &&
@@ -4183,7 +4185,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        vector<string> keys;
                        split_map(arg, opts, keys);
                        string name = normalize_filename(p.verbatim_item());
-                       string const path = getMasterFilePath();
+                       string const path = makeAbsPath(getMasterFilePath()).absFileName();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
                        if (!makeAbsPath(name, path).exists()) {
@@ -4248,7 +4250,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "loadgame") {
                        p.skip_spaces();
                        string name = normalize_filename(p.verbatim_item());
-                       string const path = getMasterFilePath();
+                       string const path = makeAbsPath(getMasterFilePath()).absFileName();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
                        if (!makeAbsPath(name, path).exists()) {