/**
- * \file GraphicsConverter.C
+ * \file GraphicsConverter.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Angus Leeming
+ * \author Angus Leeming
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "converter.h"
#include "debug.h"
+#include "format.h"
#include "support/filetools.h"
-#include "support/forkedcall.h"
+#include "support/forkedcallqueue.h"
+#include "support/tostr.h"
+#include "support/lstrings.h"
#include "support/lyxlib.h"
#include <boost/bind.hpp>
-#include <boost/signals/trackable.hpp>
-#include "Lsstream.h"
-#include "support/LOstream.h"
+#include "support/std_sstream.h"
#include <fstream>
-#include <sys/types.h> // needed for pid_t
+
+namespace support = lyx::support;
+
+using support::ChangeExtension;
+using support::Forkedcall;
+using support::ForkedCallQueue;
+using support::LibFileSearch;
+using support::LibScriptSearch;
+using support::OnlyPath;
+using support::OnlyFilename;
+using support::QuoteName;
+using support::subst;
+using support::tempName;
+using support::unlink;
using std::endl;
using std::ostream;
+using std::ostringstream;
-namespace grfx {
+
+namespace lyx {
+namespace graphics {
struct Converter::Impl : public boost::signals::trackable {
///
return pimpl_->finished_ ? pimpl_->to_file_ : empty;
}
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx
+
//------------------------------
// Implementation details follow
} // namespace anon
-namespace grfx {
+namespace lyx {
+namespace graphics {
Converter::Impl::Impl(string const & from_file, string const & to_file_base,
string const & from_format, string const & to_format)
} else {
lyxerr[Debug::GRAPHICS] << "\tConversion script:"
- << "\n--------------------------------------\n"
- << STRCONV(script.str())
- << "\n--------------------------------------\n";
+ << "\n--------------------------------------\n"
+ << script.str()
+ << "\n--------------------------------------\n";
// Output the script to file.
static int counter = 0;
if (!fs.good())
return;
- fs << STRCONV(script.str());
+ fs << script.str();
fs.close();
// The command needed to run the conversion process
// We create a dummy command for ease of understanding of the
// list of forked processes.
- // Note that 'sh ' is absolutely essential, or execvp will fail.
+ // Note: 'sh ' is absolutely essential, or execvp will fail.
script_command_ = "sh " + script_file_ + ' ' +
OnlyFilename(from_file) + ' ' + to_format;
}
return;
}
- // Initiate the conversion
- Forkedcall::SignalTypePtr convert_ptr;
- convert_ptr.reset(new Forkedcall::SignalType);
+ Forkedcall::SignalTypePtr
+ ptr = ForkedCallQueue::get().add(script_command_);
- convert_ptr->connect(
- boost::bind(&Impl::converted, this, _1, _2));
+ ptr->connect(boost::bind(&Impl::converted, this, _1, _2));
- Forkedcall call;
- int retval = call.startscript(script_command_, convert_ptr);
- if (retval > 0) {
- // Unable to even start the script, so clean-up the mess!
- converted(0, 1);
- }
}
-
void Converter::Impl::converted(pid_t /* pid */, int retval)
{
if (finished_)
finished_ = true;
// Clean-up behind ourselves
- lyx::unlink(script_file_);
+ unlink(script_file_);
if (retval > 0) {
- lyx::unlink(to_file_);
+ unlink(to_file_);
to_file_.erase();
finishedConversion(false);
} else {
}
}
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx
namespace {
<< "\t'rm' -f ${fromfile}\n"
<< "}\n";
- return STRCONV(command.str());
+ return command.str();
}
// Remember to remove the temp file because we only want the name...
static int counter = 0;
string const tmp = "gconvert" + tostr(counter++);
- string const to_base = lyx::tempName(string(), tmp);
- lyx::unlink(to_base);
+ string const to_base = tempName(string(), tmp);
+ unlink(to_base);
string outfile = from_file;