changeset 4153:6b96ce9f5743

[project @ 2002-11-06 20:38:49 by jwe]
author jwe
date Wed, 06 Nov 2002 20:38:50 +0000
parents f14251d33b01
children f10865750046
files ChangeLog configure.in libcruft/ChangeLog libcruft/Makefile.in libcruft/misc/Makefile.in libcruft/misc/f77-extern.cc libcruft/misc/f77-fcn.c libcruft/misc/f77-fcn.h libcruft/misc/quit.cc libcruft/misc/quit.h liboctave/CMatrix.cc liboctave/ChangeLog liboctave/ODESSA.cc liboctave/dMatrix.cc src/ChangeLog src/DLD-FUNCTIONS/balance.cc src/DLD-FUNCTIONS/besselj.cc src/DLD-FUNCTIONS/filter.cc src/DLD-FUNCTIONS/find.cc src/DLD-FUNCTIONS/kron.cc src/DLD-FUNCTIONS/log.cc src/DLD-FUNCTIONS/minmax.cc src/DLD-FUNCTIONS/qz.cc src/DLD-FUNCTIONS/rand.cc src/DLD-FUNCTIONS/sort.cc src/data.cc src/input.cc src/lex.h src/lex.l src/load-save.cc src/oct-stream.cc src/ov-cell.cc src/ov-mapper.cc src/ov-re-mat.cc src/ov.cc src/pr-output.cc src/pt-loop.cc src/pt-stmt.cc src/sighandlers.cc src/sighandlers.h src/toplev.cc src/utils.cc src/utils.h src/xdiv.cc src/xpow.cc
diffstat 45 files changed, 823 insertions(+), 249 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 06 18:41:50 2002 +0000
+++ b/ChangeLog	Wed Nov 06 20:38:50 2002 +0000
@@ -1,3 +1,7 @@
+2002-11-06  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* configure.in (AH_BOTTOM): Define USE_EXCEPTIONS_FOR_INTERRUPTS.
+
 2002-11-04  Joseph P. Skudlarek  <jskud@jskud.com>
 
 	* emacs/otags: handle declarations without arguments and/or return
--- a/configure.in	Wed Nov 06 18:41:50 2002 +0000
+++ b/configure.in	Wed Nov 06 20:38:50 2002 +0000
@@ -22,7 +22,7 @@
 ### 02111-1307, USA. 
 
 AC_INIT
-AC_REVISION($Revision: 1.384 $)
+AC_REVISION($Revision: 1.385 $)
 AC_PREREQ(2.52)
 AC_CONFIG_SRCDIR([src/octave.cc])
 AC_CONFIG_HEADER(config.h)
@@ -1308,6 +1308,8 @@
 #if defined (__WIN32__) && ! defined (__CYGWIN__)
 #define OCTAVE_USE_WINDOWS_API 1
 #endif
+
+#define USE_EXCEPTIONS_FOR_INTERRUPTS 1
 ])
 
 ### Do the substitutions in all the Makefiles.
--- a/libcruft/ChangeLog	Wed Nov 06 18:41:50 2002 +0000
+++ b/libcruft/ChangeLog	Wed Nov 06 20:38:50 2002 +0000
@@ -1,3 +1,20 @@
+2002-11-06  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* misc/f77-fcn.h (F77_XFCN): Adapt to new signal/exception
+	handling scheme.
+	(f77_context): Delete decl.
+	(copy_f77_context): Likewise.
+	* misc/f77-fcn.cn (copy_f77_context): Delete.
+	(Fxstopx): Set f77_exception_encountered.
+	Use octave_jump_to_enclosing_context, not longjmp.
+
+	* misc/f77-extern.cc (f77_context): Delete definition.
+
+	* misc/quit.h, misc/quit.cc: New files.
+	* misc/Makefile: Add them to the appropriate lists.
+
+	* Makefile (MISC_OBJ): Add misc/quit.o
+
 2002-10-31  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* odessa/odessa.f (ODESSA): Second arg of xerrwd is string length.
--- a/libcruft/Makefile.in	Wed Nov 06 18:41:50 2002 +0000
+++ b/libcruft/Makefile.in	Wed Nov 06 20:38:50 2002 +0000
@@ -60,7 +60,7 @@
 # a normal archive file (created from PIC code, though).
 
 MISC_OBJ := misc/machar.o misc/f77-extern.o \
-	misc/f77-fcn.o misc/lo-error.o
+	misc/f77-fcn.o misc/lo-error.o misc/quit.o
 
 CRUFT_FSRC := $(foreach dir, $(SUBDIRS), $(wildcard $(srcdir)/$(dir)/*.f))
 CRUFT_OBJ2 := $(patsubst $(srcdir)/%, %, $(CRUFT_FSRC))
--- a/libcruft/misc/Makefile.in	Wed Nov 06 18:41:50 2002 +0000
+++ b/libcruft/misc/Makefile.in	Wed Nov 06 20:38:50 2002 +0000
@@ -13,9 +13,9 @@
 VPATH = @srcdir@
 
 SPECIAL := machar.c d1mach-tst.for f77-extern.cc \
-	f77-fcn.c f77-fcn.h lo-error.c lo-error.h
+	f77-fcn.c f77-fcn.h lo-error.c lo-error.h quit.h quit.cc
 
-SPECIAL_DEPEND := machar.o f77-extern.o f77-fcn.o lo-error.o
+SPECIAL_DEPEND := machar.o f77-extern.o f77-fcn.o lo-error.o quit.o
 
 EXTERNAL_DISTFILES = $(DISTFILES)
 
@@ -25,14 +25,14 @@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 
-INCLUDES := f77-fcn.h lo-error.h
+INCLUDES := f77-fcn.h lo-error.h quit.h
 
 ifeq ($(SHARED_LIBS), true)
   ifdef CPICFLAG
     CPICDEP := pic/machar.o pic/f77-fcn.o
   endif
   ifdef CXXPICFLAG
-    CXXPICDEP := pic/f77-extern.o pic/lo-error.o
+    CXXPICDEP := pic/f77-extern.o pic/lo-error.o pic/quit.o
   endif
   SPECIAL_PICDEPEND := $(CPICDEP) $(CXXPICDEP)
 endif
--- a/libcruft/misc/f77-extern.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/libcruft/misc/f77-extern.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -34,9 +34,6 @@
 // So we can check to see if an exception has occurred.
 int f77_exception_encountered = 0;
 
-// For setjmp/longjmp.
-jmp_buf f77_context;
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/libcruft/misc/f77-fcn.c	Wed Nov 06 18:41:50 2002 +0000
+++ b/libcruft/misc/f77-fcn.c	Wed Nov 06 20:38:50 2002 +0000
@@ -28,14 +28,9 @@
 #include <string.h>
 
 #include "f77-fcn.h"
+#include "quit.h"
 #include "lo-error.h"
 
-void
-copy_f77_context (void *from, void *to, unsigned int size)
-{
-  memcpy (to, from, size);
-}
-
 /* All the STOP statements in the Fortran routines have been replaced
    with a call to XSTOPX.
 
@@ -46,11 +41,13 @@
 void
 F77_FUNC (xstopx, XSTOPX) (const char *s, long int slen)
 {
+  f77_exception_encountered = 1;
+
   /* Skip printing message if it is just a single blank character.  */
   if (s && slen > 0 && ! (slen == 1 && *s == ' '))
     (*current_liboctave_error_handler) ("%.*s", slen, s);
 
-  longjmp (f77_context, 1);
+  octave_jump_to_enclosing_context ();
 }
 
 /*
--- a/libcruft/misc/f77-fcn.h	Wed Nov 06 18:41:50 2002 +0000
+++ b/libcruft/misc/f77-fcn.h	Wed Nov 06 20:38:50 2002 +0000
@@ -27,9 +27,11 @@
 extern "C" {
 #endif
 
-#include <setjmp.h>
+#include "quit.h"
 
-/* hack to stringize macro results */
+#include <stdio.h>
+
+/* Hack to stringize macro results. */
 #define xSTRINGIZE(x) #x
 #define STRINGIZE(x) xSTRINGIZE(x)
 
@@ -41,40 +43,40 @@
      STRINGIZE (F77_FUNC (f, F)))
 
 /* This can be used to call a Fortran subroutine that might call
-   XSTOPX.  XSTOPX will call lonjmp with f77_context and we'll return,
-   call the error function, restore the previous context.  After using
-   this macro, error_state should be checked. */
+   XSTOPX.  XSTOPX will call lonjmp with current_context.  Once back
+   here, we'll restore the previous context and return.  We may also
+   end up here if an interrupt is processed when the Fortran
+   subroutine is called.  In that case, we resotre the context and go
+   to the top level.  The error_state should be checked immediately
+   after this macro is used. */
 
 #define F77_XFCN(f, F, args) \
   do \
     { \
-      jmp_buf saved_f77_context; \
+      jmp_buf saved_context; \
       f77_exception_encountered = 0; \
-      copy_f77_context ((char *) f77_context, (char *) saved_f77_context, \
-			sizeof (jmp_buf)); \
-      if (setjmp (f77_context)) \
+      octave_save_current_context ((char *) saved_context); \
+      if (octave_set_current_context) \
 	{ \
-	  f77_exception_encountered = 1; \
-	  F77_XFCN_ERROR (f, F); \
+          octave_restore_current_context ((char *) saved_context); \
+	  if (f77_exception_encountered) \
+	    F77_XFCN_ERROR (f, F); \
+          else \
+            OCTAVE_THROW_TO_TOP_LEVEL; \
 	} \
       else \
-	F77_FUNC (f, F) args; \
-      copy_f77_context ((char *) saved_f77_context, (char *) f77_context, \
-			sizeof (jmp_buf)); \
+        { \
+	  octave_interrupt_immediately++; \
+	  F77_FUNC (f, F) args; \
+	  octave_interrupt_immediately--; \
+          octave_restore_current_context ((char *) saved_context); \
+        } \
     } \
   while (0)
 
 /* So we can check to see if an exception has occurred. */
 extern int f77_exception_encountered;
 
-/* For setjmp/longjmp. */
-extern jmp_buf f77_context;
-
-/* Defining this as a separate function allows us to avoid having to
-   include string.h in this file. */
-
-extern void copy_f77_context (void *, void *, unsigned int);
-
 extern void
 F77_FUNC (xstopx, XSTOPX) (const char *s, long int slen) GCC_ATTR_NORETURN;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcruft/misc/quit.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -0,0 +1,100 @@
+/*
+
+Copyright (C) 2002 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+// Include signal.h, not csignal since the latter might only define
+// the ANSI standard C signal interface.
+
+#include <signal.h>
+
+#include "quit.h"
+
+jmp_buf current_context;
+
+void
+octave_save_current_context (void *save_buf)
+{
+  memcpy (save_buf, current_context, sizeof (jmp_buf));
+}
+
+void
+octave_restore_current_context (void *save_buf)
+{
+  memcpy (current_context, save_buf, sizeof (jmp_buf));
+}
+
+void
+octave_jump_to_enclosing_context (void)
+{
+  longjmp (current_context, 1);
+}
+
+// Allow us to save the signal mask and then restore it to the most
+// recently saved value.  This is necessary when using the POSIX
+// signal handling interface on some systems calling longjmp out of
+// the signal handler to get to the top level on an interrupt doesn't
+// restore the original signal mask.  Alternatively, we could use
+// sigsetjmp/siglongjmp, but saving and restoring the signal mask
+// ourselves works ok and seems simpler just now.
+
+#if defined (HAVE_POSIX_SIGNALS)
+static sigset_t octave_signal_mask;
+#endif
+
+void
+octave_save_signal_mask (void)
+{
+#if defined (HAVE_POSIX_SIGNALS)
+  sigprocmask (0, 0, &octave_signal_mask);
+#endif
+}
+
+void
+octave_restore_signal_mask (void)
+{
+#if defined (HAVE_POSIX_SIGNALS)
+  sigprocmask (SIG_SETMASK, &octave_signal_mask, 0);
+#endif
+}
+
+#if defined (USE_EXCEPTIONS_FOR_INTERRUPTS)
+
+int octave_interrupt_immediately = 0;
+
+int octave_interrupt_state = 0;
+
+void
+octave_throw_interrupt_exception (void)
+{
+  throw octave_interrupt_exception ();
+}
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcruft/misc/quit.h	Wed Nov 06 20:38:50 2002 +0000
@@ -0,0 +1,135 @@
+/*
+
+Copyright (C) 2002 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#if !defined (octave_quit_h)
+#define octave_quit_h 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Include setjmp.h, not csetjmp since the latter might only define
+// the ANSI standard C interface.
+
+#include <setjmp.h>
+
+extern jmp_buf current_context;
+
+extern void octave_save_current_context (void *);
+
+#define octave_set_current_context setjmp (current_context)
+
+extern void octave_restore_current_context (void *);
+
+extern void octave_jump_to_enclosing_context (void) GCC_ATTR_NORETURN;
+
+extern void octave_save_signal_mask (void);
+
+extern void octave_restore_signal_mask (void);
+
+#if defined (USE_EXCEPTIONS_FOR_INTERRUPTS)
+
+#ifdef __cplusplus
+class
+octave_interrupt_exception
+{
+};
+#endif
+
+extern int octave_interrupt_immediately;
+
+extern int octave_interrupt_state;
+
+extern void octave_throw_interrupt_exception (void) GCC_ATTR_NORETURN;
+
+#define OCTAVE_QUIT \
+  do \
+    { \
+      if (octave_interrupt_state) \
+        { \
+          octave_interrupt_state = 0; \
+          octave_throw_interrupt_exception (); \
+        } \
+    } \
+  while (0)
+
+#define OCTAVE_JUMP_TO_TOP_LEVEL \
+  do { octave_interrupt_state = 1; } while (0)
+
+#define OCTAVE_THROW_TO_TOP_LEVEL octave_throw_interrupt_exception ()
+
+#define OCTAVE_TRY_WITH_INTERRUPTS try
+
+#define OCTAVE_CATCH_INTERRUPTS catch (octave_interrupt_exception)
+
+#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
+  do \
+    { \
+      jmp_buf saved_context; \
+ \
+      octave_save_current_context ((char *) saved_context); \
+ \
+      if (octave_set_current_context) \
+	{ \
+	  octave_restore_current_context ((char *) saved_context); \
+	  OCTAVE_THROW_TO_TOP_LEVEL; \
+	} \
+      else \
+	{ \
+	  octave_interrupt_immediately++
+
+#define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
+          octave_interrupt_immediately--; \
+          octave_restore_current_context ((char *) saved_context); \
+        } \
+    } \
+  while (0)
+
+#else
+
+#define OCTAVE_QUIT do { } while (0)
+
+#define OCTAVE_JUMP_TO_TOP_LEVEL octave_jump_to_enclosing_context ()
+
+#define OCTAVE_THROW_TO_TOP_LEVEL OCTAVE_JUMP_TO_TOP_LEVEL
+
+#define OCTAVE_TRY_WITH_INTERRUPTS
+
+#define OCTAVE_CATCH_INTERRUPTS if (0)
+
+#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE do { } while (0)
+
+#define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE do { } while (0)
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- a/liboctave/CMatrix.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/liboctave/CMatrix.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -986,6 +986,8 @@
 
   for (size_t i = 0; i < nsamples; i++)
     {
+      OCTAVE_QUIT;
+
       octave_fftw::fft (&in[npts * i], &out[npts * i], npts);
     }
 
@@ -1018,6 +1020,8 @@
 
   for (size_t i = 0; i < nsamples; i++)
     {
+      OCTAVE_QUIT;
+
       octave_fftw::ifft (&in[npts * i], &out[npts * i], npts);
     }
 
@@ -1086,7 +1090,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   return retval;
 }
@@ -1123,7 +1131,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   for (int j = 0; j < npts*nsamples; j++)
     tmp_data[j] = tmp_data[j] / static_cast<double> (npts);
@@ -1163,7 +1175,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   npts = nc;
   nsamples = nr;
@@ -1179,6 +1195,8 @@
 
   for (int j = 0; j < nsamples; j++)
     {
+      OCTAVE_QUIT;
+
       for (int i = 0; i < npts; i++)
 	prow[i] = tmp_data[i*nr + j];
 
@@ -1223,7 +1241,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   for (int j = 0; j < npts*nsamples; j++)
     tmp_data[j] = tmp_data[j] / static_cast<double> (npts);
@@ -1242,6 +1264,8 @@
 
   for (int j = 0; j < nsamples; j++)
     {
+      OCTAVE_QUIT;
+
       for (int i = 0; i < npts; i++)
 	prow[i] = tmp_data[i*nr + j];
 
@@ -1937,6 +1961,8 @@
     for (int j = 0; j < nc; j++)
        retval(i,j) *= dscale(i) / dscale(j);
 
+  OCTAVE_QUIT;
+
   // construct balancing permutation vector
   Array<int> ipermute (nc);
   for (int i = 0; i < nc; i++)
@@ -1965,6 +1991,8 @@
   for (int i = 0; i < nc; i++)
     invpvec(ipermute(i)) = i;     // Thanks to R. A. Lippert for this method
 
+  OCTAVE_QUIT;
+
   ComplexMatrix tmpMat = retval;
   for (int i = 0; i < nc; i++)
     for (int j = 0; j < nc; j++)
--- a/liboctave/ChangeLog	Wed Nov 06 18:41:50 2002 +0000
+++ b/liboctave/ChangeLog	Wed Nov 06 20:38:50 2002 +0000
@@ -1,5 +1,7 @@
 2002-11-06  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* CMatrix.cc, dMatrix.cc: Sprinkle with OCTAVE_QUIT.
+
 	* ODESSA.cc (odessa_f, odessa_j, odessa_b): Abort on error.
 
 	* Array.h: Include <cstddef> here.
--- a/liboctave/ODESSA.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/liboctave/ODESSA.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -39,6 +39,7 @@
 #include "f77-fcn.h"
 #include "lo-error.h"
 #include "lo-sstream.h"
+#include "quit.h"
 
 typedef int (*odessa_fcn_ptr) (int*, const double&, double*,
 			       double*, double*);
@@ -85,7 +86,7 @@
   ColumnVector tmp_fval = user_fsub (tmp_state, t, tmp_param);
 
   if (tmp_fval.length () == 0)
-    longjmp (f77_context, 1);
+    octave_jump_to_enclosing_context ();
   else
     {
       for (int i = 0; i < n; i++)
@@ -115,7 +116,7 @@
   Matrix tmp_fval = user_jsub (tmp_state, t, tmp_param);
 
   if (tmp_fval.length () == 0)
-    longjmp (f77_context, 1);
+    octave_jump_to_enclosing_context ();
   else
     {
       for (int j = 0; j < n; j++)
@@ -146,7 +147,7 @@
   ColumnVector tmp_fval = user_bsub (tmp_state, t, tmp_param, jpar);
 
   if (tmp_fval.length () == 0)
-    longjmp (f77_context, 1);
+    octave_jump_to_enclosing_context ();
   else
     {
       for (int i = 0; i < n; i++)
--- a/liboctave/dMatrix.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/liboctave/dMatrix.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -49,6 +49,7 @@
 #include "mx-dm-m.h"
 #include "mx-inlines.cc"
 #include "oct-cmplx.h"
+#include "quit.h"
 
 #ifdef HAVE_FFTW
 #include "oct-fftw.h"
@@ -681,6 +682,8 @@
 
   for (size_t i = 0; i < nsamples; i++)
     {
+      OCTAVE_QUIT;
+
       octave_fftw::fft (&in[npts * i], &out[npts * i], npts);
     }
 
@@ -714,6 +717,8 @@
 
   for (size_t i = 0; i < nsamples; i++)
     {
+      OCTAVE_QUIT;
+
       octave_fftw::ifft (&in[npts * i], &out[npts * i], npts);
     }
 
@@ -782,7 +787,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   return retval;
 }
@@ -819,7 +828,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   for (int j = 0; j < npts*nsamples; j++)
     tmp_data[j] = tmp_data[j] / static_cast<double> (npts);
@@ -859,7 +872,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftf, CFFTF) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   npts = nc;
   nsamples = nr;
@@ -875,6 +892,8 @@
 
   for (int j = 0; j < nsamples; j++)
     {
+      OCTAVE_QUIT;
+
       for (int i = 0; i < npts; i++)
 	prow[i] = tmp_data[i*nr + j];
 
@@ -919,7 +938,11 @@
   F77_FUNC (cffti, CFFTI) (npts, pwsave);
 
   for (int j = 0; j < nsamples; j++)
-    F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    {
+      OCTAVE_QUIT;
+
+      F77_FUNC (cfftb, CFFTB) (npts, &tmp_data[npts*j], pwsave);
+    }
 
   for (int j = 0; j < npts*nsamples; j++)
     tmp_data[j] = tmp_data[j] / static_cast<double> (npts);
@@ -938,6 +961,8 @@
 
   for (int j = 0; j < nsamples; j++)
     {
+      OCTAVE_QUIT;
+
       for (int i = 0; i < npts; i++)
 	prow[i] = tmp_data[i*nr + j];
 
@@ -1610,6 +1635,8 @@
     for (int j = 0; j < nc; j++)
        retval(i,j) *= dscale(i) / dscale(j);
 
+  OCTAVE_QUIT;
+
   // construct balancing permutation vector
   Array<int> ipermute (nc);
   for (int i = 0; i < nc; i++)
@@ -1637,6 +1664,8 @@
   Array<int> invpvec (nc);
   for (int i = 0; i < nc; i++)
     invpvec(ipermute(i)) = i;     // Thanks to R. A. Lippert for this method
+
+  OCTAVE_QUIT;
  
   Matrix tmpMat = retval;
   for (int i = 0; i < nc; i++)
--- a/src/ChangeLog	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/ChangeLog	Wed Nov 06 20:38:50 2002 +0000
@@ -1,5 +1,35 @@
 2002-11-06  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* utils.cc (jump_to_top_level): Delete.
+
+	* toplev.cc (toplevel): Delete.
+	(main_loop): Adapt to new signal/exception handling scheme.
+
+	* sighandlers.cc (octave_signal_mask, octave_save_signal_mask,
+	octave_restore_signal_mask): Move to libcruft/misc/quit.cc.
+	(sigint_handler) [USE_EXCEPTIONS_FOR_INTERRUPTS]: set
+	octave_interrupt_state.  Only jump if octave_interrupt_immediately
+	is true, and then only to enclosing context.
+
+	* lex.h (YY_FATAL_ERROR): Use OCTAVE_JUMP_TO_TOP_LEVEL, not
+	jump_to_top_level.
+	* sighandlers.cc (octave_new_handler, sigfpe_handler, endif,
+	sigpipe_handler): Likewise.
+
+	* input.cc (gnu_readline): Surround call to
+	command_editor::readline with
+	BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE and 
+	END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE.
+
+	* data.cc, oct-stream.cc, ov-cell.cc, ov-mapper.cc, ov-re-mat.cc,
+	ov.cc, pr-output.cc, pt-loop.cc, pt-stmt.cc, xdiv.cc, xpow.cc,
+	DLD-FUNCTIONS/balance.cc, DLD-FUNCTIONS/besselj.cc,
+	DLD-FUNCTIONS/filter.cc, DLD-FUNCTIONS/find.cc,
+	DLD-FUNCTIONS/kron.cc, DLD-FUNCTIONS/log.cc,
+	DLD-FUNCTIONS/minmax.cc, DLD-FUNCTIONS/qz.cc,
+	DLD-FUNCTIONS/rand.cc, DLD-FUNCTIONS/sort.cc: Sprinkle with
+	OCTAVE_QUIT.
+
 	* DLD-FUNCTIONS/odessa.cc (Fodessa): Correctly extract bsub from
 	function arg.
 
--- a/src/DLD-FUNCTIONS/balance.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/balance.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -32,6 +32,7 @@
 #include "CmplxAEPBAL.h"
 #include "dbleAEPBAL.h"
 #include "dbleAEPBAL.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -272,7 +273,11 @@
 
       for (int ii = 0; ii < nn; ii++)
 	for (int jj = 0; jj < nn; jj++)
-	  Pl(ii,jj) = Pr(ii,jj) = (ii == jj ? 1.0 : 0.0);
+	  {
+	    OCTAVE_QUIT;
+
+	    Pl(ii,jj) = Pr(ii,jj) = (ii == jj ? 1.0 : 0.0);
+	  }
   
       // left first
       F77_XFCN (dggbak, DGGBAK,
--- a/src/DLD-FUNCTIONS/besselj.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/besselj.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -25,6 +25,7 @@
 #endif
 
 #include "lo-specfun.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -87,7 +88,11 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      retval(i,j) = (double) (a(i,j));
+      {
+	OCTAVE_QUIT;
+
+	retval(i,j) = (double) (a(i,j));
+      }
 
   return retval;
 }
--- a/src/DLD-FUNCTIONS/filter.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/filter.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -32,6 +32,8 @@
 #include <config.h>
 #endif
 
+#include "quit.h"
+
 #include "defun-dld.h"
 #include "error.h"
 #include "oct-obj.h"
@@ -93,8 +95,12 @@
 	  if (si_len > 1)
 	    {
 	      for (int j = 0; j < si_len - 1; j++)
-		si (j) = si (j+1) - a (j+1) * y (i)
-		  + b (j+1) * x (i);
+		{
+		  OCTAVE_QUIT;
+
+		  si (j) = si (j+1) - a (j+1) * y (i)
+		    + b (j+1) * x (i);
+		}
 
 	      si (si_len-1) = b (si_len) * x (i)
 		- a (si_len) * y (i);
@@ -113,7 +119,11 @@
 	  if (si_len > 1)
 	    {
 	      for (int j = 0; j < si_len - 1; j++)
-		si (j) = si (j+1) + b (j+1) * x (i);
+		{
+		  OCTAVE_QUIT;
+
+		  si (j) = si (j+1) + b (j+1) * x (i);
+		}
 
 	      si (si_len-1) = b (si_len) * x (i);
 	    }
--- a/src/DLD-FUNCTIONS/find.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/find.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -24,6 +24,8 @@
 #include <config.h>
 #endif
 
+#include "quit.h"
+
 #include "defun-dld.h"
 #include "error.h"
 #include "gripes.h"
@@ -92,8 +94,12 @@
   int i, j;
   for (j = 0; j < m_nc; j++)
     for (i = 0; i < m_nr; i++)
-      if (m (i, j) != 0.0)
-	count++;
+      {
+	OCTAVE_QUIT;
+
+	if (m (i, j) != 0.0)
+	  count++;
+      }
 
   octave_value_list retval (((nargout == 0) ? 1 : nargout), Matrix ());
 
@@ -108,6 +114,8 @@
   for (j = 0; j < m_nc; j++)
     for (i = 0; i < m_nr; i++)
       {
+	OCTAVE_QUIT;
+
 	double d = m (i, j);
 	if (d != 0.0)
 	  {
@@ -131,8 +139,12 @@
   int i, j;
   for (j = 0; j < m_nc; j++)
     for (i = 0; i < m_nr; i++)
-      if (m (i, j) != 0.0)
-	count++;
+      {
+	OCTAVE_QUIT;
+
+	if (m (i, j) != 0.0)
+	  count++;
+      }
 
   octave_value_list retval (((nargout == 0) ? 1 : nargout), Matrix ());
 
@@ -147,6 +159,8 @@
   for (j = 0; j < m_nc; j++)
     for (i = 0; i < m_nr; i++)
       {
+	OCTAVE_QUIT;
+
 	Complex c = m (i, j);
 	if (c != 0.0)
 	  {
--- a/src/DLD-FUNCTIONS/kron.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/kron.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -28,6 +28,7 @@
 
 #include "dMatrix.h"
 #include "CMatrix.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -55,7 +56,10 @@
 	const T v = A (Ar, Ac);
 	for (int Bc = 0; Bc < B.columns (); Bc++)
 	  for (int Br = 0; Br < B.rows (); Br++)
-	    C.xelem (Cr+Br, Cc+Bc) = v * B.elem (Br, Bc);
+	    {
+	      OCTAVE_QUIT;
+	      C.xelem (Cr+Br, Cc+Bc) = v * B.elem (Br, Bc);
+	    }
       }
 }
 
--- a/src/DLD-FUNCTIONS/log.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/log.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -26,6 +26,7 @@
 
 #include "EIG.h"
 #include "mx-cm-cdm.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -98,6 +99,7 @@
 
 	      for (int i = 0; i < nr; i++)
 		{
+		  OCTAVE_QUIT;
 		  Complex elt = lambda (i);
 		  if (imag (elt) == 0.0 && real (elt) > 0.0)
 		    lambda (i) = log (real (elt));
@@ -131,6 +133,7 @@
 
 	      for (int i = 0; i < nr; i++)
 		{
+		  OCTAVE_QUIT;
 		  Complex elt = lambda (i);
 		  if (imag (elt) == 0.0 && real (elt) > 0.0)
 		    lambda (i) = log (real (elt));
@@ -215,6 +218,7 @@
 
 	      for (int i = 0; i < nr; i++)
 		{
+		  OCTAVE_QUIT;
 		  Complex elt = lambda (i);
 		  if (imag (elt) == 0.0 && real (elt) > 0.0)
 		    lambda (i) = sqrt (real (elt));
@@ -248,6 +252,7 @@
 
 	      for (int i = 0; i < nr; i++)
 		{
+		  OCTAVE_QUIT;
 		  Complex elt = lambda (i);
 		  if (imag (elt) == 0.0 && real (elt) > 0.0)
 		    lambda (i) = sqrt (real (elt));
--- a/src/DLD-FUNCTIONS/minmax.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/minmax.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -28,6 +28,7 @@
 
 #include "lo-ieee.h"
 #include "lo-mappers.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -53,7 +54,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmin (d, m (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmin (d, m (i, j));
+      }
 
   return result;
 }
@@ -70,7 +74,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmin (m (i, j), d);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmin (m (i, j), d);
+      }
 
   return result;
 }
@@ -87,7 +94,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmin (c, m (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmin (c, m (i, j));
+      }
 
   return result;
 }
@@ -104,7 +114,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmin (m (i, j), c);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmin (m (i, j), c);
+      }
 
   return result;
 }
@@ -127,7 +140,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmin (a (i, j), b (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmin (a (i, j), b (i, j));
+      }
 
   return result;
 }
@@ -152,11 +168,14 @@
     {
       int columns_are_real_only = 1;
       for (int i = 0; i < nr; i++)
-	if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0)
-	  {
-	    columns_are_real_only = 0;
-	    break;
-	  }
+	{
+	  OCTAVE_QUIT;
+	  if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0)
+	    {
+	      columns_are_real_only = 0;
+	      break;
+	    }
+	}
 
       if (columns_are_real_only)
 	{
@@ -166,7 +185,10 @@
       else
 	{
 	  for (int i = 0; i < nr; i++)
-	    result (i, j) = xmin (a (i, j), b (i, j));
+	    {
+	      OCTAVE_QUIT;
+	      result (i, j) = xmin (a (i, j), b (i, j));
+	    }
 	}
     }
 
@@ -185,7 +207,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmax (d, m (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmax (d, m (i, j));
+      }
 
   return result;
 }
@@ -202,7 +227,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmax (m (i, j), d);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmax (m (i, j), d);
+      }
 
   return result;
 }
@@ -219,7 +247,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmax (c, m (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmax (c, m (i, j));
+      }
 
   return result;
 }
@@ -236,7 +267,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmax (m (i, j), c);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmax (m (i, j), c);
+      }
 
   return result;
 }
@@ -259,7 +293,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = xmax (a (i, j), b (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = xmax (a (i, j), b (i, j));
+      }
 
   return result;
 }
@@ -284,21 +321,30 @@
     {
       int columns_are_real_only = 1;
       for (int i = 0; i < nr; i++)
-	if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0)
-	  {
-	    columns_are_real_only = 0;
-	    break;
-	  }
+	{
+	  OCTAVE_QUIT;
+	  if (imag (a (i, j)) != 0.0 || imag (b (i, j)) != 0.0)
+	    {
+	      columns_are_real_only = 0;
+	      break;
+	    }
+	}
 
       if (columns_are_real_only)
 	{
 	  for (int i = 0; i < nr; i++)
-	    result (i, j) = xmax (real (a (i, j)), real (b (i, j)));
+	    {
+	      OCTAVE_QUIT;
+	      result (i, j) = xmax (real (a (i, j)), real (b (i, j)));
+	    }
 	}
       else
 	{
 	  for (int i = 0; i < nr; i++)
-	    result (i, j) = xmax (a (i, j), b (i, j));
+	    {
+	      OCTAVE_QUIT;
+	      result (i, j) = xmax (a (i, j), b (i, j));
+	    }
 	}
     }
 
@@ -428,6 +474,7 @@
  \
 	  for (int i = 0; i < len; i++) \
 	    { \
+	      OCTAVE_QUIT; \
 	      int tmp = index.elem (i) + 1; \
 	      idx.elem (i) = (tmp <= 0) \
 		? nan_val : static_cast<double> (tmp); \
--- a/src/DLD-FUNCTIONS/qz.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/qz.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -38,9 +38,11 @@
 
 #include "CmplxQRP.h"
 #include "dbleQR.h"
+#include "f77-fcn.h"
+#include "quit.h"
+
 #include "defun-dld.h"
 #include "error.h"
-#include "f77-fcn.h"
 #include "gripes.h"
 #include "oct-obj.h"
 #include "oct-map.h"
@@ -397,7 +399,10 @@
   if (compq == 'V' || compz == 'V')
     for (int ii = 0; ii < nn; ii++)
       for (int jj = 0; jj < nn; jj++)
-        QQ(ii,jj) = ZZ(ii,jj) = (ii == jj ? 1.0 : 0.0);
+	{
+	  OCTAVE_QUIT;
+	  QQ(ii,jj) = ZZ(ii,jj) = (ii == jj ? 1.0 : 0.0);
+	}
 
   // always perform permutation balancing
   char bal_job = 'P';
@@ -836,6 +841,8 @@
 
 	  while (jj < nn)
 	    {
+	      OCTAVE_QUIT;
+
 	      // see if real or complex eigenvalue
 	      int cinc = 2;	// column increment; assume complex eigenvalue
 
--- a/src/DLD-FUNCTIONS/rand.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/rand.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -30,6 +30,7 @@
 
 #include "f77-fcn.h"
 #include "lo-mappers.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -71,7 +72,7 @@
 {
   union d2i { double d; int i[2]; };
   union d2i u;
-  F77_XFCN (getsd, GETSD, (u.i[0], u.i[1]));
+  F77_FUNC (getsd, GETSD) (u.i[0], u.i[1]);
   return u.d;
 }
 
@@ -98,7 +99,7 @@
   u.d = val;
   int i0 = force_to_fit_range (u.i[0], 1, 2147483563);
   int i1 = force_to_fit_range (u.i[1], 1, 2147483399);
-  F77_XFCN (setsd, SETSD, (i0, i1));
+  F77_FUNC (setsd, SETSD) (i0, i1);
 }
 
 static const char *
@@ -139,11 +140,25 @@
   s0 = force_to_fit_range (s0, 1, 2147483563);
   s1 = force_to_fit_range (s1, 1, 2147483399);
 
-  F77_XFCN (setall, SETALL, (s0, s1));
+  F77_FUNC (setall, SETALL) (s0, s1);
 
   initialized = 1;
 }
 
+#define MAKE_RAND_MAT(mat, nr, nc, f, F) \
+  do \
+    { \
+      double val; \
+      for (volatile int j = 0; j < nc; j++) \
+	for (volatile int i = 0; i < nr; i++) \
+	  { \
+	    OCTAVE_QUIT; \
+	    F77_FUNC (f, F) (0.0, 1.0, val); \
+	    mat(i,j) = val; \
+	  } \
+    } \
+  while (0)
+
 static octave_value_list
 do_rand (const octave_value_list& args, int nargin)
 {
@@ -179,13 +194,13 @@
 	    {
 	      current_distribution = uniform_dist;
 
-	      F77_XFCN (setcgn, SETCGN, (uniform_dist));
+	      F77_FUNC (setcgn, SETCGN) (uniform_dist);
 	    }
 	  else if (s_arg == "normal")
 	    {
 	      current_distribution = normal_dist;
 
-	      F77_XFCN (setcgn, SETCGN, (normal_dist));
+	      F77_FUNC (setcgn, SETCGN) (normal_dist);
 	    }
 	  else
 	    error ("rand: unrecognized string argument");
@@ -297,27 +312,20 @@
     {
       Matrix rand_mat (n, m);
 
-      for (volatile int j = 0; j < m; j++)
-	for (volatile int i = 0; i < n; i++)
-	  {
-	    double val;
-	    switch (current_distribution)
-	      {
-	      case uniform_dist:
-		F77_XFCN (dgenunf, DGENUNF, (0.0, 1.0, val));
-		rand_mat (i, j) = val;
-		break;
+      switch (current_distribution)
+	{
+	case uniform_dist:
+	  MAKE_RAND_MAT (rand_mat, n, m, dgenunf, DGENUNF);
+	  break;
 
-	      case normal_dist:
-		F77_XFCN (dgennor, DGENNOR, (0.0, 1.0, val));
-		rand_mat (i, j) = val;
-		break;
+	case normal_dist:
+	  MAKE_RAND_MAT (rand_mat, n, m, dgennor, DGENNOR);
+	  break;
 
-	      default:
-		panic_impossible ();
-		break;
-	      }
-	  }
+	default:
+	  panic_impossible ();
+	  break;
+	}
 
       retval(0) = rand_mat;
     }
@@ -373,7 +381,7 @@
 static void
 reset_rand_generator (void *)
 {
-  F77_XFCN (setcgn, SETCGN, (current_distribution));
+  F77_FUNC (setcgn, SETCGN) (current_distribution);
 }
 
 DEFUN_DLD (randn, args, nargout,
@@ -424,7 +432,7 @@
 
       current_distribution = normal_dist;
 
-      F77_XFCN (setcgn, SETCGN, (normal_dist));
+      F77_FUNC (setcgn, SETCGN) (normal_dist);
 
       retval = do_rand (args, nargin);
 
--- a/src/DLD-FUNCTIONS/sort.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/DLD-FUNCTIONS/sort.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -25,6 +25,7 @@
 #endif
 
 #include "lo-mappers.h"
+#include "quit.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -120,6 +121,7 @@
       SORT_INIT_PHASE(n); \
       while (1) \
 	{ \
+          OCTAVE_QUIT; \
 	  if (condition) \
 	    { \
 	      SORT_REORDER_PHASE_ONE; \
@@ -137,6 +139,7 @@
   vs (0) = v (k-1); \
   for (int i = 1; i < n; i++) \
     { \
+      OCTAVE_QUIT; \
       k = l (static_cast<int> (idx (i-1))); \
       idx (i) = k; \
       vs (i) = v (k-1); \
@@ -148,6 +151,7 @@
   ms (0, j) = m (k-1, j); \
   for (int i = 1; i < nr; i++) \
     { \
+      OCTAVE_QUIT; \
       k = l (static_cast<int> (idx (i-1, j))); \
       idx (i, j) = k; \
       ms (i, j) = m (k-1, j); \
@@ -247,11 +251,14 @@
 
 	  bool all_elts_real = true;
 	  for (int i = 0; i < nr; i++)
-	    if (imag (cm (i, j)) != 0.0)
-	      {
-		all_elts_real = false;
-		break;
-	      }
+	    {
+	      OCTAVE_QUIT;
+	      if (imag (cm (i, j)) != 0.0)
+		{
+		  all_elts_real = false;
+		  break;
+		}
+	    }
 
 	  DO_SORT (nr, ((all_elts_real
 			 && (xisnan (real (cm (p-1, j)))
@@ -292,11 +299,14 @@
 
       bool all_elts_real = true;
       for (int i = 0; i < n; i++)
-	if (imag (cv (i)) != 0.0)
-	  {
-	    all_elts_real = false;
-	    break;
-	  }
+	{
+	  OCTAVE_QUIT;
+	  if (imag (cv (i)) != 0.0)
+	    {
+	      all_elts_real = false;
+	      break;
+	    }
+	}
 
       DO_SORT (n, ((all_elts_real
 		    && (xisnan (real (cv (p-1)))
--- a/src/data.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/data.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -31,6 +31,7 @@
 
 #include "lo-ieee.h"
 #include "str-vec.h"
+#include "quit.h"
 
 #include "defun.h"
 #include "error.h"
@@ -131,7 +132,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      retval (i, j) = f (x, y (i, j));
+      {
+	OCTAVE_QUIT;
+	retval (i, j) = f (x, y (i, j));
+      }
 
   return retval;
 }
@@ -146,7 +150,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      retval (i, j) = f (x (i, j), y);
+      {
+	OCTAVE_QUIT;
+	retval (i, j) = f (x (i, j), y);
+      }
 
   return retval;
 }
@@ -166,7 +173,10 @@
 
   for (int j = 0; j < x_nc; j++)
     for (int i = 0; i < x_nr; i++)
-      retval (i, j) = f (x (i, j), y (i, j));
+      {
+	OCTAVE_QUIT;
+	retval (i, j) = f (x (i, j), y (i, j));
+      }
 
   return retval;
 }
--- a/src/input.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/input.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -43,6 +43,7 @@
 
 #include "cmd-edit.h"
 #include "file-ops.h"
+#include "quit.h"
 #include "str-vec.h"
 
 #include "defun.h"
@@ -170,8 +171,12 @@
     {
       bool eof;
 
+      BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
+
       retval = command_editor::readline (s, eof);
 
+      END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
+
       if (! eof && retval.empty ())
 	retval = "\n";
     }
--- a/src/lex.h	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/lex.h	Wed Nov 06 20:38:50 2002 +0000
@@ -43,7 +43,7 @@
   do \
     { \
       error (msg); \
-      jump_to_top_level (); \
+      OCTAVE_JUMP_TO_TOP_LEVEL; \
       yy_fatal_error (msg); \
     } \
   while (0)
--- a/src/lex.l	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/lex.l	Wed Nov 06 20:38:50 2002 +0000
@@ -43,6 +43,7 @@
 #include "SLStack.h"
 
 #include "cmd-edit.h"
+#include "quit.h"
 #include "lo-sstream.h"
 
 // These would be alphabetical, but y.tab.h must be included before
--- a/src/load-save.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/load-save.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -2636,7 +2636,7 @@
 	  goto data_read_error;
 
 	// fields subelements
-	for (i=0; i < len/field_name_length; i++)
+	for (i = 0; i < len/field_name_length; i++)
 	  {
 	    char *thename;
 	    octave_value fieldtc;
--- a/src/oct-stream.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/oct-stream.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -36,6 +36,7 @@
 #include "lo-sstream.h"
 #include "lo-utils.h"
 #include "str-vec.h"
+#include "quit.h"
 
 #include "error.h"
 #include "input.h"
@@ -1436,6 +1437,8 @@
 
       for (;;)
 	{
+	  OCTAVE_QUIT;
+
 	  if (elt)
 	    {
 	      if (max_conv > 0 && conversion_count == max_conv)
@@ -2246,6 +2249,8 @@
 
       for (;;)
 	{
+	  OCTAVE_QUIT;
+
 	  if (elt)
 	    {
 	      // NSA is the number of `star' args to convert.
--- a/src/ov-cell.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/ov-cell.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -32,6 +32,7 @@
 
 #include "lo-sstream.h"
 #include "lo-utils.h"
+#include "quit.h"
 
 #include "defun.h"
 #include "error.h"
@@ -78,7 +79,10 @@
 	    int k = 0;
 	    for (int j = 0; j < nc; j++)
 	      for (int i = 0; i < nr; i++)
-		lst(k++) = tcell(i,j);
+		{
+		  OCTAVE_QUIT;
+		  lst(k++) = tcell(i,j);
+		}
 	    retval = octave_value (lst, true);
 	  }
       }
@@ -268,6 +272,8 @@
 	{
 	  for (int i = 0; i < nr; i++)
 	    {
+	      OCTAVE_QUIT;
+
 	      OSSTREAM buf;
 	      buf << "[" << i+1 << "," << j+1 << "]" << OSSTREAM_ENDS;
 
--- a/src/ov-mapper.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/ov-mapper.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -28,6 +28,8 @@
 #include <config.h>
 #endif
 
+#include "quit.h"
+
 #include "error.h"
 #include "gripes.h"
 #include "oct-obj.h"
@@ -47,8 +49,12 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      if (a (i, j) < val)
-	return true;
+      {
+	OCTAVE_QUIT;
+
+	if (a (i, j) < val)
+	  return true;
+      }
 
   return false;
 }
@@ -61,8 +67,12 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      if (a (i, j) > val)
-	return true;
+      {
+	OCTAVE_QUIT;
+
+	if (a (i, j) > val)
+	  return true;
+      }
 
   return false;
 }
@@ -84,6 +94,8 @@
 	{ \
 	   for (int i = 0; i < nr; i++) \
 	     { \
+                OCTAVE_QUIT; \
+ \
 		result (i, j) = CONV (F (M (i, j))); \
  \
 		if (error_state) \
--- a/src/ov-re-mat.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/ov-re-mat.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -35,6 +35,7 @@
 #include "lo-ieee.h"
 #include "lo-utils.h"
 #include "mx-base.h"
+#include "quit.h"
 
 #include "gripes.h"
 #include "oct-obj.h"
@@ -140,6 +141,8 @@
 	    {
 	      for (int i = 0; i < nr; i++)
 		{
+		  OCTAVE_QUIT;
+
 		  double d = matrix (i, j);
 
 		  if (xisnan (d))
--- a/src/ov.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/ov.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -30,6 +30,7 @@
 
 #include "Array-flags.h"
 #include "str-vec.h"
+#include "quit.h"
 
 #include "oct-obj.h"
 #include "ov.h"
@@ -896,7 +897,11 @@
       int k = 0;
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  retval (k++) = m (i, j);
+	  {
+	    OCTAVE_QUIT;
+
+	    retval (k++) = m (i, j);
+	  }
     }
   else
     {
@@ -926,6 +931,8 @@
       retval.resize (nc);
       for (int i = 0; i < nc; i++)
 	{
+	  OCTAVE_QUIT;
+
 	  double d = m (0, i);
 
 	  if (require_int && D_NINT (d) != d)
@@ -942,6 +949,8 @@
       retval.resize (nr);
       for (int i = 0; i < nr; i++)
 	{
+	  OCTAVE_QUIT;
+
 	  double d = m (i, 0);
 
 	  if (require_int && D_NINT (d) != d)
@@ -962,6 +971,8 @@
 	{
 	  for (int i = 0; i < nr; i++)
 	    {
+	      OCTAVE_QUIT;
+
 	      double d = m (i, j);
 
 	      if (require_int && D_NINT (d) != d)
@@ -1001,13 +1012,19 @@
     {
       retval.resize (nc);
       for (int i = 0; i < nc; i++)
-	retval (i) = m (0, i);
+	{
+	  OCTAVE_QUIT;
+	  retval (i) = m (0, i);
+	}
     }
   else if (nc == 1)
     {
       retval.resize (nr);
       for (int i = 0; i < nr; i++)
-	retval (i) = m (i, 0);
+	{
+	  OCTAVE_QUIT;
+	  retval (i) = m (i, 0);
+	}
     }
   else if (nr > 0 && nc > 0
 	   && (Vdo_fortran_indexing || force_vector_conversion))
@@ -1016,7 +1033,10 @@
       int k = 0;
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  retval (k++) = m (i, j);
+	  {
+	    OCTAVE_QUIT;
+	    retval (k++) = m (i, j);
+	  }
     }
   else
     {
--- a/src/pr-output.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/pr-output.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -41,6 +41,7 @@
 #include "lo-sstream.h"
 #include "mach-info.h"
 #include "oct-cmplx.h"
+#include "quit.h"
 #include "str-vec.h"
 
 #include "Cell.h"
@@ -1311,6 +1312,8 @@
 	{
 	  for (int j = 0; j < nc; j++)
 	    {
+	      OCTAVE_QUIT;
+
 	      if (j == 0)
 		os << "  ";
 
@@ -1370,6 +1373,8 @@
 
 		  for (int j = col; j < lim; j++)
 		    {
+		      OCTAVE_QUIT;
+
 		      if (i == 0 && j == 0)
 			os << "[ ";
 		      else
@@ -1414,6 +1419,8 @@
 
 		  for (int j = col; j < lim; j++)
 		    {
+		      OCTAVE_QUIT;
+
 		      os << "  ";
 
 		      pr_float (os, m(i,j), fw, scale);
@@ -1479,6 +1486,8 @@
 	{
 	  for (int j = 0; j < nc; j++)
 	    {
+	      OCTAVE_QUIT;
+
 	      if (j == 0)
 		os << "  ";
 
@@ -1539,6 +1548,8 @@
 
 		  for (int j = col; j < lim; j++)
 		    {
+		      OCTAVE_QUIT;
+
 		      if (i == 0 && j == 0)
 			os << "[ ";
 		      else
@@ -1583,6 +1594,8 @@
 
 		  for (int j = col; j < lim; j++)
 		    {
+		      OCTAVE_QUIT;
+
 		      os << "  ";
 
 		      pr_complex (os, cm(i,j), r_fw, i_fw, scale);
@@ -1610,6 +1623,8 @@
       os << "  ";
       for (int i = 0; i < num_elem; i++)
 	{
+	  OCTAVE_QUIT;
+
 	  double val = base + i * increment;
 	  if (val == 0.0)
 	    os << " ";
@@ -1683,6 +1698,8 @@
 
 	      for (int i = col; i < lim; i++)
 		{
+		  OCTAVE_QUIT;
+
 		  double val = base + i * increment;
 
 		  os << "  ";
@@ -1725,6 +1742,8 @@
 	{
 	  for (int i = 0; i < nstr; i++)
 	    {
+	      OCTAVE_QUIT;
+
 	      std::string row = chm.row_as_string (i);
 
 	      if (pr_as_read_syntax)
--- a/src/pt-loop.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/pt-loop.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -28,6 +28,8 @@
 #include <config.h>
 #endif
 
+#include "quit.h"
+
 #include "error.h"
 #include "gripes.h"
 #include "oct-map.h"
@@ -50,6 +52,8 @@
 static inline bool
 quit_loop_now (void)
 {
+  OCTAVE_QUIT;
+
   // Maybe handle `continue N' someday...
 
   if (tree_continue_command::continuing)
--- a/src/pt-stmt.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/pt-stmt.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -30,6 +30,8 @@
 
 #include <SLList.h>
 
+#include "quit.h"
+
 #include "defun.h"
 #include "error.h"
 #include "ov.h"
@@ -156,6 +158,8 @@
 
       if (elt)
 	{
+	  OCTAVE_QUIT;
+
 	  retval = elt->eval (silent, nargout, function_body);
 
 	  if (error_state)
--- a/src/sighandlers.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/sighandlers.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -37,6 +37,7 @@
 #endif
 
 #include "cmd-edit.h"
+#include "quit.h"
 
 #include "error.h"
 #include "load-save.h"
@@ -53,18 +54,6 @@
 // TRUE means we can be interrupted.
 bool can_interrupt = false;
 
-// Allow us to save the signal mask and then restore it to the most
-// recently saved value.  This is necessary when using the POSIX
-// signal handling interface on some systems calling longjmp out of
-// the signal handler to get to the top level on an interrupt doesn't
-// restore the original signal mask.  Alternatively, we could use
-// sigsetjmp/siglongjmp, but saving and restoring the signal mask
-// ourselves works ok and seems simpler just now.
-
-#if defined (HAVE_POSIX_SIGNALS)
-static sigset_t octave_signal_mask;
-#endif
-
 #if RETSIGTYPE == void
 #define SIGHANDLER_RETURN(status) return
 #else
@@ -95,22 +84,6 @@
 #define OCTAVE_MEMORY_EXHAUSTED_ERROR (-1)
 #endif
 
-void
-octave_save_signal_mask (void)
-{
-#if defined (HAVE_POSIX_SIGNALS)
-  sigprocmask (0, 0, &octave_signal_mask);
-#endif
-}
-
-void
-octave_restore_signal_mask (void)
-{
-#if defined (HAVE_POSIX_SIGNALS)
-  sigprocmask (SIG_SETMASK, &octave_signal_mask, 0);
-#endif
-}
-
 static void
 my_friendly_exit (const char *sig_name, int sig_number)
 {
@@ -160,7 +133,7 @@
 
   if (can_interrupt)
     {
-      jump_to_top_level ();
+      OCTAVE_JUMP_TO_TOP_LEVEL;
       panic_impossible ();
     }
   else
@@ -268,7 +241,7 @@
 
   if (can_interrupt)
     {
-      jump_to_top_level ();
+      OCTAVE_OCTAVE_JUMP_TO_TOP_LEVEL;
       panic_impossible ();
     }
 
@@ -312,8 +285,15 @@
 
   if (can_interrupt)
     {
-      jump_to_top_level ();
+#if defined (USE_EXCEPTIONS_FOR_INTERRUPTS)
+      octave_interrupt_state = 1;
+
+      if (octave_interrupt_immediately)
+	octave_jump_to_enclosing_context ();
+#else
+      OCTAVE_JUMP_TO_TOP_LEVEL;
       panic_impossible ();
+#endif
     }
 
   SIGHANDLER_RETURN (0);
@@ -333,7 +313,7 @@
   // Don't loop forever on account of this.
 
   if (pipe_handler_error_count  > 100)
-    jump_to_top_level ();
+    OCTAVE_JUMP_TO_TOP_LEVEL;
 
   SIGHANDLER_RETURN (0);
 }
--- a/src/sighandlers.h	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/sighandlers.h	Wed Nov 06 20:38:50 2002 +0000
@@ -103,10 +103,6 @@
 extern octave_interrupt_handler
 octave_set_interrupt_handler (const volatile octave_interrupt_handler&);
 
-extern void octave_save_signal_mask (void);
-
-extern void octave_restore_signal_mask (void);
-
 // extern void ignore_sigchld (void);
 
 // Maybe this should be in a separate file?
--- a/src/toplev.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/toplev.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -39,17 +39,13 @@
 #include <unistd.h>
 #endif
 
-// Include setjmp.h, not csetjmp since the latter might only define
-// the ANSI standard C interface.
-
-#include <setjmp.h>
-
 #include "cmd-edit.h"
 #include "file-ops.h"
 #include "lo-error.h"
 #include "lo-mappers.h"
 #include "lo-sstream.h"
 #include "oct-env.h"
+#include "quit.h"
 #include "str-vec.h"
 
 #include <defaults.h>
@@ -91,23 +87,21 @@
 // Original value of TEXMFDBS environment variable.
 std::string octave_original_texmfdbs;
 
-// Top level context (?)
-jmp_buf toplevel;
-
 int
 main_loop (void)
 {
-  // Allow the user to interrupt us without exiting.
-
   octave_save_signal_mask ();
 
-  if (setjmp (toplevel) != 0)
+  if (octave_set_current_context)
     {
+#if defined (USE_EXCEPTIONS_FOR_INTERRUPTS)
+      panic_impossible ();
+#else
+      unwind_protect::run_all ();
       raw_mode (0);
-
       std::cout << "\n";
-
       octave_restore_signal_mask ();
+#endif
     }
 
   can_interrupt = true;
@@ -116,59 +110,72 @@
 
   // The big loop.
 
-  int retval;
+  int retval = 0;
   do
     {
-      curr_sym_tab = top_level_sym_tab;
-
-      reset_parser ();
-
-      retval = yyparse ();
-
-      if (retval == 0)
+      OCTAVE_TRY_WITH_INTERRUPTS
 	{
-	  if (global_command)
-	    {
-	      global_command->eval ();
+	  curr_sym_tab = top_level_sym_tab;
 
-	      delete global_command;
+	  reset_parser ();
 
-	      global_command = 0;
+	  retval = yyparse ();
 
-	      if (! (interactive || forced_interactive))
+	  if (retval == 0)
+	    {
+	      if (global_command)
 		{
-		  bool quit = (tree_return_command::returning
-			       || tree_break_command::breaking);
-
-		  if (tree_return_command::returning)
-		    tree_return_command::returning = 0;
+		  global_command->eval ();
 
-		  if (tree_break_command::breaking)
-		    tree_break_command::breaking--;
+		  delete global_command;
 
-		  if (quit)
-		    break;
-		}
+		  global_command = 0;
 
-	      if (error_state)
-		{
 		  if (! (interactive || forced_interactive))
 		    {
-		      // We should exit with a non-zero status.
-		      retval = 1;
-		      break;
+		      bool quit = (tree_return_command::returning
+				   || tree_break_command::breaking);
+
+		      if (tree_return_command::returning)
+			tree_return_command::returning = 0;
+
+		      if (tree_break_command::breaking)
+			tree_break_command::breaking--;
+
+		      if (quit)
+			break;
+		    }
+
+		  if (error_state)
+		    {
+		      if (! (interactive || forced_interactive))
+			{
+			  // We should exit with a non-zero status.
+			  retval = 1;
+			  break;
+			}
+		    }
+		  else
+		    {
+		      if (octave_completion_matches_called)
+			octave_completion_matches_called = false;	    
+		      else
+			command_editor::increment_current_command_number ();
 		    }
 		}
-	      else
-		{
-		  if (octave_completion_matches_called)
-		    octave_completion_matches_called = false;	    
-		  else
-		    command_editor::increment_current_command_number ();
-		}
+	      else if (parser_end_of_input)
+		break;
 	    }
-	  else if (parser_end_of_input)
-	    break;
+	}
+      OCTAVE_CATCH_INTERRUPTS
+	{
+	  unwind_protect::run_all ();
+	  can_interrupt = true;
+	  octave_interrupt_immediately = 0;
+	  octave_interrupt_state = 0;
+	  std::cout << "\n"; \
+	  octave_restore_signal_mask (); \
+	  octave_catch_interrupts ();
 	}
     }
   while (retval == 0);
--- a/src/utils.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/utils.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -100,16 +100,6 @@
   return valid_identifier (s.c_str ());
 }
 
-// Return to the main command loop in octave.cc.
-
-void
-jump_to_top_level (void)
-{
-  unwind_protect::run_all ();
-
-  longjmp (toplevel, 1);
-}
-
 int
 almost_match (const std::string& std, const std::string& s, int min_match_len,
 	      int case_sens)
--- a/src/utils.h	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/utils.h	Wed Nov 06 20:38:50 2002 +0000
@@ -37,8 +37,6 @@
 extern bool valid_identifier (const char *s);
 extern bool valid_identifier (const std::string& s);
 
-extern void jump_to_top_level (void) GCC_ATTR_NORETURN;
-
 extern int almost_match (const std::string& std, const std::string& s,
 			 int min_match_len = 1, int case_sens = 1);
 
--- a/src/xdiv.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/xdiv.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -29,6 +29,7 @@
 #include "CMatrix.h"
 #include "dMatrix.h"
 #include "oct-cmplx.h"
+#include "quit.h"
 
 #include "error.h"
 #include "xdiv.h"
@@ -242,7 +243,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = a / b (i, j);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = a / b (i, j);
+      }
 
   return result;
 }
@@ -257,7 +261,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = a / b (i, j);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = a / b (i, j);
+      }
 
   return result;
 }
@@ -272,7 +279,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = a / b (i, j);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = a / b (i, j);
+      }
 
   return result;
 }
@@ -287,7 +297,10 @@
 
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = a / b (i, j);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = a / b (i, j);
+      }
 
   return result;
 }
--- a/src/xpow.cc	Wed Nov 06 18:41:50 2002 +0000
+++ b/src/xpow.cc	Wed Nov 06 20:38:50 2002 +0000
@@ -35,6 +35,7 @@
 #include "dMatrix.h"
 #include "mx-cm-cdm.h"
 #include "oct-cmplx.h"
+#include "quit.h"
 
 #include "error.h"
 #include "oct-obj.h"
@@ -500,7 +501,10 @@
       ComplexMatrix result (nr, nc);
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  result (i, j) = pow (atmp, b (i, j));
+	  {
+	    OCTAVE_QUIT;
+	    result (i, j) = pow (atmp, b (i, j));
+	  }
 
       retval = result;
     }
@@ -509,7 +513,10 @@
       Matrix result (nr, nc);
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  result (i, j) = pow (a, b (i, j)); 
+	  {
+	    OCTAVE_QUIT;
+	    result (i, j) = pow (a, b (i, j));
+	  }
 
       retval = result;
     }
@@ -528,7 +535,10 @@
   Complex atmp (a);
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = pow (atmp, b (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = pow (atmp, b (i, j));
+      }
 
   return result;
 }
@@ -548,6 +558,7 @@
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
 	  {
+	    OCTAVE_QUIT;
 	    Complex atmp (a (i, j));
 	    result (i, j) = pow (atmp, b);
 	  }
@@ -559,7 +570,10 @@
       Matrix result (nr, nc);
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  result (i, j) = pow (a (i, j), b);
+	  {
+	    OCTAVE_QUIT;
+	    result (i, j) = pow (a (i, j), b);
+	  }
 
       retval = result;
     }
@@ -589,6 +603,7 @@
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
       {
+	OCTAVE_QUIT;
 	double atmp = a (i, j);
 	double btmp = b (i, j);
 	if (atmp < 0.0 && static_cast<int> (btmp) != btmp)
@@ -607,6 +622,7 @@
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
 	  {
+	    OCTAVE_QUIT;
 	    Complex atmp (a (i, j));
 	    Complex btmp (b (i, j));
 	    complex_result (i, j) = pow (atmp, btmp);
@@ -620,7 +636,10 @@
 
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  result (i, j) = pow (a (i, j), b (i, j));
+	  {
+	    OCTAVE_QUIT;
+	    result (i, j) = pow (a (i, j), b (i, j));
+	  }
 
       retval = result;
     }
@@ -638,7 +657,10 @@
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = pow (Complex (a (i, j)), b);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = pow (Complex (a (i, j)), b);
+      }
 
   return result;
 }
@@ -662,7 +684,10 @@
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = pow (Complex (a (i, j)), b (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = pow (Complex (a (i, j)), b (i, j));
+      }
 
   return result;
 }
@@ -678,6 +703,7 @@
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
       {
+	OCTAVE_QUIT;
 	double btmp = b (i, j);
 	if (xisint (btmp))
 	  result (i, j) = pow (a, static_cast<int> (btmp));
@@ -698,7 +724,10 @@
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = pow (a, b (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = pow (a, b (i, j));
+      }
 
   return result;
 }
@@ -716,13 +745,19 @@
     {
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  result (i, j) = pow (a (i, j), static_cast<int> (b));
+	  {
+	    OCTAVE_QUIT;
+	    result (i, j) = pow (a (i, j), static_cast<int> (b));
+	  }
     }
   else
     {
       for (int j = 0; j < nc; j++)
 	for (int i = 0; i < nr; i++)
-	  result (i, j) = pow (a (i, j), b);
+	  {
+	    OCTAVE_QUIT;
+	    result (i, j) = pow (a (i, j), b);
+	  }
     }
 
   return result;
@@ -748,6 +783,7 @@
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
       {
+	OCTAVE_QUIT;
 	double btmp = b (i, j);
 	if (xisint (btmp))
 	  result (i, j) = pow (a (i, j), static_cast<int> (btmp));
@@ -768,7 +804,10 @@
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = pow (a (i, j), b);
+      {
+	OCTAVE_QUIT;
+	result (i, j) = pow (a (i, j), b);
+      }
 
   return result;
 }
@@ -792,7 +831,10 @@
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
-      result (i, j) = pow (a (i, j), b (i, j));
+      {
+	OCTAVE_QUIT;
+	result (i, j) = pow (a (i, j), b (i, j));
+      }
 
   return result;
 }