2004-10-26 18:39:13 +00:00
|
|
|
/**
|
|
|
|
* \file mover.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mover.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/systemcall.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using std::ostringstream;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace support = lyx::support;
|
|
|
|
|
|
|
|
Movers movers;
|
|
|
|
Movers system_movers;
|
|
|
|
|
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
bool Mover::do_copy(string const & from, string const & to,
|
|
|
|
string const &) const
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
|
|
|
return support::copy(from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
bool Mover::do_rename(string const & from, string const & to,
|
|
|
|
string const &) const
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
|
|
|
return support::rename(from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
bool SpecialisedMover::do_copy(string const & from, string const & to,
|
|
|
|
string const & latex) const
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
|
|
|
if (command_.empty())
|
2004-11-01 08:50:42 +00:00
|
|
|
return Mover::do_copy(from, to, latex);
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
|
|
string command = support::LibScriptSearch(command_);
|
|
|
|
command = support::subst(command, "$$i", from);
|
|
|
|
command = support::subst(command, "$$o", to);
|
2004-11-01 08:50:42 +00:00
|
|
|
command = support::subst(command, "$$l", latex);
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
|
|
support::Systemcall one;
|
|
|
|
return one.startscript(support::Systemcall::Wait, command) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
bool SpecialisedMover::do_rename(string const & from, string const & to,
|
|
|
|
string const & latex) const
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
|
|
|
if (command_.empty())
|
2004-11-01 08:50:42 +00:00
|
|
|
return Mover::do_rename(from, to, latex);
|
2004-10-26 18:39:13 +00:00
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
if (!do_copy(from, to, latex))
|
2004-10-26 18:39:13 +00:00
|
|
|
return false;
|
|
|
|
return support::unlink(from) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Movers::set(string const & fmt, string const & command)
|
|
|
|
{
|
|
|
|
specials_[fmt] = SpecialisedMover(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Mover const & Movers::operator()(string const & fmt) const
|
|
|
|
{
|
|
|
|
SpecialsMap::const_iterator const it = specials_.find(fmt);
|
|
|
|
return (it == specials_.end()) ? default_ : it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const Movers::command(string const & fmt) const
|
|
|
|
{
|
|
|
|
SpecialsMap::const_iterator const it = specials_.find(fmt);
|
|
|
|
return (it == specials_.end()) ? string() : it->second.command();
|
|
|
|
}
|