From: Georg Baum Date: Sun, 30 Sep 2012 13:03:07 +0000 (+0200) Subject: Fix tex2lyx path handling for relative file names X-Git-Tag: 2.1.0beta1~1480^2~5 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ccd3ecf1e9482b2c8ff8346b5dafc2cbae6949a8;p=features.git Fix tex2lyx path handling for relative file names 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. --- diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index b3604b77f5..53836804b2 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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 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()) {