ATOMS: cosmetic
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsDepTreeFlat.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3 //
4 // 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 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 // Internal function
11
12 // Input arguments :
13
14 //   name : . technical name of the package
15 //          . single string
16 //          . mandatory
17
18 //   version : . version of the package
19 //             . single string
20 //             . optional
21
22 //   tree_in : . Tree that will be concatenated in the output tree
23 //             . struct
24 //             . optional
25
26
27 // Output arguments :
28
29 //   tree_out : . Dependency tree of the package
30 //              . struct
31 //              . mandatory
32 //              . Example :
33 //                   tree_out  = 
34 //                   toolbox_5 - 1.0: [1x1 struct]
35 //                   toolbox_4 - 1.0: [1x1 struct]
36 //                   toolbox_2 - 1.3: [1x1 struct]
37 //                   toolbox_1 - 1.9: [1x1 struct]
38
39 //   version_out : . version of the package
40 //                 . single string
41 //                 . optional
42
43 function [tree_out,version_out] = atomsDepTreeFlat(name,version,tree_in)
44         
45         lhs = argn(1);
46         rhs = argn(2);
47         
48         // Check number of input arguments
49         // =========================================================================
50         
51         if (rhs < 1) | (rhs > 3) then
52                 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsDepTreeFlat",1,3));
53         end
54         
55         // Check input parameters type
56         // =========================================================================
57         
58         if type(name) <> 10 then
59                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsDepTreeFlat",1));
60         end
61         
62         if (rhs>=2) & (type(version) <> 10) then
63                 error(msprintf(gettext("%s: Wrong type for input argument #%d: A single string expected.\n"),"atomsDepTreeFlat",2));
64         end
65         
66         if (rhs==3) & (type(tree_in) <> 17) then
67                 error(msprintf(gettext("%s: Wrong type for input argument #%d: matrix oriented typed list expected.\n"),"atomsDepTreeFlat",3));
68         end
69         
70         // Check input parameters dimensions
71         // =========================================================================
72         
73         if size(name) <> 1 then
74                 error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsDepTreeFlat",1));
75         end
76         
77         if (rhs>=2) & (size(name)<>1) then
78                 error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsDepTreeFlat",1));
79         end
80         
81         // If version not define, version is the list of version compatible with
82         // the current version of Scilab
83         // =========================================================================
84         
85         if (rhs<2) | ((rhs>=2) & (version=="")) then
86                 version = atomsCompatibleVersions(name);
87         end
88         
89         // Define tree_in if not defined as input argument
90         // =========================================================================
91         
92         if rhs<3 then
93                 tree_in = struct();
94         end
95         
96         // Loop on versions
97         // =========================================================================
98         
99         for i=1:size(version,"*")
100                 
101                 this_package_details = atomsToolboxDetails([name,version(i)]);
102                 tree_out(name+" - "+version(i)) = this_package_details;
103                 
104                 if lhs>1 then
105                         version_out = version(i);
106                 end
107                 
108                 // Now, loop on dependencies
109                 // =========================================================================
110                 
111                 if isfield(this_package_details,"Depends") & (this_package_details("Depends") ~= "") then
112                         dependencies = this_package_details("Depends");
113                 else
114                         dependencies = [];
115                 end
116                 
117                 for j=1:size(dependencies,"*")
118                         
119                         this_dependency_success = %F;
120                         
121                         // Split dependencies to get 
122                         //  - direction ("=",">=",">","<=","<","~")
123                         //  - dependence name
124                         //  - dependence version (optional)
125                         
126                         this_dependency_tab     = stripblanks(strsplit(dependencies(j),regexp(stripblanks(dependencies(j)),"/\s/")));
127                         
128                         this_dependency_dir     = this_dependency_tab(1);
129                         this_dependency_name    = this_dependency_tab(2);
130                         this_dependency_version = this_dependency_tab(3);
131                         
132                         // List versions of the dependency we can test
133                         
134                         if this_dependency_dir     == "="  then
135                                 this_dependency_list = this_dependency_version;
136                         
137                         elseif this_dependency_dir == "~"  then
138                                 this_dependency_list = atomsGetVersions(this_dependency_name);
139                         
140                         elseif this_dependency_dir == ">=" then
141                                 this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version);
142                                 
143                         elseif this_dependency_dir == "<=" then
144                                 this_dependency_list = atomsGetVersions(this_dependency_name,"",this_dependency_version);
145                         
146                         elseif this_dependency_dir == ">" then
147                                 this_dependency_list = atomsGetVersions(this_dependency_name,this_dependency_version,"",%F,%F);
148                                 
149                         elseif this_dependency_dir == "<" then
150                                 this_dependency_list = atomsGetVersions(this_dependency_name,"",this_dependency_version,%F,%F);
151                                 
152                         end
153                         
154                         for k=1:size(this_dependency_list,"*")
155                                 
156                                 tree = atomsDepTreeFlat(this_dependency_name,this_dependency_list(k),tree_out);
157                                 
158                                 // Dependency Tree fails
159                                 
160                                 if (type(tree) == 4) & (~ tree) then
161                                         continue;
162                                 end
163                                 
164                                 // Dependency Tree OK
165                                 
166                                 if type(tree) == 17 then
167                                         tree_out = atomsCatTree(tree_out,tree);
168                                         this_dependency_success = %T;
169                                         break;
170                                 end
171                                 
172                         end
173                         
174                         if ~  this_dependency_success then
175                                 tree_out = %F;
176                                 break;
177                         end
178                         
179                 end
180                 
181                 
182                 if type(tree_out)==17 then
183                         return;
184                 end
185                 
186         end
187         
188 endfunction