3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
6 * \author Lars Gullik Bjønnes
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 lyx::graphics::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()) {
144 lyxerr[Debug::INIT] << "About to handle -x '"
145 << batch_command << '\'' << endl;
147 Buffer * last_loaded = 0;
149 vector<string>::const_iterator it = files.begin();
150 vector<string>::const_iterator end = files.end();
152 for (; it != end; ++it) {
153 // get absolute path of file and add ".lyx" to
154 // the filename if necessary
155 string s = FileSearch(string(), *it, "lyx");
157 last_loaded = newFile(*it, "");
159 last_loaded = bufferlist.newBuffer(s, false);
160 last_loaded->error.connect(boost::bind(&LyX::printError, this, _1));
161 if (!loadLyXFile(last_loaded, s)) {
162 bufferlist.release(last_loaded);
163 last_loaded = newFile(*it, string());
168 // try to dispatch to last loaded buffer first
170 bool success = false;
171 if (last_loaded->dispatch(batch_command, &success)) {
176 files.clear(); // the files are already loaded
179 lyx_gui::start(batch_command, files);
185 static void error_handler(int err_sig)
189 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
195 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
198 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
200 "Sorry, you have found a bug in LyX. "
201 "Please read the bug-reporting instructions "
202 "in Help->Introduction and send us a bug report, "
203 "if necessary. Thanks !" << endl;
210 // Deinstall the signal handlers
211 signal(SIGHUP, SIG_DFL);
212 signal(SIGINT, SIG_DFL);
213 signal(SIGFPE, SIG_DFL);
214 signal(SIGSEGV, SIG_DFL);
215 signal(SIGTERM, SIG_DFL);
217 LyX::emergencyCleanup();
219 lyxerr << "Bye." << endl;
220 if (err_sig!= SIGHUP &&
221 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
222 lyx::support::abort();
229 void LyX::printError(ErrorItem const & ei)
231 std::cerr << _("LyX: ") << ei.error
232 << ':' << ei.description << std::endl;
237 void LyX::init(bool gui)
239 signal(SIGHUP, error_handler);
240 signal(SIGFPE, error_handler);
241 signal(SIGSEGV, error_handler);
242 signal(SIGINT, error_handler);
243 signal(SIGTERM, error_handler);
246 // Determine path of binary
249 string binpath = os::binpath();
250 string binname = os::binname();
251 string fullbinname = MakeAbsPath(binname, binpath);
253 if (binpath.empty()) {
254 lyxerr << _("Warning: could not determine path of binary.")
256 << _("If you have problems, try starting LyX with an absolute path.")
259 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
260 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
263 // Determine system directory.
266 // Directories are searched in this order:
267 // 1) -sysdir command line parameter
268 // 2) LYX_DIR_14x environment variable
269 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
270 // 4) <path of binary>/../share/<name of binary>/
271 // 4a) repeat 4 after following the Symlink if <path of
272 // binary> is a symbolic link.
273 // 5) hardcoded lyx_dir
274 // The directory is checked for the presence of the file
275 // "chkconfig.ltx", and if that is present, the directory
276 // is accepted as the system directory.
277 // If no chkconfig.ltx file is found, a warning is given,
278 // and the hardcoded lyx_dir is used.
280 // If we had a command line switch, system_lyxdir is already set
282 if (!system_lyxdir.empty())
283 searchpath = MakeAbsPath(system_lyxdir) + ';';
285 string const lyxdir = GetEnvPath("LYX_DIR_14x");
287 if (!lyxdir.empty()) {
288 lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
289 searchpath += lyxdir + ';';
292 string fullbinpath = binpath;
293 FileInfo file(fullbinname, true);
295 lyxerr[Debug::INIT] << "binary is a link" << endl;
297 if (LyXReadLink(fullbinname, link, true)) {
298 // Path of binary/../share/name of binary/
299 searchpath += NormalizePath(AddPath(binpath,
301 + OnlyFilename(binname));
304 binpath = MakeAbsPath(OnlyPath(fullbinpath));
310 // Path of binary/../share/name of binary/
311 searchpath += NormalizePath(AddPath(binpath, "../share/") +
312 OnlyFilename(binname)) + ';';
315 FileInfo file(fullbinpath, true);
316 followlink = file.isLink();
318 lyxerr[Debug::INIT] << " directory " << fullbinpath
319 << " is a link" << endl;
321 if (LyXReadLink(fullbinpath, link, true)) {
323 binpath = MakeAbsPath(OnlyPath(fullbinpath));
329 } while (followlink);
331 // <path of binary>/TOP_SRCDIR/lib
332 build_lyxdir = MakeAbsPath("../lib", binpath);
333 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
334 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
336 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
337 "place... yes" << endl;
340 << "Checking whether LyX is run in place... no"
342 build_lyxdir.erase();
346 searchpath += LYX_DIR;
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_14x 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_14x 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 << bformat(_("Using built-in default %1$s but expect problems."),
388 lyxerr << _("Expect problems.") << endl;
390 system_lyxdir = LYX_DIR;
395 lyxerr[Debug::INIT] << "System directory: '"
396 << system_lyxdir << '\'' << endl;
399 // Determine user lyx-dir
402 // Directories are searched in this order:
403 // 1) -userdir command line parameter
404 // 2) LYX_USERDIR_14x environment variable
405 // 3) $HOME/.<name of binary>
407 // If we had a command line switch, user_lyxdir is already set
408 bool explicit_userdir = true;
409 if (user_lyxdir.empty()) {
411 // LYX_USERDIR_14x environment variable
412 user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
415 if (user_lyxdir.empty())
416 user_lyxdir = AddPath(GetEnvPath("HOME"),
417 string(".") + PACKAGE);
418 explicit_userdir = false;
421 lyxerr[Debug::INIT] << "User LyX directory: '"
422 << user_lyxdir << '\'' << endl;
424 // Check that user LyX directory is ok. We don't do that if
425 // running in batch mode.
427 queryUserLyXDir(explicit_userdir);
432 // Disable gui when easyparse says so
433 lyx_gui::use_gui = gui;
435 if (lyxrc.template_path.empty()) {
436 lyxrc.template_path = AddPath(system_lyxdir, "templates");
439 if (lyxrc.lastfiles.empty()) {
440 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
443 if (lyxrc.roman_font_name.empty())
444 lyxrc.roman_font_name = lyx_gui::roman_font_name();
445 if (lyxrc.sans_font_name.empty())
446 lyxrc.sans_font_name = lyx_gui::sans_font_name();
447 if (lyxrc.typewriter_font_name.empty())
448 lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
451 // Read configuration files
454 readRcFile("lyxrc.defaults");
455 system_lyxrc = lyxrc;
456 system_formats = formats;
457 system_converters = converters;
458 system_lcolor = lcolor;
460 string prefsfile = "preferences";
461 // back compatibility to lyxs < 1.1.6
462 if (LibFileSearch(string(), prefsfile).empty())
464 if (!LibFileSearch(string(), prefsfile).empty())
465 readRcFile(prefsfile);
467 readEncodingsFile("encodings");
468 readLanguagesFile("languages");
471 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
474 // Ensure that we have really read a bind file, so that LyX is
476 lyxrc.readBindFileIfNeeded();
479 readUIFile(lyxrc.ui_file);
481 if (lyxerr.debugging(Debug::LYXRC))
484 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
485 system_tempdir = os::getTmpDir();
486 if (lyxerr.debugging(Debug::INIT)) {
487 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
490 lyxerr[Debug::INIT] << "Reading lastfiles `"
491 << lyxrc.lastfiles << "'..." << endl;
492 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
493 lyxrc.check_lastfiles,
494 lyxrc.num_lastfiles));
498 void LyX::defaultKeyBindings(kb_keymap * kbmap)
500 kbmap->bind("Right", LFUN_RIGHT);
501 kbmap->bind("Left", LFUN_LEFT);
502 kbmap->bind("Up", LFUN_UP);
503 kbmap->bind("Down", LFUN_DOWN);
505 kbmap->bind("Tab", LFUN_CELL_FORWARD);
506 kbmap->bind("ISO_Left_Tab", LFUN_CELL_FORWARD); // jbl 2001-23-02
508 kbmap->bind("Home", LFUN_HOME);
509 kbmap->bind("End", LFUN_END);
510 kbmap->bind("Prior", LFUN_PRIOR);
511 kbmap->bind("Next", LFUN_NEXT);
513 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
514 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
516 kbmap->bind("Delete", LFUN_DELETE);
517 kbmap->bind("BackSpace", LFUN_BACKSPACE);
519 // sub- and superscript -MV
520 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
521 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
523 // kbmap->bindings to enable the use of the numeric keypad
525 //kbmap->bind("KP_0", LFUN_SELFINSERT);
526 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
527 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
528 //kbmap->bind("KP_1", LFUN_SELFINSERT);
529 //kbmap->bind("KP_2", LFUN_SELFINSERT);
530 //kbmap->bind("KP_3", LFUN_SELFINSERT);
531 //kbmap->bind("KP_4", LFUN_SELFINSERT);
532 //kbmap->bind("KP_5", LFUN_SELFINSERT);
533 //kbmap->bind("KP_6", LFUN_SELFINSERT);
534 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
535 //kbmap->bind("KP_7", LFUN_SELFINSERT);
536 //kbmap->bind("KP_8", LFUN_SELFINSERT);
537 //kbmap->bind("KP_9", LFUN_SELFINSERT);
538 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
539 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
540 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
541 kbmap->bind("KP_Right", LFUN_RIGHT);
542 kbmap->bind("KP_Left", LFUN_LEFT);
543 kbmap->bind("KP_Up", LFUN_UP);
544 kbmap->bind("KP_Down", LFUN_DOWN);
545 kbmap->bind("KP_Home", LFUN_HOME);
546 kbmap->bind("KP_End", LFUN_END);
547 kbmap->bind("KP_Prior", LFUN_PRIOR);
548 kbmap->bind("KP_Next", LFUN_NEXT);
550 kbmap->bind("C-Tab", LFUN_CELL_SPLIT); // ale970515
551 kbmap->bind("S-Tab", LFUN_CELL_BACKWARD); // jug20000522
552 kbmap->bind("S-ISO_Left_Tab", LFUN_CELL_BACKWARD); // jbl 2001-23-02
556 void LyX::emergencyCleanup()
558 // what to do about tmpfiles is non-obvious. we would
559 // like to delete any we find, but our lyxdir might
560 // contain documents etc. which might be helpful on
563 bufferlist.emergencyWriteAll();
565 lyxserver->emergencyCleanup();
569 void LyX::deadKeyBindings(kb_keymap * kbmap)
571 // bindKeyings for transparent handling of deadkeys
572 // The keysyms are gotten from XFree86 X11R6
573 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
574 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
575 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
576 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
577 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
578 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
579 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
580 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
581 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
582 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
583 // nothing with this name
584 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
585 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
586 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
587 // nothing with this name either...
588 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
589 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
590 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
591 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
595 void LyX::queryUserLyXDir(bool explicit_userdir)
597 string const configure_script = AddName(system_lyxdir, "configure");
599 // Does user directory exist?
600 FileInfo fileInfo(user_lyxdir);
601 if (fileInfo.isOK() && fileInfo.isDir()) {
603 FileInfo script(configure_script);
604 FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults"));
605 if (defaults.isOK() && script.isOK()
606 && defaults.getModificationTime() < script.getModificationTime()) {
607 lyxerr << _("LyX: reconfiguring user directory")
610 ::system(configure_script.c_str());
611 lyxerr << "LyX: " << _("Done!") << endl;
616 first_start = !explicit_userdir;
618 lyxerr << bformat(_("LyX: Creating directory %1$s"
619 " and running configure..."), user_lyxdir) << endl;
621 if (!createDirectory(user_lyxdir, 0755)) {
622 // Failed, let's use $HOME instead.
623 user_lyxdir = GetEnvPath("HOME");
624 lyxerr << bformat(_("Failed. Will use %1$s instead."),
625 user_lyxdir) << endl;
629 // Run configure in user lyx directory
631 ::system(configure_script.c_str());
632 lyxerr << "LyX: " << _("Done!") << endl;
636 void LyX::readRcFile(string const & name)
638 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
640 string const lyxrc_path = LibFileSearch(string(), name);
641 if (!lyxrc_path.empty()) {
643 lyxerr[Debug::INIT] << "Found " << name
644 << " in " << lyxrc_path << endl;
646 if (lyxrc.read(lyxrc_path) >= 0)
654 // Read the ui file `name'
655 void LyX::readUIFile(string const & name)
665 struct keyword_item uitags[ui_last - 1] = {
666 { "include", ui_include },
667 { "menuset", ui_menuset },
668 { "toolbar", ui_toolbar },
669 { "toolbars", ui_toolbars }
672 // Ensure that a file is read only once (prevents include loops)
673 static std::list<string> uifiles;
674 std::list<string>::const_iterator it = uifiles.begin();
675 std::list<string>::const_iterator end = uifiles.end();
676 it = std::find(it, end, name);
678 lyxerr[Debug::INIT] << "UI file '" << name
679 << "' has been read already. "
680 << "Is this an include loop?"
685 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
687 string const ui_path = LibFileSearch("ui", name, "ui");
689 if (ui_path.empty()) {
690 lyxerr[Debug::INIT] << "Could not find " << name << endl;
694 uifiles.push_back(name);
696 lyxerr[Debug::INIT] << "Found " << name
697 << " in " << ui_path << endl;
698 LyXLex lex(uitags, ui_last - 1);
699 lex.setFile(ui_path);
701 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
705 if (lyxerr.debugging(Debug::PARSER))
706 lex.printTable(lyxerr);
712 string const file = lex.getString();
717 menubackend.read(lex);
721 toolbarbackend.read(lex);
725 toolbarbackend.readToolbars(lex);
729 if (!rtrim(lex.getString()).empty())
730 lex.printError("LyX::ReadUIFile: "
731 "Unknown menu tag: `$$Token'");
738 // Read the languages file `name'
739 void LyX::readLanguagesFile(string const & name)
741 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
743 string const lang_path = LibFileSearch(string(), name);
744 if (lang_path.empty()) {
748 languages.read(lang_path);
752 // Read the encodings file `name'
753 void LyX::readEncodingsFile(string const & name)
755 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
757 string const enc_path = LibFileSearch(string(), name);
758 if (enc_path.empty()) {
762 encodings.read(enc_path);
771 /// return the the number of arguments consumed
772 typedef boost::function<int(string const &, string const &)> cmd_helper;
774 int parse_dbg(string const & arg, string const &)
777 lyxerr << _("List of supported debug flags:") << endl;
778 Debug::showTags(lyxerr);
781 lyxerr << bformat(_("Setting debug level to %1$s"), arg) << endl;
783 lyxerr.level(Debug::value(arg));
784 Debug::showLevel(lyxerr, lyxerr.level());
789 int parse_help(string const &, string const &)
792 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
793 "Command line switches (case sensitive):\n"
794 "\t-help summarize LyX usage\n"
795 "\t-userdir dir try to set user directory to dir\n"
796 "\t-sysdir dir try to set system directory to dir\n"
797 "\t-geometry WxH+X+Y set geometry of the main window\n"
798 "\t-dbg feature[,feature]...\n"
799 " select the features to debug.\n"
800 " Type `lyx -dbg' to see the list of features\n"
801 "\t-x [--execute] command\n"
802 " where command is a lyx command.\n"
803 "\t-e [--export] fmt\n"
804 " where fmt is the export format of choice.\n"
805 "\t-i [--import] fmt file.xxx\n"
806 " where fmt is the import format of choice\n"
807 " and file.xxx is the file to be imported.\n"
808 "\t-version summarize version and build info\n"
809 "Check the LyX man page for more details.") << endl;
814 int parse_version(string const &, string const &)
816 lyxerr << "LyX " << lyx_version
817 << " of " << lyx_release_date << endl;
818 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
820 lyxerr << lyx_version_info << endl;
825 int parse_sysdir(string const & arg, string const &)
828 lyxerr << _("Missing directory for -sysdir switch") << endl;
835 int parse_userdir(string const & arg, string const &)
838 lyxerr << _("Missing directory for -userdir switch") << endl;
845 int parse_execute(string const & arg, string const &)
848 lyxerr << _("Missing command string after --execute switch") << endl;
852 // Argh. Setting gui to false segfaults..
853 // FIXME: when ? how ?
858 int parse_export(string const & type, string const &)
861 lyxerr << _("Missing file type [eg latex, ps...] after "
862 "--export switch") << endl;
865 batch = "buffer-export " + type;
870 int parse_import(string const & type, string const & file)
873 lyxerr << _("Missing file type [eg latex, ps...] after "
874 "--import switch") << endl;
878 lyxerr << _("Missing filename for --import") << endl;
882 batch = "buffer-import " + type + ' ' + file;
889 bool LyX::easyParse(int & argc, char * argv[])
891 std::map<string, cmd_helper> cmdmap;
893 cmdmap["-dbg"] = parse_dbg;
894 cmdmap["-help"] = parse_help;
895 cmdmap["--help"] = parse_help;
896 cmdmap["-version"] = parse_version;
897 cmdmap["--version"] = parse_version;
898 cmdmap["-sysdir"] = parse_sysdir;
899 cmdmap["-userdir"] = parse_userdir;
900 cmdmap["-x"] = parse_execute;
901 cmdmap["--execute"] = parse_execute;
902 cmdmap["-e"] = parse_export;
903 cmdmap["--export"] = parse_export;
904 cmdmap["-i"] = parse_import;
905 cmdmap["--import"] = parse_import;
907 for (int i = 1; i < argc; ++i) {
908 std::map<string, cmd_helper>::const_iterator it
909 = cmdmap.find(argv[i]);
911 // don't complain if not found - may be parsed later
912 if (it == cmdmap.end())
915 string arg((i + 1 < argc) ? argv[i + 1] : "");
916 string arg2((i + 2 < argc) ? argv[i + 2] : "");
918 int const remove = 1 + it->second(arg, arg2);
920 // Now, remove used arguments by shifting
921 // the following ones remove places down.
923 for (int j = i; j < argc; ++j)
924 argv[j] = argv[j + remove];
928 batch_command = batch;