Mercurial > hg > octave-lyh
diff scripts/general/structfun.m @ 10134:be13fa20656a
error on invalid opts in structfun
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 19 Jan 2010 21:45:21 +0100 |
parents | aa0f575cf39b |
children | 95c3e38098bf |
line wrap: on
line diff
--- a/scripts/general/structfun.m +++ b/scripts/general/structfun.m @@ -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);