summaryrefslogtreecommitdiff
path: root/modules/atoms/macros/atoms_internals/atomsDESCRIPTIONrm.sci
blob: 0a0d9118eb9161a8a5562645708794dfd899939a (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
// 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

// Remove a package defined by its name and version from a DESCRIPTION struct
// 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 = atomsDESCRIPTIONrm( tree_in , package_name , package_version )

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

    rhs  = argn(2);

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

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

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

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

    if type(package_version) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"),"atomsDESCRIPTIONrm",3));
    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"),"atomsDESCRIPTIONrm",2));
    end

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

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

    tree_out     = struct();
    packages_out = struct();

    if isfield(tree_in,"packages") then
        packages_in = tree_in("packages");
    else
        return;
    end

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

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

        if package_names(i) <> package_name then
            packages_out(package_names(i)) = packages_in(package_names(i));
            continue;
        end

        package_versions_out  = struct();
        package_versions_in   = packages_in(package_names(i));
        package_versions      = getfield(1,package_versions_in);
        package_versions(1:2) = [];
        package_versions_size = size(package_versions,"*");

        if (package_versions_size == 1) & (package_versions == package_version) then
            continue;
        end

        for j=1:package_versions_size
            if package_versions(j) <> package_version then
                package_versions_out(package_versions(j)) = package_versions_in(package_versions(j));
            else
                is_present = %T;
            end
        end

        packages_out(package_names(i)) = package_versions_out;

    end

    tree_out("packages") = packages_out;

endfunction