1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
20 #include "frontends/LyXView.h"
24 #include "bufferlist.h"
26 #include "lastfiles.h"
28 #include "lyxserver.h"
30 #include "lyxtextclasslist.h"
33 #include "MenuBackend.h"
34 #include "ToolbarDefaults.h"
37 #include "converter.h"
40 #include "frontends/Alert.h"
41 #include "frontends/GUIRunTime.h"
43 #include "support/path.h"
44 #include "support/filetools.h"
45 #include "support/FileInfo.h"
46 #include "support/os.h"
53 #ifndef CXX_GLOBAL_CSTD
57 extern void LoadLyXFile(string const &);
58 extern void QuitLyX();
62 string system_tempdir;
63 string user_lyxdir; // Default $HOME/.lyx
65 // Should this be kept global? Asger says Yes.
68 boost::scoped_ptr<LastFiles> lastfiles;
70 // This is the global bufferlist object
71 BufferList bufferlist;
73 LyXServer * lyxserver = 0;
74 // this should be static, but I need it in buffer.C
75 bool finished = false; // flag, that we are quitting the program
77 // convenient to have it here.
78 boost::scoped_ptr<kb_keymap> toplevel_keymap;
81 LyX::LyX(int * argc, char * argv[])
83 // Here we need to parse the command line. At least
84 // we need to parse for "-dbg" and "-help"
85 bool gui = easyParse(argc, argv);
87 // Global bindings (this must be done as early as possible.) (Lgb)
88 toplevel_keymap.reset(new kb_keymap);
89 defaultKeyBindings(toplevel_keymap.get());
91 // Make the GUI object, and let it take care of the
92 // command line arguments that concerns it.
93 lyxerr[Debug::INIT] << "Initializing LyXGUI..." << endl;
94 lyxGUI.reset(new LyXGUI(this, argc, argv, gui));
95 lyxerr[Debug::INIT] << "Initializing LyXGUI...done" << endl;
97 // Now the GUI and LyX have taken care of their arguments, so
98 // the only thing left on the command line should be
99 // filenames. Let's check anyway.
100 for (int argi = 1; argi < *argc ; ++argi) {
101 if (argv[argi][0] == '-') {
102 lyxerr << _("Wrong command line option `")
104 << _("'. Exiting.") << endl;
109 // Initialization of LyX (reads lyxrc and more)
110 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
112 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
116 // Load the files specified in the command line.
118 lyxerr[Debug::INFO] << "Opening document..." << endl;
119 else if ((*argc) > 2)
120 lyxerr[Debug::INFO] << "Opening documents..." << endl;
122 Buffer * last_loaded = 0;
124 for (int argi = (*argc) - 1; argi >= 1; --argi) {
125 Buffer * loadb = bufferlist.loadLyXFile(argv[argi]);
132 string const splash =
133 i18nLibFileSearch("examples", "splash.lyx");
134 lyxerr[Debug::INIT] << "Opening splash document "
135 << splash << "..." << endl;
136 Buffer * loadb = bufferlist.loadLyXFile(splash);
142 if (last_loaded != 0) {
143 lyxerr[Debug::INIT] << "Yes we loaded some files." << endl;
145 lyxGUI->regBuf(last_loaded);
148 // Execute batch commands if available
149 if (!batch_command.empty()) {
150 lyxerr << "About to handle -x '"
151 << batch_command << "'" << endl;
153 // no buffer loaded, create one
155 last_loaded = bufferlist.newFile("tmpfile", string());
157 bool success = false;
159 // try to dispatch to last loaded buffer first
160 bool dispatched = last_loaded->dispatch(batch_command, &success);
162 // if this was successful, return.
163 // Maybe we could do something more clever than aborting...
169 // otherwise, let the GUI handle the batch command
170 lyxGUI->regBuf(last_loaded);
171 lyxGUI->getLyXView()->getLyXFunc()->verboseDispatch(batch_command, false);
176 // Let the ball begin...
181 // A destructor is always necessary (asierra-970604)
190 void error_handler(int err_sig)
194 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
200 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
203 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
205 "Sorry, you have found a bug in LyX. "
206 "Please read the bug-reporting instructions "
207 "in Help->Introduction and send us a bug report, "
208 "if necessary. Thanks !" << endl;
215 // Deinstall the signal handlers
216 signal(SIGHUP, SIG_DFL);
217 signal(SIGINT, SIG_DFL);
218 signal(SIGFPE, SIG_DFL);
219 signal(SIGSEGV, SIG_DFL);
220 signal(SIGTERM, SIG_DFL);
222 LyX::emergencyCleanup();
224 lyxerr << "Bye." << endl;
225 if (err_sig!= SIGHUP &&
226 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
234 void LyX::init(bool gui)
236 // Install the signal handlers
237 signal(SIGHUP, error_handler);
238 signal(SIGFPE, error_handler);
239 signal(SIGSEGV, error_handler);
240 signal(SIGINT, error_handler);
241 signal(SIGTERM, error_handler);
244 // Determine path of binary
247 string binpath = os::binpath();
248 string binname = os::binname();
249 string fullbinname = MakeAbsPath(binname, binpath);
251 if (binpath.empty()) {
252 lyxerr << _("Warning: could not determine path of binary.")
254 << _("If you have problems, try starting LyX with an absolute path.")
257 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
258 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
261 // Determine system directory.
264 // Directories are searched in this order:
265 // 1) -sysdir command line parameter
266 // 2) LYX_DIR_12x environment variable
267 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
268 // 4) <path of binary>/../share/<name of binary>/
269 // 4a) repeat 4 after following the Symlink if <path of
270 // binary> is a symbolic link.
271 // 5) hardcoded lyx_dir
272 // The directory is checked for the presence of the file
273 // "chkconfig.ltx", and if that is present, the directory
274 // is accepted as the system directory.
275 // If no chkconfig.ltx file is found, a warning is given,
276 // and the hardcoded lyx_dir is used.
278 // If we had a command line switch, system_lyxdir is already set
280 if (!system_lyxdir.empty())
281 searchpath= MakeAbsPath(system_lyxdir) + ';';
283 // LYX_DIR_12x environment variable
284 string const lyxdir = GetEnvPath("LYX_DIR_12x");
286 if (!lyxdir.empty()) {
287 lyxerr[Debug::INIT] << "LYX_DIR_12x: " << lyxdir << endl;
288 searchpath += lyxdir + ';';
291 string fullbinpath = binpath;
292 FileInfo file(fullbinname, true);
294 lyxerr[Debug::INIT] << "binary is a link" << endl;
296 if (LyXReadLink(fullbinname, link)) {
297 // Path of binary/../share/name of binary/
298 searchpath += NormalizePath(AddPath(binpath,
300 + OnlyFilename(binname));
303 binpath = MakeAbsPath(OnlyPath(fullbinpath));
309 // Path of binary/../share/name of binary/
310 searchpath += NormalizePath(AddPath(binpath, "../share/") +
311 OnlyFilename(binname)) + ';';
314 FileInfo file(fullbinpath, true);
315 followlink = file.isLink();
317 lyxerr << " directory " << fullbinpath
318 << " is a link" << endl;
320 if (LyXReadLink(fullbinpath, link)) {
322 binpath = MakeAbsPath(OnlyPath(fullbinpath));
328 } while (followlink);
330 // <path of binary>/TOP_SRCDIR/lib
331 build_lyxdir = MakeAbsPath("../lib", binpath);
332 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
333 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
335 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
336 "place... yes" << endl;
339 << "Checking whether LyX is run in place... no"
341 build_lyxdir.erase();
345 searchpath += LYX_DIR;
347 // If debugging, show complete search path
348 lyxerr[Debug::INIT] << "System directory search path: "
349 << searchpath << endl;
351 string const filename = "chkconfig.ltx";
352 string const temp = FileOpenSearch(searchpath, filename, string());
353 system_lyxdir = OnlyPath(temp);
355 // Reduce "path/../path" stuff out of system directory
356 system_lyxdir = NormalizePath(system_lyxdir);
358 bool path_shown = false;
360 // Warn if environment variable is set, but unusable
361 if (!lyxdir.empty()) {
362 if (system_lyxdir != NormalizePath(lyxdir)) {
363 lyxerr <<_("LYX_DIR_12x environment variable no good.")
365 << _("System directory set to: ")
366 << system_lyxdir << endl;
371 // Warn the user if we couldn't find "chkconfig.ltx"
372 if (system_lyxdir == "./") {
373 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
374 <<_("Try the '-sysdir' command line parameter or ")
375 <<_("set the environment variable LYX_DIR_12x to the "
376 "LyX system directory ")
377 << _("containing the file `chkconfig.ltx'.") << endl;
379 FileInfo fi(LYX_DIR);
381 lyxerr << "Couldn't even find the default LYX_DIR." << endl
382 << "Giving up." << endl;
385 lyxerr << _("Using built-in default ")
386 << LYX_DIR << _(" but expect problems.")
389 lyxerr << _("Expect problems.") << endl;
391 system_lyxdir = LYX_DIR;
394 // Report the system directory if debugging is on
396 lyxerr[Debug::INIT] << "System directory: '"
397 << system_lyxdir << '\'' << endl;
400 // Determine user lyx-dir
403 // Directories are searched in this order:
404 // 1) -userdir command line parameter
405 // 2) LYX_USERDIR_12x environment variable
406 // 3) $HOME/.<name of binary>
408 // If we had a command line switch, user_lyxdir is already set
409 bool explicit_userdir = true;
410 if (user_lyxdir.empty()) {
412 // LYX_USERDIR_12x environment variable
413 user_lyxdir = GetEnvPath("LYX_USERDIR_12x");
416 if (user_lyxdir.empty())
417 user_lyxdir = AddPath(GetEnvPath("HOME"),
418 string(".") + PACKAGE);
419 explicit_userdir = false;
422 lyxerr[Debug::INIT] << "User LyX directory: '"
423 << user_lyxdir << '\'' << endl;
425 // Check that user LyX directory is ok. We don't do that if
426 // running in batch mode.
428 queryUserLyXDir(explicit_userdir);
434 // Shine up lyxrc defaults
437 // Default template path: system_dir/templates
438 if (lyxrc.template_path.empty()) {
439 lyxrc.template_path = AddPath(system_lyxdir, "templates");
442 // Default lastfiles file: $HOME/.lyx/lastfiles
443 if (lyxrc.lastfiles.empty()) {
444 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
447 // Disable gui when either lyxrc or easyparse says so
449 lyxrc.use_gui = false;
451 // Calculate screen dpi as average of x-DPI and y-DPI:
453 lyxrc.dpi = GUIRunTime::getScreenDPI();
454 lyxerr[Debug::INIT] << "DPI setting detected to be "
455 << lyxrc.dpi + 0.5 << endl;
457 lyxrc.dpi = 1; // I hope this is safe
461 // Read configuration files
464 readRcFile("lyxrc.defaults");
465 system_lyxrc = lyxrc;
466 system_formats = formats;
467 system_converters = converters;
468 system_lcolor = lcolor;
470 // If there is a preferences file we read that instead
471 // of the old lyxrc file.
472 if (!readRcFile("preferences"))
476 readEncodingsFile("encodings");
478 readLanguagesFile("languages");
481 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
484 // Ensure that we have really read a bind file, so that LyX is
486 lyxrc.readBindFileIfNeeded();
489 readUIFile(lyxrc.ui_file);
491 // Bind the X dead keys to the corresponding LyX functions if
493 if (lyxrc.override_x_deadkeys)
494 deadKeyBindings(toplevel_keymap.get());
496 if (lyxerr.debugging(Debug::LYXRC)) {
500 // Create temp directory
501 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
502 system_tempdir = os::getTmpDir();
503 if (lyxerr.debugging(Debug::INIT)) {
504 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
507 // load the lastfiles mini-database
508 lyxerr[Debug::INIT] << "Reading lastfiles `"
509 << lyxrc.lastfiles << "'..." << endl;
510 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
511 lyxrc.check_lastfiles,
512 lyxrc.num_lastfiles));
514 // start up the lyxserver. (is this a bit early?) (Lgb)
515 // 0.12 this will be way to early, we need the GUI to be initialized
516 // first, so move it for now.
517 // lyxserver = new LyXServer;
521 // These are the default bindings known to LyX
522 void LyX::defaultKeyBindings(kb_keymap * kbmap)
524 kbmap->bind("Right", LFUN_RIGHT);
525 kbmap->bind("Left", LFUN_LEFT);
526 kbmap->bind("Up", LFUN_UP);
527 kbmap->bind("Down", LFUN_DOWN);
529 kbmap->bind("Tab", LFUN_TAB);
530 kbmap->bind("ISO_Left_Tab", LFUN_TAB); // jbl 2001-23-02
532 kbmap->bind("Home", LFUN_HOME);
533 kbmap->bind("End", LFUN_END);
534 kbmap->bind("Prior", LFUN_PRIOR);
535 kbmap->bind("Next", LFUN_NEXT);
537 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
538 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
540 kbmap->bind("Delete", LFUN_DELETE);
541 kbmap->bind("BackSpace", LFUN_BACKSPACE);
543 // sub- and superscript -MV
544 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
545 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
547 // kbmap->bindings to enable the use of the numeric keypad
549 //kbmap->bind("KP_0", LFUN_SELFINSERT);
550 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
551 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
552 //kbmap->bind("KP_1", LFUN_SELFINSERT);
553 //kbmap->bind("KP_2", LFUN_SELFINSERT);
554 //kbmap->bind("KP_3", LFUN_SELFINSERT);
555 //kbmap->bind("KP_4", LFUN_SELFINSERT);
556 //kbmap->bind("KP_5", LFUN_SELFINSERT);
557 //kbmap->bind("KP_6", LFUN_SELFINSERT);
558 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
559 //kbmap->bind("KP_7", LFUN_SELFINSERT);
560 //kbmap->bind("KP_8", LFUN_SELFINSERT);
561 //kbmap->bind("KP_9", LFUN_SELFINSERT);
562 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
563 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
564 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
565 kbmap->bind("KP_Right", LFUN_RIGHT);
566 kbmap->bind("KP_Left", LFUN_LEFT);
567 kbmap->bind("KP_Up", LFUN_UP);
568 kbmap->bind("KP_Down", LFUN_DOWN);
569 kbmap->bind("KP_Home", LFUN_HOME);
570 kbmap->bind("KP_End", LFUN_END);
571 kbmap->bind("KP_Prior", LFUN_PRIOR);
572 kbmap->bind("KP_Next", LFUN_NEXT);
574 kbmap->bind("C-Tab", LFUN_TABINSERT); // ale970515
575 kbmap->bind("S-Tab", LFUN_SHIFT_TAB); // jug20000522
576 kbmap->bind("S-ISO_Left_Tab", LFUN_SHIFT_TAB); // jbl 2001-23-02
580 void LyX::emergencyCleanup()
582 // what to do about tmpfiles is non-obvious. we would
583 // like to delete any we find, but our lyxdir might
584 // contain documents etc. which might be helpful on
587 bufferlist.emergencyWriteAll();
589 lyxserver->emergencyCleanup();
593 // LyX can optionally take over the handling of deadkeys
594 void LyX::deadKeyBindings(kb_keymap * kbmap)
596 // bindKeyings for transparent handling of deadkeys
597 // The keysyms are gotten from XFree86 X11R6
598 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
599 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
600 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
601 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
602 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
603 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
604 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
605 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
606 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
607 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
608 // nothing with this name
609 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
610 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
611 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
612 // nothing with this name either...
613 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
614 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
615 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
616 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
620 // This one is not allowed to use anything on the main form, since that
621 // one does not exist yet. (Asger)
622 void LyX::queryUserLyXDir(bool explicit_userdir)
624 // Does user directory exist?
625 FileInfo fileInfo(user_lyxdir);
626 if (fileInfo.isOK() && fileInfo.isDir()) {
630 first_start = !explicit_userdir;
633 // If the user specified explicitely a directory, ask whether
634 // to create it (otherwise, always create it)
635 if (explicit_userdir &&
636 !Alert::askQuestion(_("You have specified an invalid LyX directory."),
637 _("It is needed to keep your own configuration."),
638 _("Should I try to set it up for you (recommended)?"))) {
639 lyxerr << _("Running without personal LyX directory.") << endl;
640 // No, let's use $HOME instead.
641 user_lyxdir = GetEnvPath("HOME");
645 // Tell the user what is going on
646 lyxerr << _("LyX: Creating directory ") << user_lyxdir
647 << _(" and running configure...") << endl;
649 // Create directory structure
650 if (!createDirectory(user_lyxdir, 0755)) {
651 // Failed, let's use $HOME instead.
652 user_lyxdir = GetEnvPath("HOME");
653 lyxerr << _("Failed. Will use ") << user_lyxdir
654 << _(" instead.") << endl;
658 // Run configure in user lyx directory
660 ::system(AddName(system_lyxdir, "configure").c_str());
661 lyxerr << "LyX: " << _("Done!") << endl;
665 // Read the rc file `name'
666 bool LyX::readRcFile(string const & name)
668 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
670 string const lyxrc_path = LibFileSearch(string(), name);
671 if (!lyxrc_path.empty()) {
672 lyxerr[Debug::INIT] << "Found " << name
673 << " in " << lyxrc_path << endl;
674 if (lyxrc.read(lyxrc_path) < 0) {
675 Alert::alert(_("LyX Warning!"),
676 _("Error while reading ") + lyxrc_path + ".",
677 _("Using built-in defaults."));
682 lyxerr[Debug::INIT] << "Could not find " << name << endl;
689 // Read the ui file `name'
690 void LyX::readUIFile(string const & name)
698 struct keyword_item uitags[ui_last-1] = {
699 { "menuset", ui_menuset },
700 { "toolbar", ui_toolbar }
703 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
705 string const ui_path = LibFileSearch("ui", name, "ui");
707 if (ui_path.empty()) {
708 lyxerr[Debug::INIT] << "Could not find " << name << endl;
709 menubackend.defaults();
713 lyxerr[Debug::INIT] << "Found " << name
714 << " in " << ui_path << endl;
715 LyXLex lex(uitags, ui_last - 1);
716 lex.setFile(ui_path);
718 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
722 if (lyxerr.debugging(Debug::PARSER))
723 lex.printTable(lyxerr);
728 menubackend.read(lex);
732 toolbardefaults.read(lex);
736 if (!strip(lex.getString()).empty())
737 lex.printError("LyX::ReadUIFile: "
738 "Unknown menu tag: `$$Token'");
745 // Read the languages file `name'
746 void LyX::readLanguagesFile(string const & name)
748 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
750 string const lang_path = LibFileSearch(string(), name);
751 if (lang_path.empty()) {
752 lyxerr[Debug::INIT] << "Could not find " << name << endl;
753 languages.setDefaults();
756 languages.read(lang_path);
760 // Read the encodings file `name'
761 void LyX::readEncodingsFile(string const & name)
763 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
765 string const enc_path = LibFileSearch(string(), name);
766 if (enc_path.empty()) {
767 lyxerr[Debug::INIT] << "Could not find " << name << endl;
770 encodings.read(enc_path);
776 // Set debugging level and report result to user
777 void setDebuggingLevel(string const & dbgLevel)
779 lyxerr << _("Setting debug level to ") << dbgLevel << endl;
780 lyxerr.level(Debug::value(dbgLevel));
781 Debug::showLevel(lyxerr, lyxerr.level());
785 // Give command line help
786 void commandLineHelp()
789 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
790 "Command line switches (case sensitive):\n"
791 "\t-help summarize LyX usage\n"
792 "\t-userdir dir try to set user directory to dir\n"
793 "\t-sysdir dir try to set system directory to dir\n"
794 "\t-geometry WxH+X+Y set geometry of the main window\n"
795 "\t-dbg feature[,feature]...\n"
796 " select the features to debug.\n"
797 " Type `lyx -dbg' to see the list of features\n"
798 "\t-x [--execute] command\n"
799 " where command is a lyx command.\n"
800 "\t-e [--export] fmt\n"
801 " where fmt is the export format of choice.\n"
802 "\t-i [--import] fmt file.xxx\n"
803 " where fmt is the import format of choice\n"
804 " and file.xxx is the file to be imported.\n"
805 "\t-version summarize version and build info\n"
806 "Check the LyX man page for more details.") << endl;
809 // Give command line version information
810 void commandLineVersionInfo()
812 lyxerr << "LyX " << lyx_version
813 << " of " << lyx_release_date << endl;
814 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
816 lyxerr << lyx_version_info << endl;
823 bool LyX::easyParse(int * argc, char * argv[])
826 int removeargs = 0; // used when options are read
827 for (int i = 1; i < *argc; ++i) {
828 string arg = argv[i];
830 // Check for -dbg int
833 setDebuggingLevel(argv[i + 1]);
836 lyxerr << _("List of supported debug flags:")
838 Debug::showTags(lyxerr);
842 // Check for "-sysdir"
843 else if (arg == "-sysdir") {
845 system_lyxdir = argv[i + 1];
848 lyxerr << _("Missing directory for -sysdir switch!")
853 // Check for "-userdir"
854 else if (arg == "-userdir") {
856 user_lyxdir = argv[i + 1];
859 lyxerr << _("Missing directory for -userdir switch!")
864 // Check for --help or -help
865 else if (arg == "--help" || arg == "-help") {
869 // Check for --version or -version
870 else if (arg == "--version" || arg == "-version") {
871 commandLineVersionInfo();
874 // FIXME: why is this commented out ?
875 // Check for "-nw": No XWindows as for emacs this should
876 // give a LyX that could be used in a terminal window.
877 //else if (arg == "-nw") {
881 // Check for "-x": Execute commands
882 else if (arg == "-x" || arg == "--execute") {
884 batch_command = string(argv[i + 1]);
888 lyxerr << _("Missing command string after -x switch!") << endl;
890 // Argh. Setting gui to false segfaults..
891 // FIXME: when ? how ?
895 else if (arg == "-e" || arg == "--export") {
897 string type(argv[i+1]);
899 batch_command = "buffer-export " + type;
902 lyxerr << _("Missing file type [eg latex, "
904 << arg << _(" switch!") << endl;
908 else if (arg == "-i" || arg == "--import") {
911 lyxerr << _("Missing filename for --import") << endl;
915 string const file(argv[i+2]);
916 string const type(argv[i+1]);
919 batch_command = "buffer-import " + type + " " + file;
920 lyxerr << "batch_command: "
921 << batch_command << endl;
924 lyxerr << _("Missing type [eg latex, "
926 << arg << _(" switch!") << endl;
931 if (removeargs > 0) {
932 // Now, remove used arguments by shifting
933 // the following ones removeargs places down.
934 (*argc) -= removeargs;
935 for (int j = i; j < (*argc); ++j)
936 argv[j] = argv[j + removeargs];
937 --i; // After shift, check this number again.