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/Systemcall.h"
23 using namespace lyx::support;
28 bool Mover::copy(FileName const & from, FileName const & to) const
30 return do_copy(from, to, to.absFilename());
34 bool Mover::do_copy(FileName const & from, FileName const & to,
37 return from.copyTo(to);
41 bool Mover::rename(FileName const & from,
42 FileName const & to) const
44 return do_rename(from, to, to.absFilename());
48 bool Mover::do_rename(FileName const & from, FileName const & to,
51 return from.moveTo(to);
55 bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
56 string const & latex) const
59 return Mover::do_copy(from, to, latex);
61 string command = libScriptSearch(command_);
62 command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
63 command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
64 command = subst(command, "$$l", quoteName(latex));
67 return one.startscript(Systemcall::Wait, command) == 0;
71 bool SpecialisedMover::do_rename(FileName const & from, FileName const & to,
72 string const & latex) const
75 return Mover::do_rename(from, to, latex);
77 if (!do_copy(from, to, latex))
79 return from.removeFile();
83 void Movers::set(string const & fmt, string const & command)
85 specials_[fmt] = SpecialisedMover(command);
89 Mover const & Movers::operator()(string const & fmt) const
91 SpecialsMap::const_iterator const it = specials_.find(fmt);
92 if (it == specials_.end())
98 string const Movers::command(string const & fmt) const
100 SpecialsMap::const_iterator const it = specials_.find(fmt);
101 return (it == specials_.end()) ? string() : it->second.command();