1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
|
24 // Born February 20, 1992. |
|
25 |
240
|
26 #ifdef HAVE_CONFIG_H |
1192
|
27 #include <config.h> |
1
|
28 #endif |
|
29 |
1355
|
30 #include <cassert> |
|
31 #include <cstdlib> |
|
32 #include <cstring> |
|
33 #include <ctime> |
|
34 |
3503
|
35 #include <fstream> |
|
36 #include <iostream> |
1355
|
37 |
|
38 #ifdef HAVE_UNISTD_H |
2442
|
39 #ifdef HAVE_SYS_TYPES_H |
1
|
40 #include <sys/types.h> |
2442
|
41 #endif |
139
|
42 #include <unistd.h> |
|
43 #endif |
1355
|
44 |
2926
|
45 #include "cmd-edit.h" |
3690
|
46 #include "f77-fcn.h" |
4097
|
47 #include "file-ops.h" |
2926
|
48 #include "file-stat.h" |
240
|
49 #include "lo-error.h" |
2926
|
50 #include "oct-env.h" |
3019
|
51 #include "pathsearch.h" |
1907
|
52 #include "str-vec.h" |
223
|
53 |
2492
|
54 #include <defaults.h> |
3933
|
55 #include "Cell.h" |
1355
|
56 #include "defun.h" |
|
57 #include "error.h" |
|
58 #include "file-io.h" |
1
|
59 #include "input.h" |
|
60 #include "lex.h" |
4113
|
61 #include "octave.h" |
1742
|
62 #include "oct-hist.h" |
5654
|
63 #include "oct-map.h" |
3195
|
64 #include "oct-obj.h" |
2375
|
65 #include "ops.h" |
1670
|
66 #include "toplev.h" |
1
|
67 #include "parse.h" |
562
|
68 #include "procstream.h" |
1817
|
69 #include "prog-args.h" |
1355
|
70 #include "sighandlers.h" |
|
71 #include "sysdep.h" |
2375
|
72 #include "ov.h" |
1
|
73 #include "unwind-prot.h" |
1355
|
74 #include "utils.h" |
|
75 #include "variables.h" |
2492
|
76 #include <version.h> |
1
|
77 |
4159
|
78 // Kluge. |
5275
|
79 extern "C" void F77_FUNC (xerbla, XERBLA) (const char *, octave_idx_type, long); |
4159
|
80 |
2910
|
81 extern void install_builtins (void); |
|
82 |
1704
|
83 #if !defined (HAVE_ATEXIT) && defined (HAVE_ON_EXIT) |
|
84 extern "C" int on_exit (); |
|
85 #define atexit on_exit |
|
86 #endif |
|
87 |
1907
|
88 // The command-line options. |
|
89 static string_vector octave_argv; |
1
|
90 |
2239
|
91 // TRUE means we read ~/.octaverc and ./.octaverc. |
|
92 // (--norc; --no-init-file; -f) |
|
93 static bool read_init_files = true; |
|
94 |
|
95 // TRUE means we read the site-wide octaverc files. |
|
96 // (--norc; --no-site-file; -f) |
2240
|
97 static bool read_site_files = true; |
1
|
98 |
3019
|
99 // TRUE means we don't print the usual startup message. |
616
|
100 // (--quiet; --silent; -q) |
2239
|
101 static bool inhibit_startup_message = false; |
1
|
102 |
3019
|
103 // TRUE means we turn on compatibility options. |
1410
|
104 // (--traditional) |
2239
|
105 static bool traditional = false; |
1410
|
106 |
3019
|
107 // If TRUE, print verbose info in some cases. |
1825
|
108 // (--verbose; -V) |
2239
|
109 static bool verbose_flag = false; |
1825
|
110 |
1
|
111 // Usage message |
139
|
112 static const char *usage_string = |
5189
|
113 "octave [-?HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ |
|
114 [--exec-path path] [--help] [--info-file file] [--info-program prog]\n\ |
4356
|
115 [--interactive] [--no-history] [--no-init-file] [--no-line-editing]\n\ |
|
116 [--no-site-file] [-p path] [--path path] [--silent] [--traditional]\n\ |
|
117 [--verbose] [--version] [file]"; |
1
|
118 |
1358
|
119 // This is here so that it's more likely that the usage message and |
1410
|
120 // the real set of options will agree. Note: the `+' must come first |
|
121 // to prevent getopt from permuting arguments! |
3180
|
122 static const char *short_opts = "+?HVdfhip:qvx"; |
139
|
123 |
5189
|
124 // The code to evaluate at startup (--eval CODE) |
|
125 static std::string code_to_eval; |
|
126 |
|
127 // If TRUE, don't exit after evaluating code given by --eval option. |
|
128 static bool persist = false; |
4356
|
129 |
1103
|
130 // Long options. See the comments in getopt.h for the meanings of the |
|
131 // fields in this structure. |
5189
|
132 #define EVAL_OPTION 1 |
|
133 #define EXEC_PATH_OPTION 2 |
4356
|
134 #define INFO_FILE_OPTION 3 |
|
135 #define INFO_PROG_OPTION 4 |
|
136 #define NO_INIT_FILE_OPTION 5 |
|
137 #define NO_LINE_EDITING_OPTION 6 |
|
138 #define NO_SITE_FILE_OPTION 7 |
5189
|
139 #define PERSIST_OPTION 8 |
|
140 #define TRADITIONAL_OPTION 9 |
1817
|
141 long_options long_opts[] = |
139
|
142 { |
1855
|
143 { "debug", prog_args::no_arg, 0, 'd' }, |
2277
|
144 { "braindead", prog_args::no_arg, 0, TRADITIONAL_OPTION }, |
1855
|
145 { "echo-commands", prog_args::no_arg, 0, 'x' }, |
5189
|
146 { "eval", prog_args::required_arg, 0, EVAL_OPTION }, |
1855
|
147 { "exec-path", prog_args::required_arg, 0, EXEC_PATH_OPTION }, |
|
148 { "help", prog_args::no_arg, 0, 'h' }, |
|
149 { "info-file", prog_args::required_arg, 0, INFO_FILE_OPTION }, |
|
150 { "info-program", prog_args::required_arg, 0, INFO_PROG_OPTION }, |
|
151 { "interactive", prog_args::no_arg, 0, 'i' }, |
3180
|
152 { "no-history", prog_args::no_arg, 0, 'H' }, |
2239
|
153 { "no-init-file", prog_args::no_arg, 0, NO_INIT_FILE_OPTION }, |
1855
|
154 { "no-line-editing", prog_args::no_arg, 0, NO_LINE_EDITING_OPTION }, |
2239
|
155 { "no-site-file", prog_args::no_arg, 0, NO_SITE_FILE_OPTION }, |
1855
|
156 { "norc", prog_args::no_arg, 0, 'f' }, |
|
157 { "path", prog_args::required_arg, 0, 'p' }, |
5189
|
158 { "persist", prog_args::no_arg, 0, PERSIST_OPTION }, |
1855
|
159 { "quiet", prog_args::no_arg, 0, 'q' }, |
|
160 { "silent", prog_args::no_arg, 0, 'q' }, |
|
161 { "traditional", prog_args::no_arg, 0, TRADITIONAL_OPTION }, |
|
162 { "verbose", prog_args::no_arg, 0, 'V' }, |
|
163 { "version", prog_args::no_arg, 0, 'v' }, |
3019
|
164 { 0, 0, 0, 0 } |
139
|
165 }; |
1
|
166 |
1355
|
167 // Store the command-line options for later use. |
|
168 |
|
169 static void |
|
170 intern_argv (int argc, char **argv) |
|
171 { |
4892
|
172 symbol_record *nargin_sr = top_level_sym_tab->lookup ("__nargin__", true); |
|
173 |
|
174 nargin_sr->mark_as_static (); |
|
175 |
|
176 nargin_sr->define (argc-1); |
3195
|
177 |
4587
|
178 Cell args; |
3195
|
179 |
1355
|
180 if (argc > 1) |
|
181 { |
3933
|
182 Array<octave_value> tmp (argc-1); |
|
183 |
2495
|
184 // Skip program name in argv. |
3933
|
185 int i = argc; |
|
186 while (--i > 0) |
|
187 tmp(i-1) = octave_value (*(argv+i)); |
1411
|
188 |
4587
|
189 args = Cell (tmp, argc-1, 1); |
1355
|
190 } |
1907
|
191 |
4587
|
192 bind_builtin_constant ("argv", args, true, true); |
1355
|
193 } |
|
194 |
1792
|
195 static void |
|
196 initialize_pathsearch (void) |
|
197 { |
|
198 // This may seem odd, but doing it this way means that we don't have |
|
199 // to modify the kpathsea library... |
|
200 |
3523
|
201 std::string odb = octave_env::getenv ("OCTAVE_DB_PATH"); |
3141
|
202 |
|
203 // For backward compatibility. |
1792
|
204 |
2926
|
205 if (odb.empty ()) |
3141
|
206 odb = octave_env::getenv ("OCTAVE_DB_DIR"); |
1792
|
207 |
3141
|
208 if (odb.empty ()) |
4101
|
209 odb = Vdata_dir + file_ops::dir_sep_str + "octave:" |
|
210 + Vlibexec_dir + file_ops::dir_sep_str + "octave"; |
1792
|
211 } |
|
212 |
5654
|
213 DEFUN (__version_info__, args, , |
|
214 "-*- texinfo -*-\n\ |
5658
|
215 @deftypefn {Function File} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})\n\ |
5654
|
216 @end deftypefn") |
|
217 { |
|
218 octave_value retval; |
|
219 |
|
220 static Octave_map vinfo; |
|
221 |
|
222 int nargin = args.length (); |
|
223 |
5658
|
224 if (nargin == 4) |
5654
|
225 { |
|
226 octave_value idx (vinfo.numel () + 1); |
|
227 |
|
228 vinfo.assign (idx, "Name", Cell (octave_value (args (0)))); |
|
229 vinfo.assign (idx, "Version", Cell (octave_value (args (1)))); |
5658
|
230 vinfo.assign (idx, "Release", Cell (octave_value (args (2)))); |
|
231 vinfo.assign (idx, "Date", Cell (octave_value (args (3)))); |
5654
|
232 } |
|
233 else if (nargin == 0) |
|
234 retval = vinfo; |
|
235 else |
|
236 print_usage ("__version_info__"); |
|
237 |
|
238 return retval; |
|
239 } |
|
240 |
|
241 static void |
|
242 initialize_version_info (void) |
|
243 { |
|
244 octave_value_list args; |
|
245 |
5658
|
246 args(3) = OCTAVE_RELEASE_DATE; |
|
247 args(2) = OCTAVE_RELEASE; |
5654
|
248 args(1) = OCTAVE_VERSION; |
|
249 args(0) = "GNU Octave"; |
|
250 |
|
251 F__version_info__ (args, 0); |
|
252 } |
|
253 |
581
|
254 // Initialize by reading startup files. |
|
255 |
1
|
256 static void |
|
257 execute_startup_files (void) |
|
258 { |
2985
|
259 unwind_protect::begin_frame ("execute_startup_files"); |
315
|
260 |
3019
|
261 unwind_protect_bool (input_from_startup_file); |
1651
|
262 |
3019
|
263 input_from_startup_file = true; |
315
|
264 |
793
|
265 int verbose = (verbose_flag && ! inhibit_startup_message); |
578
|
266 |
2239
|
267 if (read_site_files) |
1
|
268 { |
2239
|
269 // Execute commands from the site-wide configuration file. |
|
270 // First from the file $(prefix)/lib/octave/site/m/octaverc |
|
271 // (if it exists), then from the file |
3597
|
272 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists). |
1755
|
273 |
2897
|
274 parse_and_execute (Vlocal_site_defaults_file, verbose); |
1755
|
275 |
2897
|
276 parse_and_execute (Vsite_defaults_file, verbose); |
1
|
277 } |
|
278 |
2239
|
279 if (read_init_files) |
|
280 { |
2512
|
281 // Try to execute commands from $HOME/$OCTAVE_INITFILE and |
|
282 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, .octaverc |
|
283 // is assumed. |
2239
|
284 |
4804
|
285 bool home_rc_already_executed = false; |
2512
|
286 |
3523
|
287 std::string initfile = octave_env::getenv ("OCTAVE_INITFILE"); |
2512
|
288 |
2926
|
289 if (initfile.empty ()) |
2512
|
290 initfile = ".octaverc"; |
|
291 |
3523
|
292 std::string home_dir = octave_env::get_home_directory (); |
2926
|
293 |
4804
|
294 std::string home_rc = octave_env::make_absolute (initfile, home_dir); |
|
295 |
|
296 std::string local_rc; |
2239
|
297 |
2926
|
298 if (! home_dir.empty ()) |
2239
|
299 { |
2897
|
300 parse_and_execute (home_rc, verbose); |
2239
|
301 |
|
302 // Names alone are not enough. |
|
303 |
|
304 file_stat fs_home_rc (home_rc); |
|
305 |
|
306 if (fs_home_rc) |
|
307 { |
4804
|
308 // We want to check for curr_dir after executing home_rc |
|
309 // because doing that may change the working directory. |
|
310 |
|
311 std::string curr_dir = octave_env::getcwd (); |
|
312 |
|
313 local_rc = octave_env::make_absolute (initfile, curr_dir); |
|
314 |
2512
|
315 file_stat fs_dot_rc (local_rc); |
2239
|
316 |
|
317 if (fs_dot_rc && fs_home_rc.ino () == fs_dot_rc.ino ()) |
4804
|
318 home_rc_already_executed = true; |
2239
|
319 } |
|
320 } |
|
321 |
|
322 if (! home_rc_already_executed) |
4804
|
323 { |
|
324 if (local_rc.empty ()) |
|
325 { |
|
326 std::string curr_dir = octave_env::getcwd (); |
|
327 |
|
328 local_rc = octave_env::make_absolute (initfile, curr_dir); |
|
329 } |
|
330 |
|
331 parse_and_execute (local_rc, verbose); |
|
332 } |
2239
|
333 } |
315
|
334 |
2985
|
335 unwind_protect::run_frame ("execute_startup_files"); |
1
|
336 } |
|
337 |
5189
|
338 static int |
|
339 execute_eval_option_code (const std::string& code) |
|
340 { |
|
341 unwind_protect::begin_frame ("execute_eval_option_code"); |
|
342 |
|
343 unwind_protect_bool (interactive); |
|
344 |
|
345 interactive = false; |
|
346 |
|
347 int parse_status = 0; |
|
348 |
|
349 eval_string (code, false, parse_status, 0); |
|
350 |
|
351 unwind_protect::run_frame ("execute_eval_option_code"); |
|
352 |
|
353 return parse_status; |
|
354 } |
|
355 |
|
356 static void |
|
357 restore_program_name (void *) |
|
358 { |
|
359 bind_builtin_variable ("program_invocation_name", |
|
360 octave_env::get_program_invocation_name ()); |
|
361 |
|
362 bind_builtin_variable ("program_name", octave_env::get_program_name ()); |
|
363 } |
|
364 |
|
365 static void |
|
366 execute_command_line_file (const std::string& fname) |
|
367 { |
|
368 unwind_protect::begin_frame ("execute_command_line_file"); |
|
369 |
|
370 unwind_protect_bool (interactive); |
|
371 unwind_protect_bool (reading_script_file); |
|
372 unwind_protect_bool (input_from_command_line_file); |
|
373 |
|
374 unwind_protect_str (curr_fcn_file_name); |
|
375 unwind_protect_str (curr_fcn_file_full_name); |
|
376 |
|
377 unwind_protect::add (restore_program_name, 0); |
|
378 |
|
379 interactive = false; |
|
380 reading_script_file = true; |
|
381 input_from_command_line_file = true; |
|
382 |
|
383 curr_fcn_file_name = fname; |
|
384 curr_fcn_file_full_name = curr_fcn_file_name; |
|
385 |
|
386 bind_builtin_variable ("program_invocation_name", curr_fcn_file_name); |
|
387 |
|
388 size_t pos = curr_fcn_file_name.find_last_of (file_ops::dir_sep_chars); |
|
389 |
|
390 std::string tmp = (pos != NPOS) |
|
391 ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name; |
|
392 |
|
393 bind_builtin_variable ("program_name", tmp); |
|
394 |
|
395 parse_and_execute (fname, false, "octave"); |
|
396 |
|
397 unwind_protect::run_frame ("execute_command_line_file"); |
|
398 } |
|
399 |
581
|
400 // Usage message with extra help. |
|
401 |
1
|
402 static void |
|
403 verbose_usage (void) |
|
404 { |
3922
|
405 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_AND_WARRANTY "\n\ |
1613
|
406 \n\ |
|
407 Usage: octave [options]\n\ |
|
408 \n\ |
|
409 Options:\n\ |
1119
|
410 \n\ |
3180
|
411 --debug, -d Enter parser debugging mode.\n\ |
|
412 --echo-commands, -x Echo commands as they are executed.\n\ |
5191
|
413 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ |
1613
|
414 --exec-path PATH Set path for executing subprograms.\n\ |
3180
|
415 --help, -h, -? Print short help message and exit.\n\ |
1613
|
416 --info-file FILE Use top-level info file FILE.\n\ |
|
417 --info-program PROGRAM Use PROGRAM for reading info files.\n\ |
3180
|
418 --interactive, -i Force interactive behavior.\n\ |
|
419 --no-history, -H Don't save commands to the history list\n\ |
2470
|
420 --no-init-file Don't read the ~/.octaverc or .octaverc files.\n\ |
2212
|
421 --no-line-editing Don't use readline for command-line editing.\n\ |
2470
|
422 --no-site-file Don't read the site-wide octaverc file.\n\ |
3238
|
423 --norc, -f Don't read any initialization files.\n\ |
3180
|
424 --path PATH, -p PATH Set initial LOADPATH to PATH.\n\ |
5189
|
425 --persist Go interactive after --eval or reading from FILE.\n\ |
3180
|
426 --silent, -q Don't print message at startup.\n\ |
1613
|
427 --traditional Set compatibility variables.\n\ |
3180
|
428 --verbose, -V Enable verbose output in some cases.\n\ |
|
429 --version, -v Print version number and exit.\n\ |
1119
|
430 \n\ |
5190
|
431 FILE Execute commands from FILE. Exit when done\n\ |
5191
|
432 unless --persist is also specified.\n\ |
4829
|
433 \n" |
|
434 OCTAVE_WWW_STATEMENT "\n\ |
4356
|
435 \n" |
|
436 OCTAVE_CONTRIB_STATEMENT "\n\ |
|
437 \n" |
|
438 OCTAVE_BUGS_STATEMENT "\n"; |
285
|
439 |
613
|
440 exit (0); |
1
|
441 } |
|
442 |
581
|
443 // Terse usage messsage. |
|
444 |
1
|
445 static void |
|
446 usage (void) |
|
447 { |
3531
|
448 std::cerr << "usage: " << usage_string << "\n"; |
1
|
449 exit (1); |
|
450 } |
|
451 |
|
452 static void |
|
453 print_version_and_exit (void) |
|
454 { |
3922
|
455 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_WARRANTY_AND_BUGS "\n"; |
1
|
456 exit (0); |
|
457 } |
|
458 |
721
|
459 static void |
|
460 initialize_error_handlers () |
|
461 { |
|
462 set_liboctave_error_handler (error); |
3325
|
463 set_liboctave_warning_handler (warning); |
721
|
464 } |
|
465 |
1410
|
466 // What happens on --traditional. |
|
467 |
|
468 static void |
|
469 maximum_braindamage (void) |
|
470 { |
5189
|
471 persist = true; |
|
472 |
1410
|
473 bind_builtin_variable ("PS1", ">> "); |
|
474 bind_builtin_variable ("PS2", ""); |
4324
|
475 bind_builtin_variable ("beep_on_error", true); |
|
476 bind_builtin_variable ("crash_dumps_octave_core", false); |
5284
|
477 bind_builtin_variable ("default_save_options", "-mat-binary"); |
4324
|
478 bind_builtin_variable ("fixed_point_format", true); |
5305
|
479 bind_builtin_variable ("history_timestamp_format_string", |
|
480 "%%-- %D %I:%M %p --%%"); |
4324
|
481 bind_builtin_variable ("page_screen_output", false); |
|
482 bind_builtin_variable ("print_empty_dimensions", false); |
|
483 bind_builtin_variable ("warn_function_name_clash", false); |
1410
|
484 } |
|
485 |
581
|
486 // You guessed it. |
|
487 |
1
|
488 int |
4368
|
489 octave_main (int argc, char **argv, int embedded) |
1
|
490 { |
3019
|
491 octave_env::set_program_name (argv[0]); |
|
492 |
2205
|
493 // The order of these calls is important. The call to |
2926
|
494 // install_defaults must come before install_builtins because |
3019
|
495 // default variable values must be available for the variables to be |
2205
|
496 // installed, and the call to install_builtins must come before the |
|
497 // options are processed because some command line options override |
|
498 // defaults by calling bind_builtin_variable. |
721
|
499 |
1
|
500 sysdep_init (); |
|
501 |
4159
|
502 // The idea here is to force xerbla to be referenced so that we will |
|
503 // link to our own version instead of the one provided by the BLAS |
|
504 // library. But octave_NaN should never be -1, so we should never |
|
505 // actually call xerbla. |
|
506 |
|
507 if (octave_NaN == -1) |
|
508 F77_FUNC (xerbla, XERBLA) ("octave", 13, 6L); |
|
509 |
721
|
510 initialize_error_handlers (); |
223
|
511 |
2926
|
512 install_defaults (); |
1
|
513 |
1792
|
514 initialize_pathsearch (); |
1744
|
515 |
4368
|
516 if (! embedded) |
|
517 install_signal_handlers (); |
2205
|
518 |
|
519 initialize_file_io (); |
|
520 |
2375
|
521 initialize_symbol_tables (); |
|
522 |
|
523 install_types (); |
|
524 |
|
525 install_ops (); |
2205
|
526 |
|
527 install_builtins (); |
|
528 |
1817
|
529 prog_args args (argc, argv, short_opts, long_opts); |
|
530 |
139
|
531 int optc; |
1817
|
532 while ((optc = args.getopt ()) != EOF) |
1
|
533 { |
139
|
534 switch (optc) |
1
|
535 { |
3180
|
536 case 'H': |
4324
|
537 bind_builtin_variable ("saving_history", false); |
3180
|
538 break; |
|
539 |
793
|
540 case 'V': |
2239
|
541 verbose_flag = true; |
793
|
542 break; |
|
543 |
1
|
544 case 'd': |
4753
|
545 // This is the same as yydebug in parse.y. |
|
546 octave_debug++; |
1
|
547 break; |
777
|
548 |
1
|
549 case 'f': |
2239
|
550 read_init_files = false; |
|
551 read_site_files = false; |
1
|
552 break; |
777
|
553 |
1
|
554 case 'h': |
|
555 case '?': |
|
556 verbose_usage (); |
|
557 break; |
777
|
558 |
1
|
559 case 'i': |
3019
|
560 forced_interactive = true; |
1
|
561 break; |
777
|
562 |
1
|
563 case 'p': |
1817
|
564 if (args.optarg ()) |
2205
|
565 bind_builtin_variable ("LOADPATH", args.optarg ()); |
1
|
566 break; |
777
|
567 |
1
|
568 case 'q': |
2239
|
569 inhibit_startup_message = true; |
1
|
570 break; |
777
|
571 |
1
|
572 case 'x': |
2205
|
573 { |
|
574 double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); |
|
575 bind_builtin_variable ("echo_executing_commands", tmp); |
|
576 } |
1
|
577 break; |
777
|
578 |
1
|
579 case 'v': |
|
580 print_version_and_exit (); |
|
581 break; |
777
|
582 |
5189
|
583 case EVAL_OPTION: |
|
584 if (args.optarg ()) |
5193
|
585 { |
|
586 if (code_to_eval.empty ()) |
|
587 code_to_eval = args.optarg (); |
|
588 else |
|
589 code_to_eval += std::string (" ") + args.optarg (); |
|
590 } |
5189
|
591 break; |
|
592 |
1613
|
593 case EXEC_PATH_OPTION: |
1817
|
594 if (args.optarg ()) |
2205
|
595 bind_builtin_variable ("EXEC_PATH", args.optarg ()); |
1613
|
596 break; |
|
597 |
186
|
598 case INFO_FILE_OPTION: |
1817
|
599 if (args.optarg ()) |
2205
|
600 bind_builtin_variable ("INFO_FILE", args.optarg ()); |
186
|
601 break; |
777
|
602 |
1613
|
603 case INFO_PROG_OPTION: |
1817
|
604 if (args.optarg ()) |
2205
|
605 bind_builtin_variable ("INFO_PROGRAM", args.optarg ()); |
1613
|
606 break; |
|
607 |
2239
|
608 case NO_INIT_FILE_OPTION: |
|
609 read_init_files = false; |
|
610 break; |
|
611 |
1821
|
612 case NO_LINE_EDITING_OPTION: |
3019
|
613 line_editing = false; |
2239
|
614 break; |
|
615 |
|
616 case NO_SITE_FILE_OPTION: |
|
617 read_site_files = 0; |
1821
|
618 break; |
|
619 |
1410
|
620 case TRADITIONAL_OPTION: |
2239
|
621 traditional = true; |
1410
|
622 break; |
|
623 |
5189
|
624 case PERSIST_OPTION: |
|
625 persist = true; |
|
626 break; |
|
627 |
1
|
628 default: |
|
629 usage (); |
|
630 break; |
|
631 } |
|
632 } |
|
633 |
1651
|
634 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
2077
|
635 // Make sure we clean up when we exit. Also allow users to register |
|
636 // functions. If we don't have atexit or on_exit, we're going to |
|
637 // leave some junk files around if we exit abnormally. |
|
638 |
|
639 atexit (do_octave_atexit); |
318
|
640 #endif |
1
|
641 |
1358
|
642 // These can come after command line args since none of them set any |
|
643 // defaults that might be changed by command line options. |
581
|
644 |
2926
|
645 initialize_command_input (); |
315
|
646 |
578
|
647 if (! inhibit_startup_message) |
3538
|
648 std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl; |
578
|
649 |
1410
|
650 if (traditional) |
|
651 maximum_braindamage (); |
|
652 |
4217
|
653 octave_interpreter_ready = true; |
|
654 |
5654
|
655 initialize_version_info (); |
|
656 |
4217
|
657 execute_default_pkg_add_files (); |
|
658 |
2239
|
659 execute_startup_files (); |
1651
|
660 |
2926
|
661 command_history::read (false); |
1
|
662 |
578
|
663 if (! inhibit_startup_message && reading_startup_message_printed) |
3538
|
664 std::cout << std::endl; |
578
|
665 |
5189
|
666 // Is input coming from a terminal? If so, we are probably |
|
667 // interactive. |
1358
|
668 |
5189
|
669 interactive = (! embedded |
|
670 && isatty (fileno (stdin)) && isatty (fileno (stdout))); |
|
671 |
|
672 if (! interactive) |
|
673 line_editing = false; |
1
|
674 |
1358
|
675 // If there is an extra argument, see if it names a file to read. |
|
676 // Additional arguments are taken as command line options for the |
|
677 // script. |
1
|
678 |
1817
|
679 int last_arg_idx = args.optind (); |
3019
|
680 |
1817
|
681 int remaining_args = argc - last_arg_idx; |
3019
|
682 |
5189
|
683 if (! code_to_eval.empty ()) |
149
|
684 { |
5189
|
685 // We probably want all the args for an --eval option. |
1355
|
686 |
|
687 intern_argv (argc, argv); |
|
688 |
5189
|
689 int parse_status = execute_eval_option_code (code_to_eval); |
|
690 |
5242
|
691 if (! (persist || remaining_args > 0)) |
5502
|
692 clean_up_and_exit (parse_status || error_state ? 1 : 0); |
1
|
693 } |
|
694 |
5189
|
695 if (remaining_args > 0) |
|
696 { |
|
697 // If we are running an executable script (#! /bin/octave) then |
|
698 // we should only see the args passed to the script. |
|
699 |
|
700 intern_argv (remaining_args, argv+last_arg_idx); |
|
701 |
|
702 execute_command_line_file (argv[last_arg_idx]); |
|
703 |
|
704 if (! persist) |
5502
|
705 clean_up_and_exit (error_state ? 1 : 0); |
5189
|
706 } |
|
707 |
|
708 // Avoid counting commands executed from startup files. |
|
709 |
|
710 command_editor::reset_current_command_number (1); |
|
711 |
|
712 // Now argv should have the full set of args. |
|
713 intern_argv (argc, argv); |
|
714 |
|
715 if (! embedded) |
|
716 switch_to_buffer (create_buffer (get_input_from_stdin ())); |
|
717 |
1358
|
718 // Force input to be echoed if not really interactive, but the user |
|
719 // has forced interactive behavior. |
1
|
720 |
1907
|
721 if (! interactive && forced_interactive) |
287
|
722 { |
2926
|
723 command_editor::blink_matching_paren (false); |
1588
|
724 |
|
725 // XXX FIXME XXX -- is this the right thing to do? |
|
726 |
4233
|
727 bind_builtin_variable ("echo_executing_commands", ECHO_CMD_LINE); |
287
|
728 } |
1
|
729 |
4368
|
730 if (embedded) |
5502
|
731 { |
|
732 // XXX FIXME XXX -- do we need to do any cleanup here before |
|
733 // returning? If we don't, what will happen to Octave functions |
|
734 // that have been registered to execute with atexit, for example? |
|
735 |
|
736 return 1; |
|
737 } |
4368
|
738 |
5189
|
739 int retval = main_loop (); |
1
|
740 |
1005
|
741 if (retval == 1 && ! error_state) |
|
742 retval = 0; |
|
743 |
1
|
744 clean_up_and_exit (retval); |
4247
|
745 |
|
746 return 0; |
1
|
747 } |
|
748 |
560
|
749 /* |
1
|
750 ;;; Local Variables: *** |
|
751 ;;; mode: C++ *** |
|
752 ;;; End: *** |
|
753 */ |