Mercurial > hg > octave-nkf
changeset 2077:2d03b8eb891d
[project @ 1996-04-24 00:21:21 by jwe]
author | jwe |
---|---|
date | Wed, 24 Apr 1996 00:21:32 +0000 |
parents | 36800cb7fe04 |
children | 4d43f960f2cc |
files | src/octave.cc src/toplev.cc src/toplev.h |
diffstat | 3 files changed, 50 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/octave.cc +++ b/src/octave.cc @@ -483,9 +483,12 @@ } #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) - // Make sure we clean up when we exit. If we don't have atexit or - // on_exit, we're going to leave some junk files around if we exit - // abnormally. + // Make sure we clean up when we exit. Also allow users to register + // functions. If we don't have atexit or on_exit, we're going to + // leave some junk files around if we exit abnormally. + + atexit (do_octave_atexit); + atexit (cleanup_tmp_files); #endif
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -684,6 +684,48 @@ DEFALIAS (shell_cmd, system); +static SLStack<string> octave_atexit_functions; + +void +do_octave_atexit (void) +{ + while (! octave_atexit_functions.empty ()) + { + Octave_object fcn = octave_atexit_functions.pop (); + + feval (fcn, 0); + } +} + +DEFUN(atexit, args, , + "atexit (NAME): register NAME as a function to call when Octave exits\n\ +\n\ +Functions are called with no arguments in the reverse of the order in +which they were registered with atexit()") +{ + Octave_object retval; + +#if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) + int nargin = args.length (); + + if (nargin == 1) + { + string arg = args(0).string_value (); + + if (! error_state) + octave_atexit_functions.push (arg); + else + error ("atexit: argument must be a string"); + } + else + print_usage ("atexit"); +#else + error ("atexit: not supported on this system"); +#endif + + return retval; +} + #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) int debug_new_delete = 0;