changeset 10091:a115046d462d

inputname: compatibility fix
author John W. Eaton <jwe@octave.org>
date Wed, 13 Jan 2010 03:00:14 -0500
parents 655ab6f6c369
children 02453ee20140
files scripts/ChangeLog scripts/miscellaneous/inputname.m
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Jan 13 08:44:24 2010 +0100
+++ b/scripts/ChangeLog	Wed Jan 13 03:00:14 2010 -0500
@@ -1,3 +1,8 @@
+2010-01-13  John W. Eaton  <jwe@octave.org>
+
+	* miscellaneous/inputname.m: Return "" if argument name is not a
+	valid identifier.  Update docstring.
+
 2010-01-12  David Bateman  <dbateman@free.fr>
 
 	* plot/__go_draw_axes_.m:  Allow patch markerfacecolor and 
--- a/scripts/miscellaneous/inputname.m	Wed Jan 13 08:44:24 2010 +0100
+++ b/scripts/miscellaneous/inputname.m	Wed Jan 13 03:00:14 2010 -0500
@@ -1,4 +1,4 @@
-## Copyright (C) 2004, 2006, 2007 Paul Kienzle
+## Copyright (C) 2004, 2006, 2007, 2010 Paul Kienzle
 ##
 ## This file is part of Octave.
 ##
@@ -21,17 +21,23 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} inputname (@var{n})
-## Return the text defining @var{n}-th input to the function.
+## Return the name of the @var{n}-th argument to the calling function.
+## If the argument is not a simple variable name, return an empty string.
 ## @end deftypefn
 
 function s = inputname (n)
 
-  if (nargin != 1)
+  if (nargin == 1)
+    s = evalin ("caller", sprintf ("deblank (argn(%d,:));", n));
+    ## For compatibility with Matlab, return empty string if argument
+    ## name is not a valid identifier.
+    if (isempty (regexp (s, "^[_a-zA-Z][_a-zA-Z0-9]*$")))
+      s = "";
+    endif
+  else
     print_usage ();
   endif
 
-  s = evalin ("caller", sprintf ("deblank (argn(%d,:));", n));
-
 endfunction
 
 ## Warning: heap big magic in the following tests!!!