From: Georg Baum Date: Wed, 5 Jul 2006 17:01:26 +0000 (+0000) Subject: Reduce calls of ::exit() X-Git-Tag: 1.6.10~13009 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=da9cdaf2189fde92ba33703d9cc3c1cc8fe93321;p=features.git Reduce calls of ::exit() * src/main.C (main): return LyX::exec() * src/frontends/{gtk,qt3,qt4}/lyx_gui.C (lyx_gui::exec): Change return value to int (lyx_gui::start): ditto * src/frontends/qt[3,4]/lyx_gui.C (lyx_gui::exit): Call QApplication::exit instead of ::exit, this hack is not needed anymore * src/frontends/lyx_gui.h (lyx_gui::exec): Change return value to int (lyx_gui::start): ditto * src/lyxtextclasslist.[Ch] (LyXSetStyle): SChange return value to bool and don't call ::exit * src/lyx_main.C (showFileError): Don't exit anymore * src/lyx_main.[Ch] (LyX::exec): Change return value to int (LyX::priv_exec): ditto (LyX::exec2): ditto (LyX::init): Change return value to bool (LyX::readRcFile): ditto (LyX::readUIFile): ditto git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14339 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index 1f2bef7b6d..12675095ea 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -118,7 +118,7 @@ private: Application * theApp; -void lyx_gui::exec(int & argc, char * argv[]) +int lyx_gui::exec(int & argc, char * argv[]) { theApp = new Application(argc, argv); @@ -131,7 +131,7 @@ void lyx_gui::exec(int & argc, char * argv[]) // must do this /before/ lyxrc gets read lyxrc.dpi = getDPI(); - LyX::ref().exec2(argc, argv); + return LyX::ref().exec2(argc, argv); } @@ -140,8 +140,9 @@ void lyx_gui::parse_lyxrc() } -void lyx_gui::start(string const & batch, std::vector const & files, - unsigned int width, unsigned int height, int posx, int posy, bool) +int lyx_gui::start(string const & batch, std::vector 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 (theApp->gui().view(view_id)); @@ -171,6 +172,7 @@ void lyx_gui::start(string const & batch, std::vector const & files, // FIXME: breaks emergencyCleanup delete lyxsocket; delete lyxserver; + return EXIT_SUCCESS; } diff --git a/src/frontends/lyx_gui.h b/src/frontends/lyx_gui.h index 0d637453f2..aa73b4ae4c 100644 --- a/src/frontends/lyx_gui.h +++ b/src/frontends/lyx_gui.h @@ -56,13 +56,14 @@ void parse_lyxrc(); * Start the main event loop, after executing the given * batch commands, and loading the given documents */ -void start(std::string const & batch, std::vector const & files, - unsigned int width, unsigned int height, int posx, int posy, bool maximize); +int start(std::string const & batch, std::vector 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. @@ -70,7 +71,8 @@ void exec(int & argc, char * argv[]); 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); diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index 83ff15f0ea..64c9b6b0c4 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -172,7 +172,7 @@ namespace lyx_gui { 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(); @@ -225,7 +225,7 @@ void exec(int & argc, char * argv[]) LoaderQueue::setPriority(10,100); - LyX::ref().exec2(argc, argv); + return LyX::ref().exec2(argc, argv); } @@ -233,8 +233,8 @@ void parse_lyxrc() {} -void start(string const & batch, vector const & files, - unsigned int width, unsigned int height, int posx, int posy, bool maximize) +int start(string const & batch, vector 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(); @@ -272,10 +272,11 @@ void start(string const & batch, vector const & files, view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch)); } - qApp->exec(); + int const status = qApp->exec(); // FIXME cleanup(); + return status; } @@ -294,13 +295,7 @@ void sync_events() 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); } diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index 1769554950..63b1abaa96 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -108,7 +108,7 @@ namespace lyx_gui { 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) @@ -185,7 +185,7 @@ void exec(int & argc, char * argv[]) LoaderQueue::setPriority(10,100); - LyX::ref().exec2(argc, argv); + return LyX::ref().exec2(argc, argv); } @@ -193,8 +193,9 @@ void parse_lyxrc() {} -void start(string const & batch, vector const & files, - unsigned int width, unsigned int height, int posx, int posy, bool maximize) +int start(string const & batch, vector 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(); @@ -245,10 +246,11 @@ void start(string const & batch, vector const & files, view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch)); } - qApp->exec(); + int const status = qApp->exec(); // FIXME cleanup(); + return status; } @@ -265,13 +267,7 @@ void sync_events() 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); } diff --git a/src/lyx_main.C b/src/lyx_main.C index 957614470a..fbe578706f 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -113,6 +113,7 @@ void lyx_exit(int 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); } @@ -123,7 +124,6 @@ void showFileError(string const & error) 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); } @@ -143,7 +143,7 @@ void reconfigureUserLyXDir() boost::scoped_ptr 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 @@ -151,7 +151,7 @@ void LyX::exec(int & argc, char * argv[]) // 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); } @@ -211,7 +211,7 @@ Buffer const * const LyX::updateInset(InsetBase const * inset) const } -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" @@ -222,13 +222,13 @@ void LyX::priv_exec(int & argc, char * argv[]) // 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 @@ -236,14 +236,16 @@ void LyX::exec2(int & argc, char * argv[]) 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(); @@ -296,7 +298,7 @@ void LyX::exec2(int & argc, char * argv[]) bool success = false; if (last_loaded->dispatch(batch_command, &success)) { quitLyX(false); - lyx_exit(!success); + return !success; } } files.clear(); // the files are already loaded @@ -341,12 +343,12 @@ void LyX::exec2(int & argc, char * argv[]) 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; } } @@ -458,7 +460,7 @@ void LyX::printError(ErrorItem const & ei) } -void LyX::init() +bool LyX::init() { #ifdef SIGHUP signal(SIGHUP, error_handler); @@ -489,7 +491,8 @@ void LyX::init() // // 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) @@ -511,7 +514,8 @@ void LyX::init() } // 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(); @@ -523,14 +527,18 @@ void LyX::init() 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 @@ -539,7 +547,8 @@ void LyX::init() toplevel_keymap->read(lyxrc.bind_file); // Read menus - readUIFile(lyxrc.ui_file); + if (!readUIFile(lyxrc.ui_file)) + return false; } if (lyxerr.debugging(Debug::LYXRC)) @@ -565,7 +574,7 @@ void LyX::init() // 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)) { @@ -574,6 +583,7 @@ void LyX::init() lyxerr[Debug::INIT] << "Reading session information '.lyx/session'..." << endl; session_.reset(new lyx::Session(lyxrc.num_lastfiles)); + return true; } @@ -731,7 +741,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir) } -void LyX::readRcFile(string const & name) +bool LyX::readRcFile(string const & name) { lyxerr[Debug::INIT] << "About to read " << name << "... "; @@ -740,16 +750,19 @@ void LyX::readRcFile(string const & 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, @@ -776,7 +789,7 @@ void LyX::readUIFile(string const & name) << "' has been read already. " << "Is this an include loop?" << endl; - return; + return false; } lyxerr[Debug::INIT] << "About to read " << name << "..." << endl; @@ -786,7 +799,7 @@ void LyX::readUIFile(string const & name) if (ui_path.empty()) { lyxerr[Debug::INIT] << "Could not find " << name << endl; showFileError(name); - return; + return false; } uifiles.push_back(name); @@ -807,7 +820,8 @@ void LyX::readUIFile(string const & name) case ui_include: { lex.next(true); string const file = lex.getString(); - readUIFile(file); + if (!readUIFile(file)) + return false; break; } case ui_menuset: @@ -829,34 +843,37 @@ void LyX::readUIFile(string const & name) 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; } diff --git a/src/lyx_main.h b/src/lyx_main.h index d69e86a9d4..55fdd631b6 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -46,9 +46,9 @@ public: * 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(); @@ -69,10 +69,10 @@ private: static boost::scoped_ptr 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 @@ -85,13 +85,13 @@ private: */ 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 diff --git a/src/lyxtextclasslist.C b/src/lyxtextclasslist.C index d0be70ff77..0b845e4c9b 100644 --- a/src/lyxtextclasslist.C +++ b/src/lyxtextclasslist.C @@ -217,15 +217,16 @@ LyXTextClassList textclasslist; // 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; } diff --git a/src/lyxtextclasslist.h b/src/lyxtextclasslist.h index 9bea70bde5..76fbaa8e09 100644 --- a/src/lyxtextclasslist.h +++ b/src/lyxtextclasslist.h @@ -24,7 +24,7 @@ class LyXLayout; /// Reads the style files -extern void LyXSetStyle(); +extern bool LyXSetStyle(); /// class LyXTextClassList : boost::noncopyable { diff --git a/src/main.C b/src/main.C index 10e9469231..5338014002 100644 --- a/src/main.C +++ b/src/main.C @@ -44,6 +44,5 @@ int main(int argc, char * argv[]) // initialize for internationalized version *EK* locale_init(); - LyX::exec(argc, argv); - return 0; + return LyX::exec(argc, argv); }