comparison src/octave.cc @ 3019:92aa3d651723

[project @ 1997-06-03 22:07:16 by jwe]
author jwe
date Tue, 03 Jun 1997 22:10:41 +0000
parents 38de16594cb4
children 95e8b5c4824a
comparison
equal deleted inserted replaced
3018:5708b8bb4f06 3019:92aa3d651723
45 45
46 #include "cmd-edit.h" 46 #include "cmd-edit.h"
47 #include "file-stat.h" 47 #include "file-stat.h"
48 #include "lo-error.h" 48 #include "lo-error.h"
49 #include "oct-env.h" 49 #include "oct-env.h"
50 #include "pathsearch.h"
50 #include "str-vec.h" 51 #include "str-vec.h"
51 52
52 #include <defaults.h> 53 #include <defaults.h>
53 #include "defun.h" 54 #include "defun.h"
54 #include "dynamic-ld.h" 55 #include "dynamic-ld.h"
58 #include "lex.h" 59 #include "lex.h"
59 #include "oct-hist.h" 60 #include "oct-hist.h"
60 #include "ops.h" 61 #include "ops.h"
61 #include "toplev.h" 62 #include "toplev.h"
62 #include "parse.h" 63 #include "parse.h"
63 #include "pathsearch.h"
64 #include "pt-plot.h" 64 #include "pt-plot.h"
65 #include "procstream.h" 65 #include "procstream.h"
66 #include "prog-args.h" 66 #include "prog-args.h"
67 #include "sighandlers.h" 67 #include "sighandlers.h"
68 #include "sysdep.h" 68 #include "sysdep.h"
77 #if !defined (HAVE_ATEXIT) && defined (HAVE_ON_EXIT) 77 #if !defined (HAVE_ATEXIT) && defined (HAVE_ON_EXIT)
78 extern "C" int on_exit (); 78 extern "C" int on_exit ();
79 #define atexit on_exit 79 #define atexit on_exit
80 #endif 80 #endif
81 81
82 // Don't redefine the variables if glibc already has.
83 #if defined (HAVE_PROGRAM_INVOCATION_NAME) || defined (WITH_KPATHSEARCH)
84 extern char *program_invocation_name;
85 extern char *program_invocation_short_name;
86 #else
87 char *program_invocation_name;
88 char *program_invocation_short_name;
89 #endif
90
91 // The command-line options. 82 // The command-line options.
92 static string_vector octave_argv; 83 static string_vector octave_argv;
93 84
94 // TRUE means we read ~/.octaverc and ./.octaverc. 85 // TRUE means we read ~/.octaverc and ./.octaverc.
95 // (--norc; --no-init-file; -f) 86 // (--norc; --no-init-file; -f)
97 88
98 // TRUE means we read the site-wide octaverc files. 89 // TRUE means we read the site-wide octaverc files.
99 // (--norc; --no-site-file; -f) 90 // (--norc; --no-site-file; -f)
100 static bool read_site_files = true; 91 static bool read_site_files = true;
101 92
102 // Nonzero means we don't print the usual startup message. 93 // TRUE means we don't print the usual startup message.
103 // (--quiet; --silent; -q) 94 // (--quiet; --silent; -q)
104 static bool inhibit_startup_message = false; 95 static bool inhibit_startup_message = false;
105 96
106 // Nonzero means we turn on compatibility options. 97 // TRUE means we turn on compatibility options.
107 // (--traditional) 98 // (--traditional)
108 static bool traditional = false; 99 static bool traditional = false;
109 100
110 // If nonzero, print verbose info in some cases. 101 // If TRUE, print verbose info in some cases.
111 // (--verbose; -V) 102 // (--verbose; -V)
112 static bool verbose_flag = false; 103 static bool verbose_flag = false;
113 104
114 // Usage message 105 // Usage message
115 static const char *usage_string = 106 static const char *usage_string =
150 { "quiet", prog_args::no_arg, 0, 'q' }, 141 { "quiet", prog_args::no_arg, 0, 'q' },
151 { "silent", prog_args::no_arg, 0, 'q' }, 142 { "silent", prog_args::no_arg, 0, 'q' },
152 { "traditional", prog_args::no_arg, 0, TRADITIONAL_OPTION }, 143 { "traditional", prog_args::no_arg, 0, TRADITIONAL_OPTION },
153 { "verbose", prog_args::no_arg, 0, 'V' }, 144 { "verbose", prog_args::no_arg, 0, 'V' },
154 { "version", prog_args::no_arg, 0, 'v' }, 145 { "version", prog_args::no_arg, 0, 'v' },
155 { 0, 0, 0, 0 } 146 { 0, 0, 0, 0 }
156 }; 147 };
157 148
158 // Store the command-line options for later use. 149 // Store the command-line options for later use.
159 150
160 static void 151 static void
161 intern_argv (int argc, char **argv) 152 intern_argv (int argc, char **argv)
162 { 153 {
163 octave_env::set_program_name (argv[0]);
164
165 // XXX FIXME XXX -- Kpathsea needs this.
166
167 #if ! defined (HAVE_PROGRAM_INVOCATION_NAME)
168 program_invocation_name
169 = strsave (octave_env::get_program_invocation_name () . c_str ());
170
171 program_invocation_short_name
172 = strsave (octave_env::get_program_name () . c_str ());
173 #endif
174
175 if (argc > 1) 154 if (argc > 1)
176 { 155 {
177 // Skip program name in argv. 156 // Skip program name in argv.
178 157
179 octave_argv = string_vector (argv+1, argc-1); 158 octave_argv = string_vector (argv+1, argc-1);
217 unwind_protect::begin_frame ("execute_startup_files"); 196 unwind_protect::begin_frame ("execute_startup_files");
218 197
219 // XXX FIXME XXX -- need to make it possible to set this in startup 198 // XXX FIXME XXX -- need to make it possible to set this in startup
220 // files. 199 // files.
221 200
222 unwind_protect_int (input_from_startup_file); 201 unwind_protect_bool (input_from_startup_file);
223 202
224 input_from_startup_file = 1; 203 input_from_startup_file = true;
225 204
226 int verbose = (verbose_flag && ! inhibit_startup_message); 205 int verbose = (verbose_flag && ! inhibit_startup_message);
227 206
228 if (read_site_files) 207 if (read_site_files)
229 { 208 {
365 // You guessed it. 344 // You guessed it.
366 345
367 int 346 int
368 main (int argc, char **argv) 347 main (int argc, char **argv)
369 { 348 {
349 octave_env::set_program_name (argv[0]);
350
370 // The order of these calls is important. The call to 351 // The order of these calls is important. The call to
371 // install_defaults must come before install_builtins because 352 // install_defaults must come before install_builtins because
372 // default variable values must be available for the varaibles to be 353 // default variable values must be available for the variables to be
373 // installed, and the call to install_builtins must come before the 354 // installed, and the call to install_builtins must come before the
374 // options are processed because some command line options override 355 // options are processed because some command line options override
375 // defaults by calling bind_builtin_variable. 356 // defaults by calling bind_builtin_variable.
376 357
377 sysdep_init (); 358 sysdep_init ();
418 case '?': 399 case '?':
419 verbose_usage (); 400 verbose_usage ();
420 break; 401 break;
421 402
422 case 'i': 403 case 'i':
423 forced_interactive = 1; 404 forced_interactive = true;
424 break; 405 break;
425 406
426 case 'p': 407 case 'p':
427 if (args.optarg ()) 408 if (args.optarg ())
428 bind_builtin_variable ("LOADPATH", args.optarg ()); 409 bind_builtin_variable ("LOADPATH", args.optarg ());
461 case NO_INIT_FILE_OPTION: 442 case NO_INIT_FILE_OPTION:
462 read_init_files = false; 443 read_init_files = false;
463 break; 444 break;
464 445
465 case NO_LINE_EDITING_OPTION: 446 case NO_LINE_EDITING_OPTION:
466 line_editing = 0; 447 line_editing = false;
467 break; 448 break;
468 449
469 case NO_SITE_FILE_OPTION: 450 case NO_SITE_FILE_OPTION:
470 read_site_files = 0; 451 read_site_files = 0;
471 break; 452 break;
515 // If there is an extra argument, see if it names a file to read. 496 // If there is an extra argument, see if it names a file to read.
516 // Additional arguments are taken as command line options for the 497 // Additional arguments are taken as command line options for the
517 // script. 498 // script.
518 499
519 int last_arg_idx = args.optind (); 500 int last_arg_idx = args.optind ();
501
520 int remaining_args = argc - last_arg_idx; 502 int remaining_args = argc - last_arg_idx;
503
521 if (remaining_args > 0) 504 if (remaining_args > 0)
522 { 505 {
523 reading_script_file = 1; 506 reading_script_file = true;
507
524 curr_fcn_file_name = argv[last_arg_idx]; 508 curr_fcn_file_name = argv[last_arg_idx];
525 curr_fcn_file_full_name = curr_fcn_file_name; 509 curr_fcn_file_full_name = curr_fcn_file_name;
526 510
527 FILE *infile = get_input_from_file (curr_fcn_file_name); 511 FILE *infile = get_input_from_file (curr_fcn_file_name);
528 512
529 if (infile) 513 if (infile)
530 { 514 {
531 input_from_command_line_file = 1; 515 input_from_command_line_file = true;
532 516
533 bind_builtin_variable ("program_invocation_name", 517 bind_builtin_variable ("program_invocation_name",
534 curr_fcn_file_name); 518 curr_fcn_file_name);
535 519
536 size_t pos = curr_fcn_file_name.rfind ('/'); 520 size_t pos = curr_fcn_file_name.rfind ('/');
573 bind_builtin_variable ("echo_executing_commands", 557 bind_builtin_variable ("echo_executing_commands",
574 static_cast<double> (ECHO_CMD_LINE)); 558 static_cast<double> (ECHO_CMD_LINE));
575 } 559 }
576 560
577 if (! interactive) 561 if (! interactive)
578 line_editing = 0; 562 line_editing = false;
579 563
580 int retval = main_loop (); 564 int retval = main_loop ();
581 565
582 if (retval == 1 && ! error_state) 566 if (retval == 1 && ! error_state)
583 retval = 0; 567 retval = 0;