#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
-#include "support/lyxlib.h"
#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
#include <iostream>
#include <csignal>
#include <map>
+#include <stdlib.h>
#include <string>
#include <vector>
-using std::endl;
-using std::for_each;
-using std::map;
-using std::make_pair;
-using std::string;
-using std::vector;
-
-#ifndef CXX_GLOBAL_CSTD
-using std::exit;
-using std::signal;
-using std::system;
-#endif
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::addName;
-using support::addPath;
-using support::bformat;
-using support::changeExtension;
-using support::createLyXTmpDir;
-using support::FileName;
-using support::fileSearch;
-using support::getEnv;
-using support::i18nLibFileSearch;
-using support::libFileSearch;
-using support::package;
-using support::prependEnvPath;
-using support::rtrim;
-using support::Systemcall;
-
namespace Alert = frontend::Alert;
namespace os = support::os;
string cl_system_support;
string cl_user_support;
-std::string geometryArg;
+string geometryArg;
LyX * singleton_ = 0;
string const configure_command = package().configure_command();
lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
- support::PathChanger p(package().user_support());
+ PathChanger p(package().user_support());
Systemcall one;
one.startscript(Systemcall::Wait, configure_command);
lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
/// has this user started lyx for the first time?
bool first_start;
/// the parsed command line batch command if any
- std::string batch_command;
+ string batch_command;
};
///
}
+void LyX::exit(int exit_code) const
+{
+ if (exit_code)
+ // Something wrong happened so better save everything, just in
+ // case.
+ emergencyCleanup();
+
+#ifndef NDEBUG
+ // Properly crash in debug mode in order to get a useful backtrace.
+ abort();
+#endif
+
+ // In release mode, try to exit gracefully.
+ if (theApp())
+ theApp()->exit(exit_code);
+ else
+ exit(exit_code);
+}
+
+
LyX & LyX::ref()
{
BOOST_ASSERT(singleton_);
}
-Messages & LyX::getMessages(std::string const & language)
+Messages & LyX::getMessages(string const & language)
{
map<string, Messages>::iterator it = pimpl_->messages_.find(language);
if (it != pimpl_->messages_.end())
return it->second;
- std::pair<map<string, Messages>::iterator, bool> result =
- pimpl_->messages_.insert(std::make_pair(language, Messages(language)));
+ pair<map<string, Messages>::iterator, bool> result =
+ pimpl_->messages_.insert(make_pair(language, Messages(language)));
BOOST_ASSERT(result.second);
return result.first->second;
}
-void LyX::setGuiLanguage(std::string const & language)
+void LyX::setGuiLanguage(string const & language)
{
pimpl_->messages_["GUI"] = Messages(language);
}
easyParse(argc, argv);
try {
- support::init_package(to_utf8(from_local8bit(argv[0])),
+ init_package(to_utf8(from_local8bit(argv[0])),
cl_system_support, cl_user_support,
- support::top_build_dir_is_one_level_up);
- } catch (support::ExceptionMessage const & message) {
- if (message.type_ == support::ErrorException) {
+ top_build_dir_is_one_level_up);
+ } catch (ExceptionMessage const & message) {
+ if (message.type_ == ErrorException) {
Alert::error(message.title_, message.details_);
exit(1);
- } else if (message.type_ == support::WarningException) {
+ } else if (message.type_ == WarningException) {
Alert::warning(message.title_, message.details_);
}
}
// close buffers first
pimpl_->buffer_list_.closeAll();
+ // register session changes and shutdown server and socket
+ if (use_gui) {
+ if (pimpl_->session_)
+ pimpl_->session_->writeFile();
+ pimpl_->session_.reset();
+ pimpl_->lyx_server_.reset();
+ pimpl_->lyx_socket_.reset();
+ }
+
// do any other cleanup procedures now
if (package().temp_dir() != package().system_temp_dir()) {
LYXERR(Debug::INFO, "Deleting tmp dir "
}
}
- if (use_gui) {
- if (pimpl_->session_)
- pimpl_->session_->writeFile();
- pimpl_->session_.reset();
- pimpl_->lyx_server_.reset();
- pimpl_->lyx_socket_.reset();
- }
-
// Kill the application object before exiting. This avoids crashes
// when exiting on Linux.
if (pimpl_->application_)
// the filename if necessary
pimpl_->files_to_load_.push_back(fileSearch(string(),
os::internal_path(to_utf8(from_local8bit(argv[argi]))),
- "lyx", support::allow_unreadable));
+ "lyx", allow_unreadable));
}
if (first_start)
void LyX::addFileToLoad(FileName const & fname)
{
- vector<FileName>::const_iterator cit = std::find(
+ vector<FileName>::const_iterator cit = find(
pimpl_->files_to_load_.begin(), pimpl_->files_to_load_.end(),
fname);
#else
if (err_sig == SIGSEGV || !getEnv("LYXDEBUG").empty())
#endif
- support::abort();
+ abort();
exit(0);
}
{
docstring tmp = _("LyX: ") + ei.error + char_type(':')
+ ei.description;
- std::cerr << to_utf8(tmp) << std::endl;
+ cerr << to_utf8(tmp) << endl;
}
};
// Ensure that a file is read only once (prevents include loops)
- static std::list<string> uifiles;
- std::list<string>::const_iterator it = uifiles.begin();
- std::list<string>::const_iterator end = uifiles.end();
- it = std::find(it, end, name);
+ static list<string> uifiles;
+ list<string>::const_iterator it = uifiles.begin();
+ list<string>::const_iterator end = uifiles.end();
+ it = find(it, end, name);
if (it != end) {
LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. "
<< "Is this an include loop?");
break;
}
case ui_menuset:
- menubackend.read(lex);
+ theApp()->menuBackend().read(lex);
break;
case ui_toolbarset:
void LyX::easyParse(int & argc, char * argv[])
{
- std::map<string, cmd_helper> cmdmap;
+ map<string, cmd_helper> cmdmap;
cmdmap["-dbg"] = parse_dbg;
cmdmap["-help"] = parse_help;
cmdmap["-geometry"] = parse_geometry;
for (int i = 1; i < argc; ++i) {
- std::map<string, cmd_helper>::const_iterator it
+ map<string, cmd_helper>::const_iterator it
= cmdmap.find(argv[i]);
// don't complain if not found - may be parsed later
}
-Mover const & getMover(std::string const & fmt)
+Mover const & getMover(string const & fmt)
{
return LyX::ref().pimpl_->movers_(fmt);
}
-void setMover(std::string const & fmt, std::string const & command)
+void setMover(string const & fmt, string const & command)
{
LyX::ref().pimpl_->movers_.set(fmt, command);
}
}
-Messages & getMessages(std::string const & language)
+Messages & getMessages(string const & language)
{
return LyX::ref().getMessages(language);
}