0
|
1 ## Copyright (C) 2000 Etienne Grossman |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## s = setfield(s,'key1',value1,...) |
|
18 ## |
|
19 ## Sets s.key1 = value1, s.key2 = value2, ... and returns s. |
|
20 ## |
|
21 ## For m****b compatibility and flexibility. |
|
22 ## |
|
23 ## See also cmpstruct, fields, rmfield, isstruct, getfield, isfield, |
|
24 ## struct. |
|
25 ## |
|
26 |
|
27 ## Author: Etienne Grossmann <etienne@isr.ist.utl.pt> |
|
28 ## Last modified: January 2000 |
|
29 ## November 2000: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
|
30 ## return error rather than trapping to keyboard |
|
31 |
|
32 function s = setfield(s,...) |
|
33 va_start() ; |
|
34 nargin-- ; |
|
35 while nargin-- , |
|
36 tmp = va_arg() ; |
|
37 if ! isstr(tmp) , |
|
38 error('setfield: called with non-string key') ; |
|
39 else |
|
40 if ! nargin-- , |
|
41 error('setfield: called with odd number of arguments\n') ; |
|
42 else |
|
43 value = va_arg() ; |
|
44 eval( ['s.',tmp,'=value;'] ) ; |
|
45 end |
|
46 end |
|
47 end |