changeset 2712:2ff2b536cc9d

[project @ 1997-02-21 21:38:21 by jwe]
author jwe
date Fri, 21 Feb 1997 21:38:21 +0000
parents b50865d6de09
children eb99ed3112d9
files src/ChangeLog src/oct-stream.cc src/oct-stream.h
diffstat 3 files changed, 74 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Feb 21 19:43:36 1997 +0000
+++ b/src/ChangeLog	Fri Feb 21 21:38:21 1997 +0000
@@ -1,3 +1,8 @@
+Fri Feb 21 15:35:18 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* oct-stream.cc (octave_base_stream::oscanf): Instead of returning
+	an error, just quit processing after a conversion fails.
+
 Thu Feb 20 02:58:05 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* Version 2.0.4 released.
--- a/src/oct-stream.cc	Fri Feb 21 19:43:36 1997 +0000
+++ b/src/oct-stream.cc	Fri Feb 21 21:38:21 1997 +0000
@@ -1224,67 +1224,16 @@
 	}
     }
   else
-    invalid_operation ("fscanf", "writing");
-
-  return retval;
-}
-
-template <class T>
-octave_value
-do_oscanf_num_conv (istream& is, const char *fmt, T valptr, bool discard)
-{
-  octave_value retval;
-
-  is.scan (fmt, valptr);
-
-  if (is)
-    {
-      if (! discard)
-	retval = (double) (*valptr);
-    }
-  else
-    error ("fscanf: conversion failed");
+    invalid_operation ("fscanf", "reading");
 
   return retval;
 }
 
-template octave_value
-do_oscanf_num_conv (istream&, const char*, int*, bool);
-
-#if 0
-template octave_value
-do_oscanf_num_conv (istream&, const char*, float*, bool);
-#endif
-
-template octave_value
-do_oscanf_num_conv (istream&, const char*, double*, bool);
-
-static inline octave_value
-do_oscanf_str_conv (istream& is, const char *fmt, char *sptr,
-		    int maxlen, bool discard)
+bool
+octave_base_stream::do_oscanf (const scanf_format_elt *elt,
+			       octave_value& retval)
 {
-  octave_value retval;
-
-  is.scan (fmt, sptr);
-
-  if (is)
-    {
-      if (! discard)
-	{
-	  sptr[maxlen] = '\0';
-	  retval = sptr;
-	}
-    }
-  else
-    error ("fscanf: conversion failed");
-
-  return retval;
-}
-
-octave_value
-octave_base_stream::do_oscanf (const scanf_format_elt *elt)
-{
-  octave_value retval;
+  bool quit = false;
 
   istream *isp = input_stream ();
 
@@ -1306,7 +1255,8 @@
 	      {
 		int dummy;
 
-		is.scan (fmt, &dummy);
+		if (! is.scan (fmt, &dummy))
+		  quit = true;
 	      }
 	      break;
 
@@ -1314,7 +1264,13 @@
 	      {
 		int tmp;
 
-		retval = do_oscanf_num_conv (is, fmt, &tmp, discard);
+		if (is.scan (fmt, &tmp))
+		  {
+		    if (! discard)
+		      retval = (double) tmp;
+		  }
+		else
+		  quit = true;
 	      }
 	      break;
 
@@ -1322,7 +1278,13 @@
 	      {
 		double tmp;
 
-		retval = do_oscanf_num_conv (is, fmt, &tmp, discard);
+		if (is.scan (fmt, &tmp))
+		  {
+		    if (! discard)
+		      retval = tmp;
+		  }
+		else
+		  quit = true;
 	      }
 	      break;
 
@@ -1334,7 +1296,16 @@
 
 		char *tmp = new char[width + 1];
 
-		retval = do_oscanf_str_conv (is, fmt, tmp, width, discard);
+		if (is.scan (fmt, tmp))
+		  {
+		    if (! discard)
+		      {
+			tmp[width] = '\0';
+			retval = tmp;
+		      }
+		  }
+		else
+		  quit = true;
 
 		is.setf (flags);
 
@@ -1349,7 +1320,16 @@
 		int width = elt->width ? elt->width : 65535;
 		char *tmp = new char [width+1];
 
-		retval = do_oscanf_str_conv (is, fmt, tmp, width, discard);
+		if (is.scan (fmt, tmp))
+		  {
+		    if (! discard)
+		      {
+			tmp[width] = '\0';
+			retval = tmp;
+		      }
+		  }
+		else
+		  quit = true;
 
 		delete [] tmp;
 	      }
@@ -1383,7 +1363,7 @@
 	}
     }
 
-  return retval;
+  return quit;
 }
 
 octave_value_list
@@ -1451,30 +1431,44 @@
 
 	    int num_values = 0;
 
+	    bool quit = false;
+
 	    for (int i = 0; i < nconv; i++)
 	      {
-		octave_value tmp = do_oscanf (elt);
-
-		if (tmp.is_defined ())
-		  retval (num_values++) = tmp;
-
-		if (! ok ())
+		octave_value tmp;
+
+		quit = do_oscanf (elt, tmp);
+
+		if (quit)
 		  break;
-
-		elt = fmt_list.next ();
+		else
+		  {
+		    if (tmp.is_defined ())
+		      retval (num_values++) = tmp;
+
+		    if (! ok ())
+		      break;
+		    elt = fmt_list.next ();
+		  }
 	      }
 
 	    retval.resize (num_values);
 
-	    // Pick up any trailing stuff.
-	    if (ok () && len > nconv)
-	      do_oscanf (elt);
+	    if (! quit)
+	      {
+		// Pick up any trailing stuff.
+		if (ok () && len > nconv)
+		  {
+		    octave_value tmp;
+		    do_oscanf (elt, tmp);
+		  }
+	      }
 	  }
 	  break;
 	}
     }
   else
-    invalid_operation ("fscanf", "writing");
+    invalid_operation ("fscanf", "reading");
 
   return retval;
 }
--- a/src/oct-stream.h	Fri Feb 21 19:43:36 1997 +0000
+++ b/src/oct-stream.h	Fri Feb 21 21:38:21 1997 +0000
@@ -317,7 +317,7 @@
 
   octave_value scanf (const string& fmt, const Matrix& size, int& count);
 
-  octave_value do_oscanf (const scanf_format_elt *elt);
+  bool do_oscanf (const scanf_format_elt *elt, octave_value&);
 
   octave_value_list oscanf (const string& fmt);