]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/ver.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / ver.m
1 ## Copyright (C) 2005-2012 William Poetra Yoga Hadisoeseno
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} ver ()
21 ## Display a header containing the current Octave version number, license
22 ## string and operating system, followed by the installed package names,
23 ## versions, and installation directories.
24 ##
25 ## @deftypefnx {Function File} {v =} ver ()
26 ## Return a vector of structures, respecting Octave and each installed package.
27 ## The structure includes the following fields.
28 ##
29 ## @table @code
30 ## @item Name
31 ## Package name.
32 ##
33 ## @item Version
34 ## Version of the package.
35 ##
36 ## @item Revision
37 ## Revision of the package.
38 ##
39 ## @item Date
40 ## Date respecting the version/revision.
41 ## @end table
42 ##
43 ## @deftypefnx {Function File} {v =} ver ("Octave")
44 ## Return version information for Octave only.
45 ##
46 ## @deftypefnx {Function File} {v =} ver (@var{package})
47 ## Return version information for @var{package}.
48 ##
49 ## @seealso{version, octave_config_info}
50 ## @end deftypefn
51
52 ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
53
54 function varargout = ver (package = "")
55
56   if (nargin > 1)
57     print_usage ();
58   endif
59
60   ## Start with the version info for Octave
61   ret = struct ("Name", "Octave", "Version", version,
62                 "Release", [], "Date", []);
63
64   ## Add the installed packages
65   lst = pkg ("list");
66   for i = 1:length (lst)
67     ret(end+1) = struct ("Name", lst{i}.name, "Version", lst{i}.version,
68                          "Release", [], "Date", lst{i}.date);
69   endfor
70
71   if (nargout == 0)
72     octave_license = license ();
73
74     [unm, status] = uname ();
75
76     if (status < 0)
77       os_string = "unknown";
78     else
79       os_string = sprintf ("%s %s %s %s", unm.sysname, unm.release,
80                            unm.version, unm.machine);
81     endif
82
83     hbar(1:70) = "-";
84     ver_line1 = "GNU Octave Version ";
85     ver_line2 = "GNU Octave License: ";
86     ver_line3 = "Operating System: ";
87
88     ver_desc = sprintf ("%s\n%s%s\n%s%s\n%s%s\n%s\n", hbar, ver_line1, version,
89                         ver_line2, octave_license, ver_line3, os_string, hbar);
90
91     puts (ver_desc);
92
93     pkg ("list");
94   else
95     if (! isempty (package))
96       n = [];
97       for r = 1:numel(ret)
98         if (strcmpi (ret(r).Name, package))
99           n = r;
100           break;
101         endif
102       endfor
103       ret = ret(n);
104     endif
105     varargout{1} = ret;
106   endif
107
108 endfunction
109
110 %!test
111 %! result = ver;
112 %! assert (result(1).Name, "Octave")
113 %! assert (result(1).Version, version)
114 %! result = ver ("octave");
115 %! assert (result(1).Name, "Octave")
116 %! assert (result(1).Version, version)
117
118 %!test
119 %! lst = pkg ("list");
120 %! for n=1:numel(lst)
121 %!   expected = lst{n}.name;
122 %!   result = ver (expected);
123 %!   assert (result.Name, expected);
124 %!   assert (isfield (result, "Version"), true);
125 %!   assert (isfield (result, "Release"), true);
126 %!   assert (isfield (result, "Date"), true);
127 %! endfor
128