whitespace.
[lyx.git] / src / Mover.cpp
blob81d13d2a5df4277aa5d674492fb5d10f146a0f48
1 /**
2 * \file Mover.cpp
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.
9 */
11 #include <config.h>
13 #include "Mover.h"
15 #include "support/FileName.h"
16 #include "support/filetools.h"
17 #include "support/lstrings.h"
18 #include "support/Systemcall.h"
20 #include <fstream>
21 #include <sstream>
23 using namespace std;
24 using namespace lyx::support;
26 namespace lyx {
29 bool Mover::copy(FileName const & from, FileName const & to) const
31 return do_copy(from, to, to.absFilename());
35 bool Mover::do_copy(FileName const & from, FileName const & to,
36 string const &) const
38 return from.copyTo(to);
42 bool Mover::rename(FileName const & from,
43 FileName const & to) const
45 return do_rename(from, to, to.absFilename());
49 bool Mover::do_rename(FileName const & from, FileName const & to,
50 string const &) const
52 return from.moveTo(to);
56 bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
57 string const & latex) const
59 if (command_.empty())
60 return Mover::do_copy(from, to, latex);
62 string command = libScriptSearch(command_);
63 command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
64 command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
65 command = subst(command, "$$l", quoteName(latex));
67 Systemcall one;
68 return one.startscript(Systemcall::Wait, command) == 0;
72 bool SpecialisedMover::do_rename(FileName const & from, FileName const & to,
73 string const & latex) const
75 if (command_.empty())
76 return Mover::do_rename(from, to, latex);
78 if (!do_copy(from, to, latex))
79 return false;
80 return from.removeFile();
84 void Movers::set(string const & fmt, string const & command)
86 specials_[fmt] = SpecialisedMover(command);
90 Mover const & Movers::operator()(string const & fmt) const
92 SpecialsMap::const_iterator const it = specials_.find(fmt);
93 if (it == specials_.end())
94 return default_;
95 return it->second;
99 string const Movers::command(string const & fmt) const
101 SpecialsMap::const_iterator const it = specials_.find(fmt);
102 return (it == specials_.end()) ? string() : it->second.command();
106 } // namespace lyx