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 "lyxserver.h"
30 #include "ToolbarDefaults.h"
31 #include "MenuBackend.h"
33 #include "lastfiles.h"
35 #include "converter.h"
36 #include "lyxtextclasslist.h"
38 #include "frontends/Alert.h"
39 #include "frontends/lyx_gui.h"
41 #include "BoostFormat.h"
42 #include <boost/function.hpp>
50 #ifndef CXX_GLOBAL_CSTD
56 extern void LoadLyXFile(string const &);
57 extern void QuitLyX();
59 extern LyXServer * lyxserver;
63 string system_tempdir;
68 boost::scoped_ptr<LastFiles> lastfiles;
70 // This is the global bufferlist object
71 BufferList bufferlist;
73 // convenient to have it here.
74 boost::scoped_ptr<kb_keymap> toplevel_keymap;
77 LyX::LyX(int & argc, char * argv[])
79 // Here we need to parse the command line. At least
80 // we need to parse for "-dbg" and "-help"
81 bool const want_gui = easyParse(argc, argv);
83 // Global bindings (this must be done as early as possible.) (Lgb)
84 toplevel_keymap.reset(new kb_keymap);
85 defaultKeyBindings(toplevel_keymap.get());
87 // set the DisplayTranslator only once; should that be done here??
88 // if this should not be in this file, please also remove
89 // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye.
90 grfx::setDisplayTranslator();
93 lyx_gui::parse_init(argc, argv);
96 // check for any spurious extra arguments
97 // other than documents
98 for (int argi = 1; argi < argc ; ++argi) {
99 if (argv[argi][0] == '-') {
101 lyxerr << boost::format(_("Wrong command line option `%1$s'. Exiting."))
105 lyxerr << _("Wrong command line option `")
106 << argv[argi] << _("'. Exiting.")
113 // Initialization of LyX (reads lyxrc and more)
114 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
116 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
119 lyx_gui::parse_lyxrc();
122 vector<string> files;
124 for (int argi = argc - 1; argi >= 1; --argi) {
125 files.push_back(argv[argi]);
129 files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
132 // Execute batch commands if available
133 if (!batch_command.empty()) {
134 lyxerr[Debug::INIT] << "About to handle -x '"
135 << batch_command << '\'' << endl;
137 Buffer * last_loaded = 0;
139 vector<string>::iterator it = files.begin();
140 vector<string>::iterator end = files.end();
141 for (; it != end; ++it) {
142 last_loaded = bufferlist.loadLyXFile(*it);
147 // no buffer loaded, create one
149 last_loaded = bufferlist.newFile("tmpfile", string());
151 bool success = false;
153 // try to dispatch to last loaded buffer first
154 bool const dispatched = last_loaded->dispatch(batch_command, &success);
162 lyx_gui::start(batch_command, files);
168 static void error_handler(int err_sig)
172 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
178 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
181 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
183 "Sorry, you have found a bug in LyX. "
184 "Please read the bug-reporting instructions "
185 "in Help->Introduction and send us a bug report, "
186 "if necessary. Thanks !" << endl;
193 // Deinstall the signal handlers
194 signal(SIGHUP, SIG_DFL);
195 signal(SIGINT, SIG_DFL);
196 signal(SIGFPE, SIG_DFL);
197 signal(SIGSEGV, SIG_DFL);
198 signal(SIGTERM, SIG_DFL);
200 LyX::emergencyCleanup();
202 lyxerr << "Bye." << endl;
203 if (err_sig!= SIGHUP &&
204 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
212 void LyX::init(bool gui)
214 signal(SIGHUP, error_handler);
215 signal(SIGFPE, error_handler);
216 signal(SIGSEGV, error_handler);
217 signal(SIGINT, error_handler);
218 signal(SIGTERM, error_handler);
221 // Determine path of binary
224 string binpath = os::binpath();
225 string binname = os::binname();
226 string fullbinname = MakeAbsPath(binname, binpath);
228 if (binpath.empty()) {
229 lyxerr << _("Warning: could not determine path of binary.")
231 << _("If you have problems, try starting LyX with an absolute path.")
234 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
235 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
238 // Determine system directory.
241 // Directories are searched in this order:
242 // 1) -sysdir command line parameter
243 // 2) LYX_DIR_13x environment variable
244 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
245 // 4) <path of binary>/../share/<name of binary>/
246 // 4a) repeat 4 after following the Symlink if <path of
247 // binary> is a symbolic link.
248 // 5) hardcoded lyx_dir
249 // The directory is checked for the presence of the file
250 // "chkconfig.ltx", and if that is present, the directory
251 // is accepted as the system directory.
252 // If no chkconfig.ltx file is found, a warning is given,
253 // and the hardcoded lyx_dir is used.
255 // If we had a command line switch, system_lyxdir is already set
257 if (!system_lyxdir.empty())
258 searchpath = MakeAbsPath(system_lyxdir) + ';';
260 string const lyxdir = GetEnvPath("LYX_DIR_13x");
262 if (!lyxdir.empty()) {
263 lyxerr[Debug::INIT] << "LYX_DIR_13x: " << lyxdir << endl;
264 searchpath += lyxdir + ';';
267 string fullbinpath = binpath;
268 FileInfo file(fullbinname, true);
270 lyxerr[Debug::INIT] << "binary is a link" << endl;
272 if (LyXReadLink(fullbinname, link, true)) {
273 // Path of binary/../share/name of binary/
274 searchpath += NormalizePath(AddPath(binpath,
276 + OnlyFilename(binname));
279 binpath = MakeAbsPath(OnlyPath(fullbinpath));
285 // Path of binary/../share/name of binary/
286 searchpath += NormalizePath(AddPath(binpath, "../share/") +
287 OnlyFilename(binname)) + ';';
290 FileInfo file(fullbinpath, true);
291 followlink = file.isLink();
293 lyxerr[Debug::INIT] << " directory " << fullbinpath
294 << " is a link" << endl;
296 if (LyXReadLink(fullbinpath, link, true)) {
298 binpath = MakeAbsPath(OnlyPath(fullbinpath));
304 } while (followlink);
306 // <path of binary>/TOP_SRCDIR/lib
307 build_lyxdir = MakeAbsPath("../lib", binpath);
308 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
309 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
311 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
312 "place... yes" << endl;
315 << "Checking whether LyX is run in place... no"
317 build_lyxdir.erase();
321 searchpath += LYX_DIR;
323 lyxerr[Debug::INIT] << "System directory search path: "
324 << searchpath << endl;
326 string const filename = "chkconfig.ltx";
327 string const temp = FileOpenSearch(searchpath, filename, string());
328 system_lyxdir = OnlyPath(temp);
330 // Reduce "path/../path" stuff out of system directory
331 system_lyxdir = NormalizePath(system_lyxdir);
333 bool path_shown = false;
335 // Warn if environment variable is set, but unusable
336 if (!lyxdir.empty()) {
337 if (system_lyxdir != NormalizePath(lyxdir)) {
338 lyxerr <<_("LYX_DIR_13x environment variable no good.")
340 << _("System directory set to: ")
341 << system_lyxdir << endl;
346 // Warn the user if we couldn't find "chkconfig.ltx"
347 if (system_lyxdir == "./") {
348 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
349 <<_("Try the '-sysdir' command line parameter or ")
350 <<_("set the environment variable LYX_DIR_13x to the "
351 "LyX system directory ")
352 << _("containing the file `chkconfig.ltx'.") << endl;
354 FileInfo fi(LYX_DIR);
356 lyxerr << "Couldn't even find the default LYX_DIR." << endl
357 << "Giving up." << endl;
361 lyxerr << boost::format(_("Using built-in default %1$s"
362 " but expect problems."))
363 % static_cast<char *>(LYX_DIR)
366 lyxerr << _("Using built-in default ") << LYX_DIR
367 << _(" but expect problems.")
371 lyxerr << _("Expect problems.") << endl;
373 system_lyxdir = LYX_DIR;
378 lyxerr[Debug::INIT] << "System directory: '"
379 << system_lyxdir << '\'' << endl;
382 // Determine user lyx-dir
385 // Directories are searched in this order:
386 // 1) -userdir command line parameter
387 // 2) LYX_USERDIR_13x environment variable
388 // 3) $HOME/.<name of binary>
390 // If we had a command line switch, user_lyxdir is already set
391 bool explicit_userdir = true;
392 if (user_lyxdir.empty()) {
394 // LYX_USERDIR_13x environment variable
395 user_lyxdir = GetEnvPath("LYX_USERDIR_13x");
398 if (user_lyxdir.empty())
399 user_lyxdir = AddPath(GetEnvPath("HOME"),
400 string(".") + PACKAGE);
401 explicit_userdir = false;
404 lyxerr[Debug::INIT] << "User LyX directory: '"
405 << user_lyxdir << '\'' << endl;
407 // Check that user LyX directory is ok. We don't do that if
408 // running in batch mode.
410 queryUserLyXDir(explicit_userdir);
416 // Shine up lyxrc defaults
419 // Default template path: system_dir/templates
420 if (lyxrc.template_path.empty()) {
421 lyxrc.template_path = AddPath(system_lyxdir, "templates");
424 // Default lastfiles file: $HOME/.lyx/lastfiles
425 if (lyxrc.lastfiles.empty()) {
426 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
429 // Disable gui when either lyxrc or easyparse says so
431 lyxrc.use_gui = false;
434 // Read configuration files
437 readRcFile("lyxrc.defaults");
438 system_lyxrc = lyxrc;
439 system_formats = formats;
440 system_converters = converters;
441 system_lcolor = lcolor;
443 // If there is a preferences file we read that instead
444 // of the old lyxrc file.
445 if (!readRcFile("preferences"))
448 readEncodingsFile("encodings");
449 readLanguagesFile("languages");
452 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
455 // Ensure that we have really read a bind file, so that LyX is
457 lyxrc.readBindFileIfNeeded();
460 readUIFile(lyxrc.ui_file);
462 if (lyxerr.debugging(Debug::LYXRC)) {
466 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
467 system_tempdir = os::getTmpDir();
468 if (lyxerr.debugging(Debug::INIT)) {
469 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
472 lyxerr[Debug::INIT] << "Reading lastfiles `"
473 << lyxrc.lastfiles << "'..." << endl;
474 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
475 lyxrc.check_lastfiles,
476 lyxrc.num_lastfiles));
480 void LyX::defaultKeyBindings(kb_keymap * kbmap)
482 kbmap->bind("Right", LFUN_RIGHT);
483 kbmap->bind("Left", LFUN_LEFT);
484 kbmap->bind("Up", LFUN_UP);
485 kbmap->bind("Down", LFUN_DOWN);
487 kbmap->bind("Tab", LFUN_TAB);
488 kbmap->bind("ISO_Left_Tab", LFUN_TAB); // jbl 2001-23-02
490 kbmap->bind("Home", LFUN_HOME);
491 kbmap->bind("End", LFUN_END);
492 kbmap->bind("Prior", LFUN_PRIOR);
493 kbmap->bind("Next", LFUN_NEXT);
495 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
496 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
498 kbmap->bind("Delete", LFUN_DELETE);
499 kbmap->bind("BackSpace", LFUN_BACKSPACE);
501 // sub- and superscript -MV
502 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
503 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
505 // kbmap->bindings to enable the use of the numeric keypad
507 //kbmap->bind("KP_0", LFUN_SELFINSERT);
508 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
509 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
510 //kbmap->bind("KP_1", LFUN_SELFINSERT);
511 //kbmap->bind("KP_2", LFUN_SELFINSERT);
512 //kbmap->bind("KP_3", LFUN_SELFINSERT);
513 //kbmap->bind("KP_4", LFUN_SELFINSERT);
514 //kbmap->bind("KP_5", LFUN_SELFINSERT);
515 //kbmap->bind("KP_6", LFUN_SELFINSERT);
516 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
517 //kbmap->bind("KP_7", LFUN_SELFINSERT);
518 //kbmap->bind("KP_8", LFUN_SELFINSERT);
519 //kbmap->bind("KP_9", LFUN_SELFINSERT);
520 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
521 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
522 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
523 kbmap->bind("KP_Right", LFUN_RIGHT);
524 kbmap->bind("KP_Left", LFUN_LEFT);
525 kbmap->bind("KP_Up", LFUN_UP);
526 kbmap->bind("KP_Down", LFUN_DOWN);
527 kbmap->bind("KP_Home", LFUN_HOME);
528 kbmap->bind("KP_End", LFUN_END);
529 kbmap->bind("KP_Prior", LFUN_PRIOR);
530 kbmap->bind("KP_Next", LFUN_NEXT);
532 kbmap->bind("C-Tab", LFUN_TABINSERT); // ale970515
533 kbmap->bind("S-Tab", LFUN_SHIFT_TAB); // jug20000522
534 kbmap->bind("S-ISO_Left_Tab", LFUN_SHIFT_TAB); // jbl 2001-23-02
538 void LyX::emergencyCleanup()
540 // what to do about tmpfiles is non-obvious. we would
541 // like to delete any we find, but our lyxdir might
542 // contain documents etc. which might be helpful on
545 bufferlist.emergencyWriteAll();
547 lyxserver->emergencyCleanup();
551 void LyX::deadKeyBindings(kb_keymap * kbmap)
553 // bindKeyings for transparent handling of deadkeys
554 // The keysyms are gotten from XFree86 X11R6
555 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
556 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
557 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
558 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
559 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
560 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
561 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
562 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
563 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
564 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
565 // nothing with this name
566 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
567 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
568 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
569 // nothing with this name either...
570 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
571 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
572 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
573 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
577 void LyX::queryUserLyXDir(bool explicit_userdir)
579 string const configure_script = AddName(system_lyxdir, "configure");
581 // Does user directory exist?
582 FileInfo fileInfo(user_lyxdir);
583 if (fileInfo.isOK() && fileInfo.isDir()) {
585 FileInfo script(configure_script);
586 FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults"));
587 if (defaults.isOK() && script.isOK()
588 && defaults.getModificationTime() < script.getModificationTime()) {
589 lyxerr << _("LyX: reconfiguring user directory")
592 ::system(configure_script.c_str());
593 lyxerr << "LyX: " << _("Done!") << endl;
598 first_start = !explicit_userdir;
600 // If the user specified explicitly a directory, ask whether
601 // to create it (otherwise, always create it)
602 if (explicit_userdir &&
603 !Alert::askQuestion(_("You have specified an invalid LyX directory."),
604 _("It is needed to keep your own configuration."),
605 _("Should I try to set it up for you (recommended)?"))) {
606 lyxerr << _("Running without personal LyX directory.") << endl;
607 // No, let's use $HOME instead.
608 user_lyxdir = GetEnvPath("HOME");
613 lyxerr << boost::format(_("LyX: Creating directory %1$s"
614 " and running configure..."))
618 lyxerr << _("LyX: Creating directory ") << user_lyxdir
619 << _(" and running configure...")
623 if (!createDirectory(user_lyxdir, 0755)) {
624 // Failed, let's use $HOME instead.
625 user_lyxdir = GetEnvPath("HOME");
627 lyxerr << boost::format(_("Failed. Will use %1$s instead."))
631 lyxerr << _("Failed. Will use ") << user_lyxdir <<
638 // Run configure in user lyx directory
640 ::system(configure_script.c_str());
641 lyxerr << "LyX: " << _("Done!") << endl;
645 bool LyX::readRcFile(string const & name)
647 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
649 string const lyxrc_path = LibFileSearch(string(), name);
650 if (!lyxrc_path.empty()) {
651 lyxerr[Debug::INIT] << "Found " << name
652 << " in " << lyxrc_path << endl;
653 if (lyxrc.read(lyxrc_path) < 0) {
655 Alert::alert(_("LyX Warning!"),
656 boost::io::str(boost::format(_("Error while reading %1$s.")) % lyxrc_path),
657 _("Using built-in defaults."));
659 Alert::alert(_("LyX Warning!"),
660 _("Error while reading ") + lyxrc_path,
661 _("Using built-in defaults."));
667 lyxerr[Debug::INIT] << "Could not find " << name << endl;
674 // Read the ui file `name'
675 void LyX::readUIFile(string const & name)
683 struct keyword_item uitags[ui_last - 1] = {
684 { "menuset", ui_menuset },
685 { "toolbar", ui_toolbar }
688 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
690 string const ui_path = LibFileSearch("ui", name, "ui");
692 if (ui_path.empty()) {
693 lyxerr[Debug::INIT] << "Could not find " << name << endl;
694 menubackend.defaults();
698 lyxerr[Debug::INIT] << "Found " << name
699 << " in " << ui_path << endl;
700 LyXLex lex(uitags, ui_last - 1);
701 lex.setFile(ui_path);
703 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
707 if (lyxerr.debugging(Debug::PARSER))
708 lex.printTable(lyxerr);
713 menubackend.read(lex);
717 toolbardefaults.read(lex);
721 if (!rtrim(lex.getString()).empty())
722 lex.printError("LyX::ReadUIFile: "
723 "Unknown menu tag: `$$Token'");
730 // Read the languages file `name'
731 void LyX::readLanguagesFile(string const & name)
733 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
735 string const lang_path = LibFileSearch(string(), name);
736 if (lang_path.empty()) {
737 lyxerr[Debug::INIT] << "Could not find " << name << endl;
738 languages.setDefaults();
741 languages.read(lang_path);
745 // Read the encodings file `name'
746 void LyX::readEncodingsFile(string const & name)
748 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
750 string const enc_path = LibFileSearch(string(), name);
751 if (enc_path.empty()) {
752 lyxerr[Debug::INIT] << "Could not find " << name << endl;
755 encodings.read(enc_path);
764 /// return the the number of arguments consumed
765 typedef boost::function<int(string const &, string const &)> cmd_helper;
767 int parse_dbg(string const & arg, string const &)
770 lyxerr << _("List of supported debug flags:") << endl;
771 Debug::showTags(lyxerr);
775 lyxerr << boost::format(_("Setting debug level to %1$s"))
779 lyxerr << _("Setting debug level to ") << arg << endl;
782 lyxerr.level(Debug::value(arg));
783 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;