changeset 478:90964309100b

[project @ 1994-06-28 16:39:41 by jwe]
author jwe
date Tue, 28 Jun 1994 16:39:41 +0000
parents 94b7d47cd064
children 8e9dcc406332
files src/builtins.cc src/parse.y src/pt-plot.cc src/t-builtins.cc src/utils.cc
diffstat 5 files changed, 101 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/builtins.cc	Tue Jun 28 14:38:00 1994 +0000
+++ b/src/builtins.cc	Tue Jun 28 16:39:41 1994 +0000
@@ -184,6 +184,10 @@
     "history [N] [-w file] [-r file] [-q]\n\n\
 display, save, or load command history", },
 
+  { "hold", -1, builtin_hold,
+    "hold [on|off]\n\n\
+determine whether the plot window is cleared before the next line is drawn", },
+
   { "load", -1, builtin_load,
     "load [-force] file\n\nload variables from a file", },
 
--- a/src/parse.y	Tue Jun 28 14:38:00 1994 +0000
+++ b/src/parse.y	Tue Jun 28 16:39:41 1994 +0000
@@ -371,13 +371,25 @@
 
 plot_command	: PLOT plot_command1
 		  {
-		    tree_subplot_list *tmp = $2->reverse ();
-		    $$ = new tree_plot_command (tmp, $1->pttype ());
-		    plotting = 0;
-		    past_plot_range = 0;
-		    in_plot_range = 0;
-		    in_plot_using = 0;
-		    in_plot_style = 0;
+		    tree_subplot_list *tmp = (tree_subplot_list *) NULL;
+		    if ($2 != (tree_subplot_list *) NULL)
+		      tmp = $2->reverse ();
+
+		    if (tmp == (tree_subplot_list *) NULL
+			&& $1->pttype () != token::replot)
+		      {
+			yyerror ("must have something to plot");
+			ABORT_PARSE;
+		      }
+		    else
+		      {
+			$$ = new tree_plot_command (tmp, $1->pttype ());
+			plotting = 0;
+			past_plot_range = 0;
+			in_plot_range = 0;
+			in_plot_using = 0;
+			in_plot_style = 0;
+		      }
 		  }
 		| PLOT ranges plot_command1
 		  {
@@ -419,7 +431,9 @@
 		  { $$ = new tree_plot_range (); }
 		;
 
-plot_command1	: plot_command2
+plot_command1	: // empty
+		  { $$ = (tree_subplot_list *) NULL; }
+		| plot_command2
 		  { $$ = $1; }
 		| plot_command1 ',' plot_command2
 		  { $$ = $1->chain ($3); }
--- a/src/pt-plot.cc	Tue Jun 28 14:38:00 1994 +0000
+++ b/src/pt-plot.cc	Tue Jun 28 16:39:41 1994 +0000
@@ -40,11 +40,14 @@
 }
 
 // The number of lines we\'ve plotted so far.
-static int plot_line_count;
+int plot_line_count;
 
 // Is this a parametric plot?  Makes a difference for 3D plotting.
 int parametric_plot = 0;
 
+// Should the graph window be cleared before plotting the next line?
+int clear_before_plotting = 1;
+
 /*
  * Plotting, eh?
  */
@@ -90,13 +93,33 @@
   switch (ndim)
     {
     case 1:
-      plot_buf << "replot";
+      if (plot_line_count == 0)
+	{
+	  if (plot_list)
+	    plot_buf << "plot";
+	  else
+	    {
+	      ::error ("replot: must have something to plot");
+	      return retval;
+	    }
+	}
+      else
+	plot_buf << "replot";
       break;
     case 2:
-      plot_buf << "plot";
+      if (clear_before_plotting || plot_line_count == 0)
+	{
+	  plot_line_count = 0;
+	  plot_buf << "plot";
+	}
+      else
+	plot_buf << "replot";
       break;
     case 3:
-      plot_buf << "splot";
+      {
+	plot_line_count = 0;
+	plot_buf << "splot";
+      }
       break;
     default:
       panic_impossible ();
@@ -104,12 +127,17 @@
     }
 
   if (range != (tree_plot_limits *) NULL)
-    range->print (ndim, plot_buf);
+    {
+      if (plot_line_count == 0)
+	range->print (ndim, plot_buf);
+      else
+	warning ("can't specify new plot ranges with `replot' or while\
+ hold is on");
+    }
 
   if (error_state)
     return retval;
 
-  plot_line_count = 0;
   tree_subplot_list *ptr = plot_list;
   for ( ; ptr != NULL_TREE ; ptr = ptr->next_elem ())
     {
--- a/src/t-builtins.cc	Tue Jun 28 14:38:00 1994 +0000
+++ b/src/t-builtins.cc	Tue Jun 28 16:39:41 1994 +0000
@@ -103,6 +103,9 @@
 // Is this a parametric plot?  Makes a difference for 3D plotting.
 extern int parametric_plot;
 
+// Should the graph window be cleared before plotting the next line?
+extern int clear_before_plotting;
+
 /*
  * Format a list in neat columns.  Mostly stolen from GNU ls.  This
  * should maybe be in utils.cc.
@@ -630,6 +633,36 @@
   return retval;
 }
 
+/*
+ * Change state flag that determines whether lines are added to plots
+ * or drawn on new plots.
+ */
+tree_constant
+builtin_hold (int argc, char **argv)
+{
+  tree_constant retval;
+  
+  switch (argc)
+    {
+    case 1:
+      clear_before_plotting = ! clear_before_plotting;
+      break;
+    case 2:
+      if (strcasecmp (argv[1], "on") == 0)
+	clear_before_plotting = 0;
+      else if (strcasecmp (argv[1], "off") == 0)
+	clear_before_plotting = 1;
+      else
+	print_usage ("hold");
+      break;
+    default:
+      print_usage ("hold");
+      break;
+    }
+
+  return retval;
+}
+
 static int
 load_variable (char *nm, int force, istream& is)
 {
--- a/src/utils.cc	Tue Jun 28 14:38:00 1994 +0000
+++ b/src/utils.cc	Tue Jun 28 16:39:41 1994 +0000
@@ -129,6 +129,9 @@
 // Top level context (?)
 extern jmp_buf toplevel;
 
+// The number of lines we\'ve plotted so far.
+extern int plot_line_count;
+
 // Pipe to gnuplot.
 static oprocstream plot_stream;
 
@@ -546,7 +549,7 @@
   else
     {
       char *infodir = octave_info_dir ();
-      info_file_string = strconcat (infodir, "octave.info");
+      info_file_string = strconcat (infodir, "/octave.info");
     }
   return info_file_string;
 }
@@ -1302,6 +1305,8 @@
 
   if (! plot_stream.is_open ())
     {
+      plot_line_count = 0;
+
       char *plot_prog = user_pref.gnuplot_binary;
       if (plot_prog != (char *) NULL)
 	{
@@ -1351,6 +1356,8 @@
 {
   if (plot_stream.is_open ())
     plot_stream.close ();
+
+  plot_line_count = 0;
 }
 
 int