annotate scripts/miscellaneous/ver.m @ 11469:c776f063fefe

Overhaul m-script files to use common variable name between code and documentation.
author Rik <octave@nomad.inbox5.com>
date Sun, 09 Jan 2011 12:41:21 -0800
parents 693e22af08ae
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7499
diff changeset
1 ## Copyright (C) 2005, 2006, 2007, 2008 William Poetra Yoga Hadisoeseno
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
2 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
4 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6615
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6615
diff changeset
8 ## your option) any later version.
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
9 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
14 ##
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6615
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6615
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
18
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
6615
687ae48b2253 [project @ 2007-05-13 06:24:57 by jwe]
jwe
parents: 6046
diff changeset
20 ## @deftypefn {Function File} {} ver ()
687ae48b2253 [project @ 2007-05-13 06:24:57 by jwe]
jwe
parents: 6046
diff changeset
21 ## Display a header containing the current Octave version
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
22 ## number, license string and operating system, followed by
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
23 ## the installed package names, versions, and installation
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
24 ## directories.
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
25 ## @deftypefnx {Function File} {v =} ver ()
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
26 ## Return a vector of structures, respecting Octave and each installed package.
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
27 ## The structure includes the following fields.
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
28 ##
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
29 ## @table @code
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
30 ## @item Name
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
31 ## Package name.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
32 ##
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
33 ## @item Version
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
34 ## Version of the package.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
35 ##
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
36 ## @item Revision
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
37 ## Revision of the package.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
38 ##
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
39 ## @item Date
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
40 ## Date respecting the version/revision.
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
41 ## @end table
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
42 ## @deftypefnx {Function File} {v =} ver (@code{"Octave"})
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
43 ## Return version information for Octave only.
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
44 ## @deftypefnx {Function File} {v =} ver (@var{package})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
45 ## Return version information for @var{package}.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5548
diff changeset
46 ## @seealso{license, version}
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
47 ## @end deftypefn
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
48
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
49 ## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
50
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
51 function varargout = ver (package = "")
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
52
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
53 if (nargin > 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
54 print_usage ();
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
55 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
56
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
57 ## Start with the version info for Octave
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
58 ret = struct ("Name", "Octave", "Version", version,
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
59 "Release", [], "Date", []);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
60
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
61 ## Add the installed packages
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
62 lst = pkg ("list");
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
63 for i = 1:length (lst)
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
64 ret(end+1) = struct ("Name", lst{i}.name, "Version", lst{i}.version,
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
65 "Release", [], "Date", lst{i}.date);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
66 endfor
5548
5cc01ba4c052 [project @ 2005-11-30 03:04:44 by jwe]
jwe
parents: 5546
diff changeset
67
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
68 if (nargout == 0)
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
69 octave_license = license ();
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
70
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
71 [unm, status] = uname ();
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
72
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
73 if (status < 0)
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
74 os_string = "unknown";
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
75 else
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
76 os_string = sprintf ("%s %s %s %s", unm.sysname, unm.release,
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
77 unm.version, unm.machine);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
78 endif
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
79
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
80 hbar(1:70) = "-";
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
81 ver_line1 = "GNU Octave Version ";
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
82 ver_line2 = "GNU Octave License: ";
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
83 ver_line3 = "Operating System: ";
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
84
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
85 ver_desc = sprintf ("%s\n%s%s\n%s%s\n%s%s\n%s\n", hbar, ver_line1, version,
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
86 ver_line2, octave_license, ver_line3, os_string, hbar);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
87
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
88 puts (ver_desc);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
89
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
90 pkg ("list");
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
91 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
92 if (! isempty (package))
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
93 n = [];
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
94 for r = 1:numel(ret)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
95 if (strcmpi (ret(r).Name, package))
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
96 n = r;
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
97 break;
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
98 endif
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
99 endfor
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
100 ret = ret(n);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
101 endif
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
102 varargout{1} = ret;
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
103 endif
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
104
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
105 endfunction
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
106
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
107 %!test
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
108 %! result = ver;
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
109 %! assert (result(1).Name, "Octave")
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
110 %! assert (result(1).Version, version)
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
111 %! result = ver ("octave");
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
112 %! assert (result(1).Name, "Octave")
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
113 %! assert (result(1).Version, version)
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
114
7499
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
115 %!test
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
116 %! lst = pkg ("list");
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
117 %! for n=1:numel(lst)
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
118 %! expected = lst{n}.name;
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
119 %! result = ver (expected);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
120 %! assert (result.Name, expected);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
121 %! assert (isfield (result, "Version"), true);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
122 %! assert (isfield (result, "Release"), true);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
123 %! assert (isfield (result, "Date"), true);
94d0cdd60dda Added pkg version info and matlab compatibility.
Ben Abbott <bpabbott@mac.com>
parents: 7017
diff changeset
124 %! endfor
5546
3ebf0e35156c [project @ 2005-11-29 17:30:50 by jwe]
jwe
parents:
diff changeset
125