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.
|
|
|
|
*/
|
|
|
|
|
2005-04-26 10:30:24 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2004-10-26 18:39:13 +00:00
|
|
|
#include "mover.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/systemcall.h"
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
#include <fstream>
|
2004-10-26 18:39:13 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
using std::ios;
|
2006-10-21 00:16:43 +00:00
|
|
|
using std::string;
|
2004-10-26 18:39:13 +00:00
|
|
|
|
|
|
|
Movers movers;
|
|
|
|
Movers system_movers;
|
|
|
|
|
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
bool Mover::do_copy(string const & from, string const & to,
|
2006-11-13 10:27:57 +00:00
|
|
|
string const &, unsigned long int mode) const
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
2006-11-13 10:27:57 +00:00
|
|
|
return support::copy(from, to, mode);
|
2004-10-26 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-01 08:50:42 +00:00
|
|
|
bool Mover::do_rename(string const & from, string const & to,
|
2006-04-05 23:56:29 +00:00
|
|
|
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,
|
2006-11-13 10:27:57 +00:00
|
|
|
string const & latex, unsigned long int mode) const
|
2004-10-26 18:39:13 +00:00
|
|
|
{
|
|
|
|
if (command_.empty())
|
2006-11-13 10:27:57 +00:00
|
|
|
return Mover::do_copy(from, to, latex, mode);
|
|
|
|
|
|
|
|
if (mode != (unsigned long int)-1) {
|
|
|
|
std::ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
|
|
|
|
if (!ofs)
|
|
|
|
return false;
|
|
|
|
ofs.close();
|
2006-11-14 16:28:44 +00:00
|
|
|
if (!support::chmod(to, mode))
|
2006-11-13 10:27:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-10-26 18:39:13 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
string command = support::libScriptSearch(command_);
|
2004-10-26 18:39:13 +00:00
|
|
|
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,
|
2006-04-05 23:56:29 +00:00
|
|
|
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
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
if (!do_copy(from, to, latex, (unsigned long int)-1))
|
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();
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|