summaryrefslogtreecommitdiff
path: root/modules/atoms/macros/atoms_internals/atomsDESCRIPTIONaddField.sci
blob: 8b5172d6b6eec6bcf58c028cf51a60ba40481f5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

// Internal function

// Add a field to the description of one ore more package
// The description struct looks like that

// DESCRIPTION
// |
// |-- packages
// |   |-- toolbox_1                         [1x1 struct]
// |   |   |-- 2.0                           [1x1 struct]
// |   |   |   |-- Toolbox: "toolbox_2"
// |   |   |   |-- Title: "Toolbox Test 2"
// |   |   |   |-- Version: "2.0"
// |   |   |   `-- ..
// |   |   `-- 1.0                           [1x1 struct]
// |   |   |   |-- Toolbox: "toolbox_2"
// |   |   |   |-- Title: "Toolbox Test 2"
// |   |   |   |-- Version: "1.0"
// |   |   |   `-- ..
// |   |-- module_lycee
// |   `-- ..
// |
// |-- categories
// |-- categories_flat


function tree_out = atomsDESCRIPTIONaddField( tree_in , package_name , package_version , field , value )

    // Check input parameters number
    // =========================================================================

    rhs  = argn(2);

    if rhs <> 5 then
        error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsDESCRIPTIONaddField",5));
    end

    // Check input parameters type
    // =========================================================================

    if type(tree_in) <> 17 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Struct expected.\n"),"atomsDESCRIPTIONaddField",1));
    end

    if type(package_name) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",2));
    end

    if type(package_version) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",3));
    end

    if type(field) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",4));
    end

    // Check input parameters size
    // =========================================================================

    if size(package_name,"*") <> 1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",2));
    end

    if size(package_version,"*") <> 1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",3));
    end

    if size(field,"*") <> 1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",4));
    end

    if size(value,"*") <> 1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONaddField",5));
    end

    // And now ... action
    // =========================================================================

    tree_out     = tree_in;
    packages_out = tree_out("packages");

    // 1st case : All packages are concerned
    // -------------------------------------------------------------------------

    if (package_name == "*") & (package_version == "*") then

        package_names      = getfield(1,packages_out);
        package_names(1:2) = [];

        for i=1:size(package_names,"*")

            package_versions_struct = packages_out(package_names(i));
            package_versions        = getfield(1,package_versions_struct);
            package_versions(1:2)   = [];

            for j=1:size(package_versions,"*")
                this_package_struct                          = package_versions_struct(package_versions(j));
                this_package_struct(field)                   = value;
                package_versions_struct(package_versions(j)) = this_package_struct;
            end

            packages_out(package_names(i)) = package_versions_struct;
        end


        // 2nd case : All versions of a package are concerned
        // -------------------------------------------------------------------------

    elseif  package_version == "*" then

        if ~ isfield(packages_out,package_name) then
            error(msprintf(gettext("%s: The package ''%s'' is not present in the struct.\n"),"atomsDESCRIPTIONaddField",package_name));
        end

        package_versions_struct = packages_out(package_name);
        package_versions        = getfield(1,package_versions_struct);
        package_versions(1:2)   = [];

        for j=1:size(package_versions,"*")
            this_package_struct                          = package_versions_struct(package_versions(j));
            this_package_struct(field)                   = value;
            package_versions_struct(package_versions(j)) = this_package_struct;
        end

        packages_out(package_name) = package_versions_struct;


        // 3rd case : Specific version of a package
        // -------------------------------------------------------------------------

    else

        if ~ isfield(packages_out,package_name) then
            error(msprintf(gettext("%s: The package ''%s'' is not present in the struct.\n"),"atomsDESCRIPTIONaddField",package_name));
        end

        package_versions_struct = packages_out(package_name);

        if ~ isfield(package_versions_struct,package_version) then
            error(msprintf(gettext("%s: The version ''%s'' of the package ''%s'' is not present in the struct.\n"),"atomsDESCRIPTIONaddField",package_version,package_name));
        end

        this_package_struct                      = package_versions_struct(package_version);
        this_package_struct(field)               = value;
        package_versions_struct(package_version) = this_package_struct;
        packages_out(package_name)               = package_versions_struct;

    end

    tree_out("packages") = packages_out;

endfunction