]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
Cmake build: support tests
[lyx.git] / src / tex2lyx / text.cpp
index 34ffbe86c1d1c198f9d1489234cbfc783f6010b0..7f7603c198b244057a8495edc381fd763e47db23 100644 (file)
@@ -814,8 +814,18 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                        if (inner_type != "makebox") {
                                latex_height = p.getArg('[', ']');
                                translate_box_len(latex_height, height_value, height_unit, height_special);
-                       } else
-                               hor_pos = p.getArg('[', ']');
+                       } else {
+                               string const opt = p.getArg('[', ']');
+                               if (!opt.empty()) {
+                                       hor_pos = opt;
+                                       if (hor_pos != "l" && hor_pos != "c" &&
+                                           hor_pos != "r" && hor_pos != "s") {
+                                               cerr << "invalid hor_pos " << hor_pos
+                                                    << " for " << inner_type << endl;
+                                               hor_pos = "c";
+                                       }
+                               }
+                       }
 
                        if (p.hasOpt()) {
                                inner_pos = p.getArg('[', ']');
@@ -839,7 +849,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                        if (!opt.empty()) {
                                hor_pos = opt;
                                if (hor_pos != "l" && hor_pos != "c" &&
-                                   hor_pos != "r") {
+                                   hor_pos != "r" && hor_pos != "s") {
                                        cerr << "invalid hor_pos " << hor_pos
                                             << " for " << outer_type << endl;
                                        hor_pos = "c";
@@ -1836,28 +1846,31 @@ void fix_child_filename(string & name)
        if (!isabs)
                name = makeAbsPath(name, absMasterTeX).absFileName();
        bool copyfile = copyFiles();
-       // convert from absolute original path to "relative to master file"
-       string const rel = to_utf8(makeRelPath(from_utf8(name),
-                                              from_utf8(absMasterTeX)));
-       // Do not copy if the file is not in or below the directory of the
-       // master, since in this case the new path might be impossible to
-       // create. Example:
-       // absMasterTeX = "/foo/bar/"
-       // absMasterLyX = "/bar/"
-       // name = "/baz.eps" => new absolute name would be "/../baz.eps"
-       if (copyfile && rel.substr(0, 3) == "../")
-               copyfile = false;
        string const absParentLyX = getParentFilePath(false);
+       string abs = name;
        if (copyfile) {
+               // convert from absolute original path to "relative to master file"
+               string const rel = to_utf8(makeRelPath(from_utf8(name),
+                                                      from_utf8(absMasterTeX)));
                // re-interpret "relative to .tex file" as "relative to .lyx file"
                // (is different if the master .lyx file resides in a
                // different path than the master .tex file)
                string const absMasterLyX = getMasterFilePath(false);
-               name = makeAbsPath(rel, absMasterLyX).absFileName();
-               if (!isabs) {
+               abs = makeAbsPath(rel, absMasterLyX).absFileName();
+               // Do not copy if the new path is impossible to create. Example:
+               // absMasterTeX = "/foo/bar/"
+               // absMasterLyX = "/bar/"
+               // name = "/baz.eps" => new absolute name would be "/../baz.eps"
+               if (contains(name, "/../"))
+                       copyfile = false;
+       }
+       if (copyfile) {
+               if (isabs)
+                       name = abs;
+               else {
                        // convert from absolute original path to
                        // "relative to .lyx file"
-                       name = to_utf8(makeRelPath(from_utf8(name),
+                       name = to_utf8(makeRelPath(from_utf8(abs),
                                                   from_utf8(absParentLyX)));
                }
        }
@@ -1880,12 +1893,6 @@ void copy_file(FileName const & src, string dstname)
        else
                dst = makeAbsPath(dstname, absParent);
        string const absMaster = getMasterFilePath(false);
-       string const rel = to_utf8(makeRelPath(from_utf8(dst.absFileName()),
-                                              from_utf8(absMaster)));
-       // Do not copy if the file is not in or below the directory of the
-       // master (see above)
-       if (rel.substr(0, 3) == "../")
-               return;
        FileName const srcpath = src.onlyPath();
        FileName const dstpath = dst.onlyPath();
        if (equivalent(srcpath, dstpath))