3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
14 #include "support/filetools.h"
15 #include "support/lyxlib.h"
16 #include "support/os.h"
17 #include "support/FileInfo.h"
18 #include "support/path.h"
23 #include "graphics/GraphicsTypes.h"
25 #include "bufferlist.h"
27 #include "buffer_funcs.h"
28 #include "lyxserver.h"
31 #include "ToolbarBackend.h"
32 #include "MenuBackend.h"
34 #include "lastfiles.h"
36 #include "converter.h"
38 #include "lyxtextclasslist.h"
40 #include "frontends/Alert.h"
41 #include "frontends/lyx_gui.h"
43 #include <boost/function.hpp>
44 #include <boost/bind.hpp>
45 #include <boost/signals/signal1.hpp>
51 using namespace lyx::support;
56 #ifndef CXX_GLOBAL_CSTD
62 extern void LoadLyXFile(string const &);
63 extern void QuitLyX();
65 extern LyXServer * lyxserver;
69 string system_tempdir;
74 boost::scoped_ptr<LastFiles> lastfiles;
76 // This is the global bufferlist object
77 BufferList bufferlist;
79 // convenient to have it here.
80 boost::scoped_ptr<kb_keymap> toplevel_keymap;
84 void showFileError(string const & error)
86 Alert::warning(_("Could not read configuration file"),
87 bformat(_("Error while reading the configuration file\n%1$s.\n"
88 "Please check your installation."), error));
94 LyX::LyX(int & argc, char * argv[])
96 // Here we need to parse the command line. At least
97 // we need to parse for "-dbg" and "-help"
98 bool const want_gui = easyParse(argc, argv);
100 // Global bindings (this must be done as early as possible.) (Lgb)
101 toplevel_keymap.reset(new kb_keymap);
102 defaultKeyBindings(toplevel_keymap.get());
104 // set the DisplayTranslator only once; should that be done here??
105 // if this should not be in this file, please also remove
106 // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye.
107 grfx::setDisplayTranslator();
110 lyx_gui::parse_init(argc, argv);
113 // check for any spurious extra arguments
114 // other than documents
115 for (int argi = 1; argi < argc ; ++argi) {
116 if (argv[argi][0] == '-') {
117 lyxerr << bformat(_("Wrong command line option `%1$s'. Exiting."),
123 // Initialization of LyX (reads lyxrc and more)
124 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
126 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
129 lyx_gui::parse_lyxrc();
132 vector<string> files;
134 for (int argi = argc - 1; argi >= 1; --argi) {
135 files.push_back(argv[argi]);
139 files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
141 // Execute batch commands if available
142 if (!batch_command.empty()) {
143 lyxerr[Debug::INIT] << "About to handle -x '"
144 << batch_command << '\'' << endl;
146 Buffer * last_loaded = 0;
148 vector<string>::const_iterator it = files.begin();
149 vector<string>::const_iterator end = files.end();
151 for (; it != end; ++it) {
152 // get absolute path of file and add ".lyx" to
153 // the filename if necessary
154 string s = FileSearch(string(), *it, "lyx");
159 last_loaded = bufferlist.newBuffer(s, false);
160 last_loaded->parseError.connect(boost::bind(&LyX::printError, this, _1));
161 loadLyXFile(last_loaded, s);
166 bool success = false;
168 // try to dispatch to last loaded buffer first
169 bool const dispatched = last_loaded->dispatch(batch_command, &success);
177 lyx_gui::start(batch_command, files);
183 static void error_handler(int err_sig)
187 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
193 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
196 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
198 "Sorry, you have found a bug in LyX. "
199 "Please read the bug-reporting instructions "
200 "in Help->Introduction and send us a bug report, "
201 "if necessary. Thanks !" << endl;
208 // Deinstall the signal handlers
209 signal(SIGHUP, SIG_DFL);
210 signal(SIGINT, SIG_DFL);
211 signal(SIGFPE, SIG_DFL);
212 signal(SIGSEGV, SIG_DFL);
213 signal(SIGTERM, SIG_DFL);
215 LyX::emergencyCleanup();
217 lyxerr << "Bye." << endl;
218 if (err_sig!= SIGHUP &&
219 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
220 lyx::support::abort();
227 void LyX::printError(ErrorItem const & ei)
229 std::cerr << _("LyX: ") << ei.error
230 << ':' << ei.description << std::endl;
235 void LyX::init(bool gui)
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_14x 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 string const lyxdir = GetEnvPath("LYX_DIR_14x");
285 if (!lyxdir.empty()) {
286 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
287 searchpath += lyxdir + ';';
290 string fullbinpath = binpath;
291 FileInfo file(fullbinname, true);
293 lyxerr[Debug::INIT] << "binary is a link" << endl;
295 if (LyXReadLink(fullbinname, link, true)) {
296 // Path of binary/../share/name of binary/
297 searchpath += NormalizePath(AddPath(binpath,
299 + OnlyFilename(binname));
302 binpath = MakeAbsPath(OnlyPath(fullbinpath));
308 // Path of binary/../share/name of binary/
309 searchpath += NormalizePath(AddPath(binpath, "../share/") +
310 OnlyFilename(binname)) + ';';
313 FileInfo file(fullbinpath, true);
314 followlink = file.isLink();
316 lyxerr[Debug::INIT] << " directory " << fullbinpath
317 << " is a link" << endl;
319 if (LyXReadLink(fullbinpath, link, true)) {
321 binpath = MakeAbsPath(OnlyPath(fullbinpath));
327 } while (followlink);
329 // <path of binary>/TOP_SRCDIR/lib
330 build_lyxdir = MakeAbsPath("../lib", binpath);
331 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
332 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
334 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
335 "place... yes" << endl;
338 << "Checking whether LyX is run in place... no"
340 build_lyxdir.erase();
344 searchpath += LYX_DIR;
346 lyxerr[Debug::INIT] << "System directory search path: "
347 << searchpath << endl;
349 string const filename = "chkconfig.ltx";
350 string const temp = FileOpenSearch(searchpath, filename, string());
351 system_lyxdir = OnlyPath(temp);
353 // Reduce "path/../path" stuff out of system directory
354 system_lyxdir = NormalizePath(system_lyxdir);
356 bool path_shown = false;
358 // Warn if environment variable is set, but unusable
359 if (!lyxdir.empty()) {
360 if (system_lyxdir != NormalizePath(lyxdir)) {
361 lyxerr <<_("LYX_DIR_14x environment variable no good.")
363 << _("System directory set to: ")
364 << system_lyxdir << endl;
369 // Warn the user if we couldn't find "chkconfig.ltx"
370 if (system_lyxdir == "./") {
371 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
372 <<_("Try the '-sysdir' command line parameter or ")
373 <<_("set the environment variable LYX_DIR_14x to the "
374 "LyX system directory ")
375 << _("containing the file `chkconfig.ltx'.") << endl;
377 FileInfo fi(LYX_DIR);
379 lyxerr << "Couldn't even find the default LYX_DIR." << endl
380 << "Giving up." << endl;
383 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
386 lyxerr << _("Expect problems.") << endl;
388 system_lyxdir = LYX_DIR;
393 lyxerr[Debug::INIT] << "System directory: '"
394 << system_lyxdir << '\'' << endl;
397 // Determine user lyx-dir
400 // Directories are searched in this order:
401 // 1) -userdir command line parameter
402 // 2) LYX_USERDIR_14x environment variable
403 // 3) $HOME/.<name of binary>
405 // If we had a command line switch, user_lyxdir is already set
406 bool explicit_userdir = true;
407 if (user_lyxdir.empty()) {
409 // LYX_USERDIR_14x environment variable
410 user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
413 if (user_lyxdir.empty())
414 user_lyxdir = AddPath(GetEnvPath("HOME"),
415 string(".") + PACKAGE);
416 explicit_userdir = false;
419 lyxerr[Debug::INIT] << "User LyX directory: '"
420 << user_lyxdir << '\'' << endl;
422 // Check that user LyX directory is ok. We don't do that if
423 // running in batch mode.
425 queryUserLyXDir(explicit_userdir);
430 // Disable gui when easyparse says so
431 lyx_gui::use_gui = gui;
433 if (lyxrc.template_path.empty()) {
434 lyxrc.template_path = AddPath(system_lyxdir, "templates");
437 if (lyxrc.lastfiles.empty()) {
438 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
441 if (lyxrc.roman_font_name.empty())
442 lyxrc.roman_font_name = lyx_gui::roman_font_name();
443 if (lyxrc.sans_font_name.empty())
444 lyxrc.sans_font_name = lyx_gui::sans_font_name();
445 if (lyxrc.typewriter_font_name.empty())
446 lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
449 // Read configuration files
452 readRcFile("lyxrc.defaults");
453 system_lyxrc = lyxrc;
454 system_formats = formats;
455 system_converters = converters;
456 system_lcolor = lcolor;
458 string prefsfile = "preferences";
459 // back compatibility to lyxs < 1.1.6
460 if (LibFileSearch(string(), prefsfile).empty())
462 if (!LibFileSearch(string(), prefsfile).empty())
463 readRcFile(prefsfile);
465 readEncodingsFile("encodings");
466 readLanguagesFile("languages");
469 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
472 // Ensure that we have really read a bind file, so that LyX is
474 lyxrc.readBindFileIfNeeded();
477 readUIFile(lyxrc.ui_file);
479 if (lyxerr.debugging(Debug::LYXRC))
482 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
483 system_tempdir = os::getTmpDir();
484 if (lyxerr.debugging(Debug::INIT)) {
485 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
488 lyxerr[Debug::INIT] << "Reading lastfiles `"
489 << lyxrc.lastfiles << "'..." << endl;
490 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
491 lyxrc.check_lastfiles,
492 lyxrc.num_lastfiles));
496 void LyX::defaultKeyBindings(kb_keymap * kbmap)
498 kbmap->bind("Right", LFUN_RIGHT);
499 kbmap->bind("Left", LFUN_LEFT);
500 kbmap->bind("Up", LFUN_UP);
501 kbmap->bind("Down", LFUN_DOWN);
503 kbmap->bind("Tab", LFUN_CELL_FORWARD);
504 kbmap->bind("ISO_Left_Tab", LFUN_CELL_FORWARD); // jbl 2001-23-02
506 kbmap->bind("Home", LFUN_HOME);
507 kbmap->bind("End", LFUN_END);
508 kbmap->bind("Prior", LFUN_PRIOR);
509 kbmap->bind("Next", LFUN_NEXT);
511 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
512 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
514 kbmap->bind("Delete", LFUN_DELETE);
515 kbmap->bind("BackSpace", LFUN_BACKSPACE);
517 // sub- and superscript -MV
518 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
519 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
521 // kbmap->bindings to enable the use of the numeric keypad
523 //kbmap->bind("KP_0", LFUN_SELFINSERT);
524 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
525 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
526 //kbmap->bind("KP_1", LFUN_SELFINSERT);
527 //kbmap->bind("KP_2", LFUN_SELFINSERT);
528 //kbmap->bind("KP_3", LFUN_SELFINSERT);
529 //kbmap->bind("KP_4", LFUN_SELFINSERT);
530 //kbmap->bind("KP_5", LFUN_SELFINSERT);
531 //kbmap->bind("KP_6", LFUN_SELFINSERT);
532 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
533 //kbmap->bind("KP_7", LFUN_SELFINSERT);
534 //kbmap->bind("KP_8", LFUN_SELFINSERT);
535 //kbmap->bind("KP_9", LFUN_SELFINSERT);
536 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
537 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
538 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
539 kbmap->bind("KP_Right", LFUN_RIGHT);
540 kbmap->bind("KP_Left", LFUN_LEFT);
541 kbmap->bind("KP_Up", LFUN_UP);
542 kbmap->bind("KP_Down", LFUN_DOWN);
543 kbmap->bind("KP_Home", LFUN_HOME);
544 kbmap->bind("KP_End", LFUN_END);
545 kbmap->bind("KP_Prior", LFUN_PRIOR);
546 kbmap->bind("KP_Next", LFUN_NEXT);
548 kbmap->bind("C-Tab", LFUN_CELL_SPLIT); // ale970515
549 kbmap->bind("S-Tab", LFUN_CELL_BACKWARD); // jug20000522
550 kbmap->bind("S-ISO_Left_Tab", LFUN_CELL_BACKWARD); // jbl 2001-23-02
554 void LyX::emergencyCleanup()
556 // what to do about tmpfiles is non-obvious. we would
557 // like to delete any we find, but our lyxdir might
558 // contain documents etc. which might be helpful on
561 bufferlist.emergencyWriteAll();
563 lyxserver->emergencyCleanup();
567 void LyX::deadKeyBindings(kb_keymap * kbmap)
569 // bindKeyings for transparent handling of deadkeys
570 // The keysyms are gotten from XFree86 X11R6
571 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
572 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
573 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
574 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
575 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
576 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
577 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
578 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
579 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
580 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
581 // nothing with this name
582 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
583 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
584 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
585 // nothing with this name either...
586 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
587 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
588 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
589 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
593 void LyX::queryUserLyXDir(bool explicit_userdir)
595 string const configure_script = AddName(system_lyxdir, "configure");
597 // Does user directory exist?
598 FileInfo fileInfo(user_lyxdir);
599 if (fileInfo.isOK() && fileInfo.isDir()) {
601 FileInfo script(configure_script);
602 FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults"));
603 if (defaults.isOK() && script.isOK()
604 && defaults.getModificationTime() < script.getModificationTime()) {
605 lyxerr << _("LyX: reconfiguring user directory")
608 ::system(configure_script.c_str());
609 lyxerr << "LyX: " << _("Done!") << endl;
614 first_start = !explicit_userdir;
616 lyxerr << bformat(_("LyX: Creating directory %1$s"
617 " and running configure..."), user_lyxdir) << endl;
619 if (!createDirectory(user_lyxdir, 0755)) {
620 // Failed, let's use $HOME instead.
621 user_lyxdir = GetEnvPath("HOME");
622 lyxerr << bformat(_("Failed. Will use %1$s instead."),
623 user_lyxdir) << endl;
627 // Run configure in user lyx directory
629 ::system(configure_script.c_str());
630 lyxerr << "LyX: " << _("Done!") << endl;
634 void LyX::readRcFile(string const & name)
636 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
638 string const lyxrc_path = LibFileSearch(string(), name);
639 if (!lyxrc_path.empty()) {
641 lyxerr[Debug::INIT] << "Found " << name
642 << " in " << lyxrc_path << endl;
644 if (lyxrc.read(lyxrc_path) >= 0)
652 // Read the ui file `name'
653 void LyX::readUIFile(string const & name)
663 struct keyword_item uitags[ui_last - 1] = {
664 { "include", ui_include },
665 { "menuset", ui_menuset },
666 { "toolbar", ui_toolbar },
667 { "toolbars", ui_toolbars }
670 // Ensure that a file is read only once (prevents include loops)
671 static std::list<string> uifiles;
672 std::list<string>::const_iterator it = uifiles.begin();
673 std::list<string>::const_iterator end = uifiles.end();
674 it = std::find(it, end, name);
676 lyxerr[Debug::INIT] << "UI file '" << name
677 << "' has been read already. "
678 << "Is this an include loop?"
683 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
685 string const ui_path = LibFileSearch("ui", name, "ui");
687 if (ui_path.empty()) {
688 lyxerr[Debug::INIT] << "Could not find " << name << endl;
692 uifiles.push_back(name);
694 lyxerr[Debug::INIT] << "Found " << name
695 << " in " << ui_path << endl;
696 LyXLex lex(uitags, ui_last - 1);
697 lex.setFile(ui_path);
699 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
703 if (lyxerr.debugging(Debug::PARSER))
704 lex.printTable(lyxerr);
710 string const file = lex.getString();
715 menubackend.read(lex);
719 toolbarbackend.read(lex);
723 toolbarbackend.readToolbars(lex);
727 if (!rtrim(lex.getString()).empty())
728 lex.printError("LyX::ReadUIFile: "
729 "Unknown menu tag: `$$Token'");
736 // Read the languages file `name'
737 void LyX::readLanguagesFile(string const & name)
739 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
741 string const lang_path = LibFileSearch(string(), name);
742 if (lang_path.empty()) {
746 languages.read(lang_path);
750 // Read the encodings file `name'
751 void LyX::readEncodingsFile(string const & name)
753 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
755 string const enc_path = LibFileSearch(string(), name);
756 if (enc_path.empty()) {
760 encodings.read(enc_path);
769 /// return the the number of arguments consumed
770 typedef boost::function<int(string const &, string const &)> cmd_helper;
772 int parse_dbg(string const & arg, string const &)
775 lyxerr << _("List of supported debug flags:") << endl;
776 Debug::showTags(lyxerr);
779 lyxerr << bformat(_("Setting debug level to %1$s"), arg) << endl;
781 lyxerr.level(Debug::value(arg));
782 Debug::showLevel(lyxerr, lyxerr.level());
787 int parse_help(string const &, string const &)
790 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
791 "Command line switches (case sensitive):\n"
792 "\t-help summarize LyX usage\n"
793 "\t-userdir dir try to set user directory to dir\n"
794 "\t-sysdir dir try to set system directory to dir\n"
795 "\t-geometry WxH+X+Y set geometry of the main window\n"
796 "\t-dbg feature[,feature]...\n"
797 " select the features to debug.\n"
798 " Type `lyx -dbg' to see the list of features\n"
799 "\t-x [--execute] command\n"
800 " where command is a lyx command.\n"
801 "\t-e [--export] fmt\n"
802 " where fmt is the export format of choice.\n"
803 "\t-i [--import] fmt file.xxx\n"
804 " where fmt is the import format of choice\n"
805 " and file.xxx is the file to be imported.\n"
806 "\t-version summarize version and build info\n"
807 "Check the LyX man page for more details.") << endl;
812 int parse_version(string const &, string const &)
814 lyxerr << "LyX " << lyx_version
815 << " of " << lyx_release_date << endl;
816 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
818 lyxerr << lyx_version_info << endl;
823 int parse_sysdir(string const & arg, string const &)
826 lyxerr << _("Missing directory for -sysdir switch") << endl;
833 int parse_userdir(string const & arg, string const &)
836 lyxerr << _("Missing directory for -userdir switch") << endl;
843 int parse_execute(string const & arg, string const &)
846 lyxerr << _("Missing command string after --execute switch") << endl;
850 // Argh. Setting gui to false segfaults..
851 // FIXME: when ? how ?
856 int parse_export(string const & type, string const &)
859 lyxerr << _("Missing file type [eg latex, ps...] after "
860 "--export switch") << endl;
863 batch = "buffer-export " + type;
868 int parse_import(string const & type, string const & file)
871 lyxerr << _("Missing file type [eg latex, ps...] after "
872 "--import switch") << endl;
876 lyxerr << _("Missing filename for --import") << endl;
880 batch = "buffer-import " + type + ' ' + file;
887 bool LyX::easyParse(int & argc, char * argv[])
889 std::map<string, cmd_helper> cmdmap;
891 cmdmap["-dbg"] = parse_dbg;
892 cmdmap["-help"] = parse_help;
893 cmdmap["--help"] = parse_help;
894 cmdmap["-version"] = parse_version;
895 cmdmap["--version"] = parse_version;
896 cmdmap["-sysdir"] = parse_sysdir;
897 cmdmap["-userdir"] = parse_userdir;
898 cmdmap["-x"] = parse_execute;
899 cmdmap["--execute"] = parse_execute;
900 cmdmap["-e"] = parse_export;
901 cmdmap["--export"] = parse_export;
902 cmdmap["-i"] = parse_import;
903 cmdmap["--import"] = parse_import;
905 for (int i = 1; i < argc; ++i) {
906 std::map<string, cmd_helper>::const_iterator it
907 = cmdmap.find(argv[i]);
909 // don't complain if not found - may be parsed later
910 if (it == cmdmap.end())
913 string arg((i + 1 < argc) ? argv[i + 1] : "");
914 string arg2((i + 2 < argc) ? argv[i + 2] : "");
916 int const remove = 1 + it->second(arg, arg2);
918 // Now, remove used arguments by shifting
919 // the following ones remove places down.
921 for (int j = i; j < argc; ++j)
922 argv[j] = argv[j + remove];
926 batch_command = batch;