changeset 3103:98d862e12945

[project @ 1997-11-18 10:46:30 by jwe]
author jwe
date Tue, 18 Nov 1997 10:46:57 +0000
parents 04119d7a7d84
children b9aea66ecbae
files scripts/ChangeLog scripts/image/colormap.m scripts/plot/figure.m scripts/plot/mplot.m scripts/plot/multiplot.m scripts/plot/oneplot.m scripts/plot/subplot.m scripts/plot/subwindow.m src/ChangeLog src/lex.l src/utils.cc src/utils.h
diffstat 12 files changed, 257 insertions(+), 224 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/ChangeLog	Tue Nov 18 10:46:57 1997 +0000
@@ -1,3 +1,23 @@
+Tue Nov 18 01:35:50 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* time/tic.m: Rename _time_tic_called to __tic_toc_timestamp__.
+	* time/toc.m: Likewise.
+
+	* image/colormap.m: Rename CURRENT_COLOR_MAP to __current_color_map__.
+
+	* plot/mplot.m, plot/multiplot.m, plot/subplot.m: Don't do
+	anything special for automatic_replot when in multiplot mode --
+	recent 3.6beta releases handle this correctly.
+
+	* plot/figure.m: Ensure that we are not in multiplot mode before
+	setting the terminal type.
+
+	* plot/mplot.m, plot/multiplot.m, plot/oneplot.m, plot/subplot.m,
+ 	plot/subwindow.m: Use leading and trailing underscores for
+ 	`private' globals.
+
+	* plot/oneplot.m: Don't do anything if gnuplot_has_multiplot is false.
+
 Fri Nov 14 10:53:11 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* plot/__pltopt__.m: Use sprintf instead of strcat when adding TITLE.
--- a/scripts/image/colormap.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/image/colormap.m	Tue Nov 18 10:46:57 1997 +0000
@@ -35,7 +35,7 @@
 
 function cmap = colormap (map)
 
-  global CURRENT_COLOR_MAP
+  global __current_color_map__
 
   if (nargin > 1)
     usage ("colormap (map)");
@@ -44,21 +44,21 @@
   if (nargin == 1)
     if (isstr (map))
       if (strcmp (map, "default"))
-        CURRENT_COLOR_MAP = gray;
+        __current_color_map__ = gray;
       else
         error ("invalid argument");
       endif
     else
       ## Set the new color map
-      CURRENT_COLOR_MAP = map;
+      __current_color_map__ = map;
     endif
-  elseif (! exist ("CURRENT_COLOR_MAP"))
+  elseif (! exist ("__current_color_map__"))
     ## If global color map doesn't exist, create the default map.
-    CURRENT_COLOR_MAP = gray;
+    __current_color_map__ = gray;
   endif
 
   ## Return current color map.
 
-  cmap = CURRENT_COLOR_MAP;
+  cmap = __current_color_map__;
 
 endfunction
--- a/scripts/plot/figure.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/plot/figure.m	Tue Nov 18 10:46:57 1997 +0000
@@ -29,6 +29,7 @@
   if (nargin == 1)
     if (gnuplot_has_frames)
       if (! isempty (getenv ("DISPLAY")))
+	oneplot ();
 	eval (sprintf ("gset term x11 %d\n", n));
       else
 	error ("figure: requires X11 and valid DISPLAY");
--- a/scripts/plot/mplot.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/plot/mplot.m	Tue Nov 18 10:46:57 1997 +0000
@@ -41,20 +41,16 @@
 
   ## global variables to keep track of multiplot options
 
-  global multiplot_mode
-  global multiplot_xsize multiplot_ysize
-  global multiplot_xn multiplot_yn
-  global multiplot_xi multiplot_yi
+  global __multiplot_mode__
+  global __multiplot_xsize__
+  global __multiplot_ysize__
+  global __multiplot_xn__
+  global __multiplot_yn__
+  global __multiplot_xi__
+  global __multiplot_yi__
 
-  ## This is a real kludge.  We gnuplot should be made so that replot can
-  ## be executed while doing multiple plots...
-
-  global multiplot_save_auto_replot = automatic_replot
-
-  if (automatic_replot)
-    warning ("turning off automatic replot for multiplot mode");
-    multiplot_save_auto_replot = automatic_replot;
-    automatic_replot = 0;
+  if (! exist ("__multiplot_mode__"))
+    __multiplot_mode__ = 0;
   endif
 
   gset nologscale;
@@ -64,23 +60,23 @@
 
   ## update the plot position
 
-  if (multiplot_mode)
+  if (__multiplot_mode__)
 
-    if (multiplot_xi < multiplot_xn)
-      multiplot_xi++;
+    if (__multiplot_xi__ < __multiplot_xn__)
+      __multiplot_xi__++;
     else
-      multiplot_xi = 1;
-      if (multiplot_yi < multiplot_xn)
-	multiplot_yi++;
+      __multiplot_xi__ = 1;
+      if (__multiplot_yi__ < multiplot_xn__)
+	__multiplot_yi__++;
       else
-	multiplot_yi = 1;
+	__multiplot_yi__ = 1;
       endif
     endif
 
-    xo = (multiplot_xi - 1.0)*multiplot_xsize;
-    yo = (multiplot_yn - multiplot_yi)*multiplot_ysize;
+    xo = (__multiplot_xi__ - 1.0) * __multiplot_xsize__;
+    yo = (__multiplot_yn__ - __multiplot_yi) * __multiplot_ysize__;
 
-    eval (sprintf ("gset origin %g, %g", xo,yo));
+    eval (sprintf ("gset origin %g, %g", xo, yo));
 
   endif
 
--- a/scripts/plot/multiplot.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/plot/multiplot.m	Tue Nov 18 10:46:57 1997 +0000
@@ -40,15 +40,17 @@
 
   ## global variables to keep track of multiplot options
 
-  global multiplot_mode
-  global multiplot_xsize multiplot_ysize
-  global multiplot_xn multiplot_yn
-  global multiplot_xi multiplot_yi
+  global __multiplot_mode__
+  global __multiplot_xsize__
+  global __multiplot_ysize__
+  global __multiplot_xn__
+  global __multiplot_yn__
+  global __multiplot_xi__
+  global __multiplot_yi__
 
-  ## This is a real kludge.  We gnuplot should be made so that replot can
-  ## be executed while doing multiple plots...
-
-  global multiplot_save_auto_replot = automatic_replot
+  if (! exist ("__multiplot_mode__"))
+    __multiplot_mode__ = 0;
+  endif
 
   if (nargin != 2)
     usage ("multiplot (xn, yn)");
@@ -58,36 +60,21 @@
     error ("multiplot: xn and yn have to be scalars");
   endif
 
-  if (automatic_replot)
-    warning ("turning off automatic replot for multiplot mode");
-    multiplot_save_auto_replot = automatic_replot;
-    automatic_replot = 0;
-  endif
-
   xn = round (xn);
   yn = round (yn);
 
   if (xn == 0 && yn == 0)
 
-    gset nomultiplot;
-    gset size 1, 1;
-    gset origin 0, 0;
+    oneplot ();
+
+    ## XXX FIXME XXX -- do we really need to reset these here?
 
-    multiplot_mode = 0;
-    multiplot_xsize = 1;
-    multiplot_ysize = 1;
-    multiplot_xn = 1;
-    multiplot_yn = 1;
-    multiplot_xi = 1;
-    multiplot_yi = 1;
-
-    ## Someone may have reset it betweeen calls...
-
-    if (! isstr (automatic_replot) && ! automatic_replot)
-      automatic_replot = multiplot_save_auto_replot;
-    endif
-
-    return;
+    __multiplot_xsize__ = 1;
+    __multiplot_ysize__ = 1;
+    __multiplot_xn__ = 1;
+    __multiplot_yn__ = 1;
+    __multiplot_xi__ = 1;
+    __multiplot_yi__ = 1;
 
   else
 
@@ -107,13 +94,13 @@
 
     eval (sprintf ("gset origin %g, %g", xo, yo));
 
-    multiplot_mode = 1;
-    multiplot_xsize = xsize;
-    multiplot_ysize = ysize;
-    multiplot_xn = xn;
-    multiplot_yn = yn;
-    multiplot_xi = 1;
-    multiplot_yi = 1;
+    __multiplot_mode__ = 1;
+    __multiplot_xsize__ = xsize;
+    __multiplot_ysize__ = ysize;
+    __multiplot_xn__ = xn;
+    __multiplot_yn__ = yn;
+    __multiplot_xi__ = 1;
+    __multiplot_yi__ = 1;
 
   endif
 
--- a/scripts/plot/oneplot.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/plot/oneplot.m	Tue Nov 18 10:46:57 1997 +0000
@@ -22,7 +22,7 @@
 ## NOTE: this will work only with gnuplot installed with
 ##       multiplot patch
 ##
-## Switches from multiplot (if in  multiplot mode) to single plot
+## Switches from multiplot (if in multiplot mode) to single plot
 ## mode
 
 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
@@ -31,15 +31,21 @@
 
 function oneplot ()
 
-  if (! gnuplot_has_multiplot)
-    error ("oneplot: gnuplot does not appear to support this feature");
+  if (gnuplot_has_multiplot)
+
+    global __multiplot_mode__
+
+    if (! exist ("__multiplot_mode__"))
+      __multiplot_mode__ = 0;
+    endif
+
+    if (__multiplot_mode__)
+      gset nomultiplot;
+      gset size 1, 1;
+      gset origin 0, 0;
+      __multiplot_mode__ = 0;
+    endif
+
   endif
 
-  global multiplot_mode
-
-  gset nomultiplot;
-  gset size 1, 1;
-  gset origin 0, 0;
-  multiplot_mode = 0;
-
 endfunction
--- a/scripts/plot/subplot.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/plot/subplot.m	Tue Nov 18 10:46:57 1997 +0000
@@ -64,26 +64,22 @@
 
   ## global variables to keep track of multiplot options
 
-  global multiplot_mode
-  global multiplot_xsize multiplot_ysize
-  global multiplot_xn multiplot_yn
-  global multiplot_xi multiplot_yi
+  global __multiplot_mode__
+  global __multiplot_xsize__
+  global __multiplot_ysize__
+  global __multiplot_xn__
+  global __multiplot_yn__
+  global __multiplot_xi__
+  global __multiplot_yi__
 
-  ## This is a real kludge.  We gnuplot should be made so that replot can
-  ## be executed while doing multiple plots...
-
-  global multiplot_save_auto_replot = automatic_replot
+  if (! exist ("__multiplot_mode__"))
+    __multiplot_mode__ = 0;
+  endif
 
   if (nargin != 3 && nargin != 1)
     usage ("subplot (rows, columns, index) or subplot (rcn)");
   endif
 
-  if (automatic_replot)
-    warning ("turning off automatic replot for multiplot mode");
-    multiplot_save_auto_replot = automatic_replot;
-    automatic_replot = 0;
-  endif
-
   if (nargin == 1)
 
     if (! (is_scalar (rows) && rows >= 0))
@@ -117,58 +113,44 @@
 
     ## switching to single plot ?
 
-    gset nomultiplot;
-    gset size 1, 1;
-    gset origin 0, 0;
+    oneplot ();
 
-    multiplot_xn = 1;
-    multiplot_yn = 1;
-    multiplot_mode = 0;
+    ## XXX FIXME XXX -- do we really need to reset these here?
 
-    ## Someone may have reset it betweeen calls...
-
-    if (! isstr (automatic_replot) && ! automatic_replot)
-      automatic_replot = multiplot_save_auto_replot;
-    endif
+    __multiplot_xn__ = 1;
+    __multiplot_yn__ = 1;
 
   else
 
     ## doing multiplot plots
 
-    doagain = 0;
+    if (! __multiplot_mode__
+ 	|| __multiplot_xn__ != columns
+	|| __multiplot_yn__ != rows)
 
-    if (exist ("multiplot_mode") != 1)
-      doagain = 1;
-    elseif (multiplot_mode != 1 || multiplot_xn != columns
-	    || multiplot_yn != rows)
-      doagain = 1;
-    endif
-
-    if (doagain)
-
-      multiplot_mode = 1;
-      multiplot_xn = columns;
-      multiplot_yn = rows;
-      multiplot_xsize = 1.0 ./ columns;
-      multiplot_ysize = 1.0 ./ rows;
+      __multiplot_mode__ = 1;
+      __multiplot_xn__ = columns;
+      __multiplot_yn__ = rows;
+      __multiplot_xsize__ = 1.0 ./ columns;
+      __multiplot_ysize__ = 1.0 ./ rows;
 
       gset multiplot;
 
-      eval (sprintf ("gset size %g, %g", multiplot_xsize, multiplot_ysize));
-
+      eval (sprintf ("gset size %g, %g", __multiplot_xsize__,
+		     __multiplot_ysize__));
     endif
 
     ## get the sub plot location
 
     yp = fix ((index-1)/columns);
     xp = index - yp*columns - 1;
-    multiplot_xi = ++xp;
-    multiplot_yi = ++yp;
+    __multiplot_xi__ = ++xp;
+    __multiplot_yi__ = ++yp;
 
     ## set the origin
 
-    xo = (xp - 1.0)*multiplot_xsize;
-    yo = (rows - yp)*multiplot_ysize;
+    xo = (xp - 1.0) * __multiplot_xsize__;
+    yo = (rows - yp) * __multiplot_ysize__;
 
     eval (sprintf ("gset origin %g, %g", xo, yo));
 
--- a/scripts/plot/subwindow.m	Tue Nov 18 08:27:08 1997 +0000
+++ b/scripts/plot/subwindow.m	Tue Nov 18 10:46:57 1997 +0000
@@ -38,9 +38,15 @@
 
   ## global variables to keep track of multiplot options
 
-  global multiplot_mode
-  global multiplot_xsize multiplot_ysize
-  global multiplot_xn multiplot_yn
+  global __multiplot_mode__
+  global __multiplot_xsize__
+  global __multiplot_ysize__
+  global __multiplot_xn__
+  global __multiplot_yn__
+
+  if (! exist ("__multiplot_mode__"))
+    __multiplot_mode__ = 0;
+  endif
 
   ## check calling argument count
 
@@ -60,19 +66,19 @@
   ## switch to multiplot mode if not already in, and use the args as the
   ## args to multiplot()
 
-  if (multiplot_mode != 1)
+  if (! __multiplot_mode__)
     multiplot (xn, yn);
     return;
   endif
 
   ## get the sub plot location
 
-  if (xn < 1 || xn > multiplot_xn || yn < 1 || yn > multiplot_yn)
+  if (xn < 1 || xn > __multiplot_xn__ || yn < 1 || yn > __multiplot_yn__)
     error ("subwindow: incorrect xn and yn");
   endif
 
-  xo = (xn - 1.0)*multiplot_xsize;
-  yo = (multiplot_yn - yn)*multiplot_ysize;
+  xo = (xn - 1.0) * __multiplot_xsize__;
+  yo = (__multiplot_yn__ - yn) * __multiplot_ysize__;
 
   eval (sprintf ("gset origin %g, %g", xo, yo));
 
--- a/src/ChangeLog	Tue Nov 18 08:27:08 1997 +0000
+++ b/src/ChangeLog	Tue Nov 18 10:46:57 1997 +0000
@@ -1,3 +1,16 @@
+Tue Nov 18 04:27:55 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* utils.cc (do_string_escapes): Move here, from lex.l.
+	Arg is now const string& instead of char*.
+	Return new string object instead of modifying arg in place.
+	(Fdo_string_escapes): New function.
+	* lex.l (handle_string): Use new version of do_string_escapes.
+	* lex.l (Vbackslash_escapes): No longer static.
+	* oct-stream.cc (octave_base_stream::scanf): If !Vbackslash_escapes,
+	call do_backslash_escapes on format string here.
+	* oct-stream.cc (octave_base_stream::oscanf): Likewise.
+	* oct-stream.cc (octave_base_stream::printf): Likewise.
+
 Fri Nov 14 01:53:13 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* parse.y (eval_string (const string&, bool, int&, int)): No
--- a/src/lex.l	Tue Nov 18 08:27:08 1997 +0000
+++ b/src/lex.l	Tue Nov 18 10:46:57 1997 +0000
@@ -166,7 +166,6 @@
 // Forward declarations for functions defined at the bottom of this
 // file.
 
-static void do_string_escapes (char *s);
 static void fixup_column_count (char *s);
 static void do_comma_insert_check (void);
 static int is_plot_keyword (const string& s);
@@ -719,82 +718,6 @@
   lexer_flags.init ();
 }
 
-// Replace backslash escapes in a string with the real values.
-
-static void
-do_string_escapes (char *s)
-{
-  if (! Vbackslash_escapes)
-    return;
-
-  char *p1 = s;
-  char *p2 = s;
-
-  while (*p2 != '\0')
-    {
-      if (*p2 == '\\' && *(p2+1) != '\0')
-	{
-	  switch (*++p2)
-	    {
-	    case 'a':
-	      *p1 = '\a';
-	      break;
-
-	    case 'b': // backspace
-	      *p1 = '\b';
-	      break;
-
-	    case 'f': // formfeed
-	      *p1 = '\f';
-	      break;
-
-	    case 'n': // newline
-	      *p1 = '\n';
-	      break;
-
-	    case 'r': // carriage return
-	      *p1 = '\r';
-	      break;
-
-	    case 't': // horizontal tab
-	      *p1 = '\t';
-	      break;
-
-	    case 'v': // vertical tab
-	      *p1 = '\v';
-	      break;
-
-	    case '\\': // backslash
-	      *p1 = '\\';
-	      break;
-
-	    case '\'': // quote
-	      *p1 = '\'';
-	      break;
-
-	    case '"': // double quote
-	      *p1 = '"';
-	      break;
-
-	    default:
-	      warning ("unrecognized escape sequence `\\%c' --\
- converting to `%c'", *p2, *p2);
-	      *p1 = *p2;
-	      break;
-	    }
-	}
-      else
-	{
-	  *p1 = *p2;
-	}
-
-      p1++;
-      p2++;
-    }
-
-  *p1 = '\0';
-}
-
 // If we read some newlines, we need figure out what column we're
 // really looking at.
 
@@ -1590,22 +1513,15 @@
 		{
 		  yyunput (c, yytext);
 		  buf << ends;
-		  char *tok = buf.str ();
-		  do_string_escapes (tok);
+		  char *tmp = buf.str ();
+		  string tok = Vbackslash_escapes
+		    ? do_string_escapes (tmp) : string (tmp);
+		  delete [] tmp;
 
 		  if (text_style && lexer_flags.doing_set)
 		    {
-		      if (tok)
-			{
-			  int len = strlen (tok) + 3;
-			  char *tmp = tok;
-			  tok = new char [len];
-			  tok[0] = delim;
-			  strcpy (tok+1, tmp);
-			  tok[len-2] = delim;
-			  tok[len-1] = '\0';
-			  delete [] tmp;
-			}
+		      if (! tok.empty ())
+			tok = string (delim, 1) + tok + string (delim, 1);
 		    }
 		  else
 		    {
@@ -1615,7 +1531,6 @@
 		    }
 
 		  yylval.tok_val = new token (tok);
-		  delete [] tok;
 		  token_stack.push (yylval.tok_val);
 		  return TEXT;
 		}
--- a/src/utils.cc	Tue Nov 18 08:27:08 1997 +0000
+++ b/src/utils.cc	Tue Nov 18 10:46:57 1997 +0000
@@ -321,6 +321,106 @@
   return retval;
 }
 
+// Replace backslash escapes in a string with the real values.
+
+string
+do_string_escapes (const string& s)
+{
+  string retval;
+
+  size_t i = 0;
+  size_t j = 0;
+  size_t len = s.length ();
+
+  retval.resize (len);
+
+  while (j < len)
+    {
+      if (s[j] == '\\' && j+1 < len)
+	{
+	  switch (s[++j])
+	    {
+	    case 'a':
+	      retval[i] = '\a';
+	      break;
+
+	    case 'b': // backspace
+	      retval[i] = '\b';
+	      break;
+
+	    case 'f': // formfeed
+	      retval[i] = '\f';
+	      break;
+
+	    case 'n': // newline
+	      retval[i] = '\n';
+	      break;
+
+	    case 'r': // carriage return
+	      retval[i] = '\r';
+	      break;
+
+	    case 't': // horizontal tab
+	      retval[i] = '\t';
+	      break;
+
+	    case 'v': // vertical tab
+	      retval[i] = '\v';
+	      break;
+
+	    case '\\': // backslash
+	      retval[i] = '\\';
+	      break;
+
+	    case '\'': // quote
+	      retval[i] = '\'';
+	      break;
+
+	    case '"': // double quote
+	      retval[i] = '"';
+	      break;
+
+	    default:
+	      warning ("unrecognized escape sequence `\\%c' --\
+ converting to `%c'", s[j], s[j]);
+	      retval[i] = s[j];
+	      break;
+	    }
+	}
+      else
+	{
+	  retval[i] = s[j];
+	}
+
+      i++;
+      j++;
+    }
+
+  retval.resize (j);
+
+  return retval;
+}
+
+DEFUN (do_string_escapes, args, ,
+  "do_string_escapes (STRING)")
+{
+  octave_value retval;
+
+  int nargin = args.length ();
+
+  if (nargin == 1)
+    {
+      if (args(0).is_string ())
+	retval = do_string_escapes (args(0).string_value ());
+      else
+	error ("do_string_escapes: argument must be a string");
+    }
+  else
+    print_usage ("do_string_escapes");
+
+  return retval;
+}
+
 const char *
 undo_string_escape (char c)
 {
@@ -384,8 +484,13 @@
 
   int nargin = args.length ();
 
-  if (nargin == 1 && args(0).is_string ())
-    retval = undo_string_escapes (args(0).string_value ());
+  if (nargin == 1)
+    {
+      if (args(0).is_string ())
+	retval = undo_string_escapes (args(0).string_value ());
+      else
+	error ("undo_string_escapes: argument must be a string");
+    }
   else
     print_usage ("undo_string_escapes");
 
--- a/src/utils.h	Tue Nov 18 08:27:08 1997 +0000
+++ b/src/utils.h	Tue Nov 18 10:46:57 1997 +0000
@@ -52,6 +52,8 @@
 
 extern const char *undo_string_escape (char c);
 
+extern string do_string_escapes (const string& s);
+
 extern string undo_string_escapes (const string& s);
 
 extern int check_preference (const string& var);