diff src/pager.cc @ 1449:df589c97e140

[project @ 1995-09-20 03:49:51 by jwe]
author jwe
date Wed, 20 Sep 1995 03:49:51 +0000
parents cd6c9be7337c
children 89c587478067
line wrap: on
line diff
--- a/src/pager.cc
+++ b/src/pager.cc
@@ -42,6 +42,7 @@
 #include "pager.h"
 #include "sighandlers.h"
 #include "tree-const.h"
+#include "unwind-prot.h"
 #include "user-prefs.h"
 #include "utils.h"
 #include "variables.h"
@@ -146,21 +147,29 @@
       char *pgr = user_pref.pager_binary;
       if (pgr)
 	{
-	  oprocstream pager_stream (pgr);
-	  if (pager_stream)
+	  volatile sig_handler *old_sigint_handler;
+	  old_sigint_handler = octave_set_signal_handler (SIGINT, SIG_IGN);
+
+	  oprocstream *pager_stream = new oprocstream (pgr);
+
+	  add_unwind_protect (cleanup_oprocstream, pager_stream);
+
+	  int output_paged = 0;
+	  if (pager_stream && *pager_stream)
 	    {
-	      volatile sig_handler *old_sigint_handler;
-	      old_sigint_handler = octave_set_signal_handler (SIGINT, SIG_IGN);
-
-	      pager_stream << message;
+	      output_paged = 1;
+	      *pager_stream << message;
 	      delete [] message;
-	      pager_stream.flush ();
-	      pager_stream.close ();
+	      pager_stream->flush ();
+	      pager_stream->close ();
+	    }
 
-	      octave_set_signal_handler (SIGINT, old_sigint_handler);
+	  run_unwind_protect ();
 
-	      return;
-	    }
+	  octave_set_signal_handler (SIGINT, old_sigint_handler);
+
+	  if (output_paged)
+	    return;
 	}
     }