Application * theApp;
-void lyx_gui::exec(int & argc, char * argv[])
+int lyx_gui::exec(int & argc, char * argv[])
{
theApp = new Application(argc, argv);
// must do this /before/ lyxrc gets read
lyxrc.dpi = getDPI();
- LyX::ref().exec2(argc, argv);
+ return LyX::ref().exec2(argc, argv);
}
}
-void lyx_gui::start(string const & batch, std::vector<string> const & files,
- unsigned int width, unsigned int height, int posx, int posy, bool)
+int lyx_gui::start(string const & batch, std::vector<string> const & files,
+ unsigned int width, unsigned int height, int posx,
+ int posy, bool)
{
int view_id = theApp->gui().newView(width, height);
GView & view = static_cast<GView &> (theApp->gui().view(view_id));
// FIXME: breaks emergencyCleanup
delete lyxsocket;
delete lyxserver;
+ return EXIT_SUCCESS;
}
* Start the main event loop, after executing the given
* batch commands, and loading the given documents
*/
-void start(std::string const & batch, std::vector<std::string> const & files,
- unsigned int width, unsigned int height, int posx, int posy, bool maximize);
+int start(std::string const & batch, std::vector<std::string> const & files,
+ unsigned int width, unsigned int height, int posx, int posy,
+ bool maximize);
/**
* Enter the main event loop (\sa LyX::exec2)
*/
-void exec(int & argc, char * argv[]);
+int exec(int & argc, char * argv[]);
/**
* Synchronise all pending events.
void sync_events();
/**
- * quit running LyX
+ * Quit running LyX. This may either quit directly or record the exit status
+ * and only stop the event loop.
*/
void exit(int);
bool use_gui = true;
-void exec(int & argc, char * argv[])
+int exec(int & argc, char * argv[])
{
// Force adding of font path _before_ QApplication is initialized
FontLoader::initFontPath();
LoaderQueue::setPriority(10,100);
- LyX::ref().exec2(argc, argv);
+ return LyX::ref().exec2(argc, argv);
}
{}
-void start(string const & batch, vector<string> const & files,
- unsigned int width, unsigned int height, int posx, int posy, bool maximize)
+int start(string const & batch, vector<string> const & files,
+ unsigned int width, unsigned int height, int posx, int posy, bool maximize)
{
// this can't be done before because it needs the Languages object
initEncodings();
view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
}
- qApp->exec();
+ int const status = qApp->exec();
// FIXME
cleanup();
+ return status;
}
void exit(int status)
{
cleanup();
-
- // we cannot call QApplication::exit(status) - that could return us
- // into a static dialog return in the lyx code (for example,
- // load autosave file QMessageBox. We have to just get the hell
- // out.
-
- ::exit(status);
+ QApplication::exit(status);
}
bool use_gui = true;
-void exec(int & argc, char * argv[])
+int exec(int & argc, char * argv[])
{
/*
FIXME : Abdel 29/05/2006 (younes.a@free.fr)
LoaderQueue::setPriority(10,100);
- LyX::ref().exec2(argc, argv);
+ return LyX::ref().exec2(argc, argv);
}
{}
-void start(string const & batch, vector<string> const & files,
- unsigned int width, unsigned int height, int posx, int posy, bool maximize)
+int start(string const & batch, vector<string> const & files,
+ unsigned int width, unsigned int height, int posx, int posy,
+ bool maximize)
{
// this can't be done before because it needs the Languages object
initEncodings();
view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
}
- qApp->exec();
+ int const status = qApp->exec();
// FIXME
cleanup();
+ return status;
}
void exit(int status)
{
cleanup();
-
- // we cannot call QApplication::exit(status) - that could return us
- // into a static dialog return in the lyx code (for example,
- // load autosave file QMessageBox. We have to just get the hell
- // out.
-
- ::exit(status);
+ QApplication::exit(status);
}
// guarantees a return to the system, no application cleanup.
// This may cause troubles with not executed destructors.
if (lyx_gui::use_gui)
+ // lyx_gui::exit may return and only schedule the exit
lyx_gui::exit(status);
exit(status);
}
Alert::warning(_("Could not read configuration file"),
bformat(_("Error while reading the configuration file\n%1$s.\n"
"Please check your installation."), error));
- lyx_exit(EXIT_FAILURE);
}
boost::scoped_ptr<LyX> LyX::singleton_;
-void LyX::exec(int & argc, char * argv[])
+int LyX::exec(int & argc, char * argv[])
{
BOOST_ASSERT(!singleton_.get());
// We must return from this before launching the gui so that
// LyX::ref and LyX::cref.
singleton_.reset(new LyX);
// Start the real execution loop.
- singleton_->priv_exec(argc, argv);
+ return singleton_->priv_exec(argc, argv);
}
}
-void LyX::priv_exec(int & argc, char * argv[])
+int LyX::priv_exec(int & argc, char * argv[])
{
// Here we need to parse the command line. At least
// we need to parse for "-dbg" and "-help"
// Start the real execution loop.
if (lyx_gui::use_gui)
- lyx_gui::exec(argc, argv);
+ return lyx_gui::exec(argc, argv);
else
- exec2(argc, argv);
+ return exec2(argc, argv);
}
-void LyX::exec2(int & argc, char * argv[])
+int LyX::exec2(int & argc, char * argv[])
{
// check for any spurious extra arguments
// other than documents
if (argv[argi][0] == '-') {
lyxerr << bformat(_("Wrong command line option `%1$s'. Exiting."),
argv[argi]) << endl;
- exit(1);
+ return EXIT_FAILURE;
}
}
// Initialization of LyX (reads lyxrc and more)
lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
- init();
+ bool const success = init();
lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
+ if (!success)
+ return EXIT_FAILURE;
if (lyx_gui::use_gui)
lyx_gui::parse_lyxrc();
bool success = false;
if (last_loaded->dispatch(batch_command, &success)) {
quitLyX(false);
- lyx_exit(!success);
+ return !success;
}
}
files.clear(); // the files are already loaded
height = 0;
}
- lyx_gui::start(batch_command, files, width, height, posx, posy, maximize);
+ return lyx_gui::start(batch_command, files, width, height, posx, posy, maximize);
} else {
// Something went wrong above
quitLyX(false);
- lyx_exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
}
}
-void LyX::init()
+bool LyX::init()
{
#ifdef SIGHUP
signal(SIGHUP, error_handler);
//
// This one may have been distributed along with LyX.
- readRcFile("lyxrc.dist");
+ if (!readRcFile("lyxrc.dist"))
+ return false;
// Set the PATH correctly.
#if !defined (USE_POSIX_PACKAGING)
}
// This one is generated in user_support directory by lib/configure.py.
- readRcFile("lyxrc.defaults");
+ if (!readRcFile("lyxrc.defaults"))
+ return false;
// Query the OS to know what formats are viewed natively
formats.setAutoOpen();
system_lcolor = lcolor;
// This one is edited through the preferences dialog.
- readRcFile("preferences");
+ if (!readRcFile("preferences"))
+ return false;
- readEncodingsFile("encodings");
- readLanguagesFile("languages");
+ if (!readEncodingsFile("encodings"))
+ return false;
+ if (!readLanguagesFile("languages"))
+ return false;
// Load the layouts
lyxerr[Debug::INIT] << "Reading layouts..." << endl;
- LyXSetStyle();
+ if (!LyXSetStyle())
+ return false;
if (lyx_gui::use_gui) {
// Set up bindings
toplevel_keymap->read(lyxrc.bind_file);
// Read menus
- readUIFile(lyxrc.ui_file);
+ if (!readUIFile(lyxrc.ui_file))
+ return false;
}
if (lyxerr.debugging(Debug::LYXRC))
// close to zero. We therefore don't try to overcome this
// problem with e.g. asking the user for a new path and
// trying again but simply exit.
- lyx_exit(EXIT_FAILURE);
+ return false;
}
if (lyxerr.debugging(Debug::INIT)) {
lyxerr[Debug::INIT] << "Reading session information '.lyx/session'..." << endl;
session_.reset(new lyx::Session(lyxrc.num_lastfiles));
+ return true;
}
}
-void LyX::readRcFile(string const & name)
+bool LyX::readRcFile(string const & name)
{
lyxerr[Debug::INIT] << "About to read " << name << "... ";
lyxerr[Debug::INIT] << "Found in " << lyxrc_path << endl;
- if (lyxrc.read(lyxrc_path) < 0)
+ if (lyxrc.read(lyxrc_path) < 0) {
showFileError(name);
+ return false;
+ }
} else
lyxerr[Debug::INIT] << "Not found." << lyxrc_path << endl;
+ return true;
}
// Read the ui file `name'
-void LyX::readUIFile(string const & name)
+bool LyX::readUIFile(string const & name)
{
enum Uitags {
ui_menuset = 1,
<< "' has been read already. "
<< "Is this an include loop?"
<< endl;
- return;
+ return false;
}
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
if (ui_path.empty()) {
lyxerr[Debug::INIT] << "Could not find " << name << endl;
showFileError(name);
- return;
+ return false;
}
uifiles.push_back(name);
case ui_include: {
lex.next(true);
string const file = lex.getString();
- readUIFile(file);
+ if (!readUIFile(file))
+ return false;
break;
}
case ui_menuset:
break;
}
}
+ return true;
}
// Read the languages file `name'
-void LyX::readLanguagesFile(string const & name)
+bool LyX::readLanguagesFile(string const & name)
{
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
string const lang_path = libFileSearch(string(), name);
if (lang_path.empty()) {
showFileError(name);
- return;
+ return false;
}
languages.read(lang_path);
+ return true;
}
// Read the encodings file `name'
-void LyX::readEncodingsFile(string const & name)
+bool LyX::readEncodingsFile(string const & name)
{
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
string const enc_path = libFileSearch(string(), name);
if (enc_path.empty()) {
showFileError(name);
- return;
+ return false;
}
encodings.read(enc_path);
+ return true;
}
* objects lead either to harmless error messages on exit
* ("Mutex destroy failure") or crashes (OS X).
*/
- static void exec(int & argc, char * argv[]);
+ static int exec(int & argc, char * argv[]);
/// Execute LyX (inner execution loop, \sa exec)
- void exec2(int & argc, char * argv[]);
+ int exec2(int & argc, char * argv[]);
static LyX & ref();
static LyX const & cref();
static boost::scoped_ptr<LyX> singleton_;
LyX();
- void priv_exec(int & argc, char * argv[]);
+ int priv_exec(int & argc, char * argv[]);
/// initial LyX set up
- void init();
+ bool init();
/// set up the default key bindings
void defaultKeyBindings(kb_keymap * kbmap);
/// set up the default dead key bindings if requested
*/
bool queryUserLyXDir(bool explicit_userdir);
/// read lyxrc/preferences
- void readRcFile(std::string const & name);
+ bool readRcFile(std::string const & name);
/// read the given ui (menu/toolbar) file
- void readUIFile(std::string const & name);
+ bool readUIFile(std::string const & name);
/// read the given languages file
- void readLanguagesFile(std::string const & name);
+ bool readLanguagesFile(std::string const & name);
/// read the given encodings file
- void readEncodingsFile(std::string const & name);
+ bool readEncodingsFile(std::string const & name);
/// parsing of non-gui LyX options. Returns true if gui
bool easyParse(int & argc, char * argv[]);
/// shows up a parsing error on screen
// Reads the style files
-void LyXSetStyle()
+bool LyXSetStyle()
{
lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration..." << endl;
if (!textclasslist.read()) {
lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
"during parsing.\n Exiting." << endl;
- exit(1);
+ return false;
}
lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
+ return true;
}
class LyXLayout;
/// Reads the style files
-extern void LyXSetStyle();
+extern bool LyXSetStyle();
///
class LyXTextClassList : boost::noncopyable {
// initialize for internationalized version *EK*
locale_init();
- LyX::exec(argc, argv);
- return 0;
+ return LyX::exec(argc, argv);
}