# HG changeset patch # User jwe # Date 830305292 0 # Node ID 2d03b8eb891da8957c5a1a1394eaa425b501997b # Parent 36800cb7fe049ed2d89127c6c494afc0e6b57a2d [project @ 1996-04-24 00:21:21 by jwe] diff -r 36800cb7fe04 -r 2d03b8eb891d src/octave.cc --- a/src/octave.cc Tue Apr 23 23:59:49 1996 +0000 +++ b/src/octave.cc Wed Apr 24 00:21:32 1996 +0000 @@ -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 diff -r 36800cb7fe04 -r 2d03b8eb891d src/toplev.cc --- a/src/toplev.cc Tue Apr 23 23:59:49 1996 +0000 +++ b/src/toplev.cc Wed Apr 24 00:21:32 1996 +0000 @@ -684,6 +684,48 @@ DEFALIAS (shell_cmd, system); +static SLStack 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; diff -r 36800cb7fe04 -r 2d03b8eb891d src/toplev.h --- a/src/toplev.h Tue Apr 23 23:59:49 1996 +0000 +++ b/src/toplev.h Wed Apr 24 00:21:32 1996 +0000 @@ -45,6 +45,8 @@ extern int main_loop (void); +extern void do_octave_atexit (void); + // argv[0] for this program. extern string raw_prog_name;