alluser => allusers
[scilab.git] / scilab / modules / atoms / macros / atoms_internals / atomsGetDepChilds.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 // Returns true if a package is installed, false otherwise
11
12 function packages = atomsGetDepChilds(name,version,allusers)
13         
14         rhs      = argn(2);
15         packages = [];
16         
17         // Check number of input arguments
18         // =========================================================================
19         
20         if rhs < 2 | rhs > 3 then
21                 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"),"atomsGetDepChilds",2,3));
22         end
23         
24         // Check input parameters type
25         // =========================================================================
26         
27         if type(name) <> 10 then
28                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDepChilds",1));
29         end
30         
31         if type(version)<>10  then
32                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsGetDepChilds",2));
33         end
34         
35         // Check input parameters dimensions
36         // =========================================================================
37         
38         if size(name,"*") <> 1 then
39                 error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsGetDepChilds",1));
40         end
41         
42         if size(version,"*")<>1  then
43                 error(msprintf(gettext("%s: Wrong size for input argument #%d: A single string expected.\n"),"atomsGetDepChilds",2));
44         end
45         
46         // All user management
47         // =========================================================================
48         
49         if rhs == 2 then
50                 allusers = %T;
51         else
52                 // Just check if it's a boolean
53                 if type(allusers) <> 4 then
54                         error(msprintf(gettext("%s: Wrong type for input argument #%d: A boolean expected.\n"),"atomsGetDepChilds",3));
55                 end
56         end
57         
58         // Define the differents path of the file where are installed
59         // =========================================================================
60         
61         installed_deps_files = [];
62         user_file            = pathconvert(SCIHOME+"/atoms/installed_deps",%F);
63         alluser_file         = pathconvert(SCI+"/.atoms/installed_deps",%F);
64         
65         if fileinfo(user_file)<>[] then
66                 installed_deps_files = [ installed_deps_files ; user_file "user" ];
67         end
68         
69         if allusers & (fileinfo(alluser_file)<>[]) then
70                 installed_deps_files = [ installed_deps_files ; alluser_file "allusers"];
71         end
72         
73         // Loop on each "installed_deps" file specified as first input argument
74         // =========================================================================
75         
76         found = 0;
77         
78         for i=1:size(installed_deps_files(:,1),"*")
79                 
80                 if found == 1 then
81                         break;
82                 end
83                 
84                 // Get the installed package list in this file
85                 installed_deps_lines = mgetl(installed_deps_files(i,1));
86                 
87                 // Loop on each lines
88                 for j=1:size(installed_deps_lines,"*")
89                         
90                         // If this line is a "parent toolbox" or a blank line and the wanted toolbox is already found
91                         // Break the loop
92                         
93                         if (found == 1) & ..
94                                 ( (regexp(installed_deps_lines(j),"/^\[(.)*\]$/","o") <> []) | isempty(installed_deps_lines(j)) ) then
95                                 break;
96                         end
97                         
98                         // Yeah, the wanted toolbox has been found
99                         
100                         if installed_deps_lines(j) == "["+name+" - "+version+"]" then
101                                 found = 1;
102                                 continue;
103                         end
104                         
105                         // This line is a inevitably a toolbox
106                         if found == 1 then
107                                 this_line           = stripblanks(installed_deps_lines(j));
108                                 current_name_length = regexp(this_line,"/\s-\s/","o");
109                                 current_name        = part(this_line,1:current_name_length-1);
110                                 current_version     = part(this_line,current_name_length+3:length(this_line));
111                                 packages            = [ packages ; current_name current_version];
112                         end
113                         
114                 end
115         end
116         
117 endfunction