3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
13 #pragma implementation
18 #include "support/filetools.h"
19 #include "support/lyxlib.h"
20 #include "support/os.h"
21 #include "support/FileInfo.h"
22 #include "support/path.h"
27 #include "bufferlist.h"
29 #include "lyxserver.h"
32 #include "ToolbarDefaults.h"
33 #include "MenuBackend.h"
35 #include "lastfiles.h"
37 #include "converter.h"
38 #include "lyxtextclasslist.h"
40 #include "frontends/Alert.h"
41 #include "frontends/lyx_gui.h"
49 #ifndef CXX_GLOBAL_CSTD
55 extern void LoadLyXFile(string const &);
56 extern void QuitLyX();
58 extern LyXServer * lyxserver;
62 string system_tempdir;
67 boost::scoped_ptr<LastFiles> lastfiles;
69 // This is the global bufferlist object
70 BufferList bufferlist;
72 // convenient to have it here.
73 boost::scoped_ptr<kb_keymap> toplevel_keymap;
76 LyX::LyX(int & argc, char * argv[])
78 // Here we need to parse the command line. At least
79 // we need to parse for "-dbg" and "-help"
80 bool const want_gui = easyParse(argc, argv);
82 // Global bindings (this must be done as early as possible.) (Lgb)
83 toplevel_keymap.reset(new kb_keymap);
84 defaultKeyBindings(toplevel_keymap.get());
87 lyx_gui::parse_init(argc, argv);
90 // check for any spurious extra arguments
91 // other than documents
92 for (int argi = 1; argi < argc ; ++argi) {
93 if (argv[argi][0] == '-') {
94 lyxerr << _("Wrong command line option `")
96 << _("'. Exiting.") << endl;
101 // Initialization of LyX (reads lyxrc and more)
102 lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
104 lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
107 lyx_gui::parse_lyxrc();
110 vector<string> files;
112 for (int argi = argc - 1; argi >= 1; --argi) {
113 files.push_back(argv[argi]);
117 files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
120 // Execute batch commands if available
121 if (!batch_command.empty()) {
122 lyxerr[Debug::INIT] << "About to handle -x '"
123 << batch_command << "'" << endl;
125 Buffer * last_loaded = 0;
127 vector<string>::iterator it = files.begin();
128 vector<string>::iterator end = files.end();
129 for (; it != end; ++it) {
130 last_loaded = bufferlist.loadLyXFile(*it);
135 // no buffer loaded, create one
137 last_loaded = bufferlist.newFile("tmpfile", string());
139 bool success = false;
141 // try to dispatch to last loaded buffer first
142 bool const dispatched = last_loaded->dispatch(batch_command, &success);
150 lyx_gui::start(batch_command, files);
157 void error_handler(int err_sig)
161 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
167 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
170 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
172 "Sorry, you have found a bug in LyX. "
173 "Please read the bug-reporting instructions "
174 "in Help->Introduction and send us a bug report, "
175 "if necessary. Thanks !" << endl;
182 // Deinstall the signal handlers
183 signal(SIGHUP, SIG_DFL);
184 signal(SIGINT, SIG_DFL);
185 signal(SIGFPE, SIG_DFL);
186 signal(SIGSEGV, SIG_DFL);
187 signal(SIGTERM, SIG_DFL);
189 LyX::emergencyCleanup();
191 lyxerr << "Bye." << endl;
192 if (err_sig!= SIGHUP &&
193 (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
201 void LyX::init(bool gui)
203 // Install the signal handlers
204 signal(SIGHUP, error_handler);
205 signal(SIGFPE, error_handler);
206 signal(SIGSEGV, error_handler);
207 signal(SIGINT, error_handler);
208 signal(SIGTERM, error_handler);
211 // Determine path of binary
214 string binpath = os::binpath();
215 string binname = os::binname();
216 string fullbinname = MakeAbsPath(binname, binpath);
218 if (binpath.empty()) {
219 lyxerr << _("Warning: could not determine path of binary.")
221 << _("If you have problems, try starting LyX with an absolute path.")
224 lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
225 lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
228 // Determine system directory.
231 // Directories are searched in this order:
232 // 1) -sysdir command line parameter
233 // 2) LYX_DIR_13x environment variable
234 // 3) Maybe <path of binary>/TOP_SRCDIR/lib
235 // 4) <path of binary>/../share/<name of binary>/
236 // 4a) repeat 4 after following the Symlink if <path of
237 // binary> is a symbolic link.
238 // 5) hardcoded lyx_dir
239 // The directory is checked for the presence of the file
240 // "chkconfig.ltx", and if that is present, the directory
241 // is accepted as the system directory.
242 // If no chkconfig.ltx file is found, a warning is given,
243 // and the hardcoded lyx_dir is used.
245 // If we had a command line switch, system_lyxdir is already set
247 if (!system_lyxdir.empty())
248 searchpath = MakeAbsPath(system_lyxdir) + ';';
250 // LYX_DIR_13x environment variable
251 string const lyxdir = GetEnvPath("LYX_DIR_13x");
253 if (!lyxdir.empty()) {
254 lyxerr[Debug::INIT] << "LYX_DIR_13x: " << lyxdir << endl;
255 searchpath += lyxdir + ';';
258 string fullbinpath = binpath;
259 FileInfo file(fullbinname, true);
261 lyxerr[Debug::INIT] << "binary is a link" << endl;
263 if (LyXReadLink(fullbinname, link, true)) {
264 // Path of binary/../share/name of binary/
265 searchpath += NormalizePath(AddPath(binpath,
267 + OnlyFilename(binname));
270 binpath = MakeAbsPath(OnlyPath(fullbinpath));
276 // Path of binary/../share/name of binary/
277 searchpath += NormalizePath(AddPath(binpath, "../share/") +
278 OnlyFilename(binname)) + ';';
281 FileInfo file(fullbinpath, true);
282 followlink = file.isLink();
284 lyxerr << " directory " << fullbinpath
285 << " is a link" << endl;
287 if (LyXReadLink(fullbinpath, link, true)) {
289 binpath = MakeAbsPath(OnlyPath(fullbinpath));
295 } while (followlink);
297 // <path of binary>/TOP_SRCDIR/lib
298 build_lyxdir = MakeAbsPath("../lib", binpath);
299 if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
300 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
302 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
303 "place... yes" << endl;
306 << "Checking whether LyX is run in place... no"
308 build_lyxdir.erase();
312 searchpath += LYX_DIR;
314 // If debugging, show complete search path
315 lyxerr[Debug::INIT] << "System directory search path: "
316 << searchpath << endl;
318 string const filename = "chkconfig.ltx";
319 string const temp = FileOpenSearch(searchpath, filename, string());
320 system_lyxdir = OnlyPath(temp);
322 // Reduce "path/../path" stuff out of system directory
323 system_lyxdir = NormalizePath(system_lyxdir);
325 bool path_shown = false;
327 // Warn if environment variable is set, but unusable
328 if (!lyxdir.empty()) {
329 if (system_lyxdir != NormalizePath(lyxdir)) {
330 lyxerr <<_("LYX_DIR_13x environment variable no good.")
332 << _("System directory set to: ")
333 << system_lyxdir << endl;
338 // Warn the user if we couldn't find "chkconfig.ltx"
339 if (system_lyxdir == "./") {
340 lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
341 <<_("Try the '-sysdir' command line parameter or ")
342 <<_("set the environment variable LYX_DIR_13x to the "
343 "LyX system directory ")
344 << _("containing the file `chkconfig.ltx'.") << endl;
346 FileInfo fi(LYX_DIR);
348 lyxerr << "Couldn't even find the default LYX_DIR." << endl
349 << "Giving up." << endl;
352 lyxerr << _("Using built-in default ")
353 << LYX_DIR << _(" but expect problems.")
356 lyxerr << _("Expect problems.") << endl;
358 system_lyxdir = LYX_DIR;
361 // Report the system directory if debugging is on
363 lyxerr[Debug::INIT] << "System directory: '"
364 << system_lyxdir << '\'' << endl;
367 // Determine user lyx-dir
370 // Directories are searched in this order:
371 // 1) -userdir command line parameter
372 // 2) LYX_USERDIR_13x environment variable
373 // 3) $HOME/.<name of binary>
375 // If we had a command line switch, user_lyxdir is already set
376 bool explicit_userdir = true;
377 if (user_lyxdir.empty()) {
379 // LYX_USERDIR_13x environment variable
380 user_lyxdir = GetEnvPath("LYX_USERDIR_13x");
383 if (user_lyxdir.empty())
384 user_lyxdir = AddPath(GetEnvPath("HOME"),
385 string(".") + PACKAGE);
386 explicit_userdir = false;
389 lyxerr[Debug::INIT] << "User LyX directory: '"
390 << user_lyxdir << '\'' << endl;
392 // Check that user LyX directory is ok. We don't do that if
393 // running in batch mode.
395 queryUserLyXDir(explicit_userdir);
401 // Shine up lyxrc defaults
404 // Default template path: system_dir/templates
405 if (lyxrc.template_path.empty()) {
406 lyxrc.template_path = AddPath(system_lyxdir, "templates");
409 // Default lastfiles file: $HOME/.lyx/lastfiles
410 if (lyxrc.lastfiles.empty()) {
411 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
414 // Disable gui when either lyxrc or easyparse says so
416 lyxrc.use_gui = false;
419 // Read configuration files
422 readRcFile("lyxrc.defaults");
423 system_lyxrc = lyxrc;
424 system_formats = formats;
425 system_converters = converters;
426 system_lcolor = lcolor;
428 // If there is a preferences file we read that instead
429 // of the old lyxrc file.
430 if (!readRcFile("preferences"))
434 readEncodingsFile("encodings");
436 readLanguagesFile("languages");
439 lyxerr[Debug::INIT] << "Reading layouts..." << endl;
442 // Ensure that we have really read a bind file, so that LyX is
444 lyxrc.readBindFileIfNeeded();
447 readUIFile(lyxrc.ui_file);
449 // Bind the X dead keys to the corresponding LyX functions if
451 if (lyxrc.override_x_deadkeys)
452 deadKeyBindings(toplevel_keymap.get());
454 if (lyxerr.debugging(Debug::LYXRC)) {
458 // Create temp directory
459 os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
460 system_tempdir = os::getTmpDir();
461 if (lyxerr.debugging(Debug::INIT)) {
462 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
465 // load the lastfiles mini-database
466 lyxerr[Debug::INIT] << "Reading lastfiles `"
467 << lyxrc.lastfiles << "'..." << endl;
468 lastfiles.reset(new LastFiles(lyxrc.lastfiles,
469 lyxrc.check_lastfiles,
470 lyxrc.num_lastfiles));
474 // These are the default bindings known to LyX
475 void LyX::defaultKeyBindings(kb_keymap * kbmap)
477 kbmap->bind("Right", LFUN_RIGHT);
478 kbmap->bind("Left", LFUN_LEFT);
479 kbmap->bind("Up", LFUN_UP);
480 kbmap->bind("Down", LFUN_DOWN);
482 kbmap->bind("Tab", LFUN_TAB);
483 kbmap->bind("ISO_Left_Tab", LFUN_TAB); // jbl 2001-23-02
485 kbmap->bind("Home", LFUN_HOME);
486 kbmap->bind("End", LFUN_END);
487 kbmap->bind("Prior", LFUN_PRIOR);
488 kbmap->bind("Next", LFUN_NEXT);
490 kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
491 //kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
493 kbmap->bind("Delete", LFUN_DELETE);
494 kbmap->bind("BackSpace", LFUN_BACKSPACE);
496 // sub- and superscript -MV
497 kbmap->bind("~S-underscore", LFUN_SUBSCRIPT);
498 kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT);
500 // kbmap->bindings to enable the use of the numeric keypad
502 //kbmap->bind("KP_0", LFUN_SELFINSERT);
503 //kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
504 kbmap->bind("KP_Enter", LFUN_BREAKPARAGRAPH);
505 //kbmap->bind("KP_1", LFUN_SELFINSERT);
506 //kbmap->bind("KP_2", LFUN_SELFINSERT);
507 //kbmap->bind("KP_3", LFUN_SELFINSERT);
508 //kbmap->bind("KP_4", LFUN_SELFINSERT);
509 //kbmap->bind("KP_5", LFUN_SELFINSERT);
510 //kbmap->bind("KP_6", LFUN_SELFINSERT);
511 //kbmap->bind("KP_Add", LFUN_SELFINSERT);
512 //kbmap->bind("KP_7", LFUN_SELFINSERT);
513 //kbmap->bind("KP_8", LFUN_SELFINSERT);
514 //kbmap->bind("KP_9", LFUN_SELFINSERT);
515 //kbmap->bind("KP_Divide", LFUN_SELFINSERT);
516 //kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
517 //kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
518 kbmap->bind("KP_Right", LFUN_RIGHT);
519 kbmap->bind("KP_Left", LFUN_LEFT);
520 kbmap->bind("KP_Up", LFUN_UP);
521 kbmap->bind("KP_Down", LFUN_DOWN);
522 kbmap->bind("KP_Home", LFUN_HOME);
523 kbmap->bind("KP_End", LFUN_END);
524 kbmap->bind("KP_Prior", LFUN_PRIOR);
525 kbmap->bind("KP_Next", LFUN_NEXT);
527 kbmap->bind("C-Tab", LFUN_TABINSERT); // ale970515
528 kbmap->bind("S-Tab", LFUN_SHIFT_TAB); // jug20000522
529 kbmap->bind("S-ISO_Left_Tab", LFUN_SHIFT_TAB); // jbl 2001-23-02
533 void LyX::emergencyCleanup()
535 // what to do about tmpfiles is non-obvious. we would
536 // like to delete any we find, but our lyxdir might
537 // contain documents etc. which might be helpful on
540 bufferlist.emergencyWriteAll();
542 lyxserver->emergencyCleanup();
546 // LyX can optionally take over the handling of deadkeys
547 void LyX::deadKeyBindings(kb_keymap * kbmap)
549 // bindKeyings for transparent handling of deadkeys
550 // The keysyms are gotten from XFree86 X11R6
551 kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
552 kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
553 kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
554 kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
555 kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
556 kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
557 kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
558 kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
559 kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
560 kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
561 // nothing with this name
562 // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
563 kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
564 kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
565 // nothing with this name either...
566 //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
567 kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
568 kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
569 kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
573 // This one is not allowed to use anything on the main form, since that
574 // one does not exist yet. (Asger)
575 void LyX::queryUserLyXDir(bool explicit_userdir)
577 // Does user directory exist?
578 FileInfo fileInfo(user_lyxdir);
579 if (fileInfo.isOK() && fileInfo.isDir()) {
583 first_start = !explicit_userdir;
586 // If the user specified explicitely a directory, ask whether
587 // to create it (otherwise, always create it)
588 if (explicit_userdir &&
589 !Alert::askQuestion(_("You have specified an invalid LyX directory."),
590 _("It is needed to keep your own configuration."),
591 _("Should I try to set it up for you (recommended)?"))) {
592 lyxerr << _("Running without personal LyX directory.") << endl;
593 // No, let's use $HOME instead.
594 user_lyxdir = GetEnvPath("HOME");
598 // Tell the user what is going on
599 lyxerr << _("LyX: Creating directory ") << user_lyxdir
600 << _(" and running configure...") << endl;
602 // Create directory structure
603 if (!createDirectory(user_lyxdir, 0755)) {
604 // Failed, let's use $HOME instead.
605 user_lyxdir = GetEnvPath("HOME");
606 lyxerr << _("Failed. Will use ") << user_lyxdir
607 << _(" instead.") << endl;
611 // Run configure in user lyx directory
613 ::system(AddName(system_lyxdir, "configure").c_str());
614 lyxerr << "LyX: " << _("Done!") << endl;
618 // Read the rc file `name'
619 bool LyX::readRcFile(string const & name)
621 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
623 string const lyxrc_path = LibFileSearch(string(), name);
624 if (!lyxrc_path.empty()) {
625 lyxerr[Debug::INIT] << "Found " << name
626 << " in " << lyxrc_path << endl;
627 if (lyxrc.read(lyxrc_path) < 0) {
628 Alert::alert(_("LyX Warning!"),
629 _("Error while reading ") + lyxrc_path + ".",
630 _("Using built-in defaults."));
635 lyxerr[Debug::INIT] << "Could not find " << name << endl;
642 // Read the ui file `name'
643 void LyX::readUIFile(string const & name)
651 struct keyword_item uitags[ui_last-1] = {
652 { "menuset", ui_menuset },
653 { "toolbar", ui_toolbar }
656 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
658 string const ui_path = LibFileSearch("ui", name, "ui");
660 if (ui_path.empty()) {
661 lyxerr[Debug::INIT] << "Could not find " << name << endl;
662 menubackend.defaults();
666 lyxerr[Debug::INIT] << "Found " << name
667 << " in " << ui_path << endl;
668 LyXLex lex(uitags, ui_last - 1);
669 lex.setFile(ui_path);
671 lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
675 if (lyxerr.debugging(Debug::PARSER))
676 lex.printTable(lyxerr);
681 menubackend.read(lex);
685 toolbardefaults.read(lex);
689 if (!rtrim(lex.getString()).empty())
690 lex.printError("LyX::ReadUIFile: "
691 "Unknown menu tag: `$$Token'");
698 // Read the languages file `name'
699 void LyX::readLanguagesFile(string const & name)
701 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
703 string const lang_path = LibFileSearch(string(), name);
704 if (lang_path.empty()) {
705 lyxerr[Debug::INIT] << "Could not find " << name << endl;
706 languages.setDefaults();
709 languages.read(lang_path);
713 // Read the encodings file `name'
714 void LyX::readEncodingsFile(string const & name)
716 lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
718 string const enc_path = LibFileSearch(string(), name);
719 if (enc_path.empty()) {
720 lyxerr[Debug::INIT] << "Could not find " << name << endl;
723 encodings.read(enc_path);
729 // Set debugging level and report result to user
730 void setDebuggingLevel(string const & dbgLevel)
732 lyxerr << _("Setting debug level to ") << dbgLevel << endl;
733 lyxerr.level(Debug::value(dbgLevel));
734 Debug::showLevel(lyxerr, lyxerr.level());
738 // Give command line help
739 void commandLineHelp()
742 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
743 "Command line switches (case sensitive):\n"
744 "\t-help summarize LyX usage\n"
745 "\t-userdir dir try to set user directory to dir\n"
746 "\t-sysdir dir try to set system directory to dir\n"
747 "\t-geometry WxH+X+Y set geometry of the main window\n"
748 "\t-dbg feature[,feature]...\n"
749 " select the features to debug.\n"
750 " Type `lyx -dbg' to see the list of features\n"
751 "\t-x [--execute] command\n"
752 " where command is a lyx command.\n"
753 "\t-e [--export] fmt\n"
754 " where fmt is the export format of choice.\n"
755 "\t-i [--import] fmt file.xxx\n"
756 " where fmt is the import format of choice\n"
757 " and file.xxx is the file to be imported.\n"
758 "\t-version summarize version and build info\n"
759 "Check the LyX man page for more details.") << endl;
762 // Give command line version information
763 void commandLineVersionInfo()
765 lyxerr << "LyX " << lyx_version
766 << " of " << lyx_release_date << endl;
767 lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
769 lyxerr << lyx_version_info << endl;
776 bool LyX::easyParse(int & argc, char * argv[])
779 int removeargs = 0; // used when options are read
780 for (int i = 1; i < argc; ++i) {
781 string arg = argv[i];
783 // Check for -dbg int
786 setDebuggingLevel(argv[i + 1]);
789 lyxerr << _("List of supported debug flags:")
791 Debug::showTags(lyxerr);
795 // Check for "-sysdir"
796 else if (arg == "-sysdir") {
798 system_lyxdir = argv[i + 1];
801 lyxerr << _("Missing directory for -sysdir switch!")
806 // Check for "-userdir"
807 else if (arg == "-userdir") {
809 user_lyxdir = argv[i + 1];
812 lyxerr << _("Missing directory for -userdir switch!")
817 // Check for --help or -help
818 else if (arg == "--help" || arg == "-help") {
822 // Check for --version or -version
823 else if (arg == "--version" || arg == "-version") {
824 commandLineVersionInfo();
827 // FIXME: why is this commented out ?
828 // Check for "-nw": No XWindows as for emacs this should
829 // give a LyX that could be used in a terminal window.
830 //else if (arg == "-nw") {
834 // Check for "-x": Execute commands
835 else if (arg == "-x" || arg == "--execute") {
837 batch_command = string(argv[i + 1]);
841 lyxerr << _("Missing command string after -x switch!") << endl;
843 // Argh. Setting gui to false segfaults..
844 // FIXME: when ? how ?
848 else if (arg == "-e" || arg == "--export") {
850 string type(argv[i+1]);
852 batch_command = "buffer-export " + type;
855 lyxerr << _("Missing file type [eg latex, "
857 << arg << _(" switch!") << endl;
861 else if (arg == "-i" || arg == "--import") {
864 lyxerr << _("Missing filename for --import") << endl;
868 string const file(argv[i+2]);
869 string const type(argv[i+1]);
872 batch_command = "buffer-import " + type + " " + file;
873 lyxerr << "batch_command: "
874 << batch_command << endl;
877 lyxerr << _("Missing type [eg latex, "
879 << arg << _(" switch!") << endl;
884 if (removeargs > 0) {
885 // Now, remove used arguments by shifting
886 // the following ones removeargs places down.
888 for (int j = i; j < argc; ++j)
889 argv[j] = argv[j + removeargs];
890 --i; // After shift, check this number again.