# HG changeset patch # User jwe # Date 776460850 0 # Node ID 205b8c2ef74904dc2fc2ad9b3f91121d60ce141f # Parent 07e689d6e7e578fc19981664bcb70f78f56c3509 [project @ 1994-08-09 19:31:39 by jwe] diff -r 07e689d6e7e5 -r 205b8c2ef749 src/data.cc --- a/src/data.cc Tue Aug 09 19:04:29 1994 +0000 +++ b/src/data.cc Tue Aug 09 19:34:10 1994 +0000 @@ -243,7 +243,10 @@ if (nr < 0 || nc < 0) { if (user_pref.treat_neg_dim_as_zero) - nr = nc = 0; + { + nr = (nr < 0) ? 0 : nr; + nc = (nc < 0) ? 0 : nc; + } else error ("%s: can't create a matrix with negative dimensions", warnfor); diff -r 07e689d6e7e5 -r 205b8c2ef749 src/pt-plot.cc --- a/src/pt-plot.cc Tue Aug 09 19:04:29 1994 +0000 +++ b/src/pt-plot.cc Tue Aug 09 19:34:10 1994 +0000 @@ -33,9 +33,10 @@ #ifdef HAVE_UNISTD_H #include #endif +#include #include +#include #include -#include #include "SLStack.h" #include "procstream.h" @@ -71,6 +72,76 @@ // Pipe to gnuplot. static oprocstream plot_stream; +static void +open_plot_stream (void) +{ + static int initialized = 0; + + if (! plot_stream.is_open ()) + { + plot_line_count = 0; + + char *plot_prog = user_pref.gnuplot_binary; + if (plot_prog) + { + plot_stream.open (plot_prog); + if (! plot_stream.is_open ()) + { + warning ("plot: unable to open pipe to `%s'", + plot_prog); + + if (strcmp (plot_prog, "gnuplot") != 0) + { + warning ("having trouble finding plotting program."); + warning ("trying again with `gnuplot'"); + goto last_chance; + } + } + } + else + { + last_chance: + + plot_stream.open ("gnuplot"); + + if (! plot_stream.is_open ()) + error ("plot: unable to open pipe to `%s'", plot_prog); + } + } + + if (! initialized) + { + initialized = 1; + plot_stream << "set data style lines\n"; + } +} + +static int +send_to_plot_stream (const char *cmd) +{ +// From sighandlers.cc: + extern int pipe_handler_error_count; + + if (! plot_stream.is_open ()) + { + open_plot_stream (); + + if (error_state) + return -1; + } + + if (plot_line_count == 0 && strncmp (cmd, "replot", 6) == 0) + error ("replot: no previous plot"); + else + { + plot_stream << cmd; + plot_stream.flush (); + pipe_handler_error_count = 0; + } + + return 0; +} + // Plotting, eh? tree_plot_command::tree_plot_command (void) : tree_command () @@ -109,6 +180,8 @@ if (error_state) return; + open_plot_stream (); + ostrstream plot_buf; switch (ndim) @@ -771,62 +844,6 @@ } } -int -send_to_plot_stream (const char *cmd) -{ -// From sighandlers.cc: - extern int pipe_handler_error_count; - - static int initialized = 0; - - if (! plot_stream.is_open ()) - { - plot_line_count = 0; - - char *plot_prog = user_pref.gnuplot_binary; - if (plot_prog) - { - plot_stream.open (plot_prog); - if (! plot_stream.is_open ()) - { - warning ("plot: unable to open pipe to `%s'", - plot_prog); - - if (strcmp (plot_prog, "gnuplot") != 0) - { - warning ("having trouble finding plotting program."); - warning ("trying again with `gnuplot'"); - goto last_chance; - } - } - } - else - { - last_chance: - - plot_stream.open ("gnuplot"); - - if (! plot_stream.is_open ()) - { - error ("plot: unable to open pipe to `%s'", plot_prog); - return -1; - } - } - } - - if (! initialized) - { - initialized = 1; - plot_stream << "set data style lines\n"; - } - - plot_stream << cmd; - plot_stream.flush (); - pipe_handler_error_count = 0; - - return 0; -} - void close_plot_stream (void) {