summaryrefslogtreecommitdiffstats
path: root/scilab/modules/data_structures/macros
diff options
context:
space:
mode:
authorPierre MARECHAL <pierre.marechal@scilab.org>2009-03-23 14:00:40 +0100
committerPierre MARECHAL <pierre.marechal@scilab.org>2009-03-23 14:00:40 +0100
commit443093754e54c86f26479703ffb353021775cbf3 (patch)
tree9069d1f9cd225dccbc11aad0405e7557ebe0b4ec /scilab/modules/data_structures/macros
parent1fd523020e4af82f74c4c80203584324910da8eb (diff)
downloadscilab-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.sci30
-rw-r--r--scilab/modules/data_structures/macros/struct.sci2
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
11function r=isfield(s,field) 13function r = isfield(s,field)
12if ~isstruct(s) then 14
13r=0;return;end 15 r = %f;
14w=getfield(1,s); 16
15r=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
16endfunction 34endfunction
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
22end 22end
23 23
24if floor(rhs/2)*2<>rhs then 24if 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"));
26end 26end
27 27
28nbfields=size(varargin)/2 28nbfields=size(varargin)/2