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/FileName.h"
16 #include "support/filetools.h"
17 #include "support/lstrings.h"
18 #include "support/Systemcall.h"
24 using namespace lyx::support;
29 bool Mover::copy(FileName const & from, FileName const & to) const
31 return from.copyTo(to);
35 bool Mover::rename(FileName const & from,
36 FileName const & to) const
38 return do_rename(from, to, to.absFilename());
42 bool Mover::do_rename(FileName const & from, FileName const & to,
45 return from.moveTo(to);
49 bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
50 string const & latex) const
53 return Mover::copy(from, to);
55 string command = libScriptSearch(command_);
56 command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
57 command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
58 command = subst(command, "$$l", quoteName(latex));
61 return one.startscript(Systemcall::Wait, command) == 0;
65 bool SpecialisedMover::do_rename(FileName const & from, FileName const & to,
66 string const & latex) const
69 return Mover::do_rename(from, to, latex);
71 if (!do_copy(from, to, latex))
73 return from.removeFile();
77 void Movers::set(string const & fmt, string const & command)
79 specials_[fmt] = SpecialisedMover(command);
83 Mover const & Movers::operator()(string const & fmt) const
85 SpecialsMap::const_iterator const it = specials_.find(fmt);
86 if (it == specials_.end())
92 string const Movers::command(string const & fmt) const
94 SpecialsMap::const_iterator const it = specials_.find(fmt);
95 return (it == specials_.end()) ? string() : it->second.command();