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