Mercurial > octave
changeset 26722:f51e8a7c33f4
run Matlab user files from interpreter, not startup scripts (bug #55681)
* interpreter.cc, interpreter.h (interpreter::execute_startup_files): Run
startup.m when reading Octave user init files. Schedule finish.m to run on
exit when reading Octave user init files.
* __finish__.m: Check for finish.m to exist on the load path.
* version-rcfile: Delete code to run startup.m and finish.m.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Mon, 11 Feb 2019 16:16:00 -0800 |
parents | 72b9040ab196 |
children | 259953dac9b8 |
files | libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h scripts/startup/__finish__.m scripts/startup/version-rcfile |
diffstat | 4 files changed, 34 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc Mon Feb 11 14:37:34 2019 -0800 +++ b/libinterp/corefcn/interpreter.cc Mon Feb 11 16:16:00 2019 -0800 @@ -711,7 +711,7 @@ // occurs when reading any of them, but don't exit early because of an // exception. - int interpreter::execute_startup_files (void) const + int interpreter::execute_startup_files (void) { bool read_site_files = m_read_site_files; bool read_init_files = m_read_init_files; @@ -758,6 +758,37 @@ if (read_init_files) { + // Try to execute commands from the Matlab compatible startup.m file + // if it exists anywhere in the load path when starting Octave. + std::string ff_startup_m = file_in_path ("startup.m", ""); + + if (! ff_startup_m.empty ()) + { + int parse_status = 0; + + try + { + eval_string (std::string ("startup"), false, parse_status, 0); + } + catch (const interrupt_exception&) + { + recover_from_exception (); + } + catch (const execution_exception& e) + { + std::string stack_trace = e.info (); + + if (! stack_trace.empty ()) + std::cerr << stack_trace; + + recover_from_exception (); + } + } + + // Schedule the Matlab compatible finish.m file to run if it exists + // anywhere in the load path when exiting Octave. + add_atexit_function ("__finish__"); + // Try to execute commands from $HOME/$OCTAVE_INITFILE and // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, // .octaverc is assumed.
--- a/libinterp/corefcn/interpreter.h Mon Feb 11 14:37:34 2019 -0800 +++ b/libinterp/corefcn/interpreter.h Mon Feb 11 16:16:00 2019 -0800 @@ -343,7 +343,7 @@ void display_startup_message (void) const; - int execute_startup_files (void) const; + int execute_startup_files (void); int execute_eval_option_code (void);
--- a/scripts/startup/__finish__.m Mon Feb 11 14:37:34 2019 -0800 +++ b/scripts/startup/__finish__.m Mon Feb 11 16:16:00 2019 -0800 @@ -29,7 +29,7 @@ function __finish__ () - if (exist ("finish", "file")) + if (exist ("finish.m", "file")) ## Must use evalin for access to base workspace and user variables. ## No argument list for finish because it might be a script, not function. evalin ("base", "finish;");
--- a/scripts/startup/version-rcfile Mon Feb 11 14:37:34 2019 -0800 +++ b/scripts/startup/version-rcfile Mon Feb 11 16:16:00 2019 -0800 @@ -25,13 +25,3 @@ if (strcmp (PAGER (), "less") && isempty (getenv ("LESS"))) PAGER_FLAGS ('-e -X -P"-- less ?pB(%pB\\%):--. (f)orward, (b)ack, (q)uit$"'); endif - -## Run Matlab-compatible personal rc files unless skipping user rc files. -if (! any (strcmp ("--no-init-file", argv ()))) - if (exist ("startup.m", "file") == 2) - startup; # No arg list here since startup might be a script. - endif - - ## Schedule finish.m to run when exiting Octave. - atexit ("__finish__"); -endif