ATOMS: homogenize function's profile
[scilab.git] / scilab / modules / atoms / macros / atomsDepTreeShow.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 // Output arguments :
23
24 function atomsDepTreeShow(package)
25         
26         // Load Atoms Internals lib if it's not already loaded
27         // =========================================================================
28         if ~ exists("atomsinternalslib") then
29                 load("SCI/modules/atoms/macros/atoms_internals/lib");
30         end
31         
32         rhs = argn(2);
33         
34         // Check number of input arguments
35         // =========================================================================
36         
37         if rhs <> 1 then
38                 error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsDepTreeShow",1));
39         end
40         
41         // Check input parameters type
42         // =========================================================================
43         
44         if type(package) <> 10 then
45                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetLoadedPath",1));
46         end
47         
48         if size(package(1,:),"*") > 2 then
49                 error(msprintf(gettext("%s: Wrong size for input argument #%d: 1x1 or 1x2 string matrix expected.\n"),"atomsGetLoadedPath",1));
50         end
51         
52         // Get the dependency tree
53         // =========================================================================
54         
55         if size(package(1,:),"*") == 2 then
56                 tree = atomsDepTreeExt(package(1),package(2));
57         else
58                 tree = atomsDepTreeExt(package(1));
59         end
60         
61         situation = struct();
62         situation("current_level")  = 1;
63         
64         mprintf("\n");
65         atomsDispTree(tree,situation)
66         
67 endfunction
68
69
70 function atomsDispTree(tree,situation)
71         
72         fields      = getfield(1,tree);
73         fields(1:2) = [];
74         
75         current_level = situation("current_level");
76         situation("level"+string(current_level)+"_number") = size(fields,"*");
77         situation("level"+string(current_level)+"_pos")    = 1;
78         
79         for i=1:size(fields,"*")
80                 
81                 this_package_details = tree(fields(i));
82                 
83                 for j=1:current_level-1
84                         if situation("level"+string(j)+"_pos") < situation("level"+string(j)+"_number") then
85                                 mprintf("|   ");
86                         else
87                                 mprintf("    ");
88                         end
89                 end
90                 
91                 if current_level == 1 then
92                         mprintf("    ");
93                 elseif situation("level"+string(current_level)+"_pos") == situation("level"+string(current_level)+"_number") then
94                         mprintf("`-- ");
95                 else
96                         mprintf("|-- ");
97                 end
98                 
99                 mprintf("%s - %s\n",this_package_details("Toolbox"),this_package_details("Version"));
100                 
101                 if isfield(this_package_details,"DependencyTree") then
102                         
103                         next_situation                  = situation;
104                         next_situation("current_level") = current_level + 1;
105                         this_package_deptree            = this_package_details("DependencyTree");
106                         atomsDispTree(this_package_deptree,next_situation);
107                         
108                 end
109                 
110                 situation("level"+string(current_level)+"_pos") = situation("level"+string(current_level)+"_pos") + 1;
111                 
112         end
113         
114 endfunction