replace most &dquot;...&dquot; by <...>
[lyx.git] / src / mover.C
bloba646f49478ce8d28923a131fceec26d398d4fcb9
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  */
11 #include "mover.h"
13 #include "support/filetools.h"
14 #include "support/lstrings.h"
15 #include "support/lyxlib.h"
16 #include "support/systemcall.h"
18 #include <sstream>
20 using std::ostringstream;
21 using std::string;
23 namespace support = lyx::support;
25 Movers movers;
26 Movers system_movers;
29 bool Mover::do_copy(string const & from, string const & to) const
31         return support::copy(from, to);
35 bool Mover::do_rename(string const & from, string const & to) const
37         return support::rename(from, to);
41 bool SpecialisedMover::do_copy(string const & from, string const & to) const
43         if (command_.empty())
44                 return Mover::do_copy(from, to);
46         string command = support::LibScriptSearch(command_);
47         command = support::subst(command, "$$i", from);
48         command = support::subst(command, "$$o", to);
50         support::Systemcall one;
51         return one.startscript(support::Systemcall::Wait, command) == 0;
55 bool SpecialisedMover::do_rename(string const & from, string const & to) const
57         if (command_.empty())
58                 return Mover::do_rename(from, to);
60         if (!do_copy(from, to))
61                 return false;
62         return support::unlink(from) == 0;
66 void Movers::set(string const & fmt, string const & command)
68         specials_[fmt] = SpecialisedMover(command);
72 Mover const & Movers::operator()(string const & fmt) const
74         SpecialsMap::const_iterator const it = specials_.find(fmt);
75         return (it == specials_.end()) ? default_ : it->second;
79 string const Movers::command(string  const & fmt) const
81         SpecialsMap::const_iterator const it = specials_.find(fmt);
82         return (it == specials_.end()) ? string() : it->second.command();