Mercurial > hg > octave-lojdl
changeset 1449:df589c97e140
[project @ 1995-09-20 03:49:51 by jwe]
author | jwe |
---|---|
date | Wed, 20 Sep 1995 03:49:51 +0000 |
parents | 067f11a46742 |
children | 2f4a1acb555d |
files | src/dirfns.cc src/octave.cc src/pager.cc src/pt-plot.cc |
diffstat | 4 files changed, 105 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -62,6 +62,7 @@ #include "sysdir.h" #include "tree-const.h" #include "tree-plot.h" +#include "unwind-prot.h" #include "utils.h" extern "C" @@ -427,21 +428,27 @@ } ls_buf << ends; + char *ls_command = ls_buf.str (); + delete [] ls_command; - char *ls_command = ls_buf.str (); + iprocstream *cmd = new iprocstream (ls_command); - iprocstream cmd (ls_command); + add_unwind_protect (cleanup_iprocstream, cmd); - char ch; - ostrstream output_buf; - while (cmd.get (ch)) - output_buf.put (ch); + if (cmd && *cmd) + { + int ch; + ostrstream output_buf; + while ((ch = cmd->get ()) != EOF) + output_buf << (char) ch; + output_buf << ends; - output_buf << ends; + maybe_page_output (output_buf); + } + else + error ("couldn't start process for ls!"); - maybe_page_output (output_buf); - - delete [] ls_command; + run_unwind_protect (); DELETE_ARGV;
--- a/src/octave.cc +++ b/src/octave.cc @@ -1024,38 +1024,47 @@ } else { - iprocstream cmd (tmp_str); + iprocstream *cmd = new iprocstream (tmp_str); - ostrstream output_buf; + add_unwind_protect (cleanup_iprocstream, cmd); + + int status = 127; - char ch; - while (cmd.get (ch)) - output_buf.put (ch); + if (cmd && *cmd) + { + ostrstream output_buf; - output_buf << ends; + char ch; + while (cmd->get (ch)) + output_buf.put (ch); - int status = cmd.close (); + output_buf << ends; + + status = cmd->close (); - // The value in status is as returned by waitpid. If the - // process exited normally, extract the actual exit status of - // the command. Otherwise, return 127 as a failure code. + // The value in status is as returned by waitpid. If the + // process exited normally, extract the actual exit status of + // the command. Otherwise, return 127 as a failure code. - if ((status & 0xff) == 0) - status = (status & 0xff00) >> 8; - else - status = 127; + if ((status & 0xff) == 0) + status = (status & 0xff00) >> 8; - if (nargout > 0 || nargin > 1) - { - char *msg = output_buf.str (); + if (nargout > 0 || nargin > 1) + { + char *msg = output_buf.str (); - retval(1) = (double) status; - retval(0) = msg; + retval(1) = (double) status; + retval(0) = msg; - delete [] msg; + delete [] msg; + } + else + maybe_page_output (output_buf); } else - maybe_page_output (output_buf); + error ("unable to start subprocess for `%s'", tmp_str); + + run_unwind_protect (); } return retval;
--- 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; } }
--- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -77,7 +77,7 @@ static SLStack <char *> tmp_files; // Pipe to gnuplot. -static oprocstream plot_stream; +static oprocstream *plot_stream = 0; // Use shortest possible abbreviations to minimize trouble caused by // gnuplot's fixed-length command line buffer. @@ -111,7 +111,13 @@ { static int initialized = 0; - if (! plot_stream.is_open ()) + if (plot_stream && ! *plot_stream) + { + delete plot_stream; + plot_stream = 0; + } + + if (! plot_stream) { initialized = 0; @@ -120,8 +126,15 @@ char *plot_prog = user_pref.gnuplot_binary; if (plot_prog) { - plot_stream.open (plot_prog); - if (! plot_stream.is_open ()) + plot_stream = new oprocstream (plot_prog); + + if (plot_stream && ! *plot_stream) + { + delete plot_stream; + plot_stream = 0; + } + + if (! plot_stream) { warning ("plot: unable to open pipe to `%s'", plot_prog); @@ -138,20 +151,26 @@ { last_chance: - plot_stream.open ("gnuplot"); + plot_stream = new oprocstream ("gnuplot"); - if (! plot_stream.is_open ()) + if (plot_stream && ! *plot_stream) + { + delete plot_stream; + plot_stream = 0; + } + + if (! plot_stream) error ("plot: unable to open pipe to `%s'", plot_prog); } } - if (! initialized) + if (! error_state && plot_stream && *plot_stream && ! initialized) { initialized = 1; - plot_stream << "set data style lines\n"; + *plot_stream << "set data style lines\n"; if (gnuplot_terminal_type) - plot_stream << "set term " << gnuplot_terminal_type << "\n"; + *plot_stream << "set term " << gnuplot_terminal_type << "\n"; } } @@ -162,7 +181,7 @@ extern int pipe_handler_error_count; - if (! plot_stream.is_open ()) + if (! (plot_stream && *plot_stream)) { open_plot_stream (); @@ -182,14 +201,14 @@ error ("replot: no previous plot"); else { - plot_stream << cmd; + *plot_stream << cmd; if (! (is_replot || is_splot || is_plot) && plot_line_count > 0 && user_pref.automatic_replot) - plot_stream << GNUPLOT_COMMAND_REPLOT << "\n"; + *plot_stream << GNUPLOT_COMMAND_REPLOT << "\n"; - plot_stream.flush (); + plot_stream->flush (); pipe_handler_error_count = 0; } @@ -1071,8 +1090,11 @@ void close_plot_stream (void) { - if (plot_stream.is_open ()) - plot_stream.close (); + if (plot_stream) + { + delete plot_stream; + plot_stream = 0; + } plot_line_count = 0; } @@ -1080,7 +1102,7 @@ void do_external_plotter_cd (const char *newdir) { - if (plot_stream.is_open ()) + if (plot_stream && *plot_stream) { ostrstream plot_buf; plot_buf << "cd \"" << newdir << "\"\n" << ends;