diff options
author | Pierre MARECHAL <pierre.marechal@scilab.org> | 2009-03-23 14:00:40 +0100 |
---|---|---|
committer | Pierre MARECHAL <pierre.marechal@scilab.org> | 2009-03-23 14:00:40 +0100 |
commit | 443093754e54c86f26479703ffb353021775cbf3 (patch) | |
tree | 9069d1f9cd225dccbc11aad0405e7557ebe0b4ec /scilab/modules/data_structures/macros | |
parent | 1fd523020e4af82f74c4c80203584324910da8eb (diff) | |
download | scilab-443093754e54c86f26479703ffb353021775cbf3.zip scilab-443093754e54c86f26479703ffb353021775cbf3.tar.gz |
- isfield : check input parameters
- Add some tests of isfield functions
- struct : bring precision to the error message
Diffstat (limited to 'scilab/modules/data_structures/macros')
-rw-r--r-- | scilab/modules/data_structures/macros/isfield.sci | 30 | ||||
-rw-r--r-- | scilab/modules/data_structures/macros/struct.sci | 2 |
2 files changed, 25 insertions, 7 deletions
diff --git a/scilab/modules/data_structures/macros/isfield.sci b/scilab/modules/data_structures/macros/isfield.sci index 5635bef..b85f9ef 100644 --- a/scilab/modules/data_structures/macros/isfield.sci +++ b/scilab/modules/data_structures/macros/isfield.sci | |||
@@ -1,5 +1,6 @@ | |||
1 | // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | 1 | // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab |
2 | // Copyright (C) ????-2008 - INRIA | 2 | // Copyright (C) 2004 - INRIA |
3 | // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org> | ||
3 | // | 4 | // |
4 | // This file must be used under the terms of the CeCILL. | 5 | // This file must be used under the terms of the CeCILL. |
5 | // This source file is licensed as described in the file COPYING, which | 6 | // This source file is licensed as described in the file COPYING, which |
@@ -7,10 +8,27 @@ | |||
7 | // are also available at | 8 | // are also available at |
8 | // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt | 9 | // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt |
9 | 10 | ||
11 | // This function returns TRUE if "field" is a field of the struct "s", FALSE otherwise | ||
10 | 12 | ||
11 | function r=isfield(s,field) | 13 | function r = isfield(s,field) |
12 | if ~isstruct(s) then | 14 | |
13 | r=0;return;end | 15 | r = %f; |
14 | w=getfield(1,s); | 16 | |
15 | r=bool2s(or(w(3:$)==field)); | 17 | rhs = argn(2); |
18 | |||
19 | if rhs <> 2 then | ||
20 | error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"isfield",2)); | ||
21 | end | ||
22 | |||
23 | if ~isstruct(s) then | ||
24 | error(msprintf(gettext("%s: Wrong type for input argument #%d: struct array expected.\n"),"isfield",1)); | ||
25 | end | ||
26 | |||
27 | if type(field) <> 10 then | ||
28 | error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"isfield",2)); | ||
29 | end | ||
30 | |||
31 | w = getfield(1,s); | ||
32 | r = or(w(3:$)==field); | ||
33 | |||
16 | endfunction | 34 | endfunction |
diff --git a/scilab/modules/data_structures/macros/struct.sci b/scilab/modules/data_structures/macros/struct.sci index 759d5f7..de41446 100644 --- a/scilab/modules/data_structures/macros/struct.sci +++ b/scilab/modules/data_structures/macros/struct.sci | |||
@@ -22,7 +22,7 @@ if rhs==0 then | |||
22 | end | 22 | end |
23 | 23 | ||
24 | if floor(rhs/2)*2<>rhs then | 24 | if floor(rhs/2)*2<>rhs then |
25 | error(msprintf(gettext("%s: Wrong number of input argument(s)."),'struct')); | 25 | error(msprintf(gettext("%s: Wrong number of input argument(s) : an even number is expected."),"struct")); |
26 | end | 26 | end |
27 | 27 | ||
28 | nbfields=size(varargin)/2 | 28 | nbfields=size(varargin)/2 |