1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises
5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0,
7// pursuant to article 5.3.4 of the CeCILL v.2.1.
8// This file was originally licensed under the terms of the CeCILL v2.1,
9// and continues to be available under such terms.
10// For more information, see the COPYING file which you should have received
11// along with this program.
12
13function h=generic_i_h(i,v,h)
14    hsave=h
15    //  if v==[] then error('Field property cannot be []'),end
16    if type(i)==10 then set(h,i,v),return,end
17    if type(i)<>15 then  error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1)),end
18
19    if and(type(i($))<>[1 2 4 8 129 15]) then
20        i($+1)=:
21    end
22
23    n = size(i)
24    hdl=h;hind=[]
25    for k=1:size(i)// walk down in the handle tree
26        p=i(k)
27        lasthandle=hdl,
28        if type(p)==10 then
29            hdl=get(hdl,p),
30        elseif or(type(p)==[1 2 4 8 129]) then
31            hdl=hdl(p)
32        elseif type(p)==15 then
33            hdl=hdl(p(:))
34        else
35            error("Invalid path")
36        end
37        if type(hdl)<>9 then //a leaf found
38            property=hdl
39            hdl=lasthandle
40            hind=p
41            if (k+1)==size(i) then
42                index=i($)
43            else
44                index=list(i(k+1:$))
45            end
46            break
47        end
48    end
49
50    if hind<>[] then // a property found
51        if type(index)==15 & and(type(property)<>[15 16 17]) then
52            property(index(:))=v
53        else
54            if or(size(index)<>[-1 -1]) then
55                if (index(1)=="locations" | index(1)=="labels") & size(v,"*") ~= 1 & size(property(index),"*") ~= size(v,"*") then
56                    error(msprintf(_("%s: Incompatible sizes for properties ''%s'' and ''%s'': Same sizes expected.\n"), "generic_i_h", string(i($-2))+".locations", string(i($-2))+".labels"));
57                end
58                property(index)=v
59            else
60                property=v
61            end
62        end
63        if size(hdl,"*")==1 then //a single handle
64            hdl(hind)=property
65        else //mutiple handle
66            np=size(hdl,"*")
67            for k=1:np
68                h=hdl(k);h(hind)=property
69            end
70
71        end
72    else
73        error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1));
74    end
75    h = hsave
76endfunction
77