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