Index: src/toplev.cc =================================================================== RCS file: /cvs/octave/src/toplev.cc,v retrieving revision 1.198 diff -c -r1.198 toplev.cc *** src/toplev.cc 14 May 2007 17:35:46 -0000 1.198 --- src/toplev.cc 31 May 2007 20:06:41 -0000 *************** *** 602,608 **** // FIXME -- this should really be static, but that causes // problems on some systems. ! std::stack octave_atexit_functions; void do_octave_atexit (void) --- 602,608 ---- // FIXME -- this should really be static, but that causes // problems on some systems. ! std::list octave_atexit_functions; void do_octave_atexit (void) *************** *** 611,619 **** while (! octave_atexit_functions.empty ()) { ! std::string fcn = octave_atexit_functions.top (); ! octave_atexit_functions.pop (); reset_error_handler (); --- 611,619 ---- while (! octave_atexit_functions.empty ()) { ! std::string fcn = octave_atexit_functions.front (); ! octave_atexit_functions.pop_front (); reset_error_handler (); *************** *** 658,664 **** } } ! DEFUN (atexit, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ Register a function to be called when Octave exits. For example,\n\ --- 658,664 ---- } } ! DEFUN (atexit, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ Register a function to be called when Octave exits. For example,\n\ *************** *** 674,693 **** \n\ @noindent\n\ will print the message \"Bye bye\" when Octave exits.\n\ @end deftypefn") { octave_value_list retval; int nargin = args.length (); ! if (nargin == 1) { std::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 (); --- 674,750 ---- \n\ @noindent\n\ will print the message \"Bye bye\" when Octave exits.\n\ + \n\ + @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ + Register or unregister a function to be called when Octave exits, depending\n\ + on @var{flag}. If @var{flag} is true, the function is registered, if @var{flag}\n\ + is false, it is unregistered. For example,\n\ + \n\ + @example\n\ + @group\n\ + function bye_bye ()\n\ + disp (\"Bye Bye\");\n\ + endfunction\n\ + atexit(\"bye_bye\");\n\ + @dots{}\n\ + atexit(\"bye_bye\", false);\n\ + @end group\n\ + @end example\n\ + \n\ + @noindent\n\ + will then not print a message when Octave exits. Note that only the first\n\ + occurence of a function will be removed from the stack. Therefore, if a\n\ + function was placed in the stack multiple times with @code{atexit}, it\n\ + must equally be removed from the stack multiple times.\n\ @end deftypefn") { octave_value_list retval; int nargin = args.length (); ! if (nargin == 1 || nargin == 2) { std::string arg = args(0).string_value (); if (! error_state) ! { ! bool add_mode = true; ! ! if (nargin == 2) ! { ! add_mode = args(1).bool_value (); ! ! if (error_state) ! error ("atexit: second argument must be a boolean"); ! } ! ! if (! error_state) ! if (add_mode) ! octave_atexit_functions.push_front (arg); ! else ! { ! bool found = false; ! std::list::iterator it; ! ! for (std::list::iterator p = octave_atexit_functions.begin (); ! p != octave_atexit_functions.end ();) ! { ! if ((*p) == arg) ! { ! p = octave_atexit_functions.erase (p); ! found = true; ! break; ! } ! else ! p++; ! } ! ! if (nargout > 0) ! retval(0) = found; ! } ! } else ! error ("atexit: argument must be a string"); } else print_usage ();