ATOMS: homogenize function's profile
[scilab.git] / scilab / modules / atoms / macros / atomsShow.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 // Show information on a package
11
12 function atomsShow(package)
13         
14         // Load Atoms Internals lib if it's not already loaded
15         // =========================================================================
16         if ~ exists("atomsinternalslib") then
17                 load("SCI/modules/atoms/macros/atoms_internals/lib");
18         end
19         
20         rhs = argn(2);
21         
22         // Check number of input arguments
23         // =========================================================================
24         
25         if rhs <> 1 then
26                 error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"atomsShow",1));
27         end
28         
29         // Check input parameters type
30         // =========================================================================
31         
32         if type(package) <> 10 then
33                 error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsShow",1));
34         end
35         
36         if size(package(1,:),"*") > 2 then
37                 error(msprintf(gettext("%s: Wrong size for input argument #%d: 1x1 or 1x2 string matrix expected.\n"),"atomsShow",1));
38         end
39         
40         // Remove leading and trailing parameters
41         // =========================================================================
42         package = stripblanks(package);
43         
44         // If version is not defined, the Most Recent Version is used
45         // =========================================================================
46         if size(package(1,:),"*") == 1 then
47                 package(1,2) = atomsGetMRVersion(package(1));
48         end
49         
50         
51         // Check if it's a valid package
52         // =========================================================================
53         if size(package(1,:),"*") == 1 then
54                 package(1,2) = atomsGetMRVersion(package(1));
55         end
56         
57         
58         
59         // Get the details of this package
60         // =========================================================================
61         
62         details = atomsToolboxDetails(package);
63         
64         fields_map = [];
65         fields_map = [ fields_map ; "Toolbox"        gettext("Package")        ];
66         fields_map = [ fields_map ; "Title"          gettext("Title")          ];
67         fields_map = [ fields_map ; "Summary"        gettext("Summary")        ];
68         fields_map = [ fields_map ; "Version"        gettext("Version")        ];
69         fields_map = [ fields_map ; "Depends"        gettext("Depend")         ];
70         fields_map = [ fields_map ; "Category"       gettext("Category(ies)")  ];
71         fields_map = [ fields_map ; "Author"         gettext("Author(s)")      ];
72         fields_map = [ fields_map ; "Maintainer"     gettext("Maintainer(s)")  ];
73         fields_map = [ fields_map ; "Entity"         gettext("Entity")         ];
74         fields_map = [ fields_map ; "WebSite"        gettext("WebSite")        ];
75         fields_map = [ fields_map ; "License"        gettext("License")        ];
76         fields_map = [ fields_map ; "ScilabVersion"  gettext("Scilab Version") ];
77         
78         fields_map = [ fields_map ; "Status"         gettext("Status")         ];
79         
80         if atomsIsInstalled(package) then
81                 fields_map = [ fields_map ; "InstallAutomaticaly" gettext("Automaticaly Installed")];
82                 fields_map = [ fields_map ; "installPath"         gettext("Install Directory")];
83         end
84         
85         fields_map = [ fields_map ; "Description"    gettext("Description")    ];
86         
87         // Show it
88         // =========================================================================
89         
90         max_field_len = max( length(fields_map(:,2)) );
91         
92         for i=1:size(fields_map(:,1),"*")
93                 
94                 value = "";
95                 
96                 //
97                 // Status
98                 // 
99                 
100                 if fields_map(i,1)=="Status" then
101                         if atomsIsInstalled(package) then
102                                 value = "Installed";
103                         else
104                                 value = "Not installed";
105                         end
106                 end
107                 
108                 //
109                 // Automaticaly Installed ?
110                 // 
111                 
112                 if fields_map(i,1)=="InstallAutomaticaly" then
113                         if atomsGetInstalledStatus(package) == "A" then
114                                 value = "yes";
115                         else
116                                 value = "no";
117                         end
118                 end
119                 
120                 //
121                 // Scilab Version
122                 // 
123                 
124                 if fields_map(i,1)=="ScilabVersion" then
125                         if regexp( details(fields_map(i,1)) , "/^~/" , "o" )<>[] then
126                                 value = "any";
127                         else
128                                 value = details(fields_map(i,1));
129                         end
130                 end
131                 
132                 //
133                 // Dependences
134                 // 
135                 
136                 if fields_map(i,1)=="Depends" then
137                         value = dep2str(details(fields_map(i,1)));
138                 end
139                 
140                 //
141                 // Other
142                 //
143                 
144                 if isempty(value) then
145                         value = details(fields_map(i,1));
146                 end
147                 
148                 for j=1:size(value,"*")
149                         
150                         if j==1 then
151                                 mprintf("% "+string(max_field_len)+"s : %s\n",fields_map(i,2),value(j))
152                                 
153                         else
154                                 mprintf("% "+string(max_field_len)+"s   %s\n","",value(j))
155                         end
156                 end
157         end
158         
159 endfunction
160
161 // =============================================================================
162 // string = dep2str(string)
163 //
164 // Convert a technical dependence string (For ex. : ">= toolbox_1 1.3") to a
165 // display dependence string  (For ex. : "toolbox_1 (>= 1.3)" )
166 // 
167 // =============================================================================
168
169 function str = dep2str(dep)
170         
171         str = [];
172         
173         if isempty(dep) then
174                 return;
175         end
176         
177         for i=1:size(dep,"*")
178                 
179                 this_dep = dep(i);
180                 
181                 // direction part
182                 this_dep         = stripblanks(this_dep);
183                 direction_length = regexp(this_dep,"/\s/","o");
184                 direction        = stripblanks(part(this_dep,1:direction_length-1));
185                 
186                 // name part 
187                 this_dep         = stripblanks(part(this_dep,direction_length+1:length(this_dep)));
188                 name_length      = regexp(this_dep,"/\s/","o");
189                 name             = part(this_dep,1:name_length-1);
190                 
191                 // version part
192                 version          = stripblanks(part(this_dep,name_length:length(this_dep)));
193                 
194                 this_str         = name+" ";
195                 
196                 if direction == "~" then
197                         this_str = this_str + "(Any version)";
198                 else
199                         this_str = this_str + "("+direction+" "+version+")";
200                 end
201                 
202                 str = [ str ; this_str ];
203                 
204         end
205         
206 endfunction