3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
20 #include "LayoutFile.h"
22 #include "BufferList.h"
25 #include "ConverterCache.h"
26 #include "Converter.h"
27 #include "CutAndPaste.h"
29 #include "ErrorList.h"
31 #include "FuncStatus.h"
35 #include "LyXAction.h"
38 #include "ModuleList.h"
41 #include "ServerSocket.h"
44 #include "frontends/alert.h"
45 #include "frontends/Application.h"
47 #include "graphics/Previews.h"
49 #include "support/lassert.h"
50 #include "support/debug.h"
51 #include "support/environment.h"
52 #include "support/ExceptionMessage.h"
53 #include "support/filetools.h"
54 #include "support/gettext.h"
55 #include "support/lstrings.h"
56 #include "support/Messages.h"
57 #include "support/os.h"
58 #include "support/Package.h"
59 #include "support/Path.h"
60 #include "support/Systemcall.h"
62 #include <boost/bind.hpp>
63 #include <boost/scoped_ptr.hpp>
74 using namespace lyx::support;
78 namespace Alert = frontend::Alert;
79 namespace os = support::os;
83 // Are we using the GUI at all? We default to true and this is changed
84 // to false when the export feature is used.
90 // Filled with the command line arguments "foo" of "-sysdir foo" or
92 string cl_system_support;
93 string cl_user_support;
99 void showFileError(string const & error)
101 Alert::warning(_("Could not read configuration file"),
102 bformat(_("Error while reading the configuration file\n%1$s.\n"
103 "Please check your installation."), from_utf8(error)));
107 void reconfigureUserLyXDir()
109 string const configure_command = package().configure_command();
111 lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
112 PathChanger p(package().user_support());
114 one.startscript(Systemcall::Wait, configure_command);
115 lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
121 /// The main application class private implementation.
126 // Set the default User Interface language as soon as possible.
127 // The language used will be derived from the environment
129 messages_["GUI"] = Messages();
131 /// our function handler
134 BufferList buffer_list_;
136 KeyMap toplevel_keymap_;
138 CmdDef toplevel_cmddef_;
140 boost::scoped_ptr<Server> lyx_server_;
142 boost::scoped_ptr<ServerSocket> lyx_socket_;
144 boost::scoped_ptr<frontend::Application> application_;
145 /// lyx session, containing lastfiles, lastfilepos, and lastopened
146 boost::scoped_ptr<Session> session_;
148 /// Files to load at start.
149 vector<string> files_to_load_;
151 /// The messages translators.
152 map<string, Messages> messages_;
154 /// The file converters.
155 Converters converters_;
157 // The system converters copy after reading lyxrc.defaults.
158 Converters system_converters_;
163 Movers system_movers_;
165 /// has this user started lyx for the first time?
167 /// the parsed command line batch command if any
168 vector<string> batch_commands;
171 graphics::Previews preview_;
175 frontend::Application * theApp()
178 return singleton_->pimpl_->application_.get();
191 void lyx_exit(int exit_code)
194 // Something wrong happened so better save everything, just in
199 // Properly crash in debug mode in order to get a useful backtrace.
203 // In release mode, try to exit gracefully.
205 theApp()->exit(exit_code);
219 Messages & LyX::messages(string const & language)
221 map<string, Messages>::iterator it = pimpl_->messages_.find(language);
223 if (it != pimpl_->messages_.end())
226 pair<map<string, Messages>::iterator, bool> result =
227 pimpl_->messages_.insert(make_pair(language, Messages(language)));
229 LASSERT(result.second, /**/);
230 return result.first->second;
234 void setRcGuiLanguage()
236 LASSERT(singleton_, /**/);
237 if (lyxrc.gui_language == "auto")
239 Language const * language = languages.getLanguage(lyxrc.gui_language);
241 LYXERR(Debug::LOCALE, "Setting LANGUAGE to " << language->code());
242 if (!setEnv("LANGUAGE", language->code()))
243 LYXERR(Debug::LOCALE, "\t... failed!");
245 LYXERR(Debug::LOCALE, "Setting LC_ALL to en_US");
246 if (!setEnv("LC_ALL", "en_US"))
247 LYXERR(Debug::LOCALE, "\t... failed!");
248 singleton_->pimpl_->messages_["GUI"] = Messages();
252 int LyX::exec(int & argc, char * argv[])
254 // Here we need to parse the command line. At least
255 // we need to parse for "-dbg" and "-help"
256 easyParse(argc, argv);
259 init_package(to_utf8(from_local8bit(argv[0])),
260 cl_system_support, cl_user_support,
261 top_build_dir_is_one_level_up);
262 } catch (ExceptionMessage const & message) {
263 if (message.type_ == ErrorException) {
264 Alert::error(message.title_, message.details_);
266 } else if (message.type_ == WarningException) {
267 Alert::warning(message.title_, message.details_);
271 // Reinit the messages machinery in case package() knows
272 // something interesting about the locale directory.
276 // FIXME: create a ConsoleApplication
277 int exit_status = init(argc, argv);
283 // this is correct, since return values are inverted.
284 exit_status = !loadFiles();
286 if (pimpl_->batch_commands.empty() || pimpl_->buffer_list_.empty()) {
291 BufferList::iterator begin = pimpl_->buffer_list_.begin();
293 bool final_success = false;
294 for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) {
296 if (buf != buf->masterBuffer())
298 bool success = false;
299 vector<string>::const_iterator bcit = pimpl_->batch_commands.begin();
300 vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
301 for (; bcit != bcend; bcit++) {
302 buf->dispatch(*bcit, &success);
303 final_success |= success;
307 return !final_success;
310 // Let the frontend parse and remove all arguments that it knows
311 pimpl_->application_.reset(createApplication(argc, argv));
313 // Reestablish our defaults, as Qt overwrites them
314 // after createApplication()
317 // Parse and remove all known arguments in the LyX singleton
318 // Give an error for all remaining ones.
319 int exit_status = init(argc, argv);
321 // Kill the application object before exiting.
322 pimpl_->application_.reset();
329 /* Create a CoreApplication class that will provide the main event loop
330 * and the socket callback registering. With Qt4, only QtCore
331 * library would be needed.
332 * When this is done, a server_mode could be created and the following two
333 * line would be moved out from here.
335 // Note: socket callback must be registered after init(argc, argv)
336 // such that package().temp_dir() is properly initialized.
337 pimpl_->lyx_server_.reset(new Server(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
338 pimpl_->lyx_socket_.reset(new ServerSocket(&pimpl_->lyxfunc_,
339 FileName(package().temp_dir().absFilename() + "/lyxsocket")));
341 // Start the real execution loop.
342 exit_status = pimpl_->application_->exec();
350 void LyX::prepareExit()
352 // Clear the clipboard and selection stack:
353 cap::clearCutStack();
354 cap::clearSelection();
356 // close buffers first
357 pimpl_->buffer_list_.closeAll();
359 // register session changes and shutdown server and socket
361 if (pimpl_->session_)
362 pimpl_->session_->writeFile();
363 pimpl_->session_.reset();
364 pimpl_->lyx_server_.reset();
365 pimpl_->lyx_socket_.reset();
368 // do any other cleanup procedures now
369 if (package().temp_dir() != package().system_temp_dir()) {
370 string const abs_tmpdir = package().temp_dir().absFilename();
371 if (!contains(package().temp_dir().absFilename(), "lyx_tmpdir")) {
372 docstring const msg =
373 bformat(_("%1$s does not appear like a LyX created temporary directory."),
374 from_utf8(abs_tmpdir));
375 Alert::warning(_("Cannot remove temporary directory"), msg);
377 LYXERR(Debug::INFO, "Deleting tmp dir "
378 << package().temp_dir().absFilename());
379 if (!package().temp_dir().destroyDirectory()) {
380 docstring const msg =
381 bformat(_("Unable to remove the temporary directory %1$s"),
382 from_utf8(package().temp_dir().absFilename()));
383 Alert::warning(_("Unable to remove temporary directory"), msg);
388 // Kill the application object before exiting. This avoids crashes
389 // when exiting on Linux.
390 if (pimpl_->application_)
391 pimpl_->application_.reset();
395 void LyX::earlyExit(int status)
397 LASSERT(pimpl_->application_.get(), /**/);
398 // LyX::pimpl_::application_ is not initialised at this
399 // point so it's safe to just exit after some cleanup.
405 int LyX::init(int & argc, char * argv[])
407 // check for any spurious extra arguments
408 // other than documents
409 for (int argi = 1; argi < argc ; ++argi) {
410 if (argv[argi][0] == '-') {
412 bformat(_("Wrong command line option `%1$s'. Exiting."),
413 from_utf8(argv[argi]))) << endl;
418 // Initialization of LyX (reads lyxrc and more)
419 LYXERR(Debug::INIT, "Initializing LyX::init...");
420 bool success = init();
421 LYXERR(Debug::INIT, "Initializing LyX::init...done");
425 // Remaining arguments are assumed to be files to load.
426 for (int argi = argc - 1; argi >= 1; --argi)
427 pimpl_->files_to_load_.push_back(to_utf8(from_local8bit(argv[argi])));
430 pimpl_->files_to_load_.push_back(
431 i18nLibFileSearch("examples", "splash.lyx").absFilename());
438 bool LyX::loadFiles()
440 LASSERT(!use_gui, /**/);
442 vector<string>::const_iterator it = pimpl_->files_to_load_.begin();
443 vector<string>::const_iterator end = pimpl_->files_to_load_.end();
445 for (; it != end; ++it) {
446 // get absolute path of file and add ".lyx" to
447 // the filename if necessary
448 FileName fname = fileSearch(string(), os::internal_path(*it), "lyx",
454 Buffer * buf = pimpl_->buffer_list_.newBuffer(fname.absFilename(), false);
455 if (buf->loadLyXFile(fname)) {
456 ErrorList const & el = buf->errorList("Parse");
458 for_each(el.begin(), el.end(),
459 boost::bind(&LyX::printError, this, _1));
462 pimpl_->buffer_list_.release(buf);
470 void execBatchCommands()
472 LASSERT(singleton_, /**/);
473 singleton_->execCommands();
477 void LyX::execCommands()
479 // The advantage of doing this here is that the event loop
480 // is already started. So any need for interaction will be
483 // if reconfiguration is needed.
484 while (LayoutFileList::get().empty()) {
485 switch (Alert::prompt(
486 _("No textclass is found"),
487 _("LyX cannot continue because no textclass is found. "
488 "You can either reconfigure normally, or reconfigure using "
489 "default textclasses, or quit LyX."),
496 // regular reconfigure
497 pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE, ""));
500 // reconfigure --without-latex-config
501 pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE,
502 " --without-latex-config"));
505 pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_LYX_QUIT));
510 // create the first main window
511 pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_WINDOW_NEW, geometryArg));
513 if (!pimpl_->files_to_load_.empty()) {
514 // if some files were specified at command-line we assume that the
515 // user wants to edit *these* files and not to restore the session.
516 for (size_t i = 0; i != pimpl_->files_to_load_.size(); ++i) {
517 pimpl_->lyxfunc_.dispatch(
518 FuncRequest(LFUN_FILE_OPEN, pimpl_->files_to_load_[i]));
520 // clear this list to save a few bytes of RAM
521 pimpl_->files_to_load_.clear();
524 pimpl_->application_->restoreGuiSession();
526 // Execute batch commands if available
527 if (pimpl_->batch_commands.empty())
530 vector<string>::const_iterator bcit = pimpl_->batch_commands.begin();
531 vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
532 for (; bcit != bcend; bcit++) {
533 LYXERR(Debug::INIT, "About to handle -x '" << *bcit << '\'');
534 pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(*bcit));
542 The SIGHUP signal does not exist on Windows and does not need to be handled.
544 Windows handles SIGFPE and SIGSEGV signals as expected.
546 Cntl+C interrupts (mapped to SIGINT by Windows' POSIX compatability layer)
547 cause a new thread to be spawned. This may well result in unexpected
548 behaviour by the single-threaded LyX.
550 SIGTERM signals will come only from another process actually sending
551 that signal using 'raise' in Windows' POSIX compatability layer. It will
552 not come from the general "terminate process" methods that everyone
553 actually uses (and which can't be trapped). Killing an app 'politely' on
554 Windows involves first sending a WM_CLOSE message, something that is
555 caught already by the Qt frontend.
557 For more information see:
559 http://aspn.activestate.com/ASPN/Mail/Message/ActiveTcl/2034055
560 ...signals are mostly useless on Windows for a variety of reasons that are
563 'UNIX Application Migration Guide, Chapter 9'
564 http://msdn.microsoft.com/library/en-us/dnucmg/html/UCMGch09.asp
566 'How To Terminate an Application "Cleanly" in Win32'
567 http://support.microsoft.com/default.aspx?scid=kb;en-us;178893
571 static void error_handler(int err_sig)
573 // Throw away any signals other than the first one received.
574 static sig_atomic_t handling_error = false;
577 handling_error = true;
579 // We have received a signal indicating a fatal error, so
580 // try and save the data ASAP.
583 // These lyxerr calls may or may not work:
585 // Signals are asynchronous, so the main program may be in a very
586 // fragile state when a signal is processed and thus while a signal
587 // handler function executes.
588 // In general, therefore, we should avoid performing any
589 // I/O operations or calling most library and system functions from
592 // This shouldn't matter here, however, as we've already invoked
597 lyxerr << "\nlyx: SIGHUP signal caught\nBye." << endl;
601 lyxerr << "\nlyx: SIGFPE signal caught\nBye." << endl;
604 lyxerr << "\nlyx: SIGSEGV signal caught\n"
605 "Sorry, you have found a bug in LyX. "
606 "Please read the bug-reporting instructions "
607 "in Help->Introduction and send us a bug report, "
608 "if necessary. Thanks !\nBye." << endl;
616 // Deinstall the signal handlers
618 signal(SIGHUP, SIG_DFL);
620 signal(SIGINT, SIG_DFL);
621 signal(SIGFPE, SIG_DFL);
622 signal(SIGSEGV, SIG_DFL);
623 signal(SIGTERM, SIG_DFL);
626 if (err_sig == SIGSEGV ||
627 (err_sig != SIGHUP && !getEnv("LYXDEBUG").empty()))
629 if (err_sig == SIGSEGV || !getEnv("LYXDEBUG").empty())
638 void LyX::printError(ErrorItem const & ei)
640 docstring tmp = _("LyX: ") + ei.error + char_type(':')
642 cerr << to_utf8(tmp) << endl;
649 signal(SIGHUP, error_handler);
651 signal(SIGFPE, error_handler);
652 signal(SIGSEGV, error_handler);
653 signal(SIGINT, error_handler);
654 signal(SIGTERM, error_handler);
655 // SIGPIPE can be safely ignored.
657 lyxrc.tempdir_path = package().temp_dir().absFilename();
658 lyxrc.document_path = package().document_dir().absFilename();
660 if (lyxrc.example_path.empty()) {
661 lyxrc.example_path = addPath(package().system_support().absFilename(),
664 if (lyxrc.template_path.empty()) {
665 lyxrc.template_path = addPath(package().system_support().absFilename(),
670 // Read configuration files
673 // This one may have been distributed along with LyX.
674 if (!readRcFile("lyxrc.dist"))
677 // Set the language defined by the distributor.
680 // Set the PATH correctly.
681 #if !defined (USE_POSIX_PACKAGING)
682 // Add the directory containing the LyX executable to the path
683 // so that LyX can find things like tex2lyx.
684 if (package().build_support().empty())
685 prependEnvPath("PATH", package().binary_dir().absFilename());
687 if (!lyxrc.path_prefix.empty())
688 prependEnvPath("PATH", lyxrc.path_prefix);
690 // Check that user LyX directory is ok.
691 if (queryUserLyXDir(package().explicit_user_support()))
692 reconfigureUserLyXDir();
694 // no need for a splash when there is no GUI
699 // This one is generated in user_support directory by lib/configure.py.
700 if (!readRcFile("lyxrc.defaults"))
703 // Query the OS to know what formats are viewed natively
704 formats.setAutoOpen();
706 // Read lyxrc.dist again to be able to override viewer auto-detection.
707 readRcFile("lyxrc.dist");
709 // Set again the language defined by the distributor.
712 system_lyxrc = lyxrc;
713 system_formats = formats;
714 pimpl_->system_converters_ = pimpl_->converters_;
715 pimpl_->system_movers_ = pimpl_->movers_;
716 system_lcolor = lcolor;
718 // This one is edited through the preferences dialog.
719 if (!readRcFile("preferences"))
722 if (!readEncodingsFile("encodings", "unicodesymbols"))
724 if (!readLanguagesFile("languages"))
727 // Set the language defined by the user.
731 LYXERR(Debug::INIT, "Reading layouts...");
737 // read keymap and ui files in batch mode as well
738 // because InsetInfo needs to know these to produce
739 // the correct output
741 // Set up command definitions
742 pimpl_->toplevel_cmddef_.read(lyxrc.def_file);
745 pimpl_->toplevel_keymap_.read("site");
746 pimpl_->toplevel_keymap_.read(lyxrc.bind_file);
747 // load user bind file user.bind
748 pimpl_->toplevel_keymap_.read("user");
750 pimpl_->lyxfunc_.initKeySequences(&pimpl_->toplevel_keymap_);
752 if (lyxerr.debugging(Debug::LYXRC))
755 os::windows_style_tex_paths(lyxrc.windows_style_tex_paths);
756 if (!lyxrc.path_prefix.empty())
757 prependEnvPath("PATH", lyxrc.path_prefix);
759 FileName const document_path(lyxrc.document_path);
760 if (document_path.exists() && document_path.isDirectory())
761 package().document_dir() = document_path;
763 package().set_temp_dir(createLyXTmpDir(FileName(lyxrc.tempdir_path)));
764 if (package().temp_dir().empty()) {
765 Alert::error(_("Could not create temporary directory"),
766 bformat(_("Could not create a temporary directory in\n"
768 "Make sure that this path exists and is writable and try again."),
769 from_utf8(lyxrc.tempdir_path)));
770 // createLyXTmpDir() tries sufficiently hard to create a
771 // usable temp dir, so the probability to come here is
772 // close to zero. We therefore don't try to overcome this
773 // problem with e.g. asking the user for a new path and
774 // trying again but simply exit.
778 LYXERR(Debug::INIT, "LyX tmp dir: `"
779 << package().temp_dir().absFilename() << '\'');
781 LYXERR(Debug::INIT, "Reading session information '.lyx/session'...");
782 pimpl_->session_.reset(new Session(lyxrc.num_lastfiles));
784 // This must happen after package initialization and after lyxrc is
785 // read, therefore it can't be done by a static object.
786 ConverterCache::init();
792 void emergencyCleanup()
794 // what to do about tmpfiles is non-obvious. we would
795 // like to delete any we find, but our lyxdir might
796 // contain documents etc. which might be helpful on
799 singleton_->pimpl_->buffer_list_.emergencyWriteAll();
801 if (singleton_->pimpl_->lyx_server_)
802 singleton_->pimpl_->lyx_server_->emergencyCleanup();
803 singleton_->pimpl_->lyx_server_.reset();
804 singleton_->pimpl_->lyx_socket_.reset();
809 // return true if file does not exist or is older than configure.py.
810 static bool needsUpdate(string const & file)
812 // We cannot initialize configure_script directly because the package
813 // is not initialized yet when static objects are constructed.
814 static FileName configure_script;
815 static bool firstrun = true;
818 FileName(addName(package().system_support().absFilename(),
824 FileName(addName(package().user_support().absFilename(), file));
825 return !absfile.exists()
826 || configure_script.lastModified() > absfile.lastModified();
830 bool LyX::queryUserLyXDir(bool explicit_userdir)
832 // Does user directory exist?
833 FileName const sup = package().user_support();
834 if (sup.exists() && sup.isDirectory()) {
837 return needsUpdate("lyxrc.defaults")
838 || needsUpdate("lyxmodules.lst")
839 || needsUpdate("textclass.lst")
840 || needsUpdate("packages.lst");
843 first_start = !explicit_userdir;
845 // If the user specified explicitly a directory, ask whether
846 // to create it. If the user says "no", then exit.
847 if (explicit_userdir &&
849 _("Missing user LyX directory"),
850 bformat(_("You have specified a non-existent user "
851 "LyX directory, %1$s.\n"
852 "It is needed to keep your own configuration."),
853 from_utf8(package().user_support().absFilename())),
855 _("&Create directory"),
857 lyxerr << to_utf8(_("No user LyX directory. Exiting.")) << endl;
858 earlyExit(EXIT_FAILURE);
861 lyxerr << to_utf8(bformat(_("LyX: Creating directory %1$s"),
862 from_utf8(sup.absFilename()))) << endl;
864 if (!sup.createDirectory(0755)) {
865 // Failed, so let's exit.
866 lyxerr << to_utf8(_("Failed to create directory. Exiting."))
868 earlyExit(EXIT_FAILURE);
875 bool LyX::readRcFile(string const & name)
877 LYXERR(Debug::INIT, "About to read " << name << "... ");
879 FileName const lyxrc_path = libFileSearch(string(), name);
880 if (!lyxrc_path.empty()) {
881 LYXERR(Debug::INIT, "Found in " << lyxrc_path);
882 if (lyxrc.read(lyxrc_path) < 0) {
887 LYXERR(Debug::INIT, "Not found." << lyxrc_path);
892 // Read the languages file `name'
893 bool LyX::readLanguagesFile(string const & name)
895 LYXERR(Debug::INIT, "About to read " << name << "...");
897 FileName const lang_path = libFileSearch(string(), name);
898 if (lang_path.empty()) {
902 languages.read(lang_path);
907 // Read the encodings file `name'
908 bool LyX::readEncodingsFile(string const & enc_name,
909 string const & symbols_name)
911 LYXERR(Debug::INIT, "About to read " << enc_name << " and "
912 << symbols_name << "...");
914 FileName const symbols_path = libFileSearch(string(), symbols_name);
915 if (symbols_path.empty()) {
916 showFileError(symbols_name);
920 FileName const enc_path = libFileSearch(string(), enc_name);
921 if (enc_path.empty()) {
922 showFileError(enc_name);
925 encodings.read(enc_path, symbols_path);
932 /// return the the number of arguments consumed
933 typedef boost::function<int(string const &, string const &, string &)> cmd_helper;
935 int parse_dbg(string const & arg, string const &, string &)
938 lyxerr << to_utf8(_("List of supported debug flags:")) << endl;
939 Debug::showTags(lyxerr);
942 lyxerr << to_utf8(bformat(_("Setting debug level to %1$s"), from_utf8(arg))) << endl;
944 lyxerr.level(Debug::value(arg));
945 Debug::showLevel(lyxerr, lyxerr.level());
950 int parse_help(string const &, string const &, string &)
953 to_utf8(_("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
954 "Command line switches (case sensitive):\n"
955 "\t-help summarize LyX usage\n"
956 "\t-userdir dir set user directory to dir\n"
957 "\t-sysdir dir set system directory to dir\n"
958 "\t-geometry WxH+X+Y set geometry of the main window\n"
959 "\t-dbg feature[,feature]...\n"
960 " select the features to debug.\n"
961 " Type `lyx -dbg' to see the list of features\n"
962 "\t-x [--execute] command\n"
963 " where command is a lyx command.\n"
964 "\t-e [--export] fmt\n"
965 " where fmt is the export format of choice.\n"
966 " Look on Tools->Preferences->File formats->Format\n"
967 " to get an idea which parameters should be passed.\n"
968 "\t-i [--import] fmt file.xxx\n"
969 " where fmt is the import format of choice\n"
970 " and file.xxx is the file to be imported.\n"
971 "\t-version summarize version and build info\n"
972 "Check the LyX man page for more details.")) << endl;
978 int parse_version(string const &, string const &, string &)
980 lyxerr << "LyX " << lyx_version
981 << " (" << lyx_release_date << ")" << endl;
982 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
984 lyxerr << lyx_version_info << endl;
990 int parse_sysdir(string const & arg, string const &, string &)
993 Alert::error(_("No system directory"),
994 _("Missing directory for -sysdir switch"));
997 cl_system_support = arg;
1002 int parse_userdir(string const & arg, string const &, string &)
1005 Alert::error(_("No user directory"),
1006 _("Missing directory for -userdir switch"));
1009 cl_user_support = arg;
1014 int parse_execute(string const & arg, string const &, string & batch)
1017 Alert::error(_("Incomplete command"),
1018 _("Missing command string after --execute switch"));
1026 int parse_export(string const & type, string const &, string & batch)
1029 lyxerr << to_utf8(_("Missing file type [eg latex, ps...] after "
1030 "--export switch")) << endl;
1033 batch = "buffer-export " + type;
1039 int parse_import(string const & type, string const & file, string & batch)
1042 lyxerr << to_utf8(_("Missing file type [eg latex, ps...] after "
1043 "--import switch")) << endl;
1047 lyxerr << to_utf8(_("Missing filename for --import")) << endl;
1051 batch = "buffer-import " + type + ' ' + file;
1056 int parse_geometry(string const & arg1, string const &, string &)
1059 #if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING))
1060 // remove also the arg
1063 // don't remove "-geometry"
1072 void LyX::easyParse(int & argc, char * argv[])
1074 map<string, cmd_helper> cmdmap;
1076 cmdmap["-dbg"] = parse_dbg;
1077 cmdmap["-help"] = parse_help;
1078 cmdmap["--help"] = parse_help;
1079 cmdmap["-version"] = parse_version;
1080 cmdmap["--version"] = parse_version;
1081 cmdmap["-sysdir"] = parse_sysdir;
1082 cmdmap["-userdir"] = parse_userdir;
1083 cmdmap["-x"] = parse_execute;
1084 cmdmap["--execute"] = parse_execute;
1085 cmdmap["-e"] = parse_export;
1086 cmdmap["--export"] = parse_export;
1087 cmdmap["-i"] = parse_import;
1088 cmdmap["--import"] = parse_import;
1089 cmdmap["-geometry"] = parse_geometry;
1091 for (int i = 1; i < argc; ++i) {
1092 map<string, cmd_helper>::const_iterator it
1093 = cmdmap.find(argv[i]);
1095 // don't complain if not found - may be parsed later
1096 if (it == cmdmap.end())
1100 (i + 1 < argc) ? to_utf8(from_local8bit(argv[i + 1])) : string();
1102 (i + 2 < argc) ? to_utf8(from_local8bit(argv[i + 2])) : string();
1105 int const remove = 1 + it->second(arg, arg2, batch);
1107 pimpl_->batch_commands.push_back(batch);
1109 // Now, remove used arguments by shifting
1110 // the following ones remove places down.
1113 for (int j = i; j < argc; ++j)
1114 argv[j] = argv[j + remove];
1121 FuncStatus getStatus(FuncRequest const & action)
1123 LASSERT(singleton_, /**/);
1124 return singleton_->pimpl_->lyxfunc_.getStatus(action);
1128 void dispatch(FuncRequest const & action)
1130 LASSERT(singleton_, /**/);
1131 singleton_->pimpl_->lyxfunc_.dispatch(action);
1135 BufferList & theBufferList()
1137 LASSERT(singleton_, /**/);
1138 return singleton_->pimpl_->buffer_list_;
1142 LyXFunc & theLyXFunc()
1144 LASSERT(singleton_, /**/);
1145 return singleton_->pimpl_->lyxfunc_;
1149 Server & theServer()
1151 // FIXME: this should not be use_gui dependent
1152 LASSERT(use_gui, /**/);
1153 LASSERT(singleton_, /**/);
1154 return *singleton_->pimpl_->lyx_server_.get();
1158 ServerSocket & theServerSocket()
1160 // FIXME: this should not be use_gui dependent
1161 LASSERT(use_gui, /**/);
1162 LASSERT(singleton_, /**/);
1163 return *singleton_->pimpl_->lyx_socket_.get();
1167 KeyMap & theTopLevelKeymap()
1169 LASSERT(singleton_, /**/);
1170 return singleton_->pimpl_->toplevel_keymap_;
1174 Converters & theConverters()
1176 LASSERT(singleton_, /**/);
1177 return singleton_->pimpl_->converters_;
1181 Converters & theSystemConverters()
1183 LASSERT(singleton_, /**/);
1184 return singleton_->pimpl_->system_converters_;
1188 Movers & theMovers()
1190 LASSERT(singleton_, /**/);
1191 return singleton_->pimpl_->movers_;
1195 Mover const & getMover(string const & fmt)
1197 LASSERT(singleton_, /**/);
1198 return singleton_->pimpl_->movers_(fmt);
1202 void setMover(string const & fmt, string const & command)
1204 LASSERT(singleton_, /**/);
1205 singleton_->pimpl_->movers_.set(fmt, command);
1209 Movers & theSystemMovers()
1211 LASSERT(singleton_, /**/);
1212 return singleton_->pimpl_->system_movers_;
1216 Messages & getMessages(string const & language)
1218 LASSERT(singleton_, /**/);
1219 return singleton_->messages(language);
1223 Messages & getGuiMessages()
1225 LASSERT(singleton_, /**/);
1226 return singleton_->pimpl_->messages_["GUI"];
1230 graphics::Previews & thePreviews()
1232 LASSERT(singleton_, /**/);
1233 return singleton_->pimpl_->preview_;
1237 Session & theSession()
1239 LASSERT(singleton_, /**/);
1240 return *singleton_->pimpl_->session_.get();
1244 CmdDef & theTopLevelCmdDef()
1246 LASSERT(singleton_, /**/);
1247 return singleton_->pimpl_->toplevel_cmddef_;