changeset 2796:74bc1ede3c3d

[project @ 1997-03-07 06:55:47 by jwe]
author jwe
date Fri, 07 Mar 1997 06:56:11 +0000
parents 14d07e4a0265
children f81117f4754d
files src/toplev.cc src/toplev.h src/variables.cc src/variables.h
diffstat 4 files changed, 66 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/toplev.cc	Fri Mar 07 02:21:37 1997 +0000
+++ b/src/toplev.cc	Fri Mar 07 06:56:11 1997 +0000
@@ -525,8 +525,7 @@
 }
 
 static octave_value_list
-eval_string (const string& s, int print, int& parse_status,
-	     int nargout) 
+eval_string (const string& s, int print, int& parse_status, int nargout)
 {
   begin_unwind_frame ("eval_string");
 
--- a/src/toplev.h	Fri Mar 07 02:21:37 1997 +0000
+++ b/src/toplev.h	Fri Mar 07 06:56:11 1997 +0000
@@ -26,26 +26,31 @@
 #include <cstdio>
 
 class octave_value;
+class octave_value_list;
 class tree_function;
 class tree_statement_list;
 class charMatrix;
 
 #include <string>
 
-extern void clean_up_and_exit (int) GCC_ATTR_NORETURN;
+extern void
+clean_up_and_exit (int) GCC_ATTR_NORETURN;
 
-extern void parse_and_execute (FILE *f, int print = 0);
+extern void
+parse_and_execute (FILE *f, int print = 0);
 
-extern void parse_and_execute (const string& s, int print = 0,
-			       int verbose = 0,
-			       const char *warn_for = 0);
+extern void
+parse_and_execute (const string& s, int print = 0, int verbose = 0,
+		   const char *warn_for = 0);
 
-extern octave_value eval_string (const string&, int print,
-				  int& parse_status);
+extern octave_value
+eval_string (const string&, int print, int& parse_status);
 
-extern int main_loop (void);
+extern int
+main_loop (void);
 
-extern void do_octave_atexit (void);
+extern void
+do_octave_atexit (void);
 
 // argv[0] for this program.
 extern string Vprogram_invocation_name;
--- a/src/variables.cc	Fri Mar 07 02:21:37 1997 +0000
+++ b/src/variables.cc	Fri Mar 07 06:56:11 1997 +0000
@@ -272,6 +272,53 @@
   return ans;
 }
 
+tree_fvc *
+extract_function (const octave_value& arg, const string& warn_for,
+		  const string& fname, const string& header,
+		  const string& trailer)
+{
+  tree_fvc *retval = 0;
+
+  retval = is_valid_function (arg, warn_for, 0);
+
+  if (! retval)
+    {
+      string s = arg.string_value ();
+
+      string cmd = header;
+      cmd.append (s);
+      cmd.append (trailer);
+
+      if (! error_state)
+	{
+	  int parse_status;
+
+	  eval_string (cmd, 0, parse_status);
+
+	  if (parse_status == 0)
+	    {
+	      retval = is_valid_function (fname, warn_for, 0);
+      
+	      if (! retval)
+		{
+		  error ("%s: `%s' is not valid as a function",
+			 warn_for.c_str (), fname.c_str ());
+		  return retval;
+		}
+	    }
+	  else
+	    error ("%s: `%s' is not valid as a function",
+		   warn_for.c_str (), fname.c_str ());
+	}
+      else
+	error ("%s: expecting first argument to be a string",
+	       warn_for.c_str ());
+    }
+
+  return retval;
+}
+
+
 DEFUN (is_global, args, ,
   "is_global (X): return 1 if the string X names a global variable\n\
 otherwise, return 0.")
--- a/src/variables.h	Fri Mar 07 02:21:37 1997 +0000
+++ b/src/variables.h	Fri Mar 07 06:56:11 1997 +0000
@@ -128,6 +128,10 @@
 extern tree_fvc *is_valid_function (const octave_value&, const string&,
 				    int warn = 0); 
 
+tree_fvc *extract_function (const octave_value& arg, const string& warn_for,
+			    const string& fname, const string& header,
+			    const string& trailer);
+
 extern string_vector make_name_list (void);
 
 extern void install_builtin_mapper (const builtin_mapper_function& mf);