#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
-
-#include "support/bind.h"
-#include <boost/scoped_ptr.hpp>
+#include "support/unique_ptr.h"
#include <algorithm>
-#include <iostream>
#include <csignal>
+#include <iostream>
+#include <functional>
#include <map>
#include <stdlib.h>
#include <string>
bool use_gui = true;
+// Report on the terminal about spawned commands. The default is false
+// and can be changed with the option -v (--verbose).
+
+bool verbose = false;
+
+
// We default to open documents in an already running instance, provided that
// the lyxpipe has been setup. This can be overridden either on the command
// line or through preference settings.
///
CmdDef toplevel_cmddef_;
///
- boost::scoped_ptr<Server> lyx_server_;
+ unique_ptr<Server> lyx_server_;
///
- boost::scoped_ptr<ServerSocket> lyx_socket_;
+ unique_ptr<ServerSocket> lyx_socket_;
///
- boost::scoped_ptr<frontend::Application> application_;
+ unique_ptr<frontend::Application> application_;
/// lyx session, containing lastfiles, lastfilepos, and lastopened
- boost::scoped_ptr<Session> session_;
+ unique_ptr<Session> session_;
/// Files to load at start.
vector<string> files_to_load_;
///
Movers system_movers_;
- /// has this user started lyx for the first time?
-// bool first_start;
/// the parsed command line batch command if any
vector<string> batch_commands;
LYXERR(Debug::INFO, "Deleting tmp dir "
<< package().temp_dir().absFileName());
if (!package().temp_dir().destroyDirectory()) {
- docstring const msg =
- bformat(_("Unable to remove the temporary directory %1$s"),
- from_utf8(package().temp_dir().absFileName()));
- Alert::warning(_("Unable to remove temporary directory"), msg);
+ LYXERR0(bformat(_("Unable to remove the temporary directory %1$s"),
+ from_utf8(package().temp_dir().absFileName())));
}
}
}
{
int exit_status = init(argc, argv);
if (exit_status) {
- prepareExit();
- return exit_status;
- }
-
- // this is correct, since return values are inverted.
- exit_status = !loadFiles();
-
- if (pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) {
prepareExit();
return exit_status;
}
- BufferList::iterator begin = pimpl_->buffer_list_.begin();
-
- bool final_success = false;
- for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) {
- Buffer * buf = *I;
- if (buf != buf->masterBuffer())
- continue;
- vector<string>::const_iterator bcit = pimpl_->batch_commands.begin();
- vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
- DispatchResult dr;
- for (; bcit != bcend; ++bcit) {
- LYXERR(Debug::ACTION, "Buffer::dispatch: cmd: " << *bcit);
- buf->dispatch(*bcit, dr);
- final_success |= !dr.error();
- }
- }
- prepareExit();
- return !final_success;
-}
-
+ // Used to keep track of which buffers were explicitly loaded by user request.
+ // This is necessary because master and child document buffers are loaded, even
+ // if they were not named on the command line. We do not want to dispatch to
+ // those.
+ vector<Buffer *> command_line_buffers;
-bool LyX::loadFiles()
-{
- LATTEST(!use_gui);
- bool success = true;
+ // Load the files specified on the command line
vector<string>::const_iterator it = pimpl_->files_to_load_.begin();
vector<string>::const_iterator end = pimpl_->files_to_load_.end();
-
for (; it != end; ++it) {
- // get absolute path of file and add ".lyx" to
- // the filename if necessary
+ // get absolute path of file and add ".lyx" to the filename if necessary
FileName fname = fileSearch(string(), os::internal_path(*it), "lyx",
- may_not_exist);
+ may_not_exist);
if (fname.empty())
continue;
Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFileName());
- if (buf->loadLyXFile() == Buffer::ReadSuccess) {
+ LYXERR(Debug::FILES, "Loading " << fname);
+ if (buf && buf->loadLyXFile() == Buffer::ReadSuccess) {
ErrorList const & el = buf->errorList("Parse");
- if (!el.empty())
- for_each(el.begin(), el.end(),
- bind(&LyX::printError, this, _1));
- }
- else {
- pimpl_->buffer_list_.release(buf);
+ for(ErrorItem const & e : el)
+ printError(e);
+ command_line_buffers.push_back(buf);
+ } else {
+ if (buf)
+ pimpl_->buffer_list_.release(buf);
docstring const error_message =
- bformat(_("LyX failed to load the following file: %1$s"),
- from_utf8(fname.absFileName()));
+ bformat(_("LyX failed to load the following file: %1$s"),
+ from_utf8(fname.absFileName()));
lyxerr << to_utf8(error_message) << endl;
- success = false;
+ exit_status = 1; // failed
}
}
- return success;
+
+ if (exit_status || pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) {
+ prepareExit();
+ return exit_status;
+ }
+
+ // Iterate through the buffers that were specified on the command line
+ bool final_success = false;
+ vector<Buffer *>::iterator buf_it = command_line_buffers.begin();
+ for (; buf_it != command_line_buffers.end(); ++buf_it) {
+ Buffer * buf = *buf_it;
+ vector<string>::const_iterator bcit = pimpl_->batch_commands.begin();
+ vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
+ DispatchResult dr;
+ for (; bcit != bcend; ++bcit) {
+ LYXERR(Debug::ACTION, "Buffer::dispatch: cmd: " << *bcit);
+ buf->dispatch(*bcit, dr);
+ final_success |= !dr.error();
+ }
+ }
+ prepareExit();
+ return !final_success;
}
// Loop over the list of duplicated variables
std::set<std::string>::iterator dupe = dupes.begin();
- std::set<std::string>::iterator const dend = dupes.end();
+ std::set<std::string>::iterator const dend = dupes.end();
for (; dupe != dend; ++dupe) {
const char *name = (*dupe).c_str();
char *val = getenv(name);
}
#endif
+
+static void initTemplatePath()
+{
+ FileName const package_template_path =
+ FileName(addName(package().system_support().absFileName(), "templates"));
+
+ if (lyxrc.template_path.empty()) {
+ lyxrc.template_path = package_template_path.absFileName();
+ }
+#if defined (USE_MACOSX_PACKAGING)
+ FileName const user_template_path =
+ FileName(addName(package().user_support().absFileName(), "templates"));
+
+ if (package_template_path != FileName(lyxrc.template_path) &&
+ user_template_path != FileName(lyxrc.template_path))
+ {
+ return;
+ }
+ FileName const user_template_link =
+ FileName(addName(user_template_path.absFileName(),"SystemTemplates"));
+ if (user_template_link.isSymLink() && !equivalent(user_template_link, package_template_path)) {
+ user_template_link.removeFile();
+ }
+ if (!user_template_link.exists()) {
+ if (!package_template_path.link(user_template_link)) {
+ FileName const user_support = package().user_support();
+ if (user_support.exists() && user_support.isDirectory()) {
+ LYXERR(Debug::INIT, "Cannot create symlink " + user_template_link.absFileName());
+ lyxrc.template_path = package_template_path.absFileName();
+ }
+ return;
+ }
+ LYXERR(Debug::INIT, "Symlink \"" << user_template_link.absFileName() << "\" created.");
+ }
+ lyxrc.template_path = user_template_path.absFileName();
+#endif
+}
+
+
bool LyX::init()
{
#ifdef SIGHUP
lyxrc.example_path = addPath(package().system_support().absFileName(),
"examples");
}
- if (lyxrc.template_path.empty()) {
- lyxrc.template_path = addPath(package().system_support().absFileName(),
- "templates");
- }
+ initTemplatePath();
// init LyXDir environment variable
string const lyx_dir = package().lyx_dir().absFileName();
return false;
// Set the PATH correctly.
-#if !defined (USE_POSIX_PACKAGING)
+#if !defined (USE_POSIX_PACKAGING) && !defined (USE_HAIKU_PACKAGING)
// Add the directory containing the LyX executable to the path
// so that LyX can find things like tex2lyx.
if (package().build_support().empty())
if (queryUserLyXDir(package().explicit_user_support())) {
package().reconfigureUserLyXDir("");
+ // Now the user directory is present on first start.
+ initTemplatePath();
}
fileUnlock(fd, lock_file.c_str());
}
namespace {
/// return the the number of arguments consumed
-typedef boost::function<int(string const &, string const &, string &)> cmd_helper;
+typedef function<int(string const &, string const &, string &)> cmd_helper;
int parse_dbg(string const & arg, string const &, string &)
{
"\t-r [--remote]\n"
" open documents in an already running instance\n"
" (a working lyxpipe is needed)\n"
+ "\t-v [--verbose]\n"
+ " report on terminal about spawned commands.\n"
"\t-batch execute commands without launching GUI and exit.\n"
"\t-version summarize version and build info\n"
"Check the LyX man page for more details.")) << endl;
if (string(lyx_git_commit_hash) != "none")
cout << to_utf8(_(" Git commit hash "))
<< string(lyx_git_commit_hash).substr(0,8) << endl;
- cout << to_utf8(bformat(_("Built on %1$s[[date]], %2$s[[time]]"),
- from_ascii(lyx_build_date), from_ascii(lyx_build_time))) << endl;
cout << lyx_version_info << endl;
exit(0);
return 0;
}
+int parse_verbose(string const &, string const &, string &)
+{
+ verbose = true;
+ return 0;
+}
+
+
int parse_force(string const & arg, string const &, string &)
{
if (arg == "all") {
cmdmap["-userdir"] = parse_userdir;
cmdmap["-x"] = parse_execute;
cmdmap["--execute"] = parse_execute;
- cmdmap["-e"] = parse_export;
+ cmdmap["-e"] = parse_export;
cmdmap["--export"] = parse_export;
cmdmap["-E"] = parse_export_to;
cmdmap["--export-to"] = parse_export_to;
cmdmap["--no-remote"] = parse_noremote;
cmdmap["-r"] = parse_remote;
cmdmap["--remote"] = parse_remote;
+ cmdmap["-v"] = parse_verbose;
+ cmdmap["--verbose"] = parse_verbose;
for (int i = 1; i < argc; ++i) {
map<string, cmd_helper>::const_iterator it
}
-void dispatch(FuncRequest const & action)
+DispatchResult const & dispatch(FuncRequest const & action)
{
LAPPERR(theApp());
return theApp()->dispatch(action);
void dispatch(FuncRequest const & action, DispatchResult & dr)
{
LAPPERR(theApp());
- return theApp()->dispatch(action, dr);
+ theApp()->dispatch(action, dr);
}
// FIXME: this should not be use_gui dependent
LWARNIF(use_gui);
LAPPERR(singleton_);
- return *singleton_->pimpl_->lyx_server_.get();
+ return *singleton_->pimpl_->lyx_server_;
}
// FIXME: this should not be use_gui dependent
LWARNIF(use_gui);
LAPPERR(singleton_);
- return *singleton_->pimpl_->lyx_socket_.get();
+ return *singleton_->pimpl_->lyx_socket_;
}