changeset 10134:be13fa20656a

error on invalid opts in structfun
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 19 Jan 2010 21:45:21 +0100
parents 2e4fc7fdba15
children 4516a0c97ced
files scripts/ChangeLog scripts/general/structfun.m
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Jan 19 13:24:54 2010 +0100
+++ b/scripts/ChangeLog	Tue Jan 19 21:45:21 2010 +0100
@@ -1,3 +1,7 @@
+2010-01-19  Jaroslav Hajek  <highegg@gmail.com>
+
+	* general/structfun.m: Error when invalid options are specified.
+
 2010-01-19  Jaroslav Hajek  <highegg@gmail.com>, Thorsten Meyer <thorsten.meyier@gmx.de>
 
 	* general/structfun.m: Correctly support multiple arguments with
--- a/scripts/general/structfun.m	Tue Jan 19 13:24:54 2010 +0100
+++ b/scripts/general/structfun.m	Tue Jan 19 21:45:21 2010 +0100
@@ -71,18 +71,32 @@
 ## @end deftypefn
 
 function varargout = structfun (fun, s, varargin);
+
   if (nargin < 2)
     print_usage ();
   endif
 
+  nargs = length (varargin);
+
+  recognized_opts = {"UniformOutput", "ErrorHandler"};
+  uo_str = recognized_opts{1};
+
   uniform_output = true;
-  uo_str = "uniformoutput";
 
-  nargs = length (varargin);
-  if (nargs >= 2 && strcmpi (varargin{1}, uo_str))
-    uniform_output =varargin{2};
-  elseif (nargs >= 4 && strcmpi (varargin{3}, uo_str))
-    uniform_output =varargin{4};
+  while (nargs >= 2)
+    opt_match = strcmpi (varargin{nargs-1}, recognized_opts);
+    if (opt_match(1))
+      uniform_output = varargin{nargs};
+    endif
+    if (any (opt_match))
+      nargs -= 2;
+    else
+      break;
+    endif
+  endwhile
+
+  if (nargs > 0)
+    error ("structfun: invalid options");
   endif
 
   varargout = cell (max ([nargout, 1]), 1);