comparison src/octave.cc @ 11140:8aa93f43bae8

use getopt_long correctly
author John W. Eaton <jwe@octave.org>
date Fri, 22 Oct 2010 21:18:00 -0400
parents 5677f3f7b5fa
children c75130f19440
comparison
equal deleted inserted replaced
11139:0dd95d1d57e6 11140:8aa93f43bae8
112 // (--verbose; -V) 112 // (--verbose; -V)
113 static bool verbose_flag = false; 113 static bool verbose_flag = false;
114 114
115 // Usage message 115 // Usage message
116 static const char *usage_string = 116 static const char *usage_string =
117 "octave [-?HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ 117 "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\
118 [--exec-path path] [--help] [--image-path path] [--info-file file]\n\ 118 [--exec-path path] [--help] [--image-path path] [--info-file file]\n\
119 [--info-program prog] [--interactive] [--line-editing]\n\ 119 [--info-program prog] [--interactive] [--line-editing]\n\
120 [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing]\n\ 120 [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing]\n\
121 [--no-site-file] [--no-window-system] [-p path] [--path path]\n\ 121 [--no-site-file] [--no-window-system] [-p path] [--path path]\n\
122 [--silent] [--traditional] [--verbose] [--version] [file]"; 122 [--silent] [--traditional] [--verbose] [--version] [file]";
123 123
124 // This is here so that it's more likely that the usage message and 124 // This is here so that it's more likely that the usage message and
125 // the real set of options will agree. Note: the `+' must come first 125 // the real set of options will agree. Note: the `+' must come first
126 // to prevent getopt from permuting arguments! 126 // to prevent getopt from permuting arguments!
127 static const char *short_opts = "+?HVdfhip:qvx"; 127 static const char *short_opts = "+HVdfhip:qvx";
128 128
129 // The code to evaluate at startup (--eval CODE) 129 // The code to evaluate at startup (--eval CODE)
130 static std::string code_to_eval; 130 static std::string code_to_eval;
131 131
132 // If TRUE, don't exit after evaluating code given by --eval option. 132 // If TRUE, don't exit after evaluating code given by --eval option.
474 --debug, -d Enter parser debugging mode.\n\ 474 --debug, -d Enter parser debugging mode.\n\
475 --doc-cache-file FILE Use doc cache file FILE.\n\ 475 --doc-cache-file FILE Use doc cache file FILE.\n\
476 --echo-commands, -x Echo commands as they are executed.\n\ 476 --echo-commands, -x Echo commands as they are executed.\n\
477 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ 477 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\
478 --exec-path PATH Set path for executing subprograms.\n\ 478 --exec-path PATH Set path for executing subprograms.\n\
479 --help, -h, -? Print short help message and exit.\n\ 479 --help, -h, Print short help message and exit.\n\
480 --image-path PATH Add PATH to head of image search path.\n\ 480 --image-path PATH Add PATH to head of image search path.\n\
481 --info-file FILE Use top-level info file FILE.\n\ 481 --info-file FILE Use top-level info file FILE.\n\
482 --info-program PROGRAM Use PROGRAM for reading info files.\n\ 482 --info-program PROGRAM Use PROGRAM for reading info files.\n\
483 --interactive, -i Force interactive behavior.\n\ 483 --interactive, -i Force interactive behavior.\n\
484 --line-editing Force readline use for command-line editing.\n\ 484 --line-editing Force readline use for command-line editing.\n\
511 // Terse usage messsage. 511 // Terse usage messsage.
512 512
513 static void 513 static void
514 usage (void) 514 usage (void)
515 { 515 {
516 std::cerr << "usage: " << usage_string << "\n"; 516 std::cerr << "\nusage: " << usage_string << "\n\n";
517 exit (1); 517 exit (1);
518 } 518 }
519 519
520 static void 520 static void
521 print_version_and_exit (void) 521 print_version_and_exit (void)
646 if (optc < 0) 646 if (optc < 0)
647 break; 647 break;
648 648
649 switch (optc) 649 switch (optc)
650 { 650 {
651 case '?':
652 // Unrecognized option. getopt_long already printed a
653 // message about that, so we will just print the usage string
654 // and exit.
655 usage ();
656 break;
657
651 case 'H': 658 case 'H':
652 read_history_file = false; 659 read_history_file = false;
653 bind_internal_variable ("saving_history", false); 660 bind_internal_variable ("saving_history", false);
654 break; 661 break;
655 662
666 read_init_files = false; 673 read_init_files = false;
667 read_site_files = false; 674 read_site_files = false;
668 break; 675 break;
669 676
670 case 'h': 677 case 'h':
671 case '?':
672 verbose_usage (); 678 verbose_usage ();
673 break; 679 break;
674 680
675 case 'i': 681 case 'i':
676 forced_interactive = true; 682 forced_interactive = true;
762 case TRADITIONAL_OPTION: 768 case TRADITIONAL_OPTION:
763 traditional = true; 769 traditional = true;
764 break; 770 break;
765 771
766 default: 772 default:
767 usage (); 773 // getopt_long should print a message about unrecognized
774 // options and return '?', which is handled above. So if we
775 // end up here, it is because there was an option but we
776 // forgot to handle it. That should be fatal.
777 panic_impossible ();
768 break; 778 break;
769 } 779 }
770 } 780 }
771 781
772 // Make sure we clean up when we exit. Also allow users to register 782 // Make sure we clean up when we exit. Also allow users to register