]> git.lyx.org Git - lyx.git/blob - src/mover.C
Fix bug 886 and others not reported related with the document paper size.
[lyx.git] / src / mover.C
1 /**
2  * \file mover.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "mover.h"
14
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/lyxlib.h"
18 #include "support/systemcall.h"
19
20 #include <sstream>
21
22 using std::ostringstream;
23 using std::string;
24
25 namespace support = lyx::support;
26
27 Movers movers;
28 Movers system_movers;
29
30
31 bool Mover::do_copy(string const & from, string const & to,
32                     string const &) const
33 {
34         return support::copy(from, to);
35 }
36
37
38 bool Mover::do_rename(string const & from, string const & to,
39                       string const &) const
40 {
41         return support::rename(from, to);
42 }
43
44
45 bool SpecialisedMover::do_copy(string const & from, string const & to,
46                                string const & latex) const
47 {
48         if (command_.empty())
49                 return Mover::do_copy(from, to, latex);
50
51         string command = support::LibScriptSearch(command_);
52         command = support::subst(command, "$$i", from);
53         command = support::subst(command, "$$o", to);
54         command = support::subst(command, "$$l", latex);
55
56         support::Systemcall one;
57         return one.startscript(support::Systemcall::Wait, command) == 0;
58 }
59
60
61 bool SpecialisedMover::do_rename(string const & from, string const & to,
62                                  string const & latex) const
63 {
64         if (command_.empty())
65                 return Mover::do_rename(from, to, latex);
66
67         if (!do_copy(from, to, latex))
68                 return false;
69         return support::unlink(from) == 0;
70 }
71
72
73 void Movers::set(string const & fmt, string const & command)
74 {
75         specials_[fmt] = SpecialisedMover(command);
76 }
77
78
79 Mover const & Movers::operator()(string const & fmt) const
80 {
81         SpecialsMap::const_iterator const it = specials_.find(fmt);
82         return (it == specials_.end()) ? default_ : it->second;
83 }
84
85
86 string const Movers::command(string  const & fmt) const
87 {
88         SpecialsMap::const_iterator const it = specials_.find(fmt);
89         return (it == specials_.end()) ? string() : it->second.command();
90 }