+ loadFiles();
+
+ if (batch_command.empty() || pimpl_->buffer_list_.empty()) {
+ prepareExit();
+ return EXIT_SUCCESS;
+ }
+
+ BufferList::iterator begin = pimpl_->buffer_list_.begin();
+ BufferList::iterator end = pimpl_->buffer_list_.end();
+
+ bool final_success = false;
+ for (BufferList::iterator I = begin; I != end; ++I) {
+ Buffer * buf = *I;
+ bool success = false;
+ buf->dispatch(batch_command, &success);
+ final_success |= success;
+ }
+ prepareExit();
+ return !final_success;
+ }
+
+ // Force adding of font path _before_ Application is initialized
+ support::os::addFontResources();
+
+ // Let the frontend parse and remove all arguments that it knows
+ pimpl_->application_.reset(createApplication(argc, argv));
+
+ initGuiFont();
+
+ // Parse and remove all known arguments in the LyX singleton
+ // Give an error for all remaining ones.
+ int exit_status = init(argc, argv);
+ if (exit_status) {
+ // Kill the application object before exiting.
+ pimpl_->application_.reset();
+ use_gui = false;
+ prepareExit();
+ return exit_status;
+ }
+
+ // FIXME
+ /* Create a CoreApplication class that will provide the main event loop
+ * and the socket callback registering. With Qt4, only QtCore
+ * library would be needed.
+ * When this is done, a server_mode could be created and the following two
+ * line would be moved out from here.
+ */
+ // Note: socket callback must be registered after init(argc, argv)
+ // such that package().temp_dir() is properly initialized.
+ pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
+ pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_,
+ support::os::internal_path(package().temp_dir() + "/lyxsocket")));