changeset 5981:dadcfe8b7ba4

[project @ 2006-09-05 15:33:24 by jwe]
author jwe
date Tue, 05 Sep 2006 15:33:24 +0000
parents 45f612d96d0e
children 1ed991f0ed61
files scripts/ChangeLog scripts/miscellaneous/parseparams.m
diffstat 2 files changed, 67 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,7 @@
+2006-09-05  Alexander Barth  <abarth93@users.sourceforge.net>
+
+	* miscellaneous/parseparams.m: New function.
+
 2006-09-05  Rafael Laboissiere  <rafael@debian.org>
 
 	* miscellaneous/doc.m: Swap order of --file and --directory
new file mode 100644
--- /dev/null
+++ b/scripts/miscellaneous/parseparams.m
@@ -0,0 +1,63 @@
+## Copyright (C) 2006 Alexander Barth
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, write to the Free
+## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} [@var{reg}, @var{prop}] = parseparams (@var{params})
+## Return in @var{reg} the cell elements of @var{param} up to the first
+## string element and in @var{prop} all remaining elements beginning
+## with the first string element.  For example
+##
+## @example
+## [reg, prop] = parseparams (@{1, 2, "linewidth", 10@})
+## reg =
+## {
+##   [1,1] = 1
+##   [1,2] = 2
+## }
+## prop =
+## {
+##   [1,1] = linewidth
+##   [1,2] = 10
+## }
+## @end example
+##
+## The parseparams function may be used to separate "regular"
+## arguments and additional arguments given as property/value pairs of
+## the @var{varargin} cell array.
+## @seealso{varargin}
+## @end deftypefn
+
+## Author: Alexander Barth <abarth93@users.sourceforge.net>
+## Author: Aida Alvera Azcarate <aida@netecho.info>
+
+function [reg, prop] = parseparams (params)
+
+  i = 1;
+
+  while (i <= numel (params))
+    if (ischar (params{i}))
+      break;
+    endif
+    i++;
+  endwhile
+
+  reg = params(1:i-1);
+  prop = params(i:end);
+
+endfunction