3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/lyxlib.h"
18 #include "support/systemcall.h"
33 bool Mover::do_copy(string const & from, string const & to,
34 string const &, unsigned long int mode) const
36 return support::copy(from, to, mode);
40 bool Mover::do_rename(string const & from, string const & to,
43 return support::rename(from, to);
47 bool SpecialisedMover::do_copy(string const & from, string const & to,
48 string const & latex, unsigned long int mode) const
51 return Mover::do_copy(from, to, latex, mode);
53 if (mode != (unsigned long int)-1) {
54 std::ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
58 if (!support::chmod(to, mode))
62 string command = support::libScriptSearch(command_);
63 command = support::subst(command, "$$i", from);
64 command = support::subst(command, "$$o", to);
65 command = support::subst(command, "$$l", latex);
67 support::Systemcall one;
68 return one.startscript(support::Systemcall::Wait, command) == 0;
72 bool SpecialisedMover::do_rename(string const & from, string const & to,
73 string const & latex) const
76 return Mover::do_rename(from, to, latex);
78 if (!do_copy(from, to, latex, (unsigned long int)-1))
80 return support::unlink(from) == 0;
84 void Movers::set(string const & fmt, string const & command)
86 specials_[fmt] = SpecialisedMover(command);
90 Mover const & Movers::operator()(string const & fmt) const
92 SpecialsMap::const_iterator const it = specials_.find(fmt);
93 return (it == specials_.end()) ? default_ : it->second;
97 string const Movers::command(string const & fmt) const
99 SpecialsMap::const_iterator const it = specials_.find(fmt);
100 return (it == specials_.end()) ? string() : it->second.command();