3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
21 #include "buffer_funcs.h"
22 #include "bufferlist.h"
23 #include "converter.h"
26 #include "errorlist.h"
31 #include "lastfiles.h"
36 #include "lyxtextclasslist.h"
37 #include "lyxserver.h"
38 #include "MenuBackend.h"
40 #include "ToolbarBackend.h"
42 #include "mathed/math_inset.h"
44 #include "frontends/Alert.h"
45 #include "frontends/lyx_gui.h"
46 #include "frontends/LyXView.h"
48 #include "support/FileInfo.h"
49 #include "support/filetools.h"
50 #include "support/lyxlib.h"
51 #include "support/os.h"
52 #include "support/package.h"
53 #include "support/path.h"
55 #include <boost/bind.hpp>
60 using lyx::support::AddName;
61 using lyx::support::AddPath;
62 using lyx::support::bformat;
63 using lyx::support::createDirectory;
64 using lyx::support::createLyXTmpDir;
65 using lyx::support::FileInfo;
66 using lyx::support::FileSearch;
67 using lyx::support::GetEnv;
68 using lyx::support::i18nLibFileSearch;
69 using lyx::support::LibFileSearch;
70 using lyx::support::package;
71 using lyx::support::Path;
72 using lyx::support::QuoteName;
73 using lyx::support::rtrim;
75 namespace os = lyx::support::os;
81 #ifndef CXX_GLOBAL_CSTD
88 extern void QuitLyX();
90 extern LyXServer * lyxserver;
92 // This is the global bufferlist object
93 BufferList bufferlist;
95 // convenient to have it here.
96 boost::scoped_ptr<kb_keymap> toplevel_keymap;
100 // Filled with the command line arguments "foo" of "-sysdir foo" or
102 string cl_system_support;
103 string cl_user_support;
106 void showFileError(string const & error)
108 Alert::warning(_("Could not read configuration file"),
109 bformat(_("Error while reading the configuration file\n%1$s.\n"
110 "Please check your installation."), error));
117 boost::scoped_ptr<LyX> LyX::singleton_;
119 void LyX::exec(int & argc, char * argv[])
121 BOOST_ASSERT(!singleton_.get());
122 // We must return from this before launching the gui so that
123 // other parts of the code can access singleton_ through
124 // LyX::ref and LyX::cref.
125 singleton_.reset(new LyX);
126 // Start the real execution loop.
127 singleton_->priv_exec(argc, argv);
133 BOOST_ASSERT(singleton_.get());
134 return *singleton_.get();
138 LyX const & LyX::cref()
140 BOOST_ASSERT(singleton_.get());
141 return *singleton_.get();
150 LastFiles & LyX::lastfiles()
152 BOOST_ASSERT(lastfiles_.get());
153 return *lastfiles_.get();
157 LastFiles const & LyX::lastfiles() const
159 BOOST_ASSERT(lastfiles_.get());
160 return *lastfiles_.get();
164 void LyX::addLyXView(boost::shared_ptr<LyXView> const & lyxview)
166 views_.push_back(lyxview);
170 Buffer const * const LyX::updateInset(InsetBase const * inset) const
175 Buffer const * buffer_ptr = 0;
176 ViewList::const_iterator it = views_.begin();
177 ViewList::const_iterator const end = views_.end();
178 for (; it != end; ++it) {
179 Buffer const * ptr = (*it)->updateInset(inset);
187 void LyX::priv_exec(int & argc, char * argv[])
189 // Here we need to parse the command line. At least
190 // we need to parse for "-dbg" and "-help"
191 bool const want_gui = easyParse(argc, argv);
193 lyx::support::init_package(argv[0], cl_system_support, cl_user_support);
196 lyx_gui::parse_init(argc, argv);
198 // check for any spurious extra arguments
199 // other than documents
200 for (int argi = 1; argi < argc ; ++argi) {
201 if (argv[argi][0] == '-') {
202 lyxerr << bformat(_("Wrong command line option `%1$s'. Exiting."),
208 // Initialization of LyX (reads lyxrc and more)
209 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
211 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
214 lyx_gui::parse_lyxrc();
218 vector<string> files;
220 for (int argi = argc - 1; argi >= 1; --argi)
221 files.push_back(argv[argi]);
224 files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
226 // Execute batch commands if available
227 if (!batch_command.empty()) {
229 lyxerr[Debug::INIT] << "About to handle -x '"
230 << batch_command << '\'' << endl;
232 Buffer * last_loaded = 0;
234 vector<string>::const_iterator it = files.begin();
235 vector<string>::const_iterator end = files.end();
237 for (; it != end; ++it) {
238 // get absolute path of file and add ".lyx" to
239 // the filename if necessary
240 string s = FileSearch(string(), *it, "lyx");
242 last_loaded = newFile(*it, string(), true);
244 Buffer * buf = bufferlist.newBuffer(s, false);
245 buf->error.connect(boost::bind(&LyX::printError, this, _1));
246 if (loadLyXFile(buf, s))
249 bufferlist.release(buf);
253 // try to dispatch to last loaded buffer first
255 bool success = false;
256 if (last_loaded->dispatch(batch_command, &success)) {
261 files.clear(); // the files are already loaded
264 lyx_gui::start(batch_command, files);
270 static void error_handler(int err_sig)
272 // Throw away any signals other than the first one received.
273 static sig_atomic_t handling_error = false;
276 handling_error = true;
278 // We have received a signal indicating a fatal error, so
279 // try and save the data ASAP.
280 LyX::cref().emergencyCleanup();
282 // These lyxerr calls may or may not work:
284 // Signals are asynchronous, so the main program may be in a very
285 // fragile state when a signal is processed and thus while a signal
286 // handler function executes.
287 // In general, therefore, we should avoid performing any
288 // I/O operations or calling most library and system functions from
291 // This shouldn't matter here, however, as we've already invoked
295 lyxerr << "\nlyx: SIGHUP signal caught\nBye." << endl;
298 lyxerr << "\nlyx: SIGFPE signal caught\nBye." << endl;
301 lyxerr << "\nlyx: SIGSEGV signal caught\n"
302 "Sorry, you have found a bug in LyX. "
303 "Please read the bug-reporting instructions "
304 "in Help->Introduction and send us a bug report, "
305 "if necessary. Thanks !\nBye." << endl;
313 // Deinstall the signal handlers
314 signal(SIGHUP, SIG_DFL);
315 signal(SIGINT, SIG_DFL);
316 signal(SIGFPE, SIG_DFL);
317 signal(SIGSEGV, SIG_DFL);
318 signal(SIGTERM, SIG_DFL);
320 if (err_sig == SIGSEGV ||
321 (err_sig != SIGHUP && !GetEnv("LYXDEBUG").empty()))
322 lyx::support::abort();
329 void LyX::printError(ErrorItem const & ei)
331 std::cerr << _("LyX: ") << ei.error
332 << ':' << ei.description << std::endl;
337 void LyX::init(bool gui)
339 signal(SIGHUP, error_handler);
340 signal(SIGFPE, error_handler);
341 signal(SIGSEGV, error_handler);
342 signal(SIGINT, error_handler);
343 signal(SIGTERM, error_handler);
344 // SIGPIPE can be safely ignored.
346 #if !defined (USE_POSIX_PACKAGING)
347 // Add the directory containing the LyX executable to the path
348 // so that LyX can find things like reLyX.
349 if (package.build_support().empty()) {
350 vector<string> path = getEnvPath("PATH");
351 path.insert(path.begin(), package.binary_dir());
352 setEnvPath("PATH", path);
355 #if defined (USE_MACOSX_PACKAGING)
356 // This hard-coded nastiness should be moved into a LyXRC variable.
357 vector<string> path = getEnvPath("PATH");
358 path.insert(path.begin(), "/usr/local/teTeX/bin/powerpc-apple-darwin-current");
359 path.insert(path.begin(), "/usr/local/bin");
360 path.insert(path.begin(), "/sw/bin");
361 lyxerr[Debug::INIT] << "Running from LyX/Mac bundle. "
362 "Setting PATH to: " << GetEnv("PATH") << endl;
365 // Check that user LyX directory is ok. We don't do that if
366 // running in batch mode.
368 queryUserLyXDir(package().explicit_user_support());
373 // Disable gui when easyparse says so
374 lyx_gui::use_gui = gui;
376 lyxrc.tempdir_path = package().temp_dir();
377 lyxrc.document_path = package().document_dir();
379 if (lyxrc.template_path.empty()) {
380 lyxrc.template_path = AddPath(package().system_support(),
384 if (lyxrc.lastfiles.empty()) {
385 lyxrc.lastfiles = AddName(package().user_support(), "lastfiles");
388 if (lyxrc.roman_font_name.empty())
389 lyxrc.roman_font_name = lyx_gui::roman_font_name();
390 if (lyxrc.sans_font_name.empty())
391 lyxrc.sans_font_name = lyx_gui::sans_font_name();
392 if (lyxrc.typewriter_font_name.empty())
393 lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
396 // Read configuration files
399 readRcFile("lyxrc.defaults");
400 system_lyxrc = lyxrc;
401 system_formats = formats;
402 system_converters = converters;
403 system_movers = movers;
404 system_lcolor = lcolor;
406 string prefsfile = "preferences";
407 // back compatibility to lyxs < 1.1.6
408 if (LibFileSearch(string(), prefsfile).empty())
410 if (!LibFileSearch(string(), prefsfile).empty())
411 readRcFile(prefsfile);
413 readEncodingsFile("encodings");
414 readLanguagesFile("languages");
417 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
422 toplevel_keymap.reset(new kb_keymap);
423 defaultKeyBindings(toplevel_keymap.get());
424 toplevel_keymap->read(lyxrc.bind_file);
427 readUIFile(lyxrc.ui_file);
430 if (lyxerr.debugging(Debug::LYXRC))
433 package().document_dir() = lyxrc.document_path;
435 package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
436 if (package().temp_dir().empty()) {
437 Alert::error(_("Could not create temporary directory"),
438 bformat(_("Could not create a temporary directory in\n"
439 "%1$s. Make sure that this\n"
440 "path exists and is writable and try again."),
441 lyxrc.tempdir_path));
442 // createLyXTmpDir() tries sufficiently hard to create a
443 // usable temp dir, so the probability to come here is
444 // close to zero. We therefore don't try to overcome this
445 // problem with e.g. asking the user for a new path and
446 // trying again but simply exit.
450 if (lyxerr.debugging(Debug::INIT)) {
451 lyxerr << "LyX tmp dir: `" << package().temp_dir() << '\'' << endl;
454 lyxerr[Debug::INIT] << "Reading lastfiles `"
455 << lyxrc.lastfiles << "'..." << endl;
456 lastfiles_.reset(new LastFiles(lyxrc.lastfiles,
457 lyxrc.check_lastfiles,
458 lyxrc.num_lastfiles));
462 void LyX::defaultKeyBindings(kb_keymap * kbmap)
464 kbmap->bind("Right", FuncRequest(LFUN_RIGHT));
465 kbmap->bind("Left", FuncRequest(LFUN_LEFT));
466 kbmap->bind("Up", FuncRequest(LFUN_UP));
467 kbmap->bind("Down", FuncRequest(LFUN_DOWN));
469 kbmap->bind("Tab", FuncRequest(LFUN_CELL_FORWARD));
470 kbmap->bind("ISO_Left_Tab", FuncRequest(LFUN_CELL_FORWARD));
472 kbmap->bind("Home", FuncRequest(LFUN_HOME));
473 kbmap->bind("End", FuncRequest(LFUN_END));
474 kbmap->bind("Prior", FuncRequest(LFUN_PRIOR));
475 kbmap->bind("Next", FuncRequest(LFUN_NEXT));
477 kbmap->bind("Return", FuncRequest(LFUN_BREAKPARAGRAPH));
478 //kbmap->bind("~C-~S-~M-nobreakspace", FuncRequest(LFUN_PROTECTEDSPACE));
480 kbmap->bind("Delete", FuncRequest(LFUN_DELETE));
481 kbmap->bind("BackSpace", FuncRequest(LFUN_BACKSPACE));
483 // kbmap->bindings to enable the use of the numeric keypad
485 //kbmap->bind("KP_0", FuncRequest(LFUN_SELFINSERT));
486 //kbmap->bind("KP_Decimal", FuncRequest(LFUN_SELFINSERT));
487 kbmap->bind("KP_Enter", FuncRequest(LFUN_BREAKPARAGRAPH));
488 //kbmap->bind("KP_1", FuncRequest(LFUN_SELFINSERT));
489 //kbmap->bind("KP_2", FuncRequest(LFUN_SELFINSERT));
490 //kbmap->bind("KP_3", FuncRequest(LFUN_SELFINSERT));
491 //kbmap->bind("KP_4", FuncRequest(LFUN_SELFINSERT));
492 //kbmap->bind("KP_5", FuncRequest(LFUN_SELFINSERT));
493 //kbmap->bind("KP_6", FuncRequest(LFUN_SELFINSERT));
494 //kbmap->bind("KP_Add", FuncRequest(LFUN_SELFINSERT));
495 //kbmap->bind("KP_7", FuncRequest(LFUN_SELFINSERT));
496 //kbmap->bind("KP_8", FuncRequest(LFUN_SELFINSERT));
497 //kbmap->bind("KP_9", FuncRequest(LFUN_SELFINSERT));
498 //kbmap->bind("KP_Divide", FuncRequest(LFUN_SELFINSERT));
499 //kbmap->bind("KP_Multiply", FuncRequest(LFUN_SELFINSERT));
500 //kbmap->bind("KP_Subtract", FuncRequest(LFUN_SELFINSERT));
501 kbmap->bind("KP_Right", FuncRequest(LFUN_RIGHT));
502 kbmap->bind("KP_Left", FuncRequest(LFUN_LEFT));
503 kbmap->bind("KP_Up", FuncRequest(LFUN_UP));
504 kbmap->bind("KP_Down", FuncRequest(LFUN_DOWN));
505 kbmap->bind("KP_Home", FuncRequest(LFUN_HOME));
506 kbmap->bind("KP_End", FuncRequest(LFUN_END));
507 kbmap->bind("KP_Prior", FuncRequest(LFUN_PRIOR));
508 kbmap->bind("KP_Next", FuncRequest(LFUN_NEXT));
510 kbmap->bind("C-Tab", FuncRequest(LFUN_CELL_SPLIT));
511 kbmap->bind("S-Tab", FuncRequest(LFUN_CELL_BACKWARD));
512 kbmap->bind("S-ISO_Left_Tab", FuncRequest(LFUN_CELL_BACKWARD));
516 void LyX::emergencyCleanup() const
518 // what to do about tmpfiles is non-obvious. we would
519 // like to delete any we find, but our lyxdir might
520 // contain documents etc. which might be helpful on
523 bufferlist.emergencyWriteAll();
525 lyxserver->emergencyCleanup();
529 void LyX::deadKeyBindings(kb_keymap * kbmap)
531 // bindKeyings for transparent handling of deadkeys
532 // The keysyms are gotten from XFree86 X11R6
533 kbmap->bind("~C-~S-~M-dead_acute", FuncRequest(LFUN_ACUTE));
534 kbmap->bind("~C-~S-~M-dead_breve", FuncRequest(LFUN_BREVE));
535 kbmap->bind("~C-~S-~M-dead_caron", FuncRequest(LFUN_CARON));
536 kbmap->bind("~C-~S-~M-dead_cedilla", FuncRequest(LFUN_CEDILLA));
537 kbmap->bind("~C-~S-~M-dead_abovering", FuncRequest(LFUN_CIRCLE));
538 kbmap->bind("~C-~S-~M-dead_circumflex", FuncRequest(LFUN_CIRCUMFLEX));
539 kbmap->bind("~C-~S-~M-dead_abovedot", FuncRequest(LFUN_DOT));
540 kbmap->bind("~C-~S-~M-dead_grave", FuncRequest(LFUN_GRAVE));
541 kbmap->bind("~C-~S-~M-dead_doubleacute", FuncRequest(LFUN_HUNG_UMLAUT));
542 kbmap->bind("~C-~S-~M-dead_macron", FuncRequest(LFUN_MACRON));
543 // nothing with this name
544 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
545 kbmap->bind("~C-~S-~M-dead_tilde", FuncRequest(LFUN_TILDE));
546 kbmap->bind("~C-~S-~M-dead_diaeresis", FuncRequest(LFUN_UMLAUT));
547 // nothing with this name either...
548 //kbmap->bind("~C-~S-~M-dead_underbar", FuncRequest(LFUN_UNDERBAR));
549 kbmap->bind("~C-~S-~M-dead_belowdot", FuncRequest(LFUN_UNDERDOT));
550 kbmap->bind("~C-~S-~M-dead_tie", FuncRequest(LFUN_TIE));
551 kbmap->bind("~C-~S-~M-dead_ogonek",FuncRequest(LFUN_OGONEK));
555 void LyX::queryUserLyXDir(bool explicit_userdir)
557 string const configure_script = AddName(package().system_support(), "configure");
558 string const configure_command = "sh " + QuoteName(configure_script);
560 // Does user directory exist?
561 FileInfo fileInfo(package().user_support());
562 if (fileInfo.isOK() && fileInfo.isDir()) {
564 FileInfo script(configure_script);
565 FileInfo defaults(AddName(package().user_support(), "lyxrc.defaults"));
566 if (defaults.isOK() && script.isOK()
567 && defaults.getModificationTime() < script.getModificationTime()) {
568 lyxerr << _("LyX: reconfiguring user directory")
570 Path p(package().user_support());
571 ::system(configure_command.c_str());
572 lyxerr << "LyX: " << _("Done!") << endl;
577 first_start = !explicit_userdir;
579 // If the user specified explicitly a directory, ask whether
580 // to create it. If the user says "no", then exit.
581 if (explicit_userdir &&
583 _("Missing LyX support directory"),
584 bformat(_("You have specified a non-existent user "
585 "LyX directory, %1$s.\n"
586 "It is needed to keep your own configuration."),
587 package().user_support()),
589 _("&Create directory."),
591 lyxerr << _("No user LyX directory. Exiting.") << endl;
595 lyxerr << bformat(_("LyX: Creating directory %1$s"
596 " and running configure..."), package().user_support()) << endl;
598 if (!createDirectory(package().user_support(), 0755)) {
599 // Failed, so let's exit.
600 lyxerr << _("Failed to create directory. Exiting.")
605 // Run configure in user lyx directory
606 Path p(package().user_support());
607 ::system(configure_command.c_str());
608 lyxerr << "LyX: " << _("Done!") << endl;
612 void LyX::readRcFile(string const & name)
614 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
616 string const lyxrc_path = LibFileSearch(string(), name);
617 if (!lyxrc_path.empty()) {
619 lyxerr[Debug::INIT] << "Found " << name
620 << " in " << lyxrc_path << endl;
622 if (lyxrc.read(lyxrc_path) >= 0)
630 // Read the ui file `name'
631 void LyX::readUIFile(string const & name)
641 struct keyword_item uitags[ui_last - 1] = {
642 { "include", ui_include },
643 { "menuset", ui_menuset },
644 { "toolbar", ui_toolbar },
645 { "toolbars", ui_toolbars }
648 // Ensure that a file is read only once (prevents include loops)
649 static std::list<string> uifiles;
650 std::list<string>::const_iterator it = uifiles.begin();
651 std::list<string>::const_iterator end = uifiles.end();
652 it = std::find(it, end, name);
654 lyxerr[Debug::INIT] << "UI file '" << name
655 << "' has been read already. "
656 << "Is this an include loop?"
661 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
663 string const ui_path = LibFileSearch("ui", name, "ui");
665 if (ui_path.empty()) {
666 lyxerr[Debug::INIT] << "Could not find " << name << endl;
670 uifiles.push_back(name);
672 lyxerr[Debug::INIT] << "Found " << name
673 << " in " << ui_path << endl;
674 LyXLex lex(uitags, ui_last - 1);
675 lex.setFile(ui_path);
677 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
681 if (lyxerr.debugging(Debug::PARSER))
682 lex.printTable(lyxerr);
688 string const file = lex.getString();
693 menubackend.read(lex);
697 toolbarbackend.read(lex);
701 toolbarbackend.readToolbars(lex);
705 if (!rtrim(lex.getString()).empty())
706 lex.printError("LyX::ReadUIFile: "
707 "Unknown menu tag: `$$Token'");
714 // Read the languages file `name'
715 void LyX::readLanguagesFile(string const & name)
717 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
719 string const lang_path = LibFileSearch(string(), name);
720 if (lang_path.empty()) {
724 languages.read(lang_path);
728 // Read the encodings file `name'
729 void LyX::readEncodingsFile(string const & name)
731 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
733 string const enc_path = LibFileSearch(string(), name);
734 if (enc_path.empty()) {
738 encodings.read(enc_path);
747 /// return the the number of arguments consumed
748 typedef boost::function<int(string const &, string const &)> cmd_helper;
750 int parse_dbg(string const & arg, string const &)
753 lyxerr << _("List of supported debug flags:") << endl;
754 Debug::showTags(lyxerr);
757 lyxerr << bformat(_("Setting debug level to %1$s"), arg) << endl;
759 lyxerr.level(Debug::value(arg));
760 Debug::showLevel(lyxerr, lyxerr.level());
765 int parse_help(string const &, string const &)
768 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
769 "Command line switches (case sensitive):\n"
770 "\t-help summarize LyX usage\n"
771 "\t-userdir dir try to set user directory to dir\n"
772 "\t-sysdir dir try to set system directory to dir\n"
773 "\t-geometry WxH+X+Y set geometry of the main window\n"
774 "\t-dbg feature[,feature]...\n"
775 " select the features to debug.\n"
776 " Type `lyx -dbg' to see the list of features\n"
777 "\t-x [--execute] command\n"
778 " where command is a lyx command.\n"
779 "\t-e [--export] fmt\n"
780 " where fmt is the export format of choice.\n"
781 "\t-i [--import] fmt file.xxx\n"
782 " where fmt is the import format of choice\n"
783 " and file.xxx is the file to be imported.\n"
784 "\t-version summarize version and build info\n"
785 "Check the LyX man page for more details.") << endl;
790 int parse_version(string const &, string const &)
792 lyxerr << "LyX " << lyx_version
793 << " of " << lyx_release_date << endl;
794 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
796 lyxerr << lyx_version_info << endl;
801 int parse_sysdir(string const & arg, string const &)
804 lyxerr << _("Missing directory for -sysdir switch") << endl;
807 cl_system_support = arg;
811 int parse_userdir(string const & arg, string const &)
814 lyxerr << _("Missing directory for -userdir switch") << endl;
817 cl_user_support = arg;
821 int parse_execute(string const & arg, string const &)
824 lyxerr << _("Missing command string after --execute switch") << endl;
828 // Argh. Setting gui to false segfaults..
829 // FIXME: when ? how ?
834 int parse_export(string const & type, string const &)
837 lyxerr << _("Missing file type [eg latex, ps...] after "
838 "--export switch") << endl;
841 batch = "buffer-export " + type;
846 int parse_import(string const & type, string const & file)
849 lyxerr << _("Missing file type [eg latex, ps...] after "
850 "--import switch") << endl;
854 lyxerr << _("Missing filename for --import") << endl;
858 batch = "buffer-import " + type + ' ' + file;
865 bool LyX::easyParse(int & argc, char * argv[])
867 std::map<string, cmd_helper> cmdmap;
869 cmdmap["-dbg"] = parse_dbg;
870 cmdmap["-help"] = parse_help;
871 cmdmap["--help"] = parse_help;
872 cmdmap["-version"] = parse_version;
873 cmdmap["--version"] = parse_version;
874 cmdmap["-sysdir"] = parse_sysdir;
875 cmdmap["-userdir"] = parse_userdir;
876 cmdmap["-x"] = parse_execute;
877 cmdmap["--execute"] = parse_execute;
878 cmdmap["-e"] = parse_export;
879 cmdmap["--export"] = parse_export;
880 cmdmap["-i"] = parse_import;
881 cmdmap["--import"] = parse_import;
883 for (int i = 1; i < argc; ++i) {
884 std::map<string, cmd_helper>::const_iterator it
885 = cmdmap.find(argv[i]);
887 // don't complain if not found - may be parsed later
888 if (it == cmdmap.end())
891 string arg((i + 1 < argc) ? argv[i + 1] : "");
892 string arg2((i + 2 < argc) ? argv[i + 2] : "");
894 int const remove = 1 + it->second(arg, arg2);
896 // Now, remove used arguments by shifting
897 // the following ones remove places down.
899 for (int j = i; j < argc; ++j)
900 argv[j] = argv[j + remove];
904 batch_command = batch;