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>
54 #ifndef CXX_GLOBAL_CSTD
60 extern void LoadLyXFile(string const &);
61 extern void QuitLyX();
63 extern LyXServer * lyxserver;
67 string system_tempdir;
72 boost::scoped_ptr<LastFiles> lastfiles;
74 // This is the global bufferlist object
75 BufferList bufferlist;
77 // convenient to have it here.
78 boost::scoped_ptr<kb_keymap> toplevel_keymap;
82 void showFileError(string const & error)
84 Alert::warning(_("Could not read configuration file"),
85 bformat(_("Error while reading the configuration file\n%1$s.\n"
86 "Please check your installation."), error));
92 LyX::LyX(int & argc, char * argv[])
94 // Here we need to parse the command line. At least
95 // we need to parse for "-dbg" and "-help"
96 bool const want_gui = easyParse(argc, argv);
98 // Global bindings (this must be done as early as possible.) (Lgb)
99 toplevel_keymap.reset(new kb_keymap);
100 defaultKeyBindings(toplevel_keymap.get());
102 // set the DisplayTranslator only once; should that be done here??
103 // if this should not be in this file, please also remove
104 // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye.
105 grfx::setDisplayTranslator();
108 lyx_gui::parse_init(argc, argv);
111 // check for any spurious extra arguments
112 // other than documents
113 for (int argi = 1; argi < argc ; ++argi) {
114 if (argv[argi][0] == '-') {
115 lyxerr << bformat(_("Wrong command line option `%1$s'. Exiting."),
121 // Initialization of LyX (reads lyxrc and more)
122 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
124 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
127 lyx_gui::parse_lyxrc();
130 vector<string> files;
132 for (int argi = argc - 1; argi >= 1; --argi) {
133 files.push_back(argv[argi]);
137 files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
139 // Execute batch commands if available
140 if (!batch_command.empty()) {
141 lyxerr[Debug::INIT] << "About to handle -x '"
142 << batch_command << '\'' << endl;
144 Buffer * last_loaded = 0;
146 vector<string>::iterator it = files.begin();
147 vector<string>::iterator end = files.end();
148 for (; it != end; ++it) {
149 last_loaded = bufferlist.newBuffer(*it, false);
150 last_loaded->parseError.connect(boost::bind(&LyX::printError, this, _1));
151 loadLyXFile(last_loaded, *it);
156 // no buffer loaded, create one
157 string const tmpfile = "tmpfile";
159 last_loaded = newFile(tmpfile, string());
161 bool success = false;
163 // try to dispatch to last loaded buffer first
164 bool const dispatched = last_loaded->dispatch(batch_command, &success);
172 lyx_gui::start(batch_command, files);
178 static void error_handler(int err_sig)
182 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
188 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
191 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
193 "Sorry, you have found a bug in LyX. "
194 "Please read the bug-reporting instructions "
195 "in Help->Introduction and send us a bug report, "
196 "if necessary. Thanks !" << endl;
203 // Deinstall the signal handlers
204 signal(SIGHUP, SIG_DFL);
205 signal(SIGINT, SIG_DFL);
206 signal(SIGFPE, SIG_DFL);
207 signal(SIGSEGV, SIG_DFL);
208 signal(SIGTERM, SIG_DFL);
210 LyX::emergencyCleanup();
212 lyxerr << "Bye." << endl;
213 if (err_sig!= SIGHUP &&
214 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
222 void LyX::printError(ErrorItem const & ei)
224 std::cerr << _("LyX: ") << ei.error
225 << ':' << ei.description << std::endl;
230 void LyX::init(bool gui)
232 signal(SIGHUP, error_handler);
233 signal(SIGFPE, error_handler);
234 signal(SIGSEGV, error_handler);
235 signal(SIGINT, error_handler);
236 signal(SIGTERM, error_handler);
239 // Determine path of binary
242 string binpath = os::binpath();
243 string binname = os::binname();
244 string fullbinname = MakeAbsPath(binname, binpath);
246 if (binpath.empty()) {
247 lyxerr << _("Warning: could not determine path of binary.")
249 << _("If you have problems, try starting LyX with an absolute path.")
252 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
253 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
256 // Determine system directory.
259 // Directories are searched in this order:
260 // 1) -sysdir command line parameter
261 // 2) LYX_DIR_14x environment variable
262 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
263 // 4) <path of binary>/../share/<name of binary>/
264 // 4a) repeat 4 after following the Symlink if <path of
265 // binary> is a symbolic link.
266 // 5) hardcoded lyx_dir
267 // The directory is checked for the presence of the file
268 // "chkconfig.ltx", and if that is present, the directory
269 // is accepted as the system directory.
270 // If no chkconfig.ltx file is found, a warning is given,
271 // and the hardcoded lyx_dir is used.
273 // If we had a command line switch, system_lyxdir is already set
275 if (!system_lyxdir.empty())
276 searchpath = MakeAbsPath(system_lyxdir) + ';';
278 string const lyxdir = GetEnvPath("LYX_DIR_14x");
280 if (!lyxdir.empty()) {
281 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
282 searchpath += lyxdir + ';';
285 string fullbinpath = binpath;
286 FileInfo file(fullbinname, true);
288 lyxerr[Debug::INIT] << "binary is a link" << endl;
290 if (LyXReadLink(fullbinname, link, true)) {
291 // Path of binary/../share/name of binary/
292 searchpath += NormalizePath(AddPath(binpath,
294 + OnlyFilename(binname));
297 binpath = MakeAbsPath(OnlyPath(fullbinpath));
303 // Path of binary/../share/name of binary/
304 searchpath += NormalizePath(AddPath(binpath, "../share/") +
305 OnlyFilename(binname)) + ';';
308 FileInfo file(fullbinpath, true);
309 followlink = file.isLink();
311 lyxerr[Debug::INIT] << " directory " << fullbinpath
312 << " is a link" << endl;
314 if (LyXReadLink(fullbinpath, link, true)) {
316 binpath = MakeAbsPath(OnlyPath(fullbinpath));
322 } while (followlink);
324 // <path of binary>/TOP_SRCDIR/lib
325 build_lyxdir = MakeAbsPath("../lib", binpath);
326 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
327 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
329 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
330 "place... yes" << endl;
333 << "Checking whether LyX is run in place... no"
335 build_lyxdir.erase();
339 searchpath += LYX_DIR;
341 lyxerr[Debug::INIT] << "System directory search path: "
342 << searchpath << endl;
344 string const filename = "chkconfig.ltx";
345 string const temp = FileOpenSearch(searchpath, filename, string());
346 system_lyxdir = OnlyPath(temp);
348 // Reduce "path/../path" stuff out of system directory
349 system_lyxdir = NormalizePath(system_lyxdir);
351 bool path_shown = false;
353 // Warn if environment variable is set, but unusable
354 if (!lyxdir.empty()) {
355 if (system_lyxdir != NormalizePath(lyxdir)) {
356 lyxerr <<_("LYX_DIR_14x environment variable no good.")
358 << _("System directory set to: ")
359 << system_lyxdir << endl;
364 // Warn the user if we couldn't find "chkconfig.ltx"
365 if (system_lyxdir == "./") {
366 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
367 <<_("Try the '-sysdir' command line parameter or ")
368 <<_("set the environment variable LYX_DIR_14x to the "
369 "LyX system directory ")
370 << _("containing the file `chkconfig.ltx'.") << endl;
372 FileInfo fi(LYX_DIR);
374 lyxerr << "Couldn't even find the default LYX_DIR." << endl
375 << "Giving up." << endl;
378 lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
381 lyxerr << _("Expect problems.") << endl;
383 system_lyxdir = LYX_DIR;
388 lyxerr[Debug::INIT] << "System directory: '"
389 << system_lyxdir << '\'' << endl;
392 // Determine user lyx-dir
395 // Directories are searched in this order:
396 // 1) -userdir command line parameter
397 // 2) LYX_USERDIR_14x environment variable
398 // 3) $HOME/.<name of binary>
400 // If we had a command line switch, user_lyxdir is already set
401 bool explicit_userdir = true;
402 if (user_lyxdir.empty()) {
404 // LYX_USERDIR_14x environment variable
405 user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
408 if (user_lyxdir.empty())
409 user_lyxdir = AddPath(GetEnvPath("HOME"),
410 string(".") + PACKAGE);
411 explicit_userdir = false;
414 lyxerr[Debug::INIT] << "User LyX directory: '"
415 << user_lyxdir << '\'' << endl;
417 // Check that user LyX directory is ok. We don't do that if
418 // running in batch mode.
420 queryUserLyXDir(explicit_userdir);
425 // Disable gui when easyparse says so
426 lyx_gui::use_gui = gui;
428 if (lyxrc.template_path.empty()) {
429 lyxrc.template_path = AddPath(system_lyxdir, "templates");
432 if (lyxrc.lastfiles.empty()) {
433 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
436 if (lyxrc.roman_font_name.empty())
437 lyxrc.roman_font_name = lyx_gui::roman_font_name();
438 if (lyxrc.sans_font_name.empty())
439 lyxrc.sans_font_name = lyx_gui::sans_font_name();
440 if (lyxrc.typewriter_font_name.empty())
441 lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
444 // Read configuration files
447 readRcFile("lyxrc.defaults");
448 system_lyxrc = lyxrc;
449 system_formats = formats;
450 system_converters = converters;
451 system_lcolor = lcolor;
453 string prefsfile = "preferences";
454 // back compatibility to lyxs < 1.1.6
455 if (LibFileSearch(string(), prefsfile).empty())
457 if (!LibFileSearch(string(), prefsfile).empty())
458 readRcFile(prefsfile);
460 readEncodingsFile("encodings");
461 readLanguagesFile("languages");
464 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
467 // Ensure that we have really read a bind file, so that LyX is
469 lyxrc.readBindFileIfNeeded();
472 readUIFile(lyxrc.ui_file);
474 if (lyxerr.debugging(Debug::LYXRC))
477 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
478 system_tempdir = os::getTmpDir();
479 if (lyxerr.debugging(Debug::INIT)) {
480 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
483 lyxerr[Debug::INIT] << "Reading lastfiles `"
484 << lyxrc.lastfiles << "'..." << endl;
485 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
486 lyxrc.check_lastfiles,
487 lyxrc.num_lastfiles));
491 void LyX::defaultKeyBindings(kb_keymap * kbmap)
493 kbmap->bind("Right", LFUN_RIGHT);
494 kbmap->bind("Left", LFUN_LEFT);
495 kbmap->bind("Up", LFUN_UP);
496 kbmap->bind("Down", LFUN_DOWN);
498 kbmap->bind("Tab", LFUN_CELL_FORWARD);
499 kbmap->bind("ISO_Left_Tab", LFUN_CELL_FORWARD); // jbl 2001-23-02
501 kbmap->bind("Home", LFUN_HOME);
502 kbmap->bind("End", LFUN_END);
503 kbmap->bind("Prior", LFUN_PRIOR);
504 kbmap->bind("Next", LFUN_NEXT);
506 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
507 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
509 kbmap->bind("Delete", LFUN_DELETE);
510 kbmap->bind("BackSpace", LFUN_BACKSPACE);
512 // sub- and superscript -MV
513 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
514 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
516 // kbmap->bindings to enable the use of the numeric keypad
518 //kbmap->bind("KP_0", LFUN_SELFINSERT);
519 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
520 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
521 //kbmap->bind("KP_1", LFUN_SELFINSERT);
522 //kbmap->bind("KP_2", LFUN_SELFINSERT);
523 //kbmap->bind("KP_3", LFUN_SELFINSERT);
524 //kbmap->bind("KP_4", LFUN_SELFINSERT);
525 //kbmap->bind("KP_5", LFUN_SELFINSERT);
526 //kbmap->bind("KP_6", LFUN_SELFINSERT);
527 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
528 //kbmap->bind("KP_7", LFUN_SELFINSERT);
529 //kbmap->bind("KP_8", LFUN_SELFINSERT);
530 //kbmap->bind("KP_9", LFUN_SELFINSERT);
531 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
532 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
533 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
534 kbmap->bind("KP_Right", LFUN_RIGHT);
535 kbmap->bind("KP_Left", LFUN_LEFT);
536 kbmap->bind("KP_Up", LFUN_UP);
537 kbmap->bind("KP_Down", LFUN_DOWN);
538 kbmap->bind("KP_Home", LFUN_HOME);
539 kbmap->bind("KP_End", LFUN_END);
540 kbmap->bind("KP_Prior", LFUN_PRIOR);
541 kbmap->bind("KP_Next", LFUN_NEXT);
543 kbmap->bind("C-Tab", LFUN_CELL_SPLIT); // ale970515
544 kbmap->bind("S-Tab", LFUN_CELL_BACKWARD); // jug20000522
545 kbmap->bind("S-ISO_Left_Tab", LFUN_CELL_BACKWARD); // jbl 2001-23-02
549 void LyX::emergencyCleanup()
551 // what to do about tmpfiles is non-obvious. we would
552 // like to delete any we find, but our lyxdir might
553 // contain documents etc. which might be helpful on
556 bufferlist.emergencyWriteAll();
558 lyxserver->emergencyCleanup();
562 void LyX::deadKeyBindings(kb_keymap * kbmap)
564 // bindKeyings for transparent handling of deadkeys
565 // The keysyms are gotten from XFree86 X11R6
566 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
567 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
568 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
569 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
570 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
571 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
572 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
573 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
574 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
575 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
576 // nothing with this name
577 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
578 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
579 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
580 // nothing with this name either...
581 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
582 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
583 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
584 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
588 void LyX::queryUserLyXDir(bool explicit_userdir)
590 string const configure_script = AddName(system_lyxdir, "configure");
592 // Does user directory exist?
593 FileInfo fileInfo(user_lyxdir);
594 if (fileInfo.isOK() && fileInfo.isDir()) {
596 FileInfo script(configure_script);
597 FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults"));
598 if (defaults.isOK() && script.isOK()
599 && defaults.getModificationTime() < script.getModificationTime()) {
600 lyxerr << _("LyX: reconfiguring user directory")
603 ::system(configure_script.c_str());
604 lyxerr << "LyX: " << _("Done!") << endl;
609 first_start = !explicit_userdir;
611 lyxerr << bformat(_("LyX: Creating directory %1$s"
612 " and running configure..."), user_lyxdir) << endl;
614 if (!createDirectory(user_lyxdir, 0755)) {
615 // Failed, let's use $HOME instead.
616 user_lyxdir = GetEnvPath("HOME");
617 lyxerr << bformat(_("Failed. Will use %1$s instead."),
618 user_lyxdir) << endl;
622 // Run configure in user lyx directory
624 ::system(configure_script.c_str());
625 lyxerr << "LyX: " << _("Done!") << endl;
629 void LyX::readRcFile(string const & name)
631 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
633 string const lyxrc_path = LibFileSearch(string(), name);
634 if (!lyxrc_path.empty()) {
636 lyxerr[Debug::INIT] << "Found " << name
637 << " in " << lyxrc_path << endl;
639 if (lyxrc.read(lyxrc_path) >= 0)
647 // Read the ui file `name'
648 void LyX::readUIFile(string const & name)
658 struct keyword_item uitags[ui_last - 1] = {
659 { "include", ui_include },
660 { "menuset", ui_menuset },
661 { "toolbar", ui_toolbar },
662 { "toolbars", ui_toolbars }
665 // Ensure that a file is read only once (prevents include loops)
666 static std::list<string> uifiles;
667 std::list<string>::const_iterator it = uifiles.begin();
668 std::list<string>::const_iterator end = uifiles.end();
669 it = std::find(it, end, name);
671 lyxerr[Debug::INIT] << "UI file '" << name
672 << "' has been read already. "
673 << "Is this an include loop?"
678 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
680 string const ui_path = LibFileSearch("ui", name, "ui");
682 if (ui_path.empty()) {
683 lyxerr[Debug::INIT] << "Could not find " << name << endl;
687 uifiles.push_back(name);
689 lyxerr[Debug::INIT] << "Found " << name
690 << " in " << ui_path << endl;
691 LyXLex lex(uitags, ui_last - 1);
692 lex.setFile(ui_path);
694 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
698 if (lyxerr.debugging(Debug::PARSER))
699 lex.printTable(lyxerr);
705 string const file = lex.getString();
710 menubackend.read(lex);
714 toolbarbackend.read(lex);
718 toolbarbackend.readToolbars(lex);
722 if (!rtrim(lex.getString()).empty())
723 lex.printError("LyX::ReadUIFile: "
724 "Unknown menu tag: `$$Token'");
731 // Read the languages file `name'
732 void LyX::readLanguagesFile(string const & name)
734 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
736 string const lang_path = LibFileSearch(string(), name);
737 if (lang_path.empty()) {
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()) {
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);
774 lyxerr << bformat(_("Setting debug level to %1$s"), arg) << endl;
776 lyxerr.level(Debug::value(arg));
777 Debug::showLevel(lyxerr, lyxerr.level());
782 int parse_help(string const &, string const &)
785 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
786 "Command line switches (case sensitive):\n"
787 "\t-help summarize LyX usage\n"
788 "\t-userdir dir try to set user directory to dir\n"
789 "\t-sysdir dir try to set system directory to dir\n"
790 "\t-geometry WxH+X+Y set geometry of the main window\n"
791 "\t-dbg feature[,feature]...\n"
792 " select the features to debug.\n"
793 " Type `lyx -dbg' to see the list of features\n"
794 "\t-x [--execute] command\n"
795 " where command is a lyx command.\n"
796 "\t-e [--export] fmt\n"
797 " where fmt is the export format of choice.\n"
798 "\t-i [--import] fmt file.xxx\n"
799 " where fmt is the import format of choice\n"
800 " and file.xxx is the file to be imported.\n"
801 "\t-version summarize version and build info\n"
802 "Check the LyX man page for more details.") << endl;
807 int parse_version(string const &, string const &)
809 lyxerr << "LyX " << lyx_version
810 << " of " << lyx_release_date << endl;
811 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
813 lyxerr << lyx_version_info << endl;
818 int parse_sysdir(string const & arg, string const &)
821 lyxerr << _("Missing directory for -sysdir switch") << endl;
828 int parse_userdir(string const & arg, string const &)
831 lyxerr << _("Missing directory for -userdir switch") << endl;
838 int parse_execute(string const & arg, string const &)
841 lyxerr << _("Missing command string after --execute switch") << endl;
845 // Argh. Setting gui to false segfaults..
846 // FIXME: when ? how ?
851 int parse_export(string const & type, string const &)
854 lyxerr << _("Missing file type [eg latex, ps...] after "
855 "--export switch") << endl;
858 batch = "buffer-export " + type;
863 int parse_import(string const & type, string const & file)
866 lyxerr << _("Missing file type [eg latex, ps...] after "
867 "--import switch") << endl;
871 lyxerr << _("Missing filename for --import") << endl;
875 batch = "buffer-import " + type + ' ' + file;
882 bool LyX::easyParse(int & argc, char * argv[])
884 std::map<string, cmd_helper> cmdmap;
886 cmdmap["-dbg"] = parse_dbg;
887 cmdmap["-help"] = parse_help;
888 cmdmap["--help"] = parse_help;
889 cmdmap["-version"] = parse_version;
890 cmdmap["--version"] = parse_version;
891 cmdmap["-sysdir"] = parse_sysdir;
892 cmdmap["-userdir"] = parse_userdir;
893 cmdmap["-x"] = parse_execute;
894 cmdmap["--execute"] = parse_execute;
895 cmdmap["-e"] = parse_export;
896 cmdmap["--export"] = parse_export;
897 cmdmap["-i"] = parse_import;
898 cmdmap["--import"] = parse_import;
900 for (int i = 1; i < argc; ++i) {
901 std::map<string, cmd_helper>::const_iterator it
902 = cmdmap.find(argv[i]);
904 // don't complain if not found - may be parsed later
905 if (it == cmdmap.end())
908 string arg((i + 1 < argc) ? argv[i + 1] : "");
909 string arg2((i + 2 < argc) ? argv[i + 2] : "");
911 int const remove = 1 + it->second(arg, arg2);
913 // Now, remove used arguments by shifting
914 // the following ones remove places down.
916 for (int j = i; j < argc; ++j)
917 argv[j] = argv[j + remove];
921 batch_command = batch;