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"
37 #include "lyxtextclasslist.h"
39 #include "frontends/Alert.h"
40 #include "frontends/lyx_gui.h"
42 #include "support/BoostFormat.h"
43 #include <boost/function.hpp>
51 #ifndef CXX_GLOBAL_CSTD
57 extern void LoadLyXFile(string const &);
58 extern void QuitLyX();
60 extern LyXServer * lyxserver;
64 string system_tempdir;
69 boost::scoped_ptr<LastFiles> lastfiles;
71 // This is the global bufferlist object
72 BufferList bufferlist;
74 // convenient to have it here.
75 boost::scoped_ptr<kb_keymap> toplevel_keymap;
78 LyX::LyX(int & argc, char * argv[])
80 // Here we need to parse the command line. At least
81 // we need to parse for "-dbg" and "-help"
82 bool const want_gui = easyParse(argc, argv);
84 // Global bindings (this must be done as early as possible.) (Lgb)
85 toplevel_keymap.reset(new kb_keymap);
86 defaultKeyBindings(toplevel_keymap.get());
88 // set the DisplayTranslator only once; should that be done here??
89 // if this should not be in this file, please also remove
90 // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye.
91 grfx::setDisplayTranslator();
94 lyx_gui::parse_init(argc, argv);
97 // check for any spurious extra arguments
98 // other than documents
99 for (int argi = 1; argi < argc ; ++argi) {
100 if (argv[argi][0] == '-') {
102 lyxerr << boost::format(_("Wrong command line option `%1$s'. Exiting."))
106 lyxerr << _("Wrong command line option `")
107 << argv[argi] << _("'. Exiting.")
114 // Initialization of LyX (reads lyxrc and more)
115 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
117 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
120 lyx_gui::parse_lyxrc();
123 vector<string> files;
125 for (int argi = argc - 1; argi >= 1; --argi) {
126 files.push_back(argv[argi]);
130 files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
133 // Execute batch commands if available
134 if (!batch_command.empty()) {
135 lyxerr[Debug::INIT] << "About to handle -x '"
136 << batch_command << '\'' << endl;
138 Buffer * last_loaded = 0;
140 vector<string>::iterator it = files.begin();
141 vector<string>::iterator end = files.end();
142 for (; it != end; ++it) {
143 last_loaded = bufferlist.loadLyXFile(*it);
148 // no buffer loaded, create one
150 last_loaded = bufferlist.newFile("tmpfile", string());
152 bool success = false;
154 // try to dispatch to last loaded buffer first
155 bool const dispatched = last_loaded->dispatch(batch_command, &success);
163 lyx_gui::start(batch_command, files);
169 static void error_handler(int err_sig)
173 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
179 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
182 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
184 "Sorry, you have found a bug in LyX. "
185 "Please read the bug-reporting instructions "
186 "in Help->Introduction and send us a bug report, "
187 "if necessary. Thanks !" << endl;
194 // Deinstall the signal handlers
195 signal(SIGHUP, SIG_DFL);
196 signal(SIGINT, SIG_DFL);
197 signal(SIGFPE, SIG_DFL);
198 signal(SIGSEGV, SIG_DFL);
199 signal(SIGTERM, SIG_DFL);
201 LyX::emergencyCleanup();
203 lyxerr << "Bye." << endl;
204 if (err_sig!= SIGHUP &&
205 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
213 void LyX::init(bool gui)
215 signal(SIGHUP, error_handler);
216 signal(SIGFPE, error_handler);
217 signal(SIGSEGV, error_handler);
218 signal(SIGINT, error_handler);
219 signal(SIGTERM, error_handler);
222 // Determine path of binary
225 string binpath = os::binpath();
226 string binname = os::binname();
227 string fullbinname = MakeAbsPath(binname, binpath);
229 if (binpath.empty()) {
230 lyxerr << _("Warning: could not determine path of binary.")
232 << _("If you have problems, try starting LyX with an absolute path.")
235 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
236 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
239 // Determine system directory.
242 // Directories are searched in this order:
243 // 1) -sysdir command line parameter
244 // 2) LYX_DIR_13x environment variable
245 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
246 // 4) <path of binary>/../share/<name of binary>/
247 // 4a) repeat 4 after following the Symlink if <path of
248 // binary> is a symbolic link.
249 // 5) hardcoded lyx_dir
250 // The directory is checked for the presence of the file
251 // "chkconfig.ltx", and if that is present, the directory
252 // is accepted as the system directory.
253 // If no chkconfig.ltx file is found, a warning is given,
254 // and the hardcoded lyx_dir is used.
256 // If we had a command line switch, system_lyxdir is already set
258 if (!system_lyxdir.empty())
259 searchpath = MakeAbsPath(system_lyxdir) + ';';
261 string const lyxdir = GetEnvPath("LYX_DIR_13x");
263 if (!lyxdir.empty()) {
264 lyxerr[Debug::INIT] << "LYX_DIR_13x: " << lyxdir << endl;
265 searchpath += lyxdir + ';';
268 string fullbinpath = binpath;
269 FileInfo file(fullbinname, true);
271 lyxerr[Debug::INIT] << "binary is a link" << endl;
273 if (LyXReadLink(fullbinname, link, true)) {
274 // Path of binary/../share/name of binary/
275 searchpath += NormalizePath(AddPath(binpath,
277 + OnlyFilename(binname));
280 binpath = MakeAbsPath(OnlyPath(fullbinpath));
286 // Path of binary/../share/name of binary/
287 searchpath += NormalizePath(AddPath(binpath, "../share/") +
288 OnlyFilename(binname)) + ';';
291 FileInfo file(fullbinpath, true);
292 followlink = file.isLink();
294 lyxerr[Debug::INIT] << " directory " << fullbinpath
295 << " is a link" << endl;
297 if (LyXReadLink(fullbinpath, link, true)) {
299 binpath = MakeAbsPath(OnlyPath(fullbinpath));
305 } while (followlink);
307 // <path of binary>/TOP_SRCDIR/lib
308 build_lyxdir = MakeAbsPath("../lib", binpath);
309 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
310 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
312 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
313 "place... yes" << endl;
316 << "Checking whether LyX is run in place... no"
318 build_lyxdir.erase();
322 searchpath += LYX_DIR;
324 lyxerr[Debug::INIT] << "System directory search path: "
325 << searchpath << endl;
327 string const filename = "chkconfig.ltx";
328 string const temp = FileOpenSearch(searchpath, filename, string());
329 system_lyxdir = OnlyPath(temp);
331 // Reduce "path/../path" stuff out of system directory
332 system_lyxdir = NormalizePath(system_lyxdir);
334 bool path_shown = false;
336 // Warn if environment variable is set, but unusable
337 if (!lyxdir.empty()) {
338 if (system_lyxdir != NormalizePath(lyxdir)) {
339 lyxerr <<_("LYX_DIR_13x environment variable no good.")
341 << _("System directory set to: ")
342 << system_lyxdir << endl;
347 // Warn the user if we couldn't find "chkconfig.ltx"
348 if (system_lyxdir == "./") {
349 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
350 <<_("Try the '-sysdir' command line parameter or ")
351 <<_("set the environment variable LYX_DIR_13x to the "
352 "LyX system directory ")
353 << _("containing the file `chkconfig.ltx'.") << endl;
355 FileInfo fi(LYX_DIR);
357 lyxerr << "Couldn't even find the default LYX_DIR." << endl
358 << "Giving up." << endl;
362 lyxerr << boost::format(_("Using built-in default %1$s"
363 " but expect problems."))
364 % static_cast<char *>(LYX_DIR)
367 lyxerr << _("Using built-in default ") << LYX_DIR
368 << _(" but expect problems.")
372 lyxerr << _("Expect problems.") << endl;
374 system_lyxdir = LYX_DIR;
379 lyxerr[Debug::INIT] << "System directory: '"
380 << system_lyxdir << '\'' << endl;
383 // Determine user lyx-dir
386 // Directories are searched in this order:
387 // 1) -userdir command line parameter
388 // 2) LYX_USERDIR_13x environment variable
389 // 3) $HOME/.<name of binary>
391 // If we had a command line switch, user_lyxdir is already set
392 bool explicit_userdir = true;
393 if (user_lyxdir.empty()) {
395 // LYX_USERDIR_13x environment variable
396 user_lyxdir = GetEnvPath("LYX_USERDIR_13x");
399 if (user_lyxdir.empty())
400 user_lyxdir = AddPath(GetEnvPath("HOME"),
401 string(".") + PACKAGE);
402 explicit_userdir = false;
405 lyxerr[Debug::INIT] << "User LyX directory: '"
406 << user_lyxdir << '\'' << endl;
408 // Check that user LyX directory is ok. We don't do that if
409 // running in batch mode.
411 queryUserLyXDir(explicit_userdir);
417 // Shine up lyxrc defaults
420 // Default template path: system_dir/templates
421 if (lyxrc.template_path.empty()) {
422 lyxrc.template_path = AddPath(system_lyxdir, "templates");
425 // Default lastfiles file: $HOME/.lyx/lastfiles
426 if (lyxrc.lastfiles.empty()) {
427 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
430 // Disable gui when either lyxrc or easyparse says so
432 lyxrc.use_gui = false;
435 // Read configuration files
438 readRcFile("lyxrc.defaults");
439 system_lyxrc = lyxrc;
440 system_formats = formats;
441 system_converters = converters;
442 system_lcolor = lcolor;
444 // If there is a preferences file we read that instead
445 // of the old lyxrc file.
446 if (!readRcFile("preferences"))
449 readEncodingsFile("encodings");
450 readLanguagesFile("languages");
453 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
456 // Ensure that we have really read a bind file, so that LyX is
458 lyxrc.readBindFileIfNeeded();
461 readUIFile(lyxrc.ui_file);
463 if (lyxerr.debugging(Debug::LYXRC)) {
467 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
468 system_tempdir = os::getTmpDir();
469 if (lyxerr.debugging(Debug::INIT)) {
470 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
473 lyxerr[Debug::INIT] << "Reading lastfiles `"
474 << lyxrc.lastfiles << "'..." << endl;
475 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
476 lyxrc.check_lastfiles,
477 lyxrc.num_lastfiles));
481 void LyX::defaultKeyBindings(kb_keymap * kbmap)
483 kbmap->bind("Right", LFUN_RIGHT);
484 kbmap->bind("Left", LFUN_LEFT);
485 kbmap->bind("Up", LFUN_UP);
486 kbmap->bind("Down", LFUN_DOWN);
488 kbmap->bind("Tab", LFUN_TAB);
489 kbmap->bind("ISO_Left_Tab", LFUN_TAB); // jbl 2001-23-02
491 kbmap->bind("Home", LFUN_HOME);
492 kbmap->bind("End", LFUN_END);
493 kbmap->bind("Prior", LFUN_PRIOR);
494 kbmap->bind("Next", LFUN_NEXT);
496 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
497 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
499 kbmap->bind("Delete", LFUN_DELETE);
500 kbmap->bind("BackSpace", LFUN_BACKSPACE);
502 // sub- and superscript -MV
503 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
504 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
506 // kbmap->bindings to enable the use of the numeric keypad
508 //kbmap->bind("KP_0", LFUN_SELFINSERT);
509 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
510 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
511 //kbmap->bind("KP_1", LFUN_SELFINSERT);
512 //kbmap->bind("KP_2", LFUN_SELFINSERT);
513 //kbmap->bind("KP_3", LFUN_SELFINSERT);
514 //kbmap->bind("KP_4", LFUN_SELFINSERT);
515 //kbmap->bind("KP_5", LFUN_SELFINSERT);
516 //kbmap->bind("KP_6", LFUN_SELFINSERT);
517 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
518 //kbmap->bind("KP_7", LFUN_SELFINSERT);
519 //kbmap->bind("KP_8", LFUN_SELFINSERT);
520 //kbmap->bind("KP_9", LFUN_SELFINSERT);
521 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
522 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
523 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
524 kbmap->bind("KP_Right", LFUN_RIGHT);
525 kbmap->bind("KP_Left", LFUN_LEFT);
526 kbmap->bind("KP_Up", LFUN_UP);
527 kbmap->bind("KP_Down", LFUN_DOWN);
528 kbmap->bind("KP_Home", LFUN_HOME);
529 kbmap->bind("KP_End", LFUN_END);
530 kbmap->bind("KP_Prior", LFUN_PRIOR);
531 kbmap->bind("KP_Next", LFUN_NEXT);
533 kbmap->bind("C-Tab", LFUN_TABINSERT); // ale970515
534 kbmap->bind("S-Tab", LFUN_SHIFT_TAB); // jug20000522
535 kbmap->bind("S-ISO_Left_Tab", LFUN_SHIFT_TAB); // jbl 2001-23-02
539 void LyX::emergencyCleanup()
541 // what to do about tmpfiles is non-obvious. we would
542 // like to delete any we find, but our lyxdir might
543 // contain documents etc. which might be helpful on
546 bufferlist.emergencyWriteAll();
548 lyxserver->emergencyCleanup();
552 void LyX::deadKeyBindings(kb_keymap * kbmap)
554 // bindKeyings for transparent handling of deadkeys
555 // The keysyms are gotten from XFree86 X11R6
556 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
557 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
558 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
559 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
560 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
561 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
562 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
563 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
564 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
565 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
566 // nothing with this name
567 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
568 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
569 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
570 // nothing with this name either...
571 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
572 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
573 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
574 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
578 void LyX::queryUserLyXDir(bool explicit_userdir)
580 string const configure_script = AddName(system_lyxdir, "configure");
582 // Does user directory exist?
583 FileInfo fileInfo(user_lyxdir);
584 if (fileInfo.isOK() && fileInfo.isDir()) {
586 FileInfo script(configure_script);
587 FileInfo defaults(AddName(user_lyxdir, "lyxrc.defaults"));
588 if (defaults.isOK() && script.isOK()
589 && defaults.getModificationTime() < script.getModificationTime()) {
590 lyxerr << _("LyX: reconfiguring user directory")
593 ::system(configure_script.c_str());
594 lyxerr << "LyX: " << _("Done!") << endl;
599 first_start = !explicit_userdir;
602 lyxerr << boost::format(_("LyX: Creating directory %1$s"
603 " and running configure..."))
607 lyxerr << _("LyX: Creating directory ") << user_lyxdir
608 << _(" and running configure...")
612 if (!createDirectory(user_lyxdir, 0755)) {
613 // Failed, let's use $HOME instead.
614 user_lyxdir = GetEnvPath("HOME");
616 lyxerr << boost::format(_("Failed. Will use %1$s instead."))
620 lyxerr << _("Failed. Will use ") << user_lyxdir <<
627 // Run configure in user lyx directory
629 ::system(configure_script.c_str());
630 lyxerr << "LyX: " << _("Done!") << endl;
634 bool 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()) {
640 lyxerr[Debug::INIT] << "Found " << name
641 << " in " << lyxrc_path << endl;
642 if (lyxrc.read(lyxrc_path) < 0) {
644 Alert::warning(_("Could not read configuration file"),
645 boost::io::str(boost::format(
646 _("Error while reading the configuration file\n%1$s.\n"
647 ".\nLyX will use the built-in defaults.")) % lyxrc_path));
649 Alert::warning(_("Could not read configuration file"),
650 string(_("Error while reading the configuration file\n"))
651 + lyxrc_path + _(".\nLyX will use the built-in defaults."));
657 lyxerr[Debug::INIT] << "Could not find " << name << endl;
664 // Read the ui file `name'
665 void LyX::readUIFile(string const & name)
673 struct keyword_item uitags[ui_last - 1] = {
674 { "menuset", ui_menuset },
675 { "toolbar", ui_toolbar }
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;
684 menubackend.defaults();
688 lyxerr[Debug::INIT] << "Found " << name
689 << " in " << ui_path << endl;
690 LyXLex lex(uitags, ui_last - 1);
691 lex.setFile(ui_path);
693 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
697 if (lyxerr.debugging(Debug::PARSER))
698 lex.printTable(lyxerr);
703 menubackend.read(lex);
707 toolbardefaults.read(lex);
711 if (!rtrim(lex.getString()).empty())
712 lex.printError("LyX::ReadUIFile: "
713 "Unknown menu tag: `$$Token'");
720 // Read the languages file `name'
721 void LyX::readLanguagesFile(string const & name)
723 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
725 string const lang_path = LibFileSearch(string(), name);
726 if (lang_path.empty()) {
727 lyxerr[Debug::INIT] << "Could not find " << name << endl;
728 languages.setDefaults();
731 languages.read(lang_path);
735 // Read the encodings file `name'
736 void LyX::readEncodingsFile(string const & name)
738 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
740 string const enc_path = LibFileSearch(string(), name);
741 if (enc_path.empty()) {
742 lyxerr[Debug::INIT] << "Could not find " << name << endl;
745 encodings.read(enc_path);
754 /// return the the number of arguments consumed
755 typedef boost::function<int(string const &, string const &)> cmd_helper;
757 int parse_dbg(string const & arg, string const &)
760 lyxerr << _("List of supported debug flags:") << endl;
761 Debug::showTags(lyxerr);
765 lyxerr << boost::format(_("Setting debug level to %1$s"))
769 lyxerr << _("Setting debug level to ") << arg << endl;
772 lyxerr.level(Debug::value(arg));
773 Debug::showLevel(lyxerr, lyxerr.level());
777 int parse_help(string const &, string const &)
780 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
781 "Command line switches (case sensitive):\n"
782 "\t-help summarize LyX usage\n"
783 "\t-userdir dir try to set user directory to dir\n"
784 "\t-sysdir dir try to set system directory to dir\n"
785 "\t-geometry WxH+X+Y set geometry of the main window\n"
786 "\t-dbg feature[,feature]...\n"
787 " select the features to debug.\n"
788 " Type `lyx -dbg' to see the list of features\n"
789 "\t-x [--execute] command\n"
790 " where command is a lyx command.\n"
791 "\t-e [--export] fmt\n"
792 " where fmt is the export format of choice.\n"
793 "\t-i [--import] fmt file.xxx\n"
794 " where fmt is the import format of choice\n"
795 " and file.xxx is the file to be imported.\n"
796 "\t-version summarize version and build info\n"
797 "Check the LyX man page for more details.") << endl;
802 int parse_version(string const &, string const &)
804 lyxerr << "LyX " << lyx_version
805 << " of " << lyx_release_date << endl;
806 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
808 lyxerr << lyx_version_info << endl;
813 int parse_sysdir(string const & arg, string const &)
816 lyxerr << _("Missing directory for -sysdir switch") << endl;
823 int parse_userdir(string const & arg, string const &)
826 lyxerr << _("Missing directory for -userdir switch") << endl;
833 int parse_execute(string const & arg, string const &)
836 lyxerr << _("Missing command string after --execute switch") << endl;
840 // Argh. Setting gui to false segfaults..
841 // FIXME: when ? how ?
846 int parse_export(string const & type, string const &)
849 lyxerr << _("Missing file type [eg latex, ps...] after "
850 "--export switch") << endl;
853 batch = "buffer-export " + type;
858 int parse_import(string const & type, string const & file)
861 lyxerr << _("Missing file type [eg latex, ps...] after "
862 "--import switch") << endl;
866 lyxerr << _("Missing filename for --import") << endl;
870 batch = "buffer-import " + type + ' ' + file;
877 bool LyX::easyParse(int & argc, char * argv[])
879 std::map<string, cmd_helper> cmdmap;
881 cmdmap["-dbg"] = parse_dbg;
882 cmdmap["-help"] = parse_help;
883 cmdmap["--help"] = parse_help;
884 cmdmap["-version"] = parse_version;
885 cmdmap["--version"] = parse_version;
886 cmdmap["-sysdir"] = parse_sysdir;
887 cmdmap["-userdir"] = parse_userdir;
888 cmdmap["-x"] = parse_execute;
889 cmdmap["--execute"] = parse_execute;
890 cmdmap["-e"] = parse_export;
891 cmdmap["--export"] = parse_export;
892 cmdmap["-i"] = parse_import;
893 cmdmap["--import"] = parse_import;
895 for (int i = 1; i < argc; ++i) {
896 std::map<string, cmd_helper>::const_iterator it
897 = cmdmap.find(argv[i]);
899 // don't complain if not found - may be parsed later
900 if (it == cmdmap.end())
903 string arg((i + 1 < argc) ? argv[i + 1] : "");
904 string arg2((i + 2 < argc) ? argv[i + 2] : "");
906 int const remove = 1 + it->second(arg, arg2);
908 // Now, remove used arguments by shifting
909 // the following ones remove places down.
911 for (int j = i; j < argc; ++j)
912 argv[j] = argv[j + remove];
916 batch_command = batch;