comparison libinterp/octave.cc @ 17777:ae8905fbf1f8

move usage and options strings and funtions to separate file * options-usage.h: New file. * libinterp/Makefile.am: Update lists. * octave.cc (usage_string, short_opts, long_opts): Move variable definitions to options-usage.h. (BUILT_IN_DOCSTRINGS_FILE_OPTION, DOC_CACHE_FILE_OPTION, EVAL_OPTION, EXEC_PATH_OPTION, FORCE_GUI_OPTION, IMAGE_PATH_OPTION, INFO_FILE_OPTION, INFO_PROG_OPTION, DEBUG_JIT_OPTION, LINE_EDITING_OPTION, NO_FORK_OPTION, NO_GUI_OPTION, NO_INIT_FILE_OPTION, NO_INIT_PATH_OPTION, NO_JIT_COMPILER_OPTION, NO_LINE_EDITING_OPTION, NO_SITE_FILE_OPTION, PERSIST_OPTION, TEXI_MACROS_FILE_OPTION, TRADITIONAL_OPTION): Move macro definitions to options-usage.h. (print_version_and_exit): Move to options-usage.h. (verbose_usage): Move to options-usage.h and rename to octave_print_verbose_usage_and_exit. Change all uses. (usage): Move to options-usage.h and rename to octave_print_terse_usage_and_exit. Change all uses.
author John W. Eaton <jwe@octave.org>
date Sun, 27 Oct 2013 08:40:54 -0400
parents 9c03b071fd7b
children b5d58667d32d
comparison
equal deleted inserted replaced
17776:8402768afd2d 17777:ae8905fbf1f8
63 #include "oct-hist.h" 63 #include "oct-hist.h"
64 #include "oct-map.h" 64 #include "oct-map.h"
65 #include "oct-mutex.h" 65 #include "oct-mutex.h"
66 #include "oct-obj.h" 66 #include "oct-obj.h"
67 #include "ops.h" 67 #include "ops.h"
68 #include "options-usage.h"
68 #include "ov.h" 69 #include "ov.h"
69 #include "ov-range.h" 70 #include "ov-range.h"
70 #include "toplev.h" 71 #include "toplev.h"
71 #include "parse.h" 72 #include "parse.h"
72 #include "procstream.h" 73 #include "procstream.h"
157 158
158 // If TRUE, ignore the window system even if it is available. 159 // If TRUE, ignore the window system even if it is available.
159 // (--no-window-system, -W) 160 // (--no-window-system, -W)
160 static bool no_window_system = false; 161 static bool no_window_system = false;
161 162
162 // Usage message
163 static const char *usage_string =
164 "octave [-HVWdfhiqvx] [--debug] [--debug-jit] [--doc-cache-file file]\n\
165 [--echo-commands] [--eval CODE] [--exec-path path]\n\
166 [--force-gui] [--help] [--image-path path]\n\
167 [--info-file file] [--info-program prog] [--interactive]\n\
168 [--line-editing] [--no-fork] [--no-gui] [--no-history]\n\
169 [--no-init-file] [--no-init-path] [--no-jit-compiler]\n\
170 [--no-line-editing] [--no-site-file] [--no-window-system]\n\
171 [--norc] [-p path] [--path path] [--persist] [--silent]\n\
172 [--traditional] [--verbose] [--version] [file]";
173
174 // This is here so that it's more likely that the usage message and
175 // the real set of options will agree. Note: the '+' must come first
176 // to prevent getopt from permuting arguments!
177 static const char *short_opts = "+HWVdfhip:qvx";
178
179 // The code to evaluate at startup (--eval CODE) 163 // The code to evaluate at startup (--eval CODE)
180 static std::string code_to_eval; 164 static std::string code_to_eval;
181 165
182 // If TRUE, don't exit after evaluating code given by --eval option. 166 // If TRUE, don't exit after evaluating code given by --eval option.
183 static bool persist = false; 167 static bool persist = false;
185 // If TRUE, the GUI should be started. 169 // If TRUE, the GUI should be started.
186 static bool start_gui = false; 170 static bool start_gui = false;
187 171
188 // If TRUE use traditional settings (--traditional) 172 // If TRUE use traditional settings (--traditional)
189 static bool traditional = false; 173 static bool traditional = false;
190
191 // Long options. See the comments in getopt.h for the meanings of the
192 // fields in this structure.
193 #define BUILT_IN_DOCSTRINGS_FILE_OPTION 1
194 #define DOC_CACHE_FILE_OPTION 2
195 #define EVAL_OPTION 3
196 #define EXEC_PATH_OPTION 4
197 #define FORCE_GUI_OPTION 5
198 #define IMAGE_PATH_OPTION 6
199 #define INFO_FILE_OPTION 7
200 #define INFO_PROG_OPTION 8
201 #define DEBUG_JIT_OPTION 9
202 #define LINE_EDITING_OPTION 10
203 #define NO_FORK_OPTION 11
204 #define NO_GUI_OPTION 12
205 #define NO_INIT_FILE_OPTION 13
206 #define NO_INIT_PATH_OPTION 14
207 #define NO_JIT_COMPILER_OPTION 15
208 #define NO_LINE_EDITING_OPTION 16
209 #define NO_SITE_FILE_OPTION 17
210 #define PERSIST_OPTION 18
211 #define TEXI_MACROS_FILE_OPTION 19
212 #define TRADITIONAL_OPTION 20
213 struct option long_opts[] = {
214 { "braindead", no_argument, 0, TRADITIONAL_OPTION },
215 { "built-in-docstrings-file", required_argument, 0, BUILT_IN_DOCSTRINGS_FILE_OPTION },
216 { "debug", no_argument, 0, 'd' },
217 { "debug-jit", no_argument, 0, DEBUG_JIT_OPTION },
218 { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION },
219 { "echo-commands", no_argument, 0, 'x' },
220 { "eval", required_argument, 0, EVAL_OPTION },
221 { "exec-path", required_argument, 0, EXEC_PATH_OPTION },
222 { "force-gui", no_argument, 0, FORCE_GUI_OPTION },
223 { "help", no_argument, 0, 'h' },
224 { "image-path", required_argument, 0, IMAGE_PATH_OPTION },
225 { "info-file", required_argument, 0, INFO_FILE_OPTION },
226 { "info-program", required_argument, 0, INFO_PROG_OPTION },
227 { "interactive", no_argument, 0, 'i' },
228 { "line-editing", no_argument, 0, LINE_EDITING_OPTION },
229 { "no-fork", no_argument, 0, NO_FORK_OPTION },
230 { "no-gui", no_argument, 0, NO_GUI_OPTION },
231 { "no-history", no_argument, 0, 'H' },
232 { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION },
233 { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION },
234 { "no-jit-compiler", no_argument, 0, NO_JIT_COMPILER_OPTION },
235 { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION },
236 { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION },
237 { "no-window-system", no_argument, 0, 'W' },
238 { "norc", no_argument, 0, 'f' },
239 { "path", required_argument, 0, 'p' },
240 { "persist", no_argument, 0, PERSIST_OPTION },
241 { "quiet", no_argument, 0, 'q' },
242 { "silent", no_argument, 0, 'q' },
243 { "texi-macros-file", required_argument, 0, TEXI_MACROS_FILE_OPTION },
244 { "traditional", no_argument, 0, TRADITIONAL_OPTION },
245 { "verbose", no_argument, 0, 'V' },
246 { "version", no_argument, 0, 'v' },
247 { 0, 0, 0, 0 }
248 };
249 174
250 // Store the command-line options for later use. 175 // Store the command-line options for later use.
251 176
252 static void 177 static void
253 intern_argv (int argc, char **argv) 178 intern_argv (int argc, char **argv)
515 std::string context; 440 std::string context;
516 bool verbose = false; 441 bool verbose = false;
517 bool require_file = true; 442 bool require_file = true;
518 443
519 safe_source_file (fname, context, verbose, require_file, "octave"); 444 safe_source_file (fname, context, verbose, require_file, "octave");
520 }
521
522 // Usage message with extra help.
523
524 static void
525 verbose_usage (void)
526 {
527 std::cout << octave_name_version_copyright_copying_and_warranty ()
528 << "\n\
529 \n\
530 Usage: octave [options] [FILE]\n\
531 \n\
532 Options:\n\
533 \n\
534 --built-in-docstrings-file FILE Use docs for built-ins from FILE.\n\
535 --debug, -d Enter parser debugging mode.\n\
536 --debug-jit Enable JIT compiler debugging/tracing.\n\
537 --doc-cache-file FILE Use doc cache file FILE.\n\
538 --echo-commands, -x Echo commands as they are executed.\n\
539 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\
540 --exec-path PATH Set path for executing subprograms.\n\
541 --force-gui Force graphical user interface to start.\n\
542 --help, -h, Print short help message and exit.\n\
543 --image-path PATH Add PATH to head of image search path.\n\
544 --info-file FILE Use top-level info file FILE.\n\
545 --info-program PROGRAM Use PROGRAM for reading info files.\n\
546 --interactive, -i Force interactive behavior.\n\
547 --line-editing Force readline use for command-line editing.\n\
548 --no-fork Don't fork when starting the graphical user interface.\n\
549 --no-gui Disable the graphical user interface.\n\
550 --no-history, -H Don't save commands to the history list\n\
551 --no-init-file Don't read the ~/.octaverc or .octaverc files.\n\
552 --no-init-path Don't initialize function search path.\n\
553 --no-jit-compiler Disable the JIT compiler.\n\
554 --no-line-editing Don't use readline for command-line editing.\n\
555 --no-site-file Don't read the site-wide octaverc file.\n\
556 --no-window-system, -W Disable window system, including graphics.\n\
557 --norc, -f Don't read any initialization files.\n\
558 --path PATH, -p PATH Add PATH to head of function search path.\n\
559 --persist Go interactive after --eval or reading from FILE.\n\
560 --silent, --quiet, -q Don't print message at startup.\n\
561 --texi-macros-file FILE Use Texinfo macros in FILE for makeinfo command.\n\
562 --traditional Set variables for closer MATLAB compatibility.\n\
563 --verbose, -V Enable verbose output in some cases.\n\
564 --version, -v Print version number and exit.\n\
565 \n\
566 FILE Execute commands from FILE. Exit when done\n\
567 unless --persist is also specified.\n\
568 \n"
569 << octave_www_statement ()
570 << "\n\n"
571 << octave_contrib_statement ()
572 << "\n\n"
573 << octave_bugs_statement ()
574 << "\n";
575
576 exit (0);
577 }
578
579 // Terse usage messsage.
580
581 static void
582 usage (void)
583 {
584 std::cerr << "\nusage: " << usage_string << "\n\n";
585 exit (1);
586 }
587
588 static void
589 print_version_and_exit (void)
590 {
591 std::cout << octave_name_version_copyright_copying_warranty_and_bugs ()
592 << "\n";
593 exit (0);
594 } 445 }
595 446
596 static void 447 static void
597 lo_error_handler (const char *fmt, ...) 448 lo_error_handler (const char *fmt, ...)
598 { 449 {
688 { 539 {
689 case '?': 540 case '?':
690 // Unrecognized option. getopt_long already printed a 541 // Unrecognized option. getopt_long already printed a
691 // message about that, so we will just print the usage string 542 // message about that, so we will just print the usage string
692 // and exit. 543 // and exit.
693 usage (); 544 octave_print_terse_usage_and_exit ();
694 break; 545 break;
695 546
696 case 'H': 547 case 'H':
697 Fhistory_save (octave_value (false)); 548 Fhistory_save (octave_value (false));
698 read_history_file = false; 549 read_history_file = false;
715 read_init_files = false; 566 read_init_files = false;
716 read_site_files = false; 567 read_site_files = false;
717 break; 568 break;
718 569
719 case 'h': 570 case 'h':
720 verbose_usage (); 571 octave_print_verbose_usage_and_exit ();
721 break; 572 break;
722 573
723 case 'i': 574 case 'i':
724 forced_interactive = true; 575 forced_interactive = true;
725 break; 576 break;
739 Fecho_executing_commands (octave_value (val)); 590 Fecho_executing_commands (octave_value (val));
740 } 591 }
741 break; 592 break;
742 593
743 case 'v': 594 case 'v':
744 print_version_and_exit (); 595 octave_print_version_and_exit ();
745 break; 596 break;
746 597
747 case BUILT_IN_DOCSTRINGS_FILE_OPTION: 598 case BUILT_IN_DOCSTRINGS_FILE_OPTION:
748 if (optarg) 599 if (optarg)
749 Fbuilt_in_docstrings_file (octave_value (optarg)); 600 Fbuilt_in_docstrings_file (octave_value (optarg));
848 } 699 }
849 700
850 if (force_gui_option && no_gui_option) 701 if (force_gui_option && no_gui_option)
851 { 702 {
852 error ("error: only one of --force-gui and --no-gui may be used"); 703 error ("error: only one of --force-gui and --no-gui may be used");
853 usage (); 704
705 octave_print_terse_usage_and_exit ();
854 } 706 }
855 } 707 }
856 708
857 // EMBEDDED is declared int instead of bool because this function is 709 // EMBEDDED is declared int instead of bool because this function is
858 // declared extern "C". 710 // declared extern "C".