# HG changeset patch # User Jaroslav Hajek # Date 1242805923 -7200 # Node ID ee7cf4d963f3681de8025e075dff35102f7f3b78 # Parent 9d4b84b14bf0bde8b888537da5e97d19718b6c7c smarter handling of quit() diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2009-05-20 Jaroslav Hajek + + * toplev.h (octave_quit_exception): New class. + (octave_exit): New global variable. + * toplev.cc (octave_exit): Initialize to ::exit. + (clean_up_and_exit): Call octave_exit if set. + (Fquit): Raise octave_quit_exception to quit. + (main_loop): Catch octave_quit_exception. + * octave.cc (execute_command_line_file): Ditto. + (execute_eval_option_code): Ditto. + 2009-05-19 John W. Eaton * DLD-FUNCTIONS/fltk_backend.cc (F__fltk_redraw__): New function. diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -411,6 +411,11 @@ { eval_string (code, false, parse_status, 0); } + catch (octave_quit_exception e) + { + unwind_protect::run_frame ("execute_eval_option_code"); + clean_up_and_exit (e.status); + } catch (octave_interrupt_exception) { recover_from_exception (); @@ -478,6 +483,11 @@ source_file (fname, context, verbose, require_file, "octave"); } + catch (octave_quit_exception e) + { + unwind_protect::run_frame ("execute_command_line_file"); + clean_up_and_exit (e.status); + } catch (octave_interrupt_exception) { recover_from_exception (); diff --git a/src/toplev.cc b/src/toplev.cc --- a/src/toplev.cc +++ b/src/toplev.cc @@ -79,6 +79,8 @@ #include "variables.h" #include +void (*octave_exit) (int) = ::exit; + // TRUE means we are exiting via the builtin exit or quit functions. static bool quitting_gracefully = false; @@ -598,6 +600,11 @@ break; } } + catch (octave_quit_exception e) + { + unwind_protect::run_all (); + clean_up_and_exit (e.status); + } catch (octave_interrupt_exception) { recover_from_exception (); @@ -632,7 +639,8 @@ sysdep_cleanup (); - exit (retval == EOF ? 0 : retval); + if (octave_exit) + (*octave_exit) (retval == EOF ? 0 : retval); } DEFUN (quit, args, nargout, @@ -660,7 +668,7 @@ exit_status = tmp; } - clean_up_and_exit (exit_status); + throw octave_quit_exception (exit_status); } else error ("quit: invalid number of output arguments"); diff --git a/src/toplev.h b/src/toplev.h --- a/src/toplev.h +++ b/src/toplev.h @@ -37,11 +37,26 @@ class tree_statement_list; class charMatrix; +#include "quit.h" + #include "input.h" #include "oct-map.h" + +extern void (*octave_exit) (int); + +// quit is a lot like an interrupt, so we subclass it to simplify possible +// handling. +class octave_quit_exception +: public octave_interrupt_exception +{ +public: + int status; + octave_quit_exception (int s) : status (s) { } +}; + extern OCTINTERP_API void -clean_up_and_exit (int) GCC_ATTR_NORETURN; +clean_up_and_exit (int); extern OCTINTERP_API void recover_from_exception (void);