changelog shortlog tags changeset files revisions annotate raw

scripts/miscellaneous/license.m

changeset 10289: 4b124317dc38
parent:1bf0ce0930be
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (62 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2005, 2006, 2007, 2009 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} {} license
21## Display the license of Octave.
22##
23## @deftypefnx {Function File} {} license ("inuse")
24## Display a list of packages currently being used.
25##
26## @deftypefnx {Function File} {@var{retval} =} license ("inuse")
27## Return a structure containing the fields @code{feature} and @code{user}.
28##
29## @deftypefnx {Function File} {@var{retval} =} license ("test", @var{feature})
30## Return 1 if a license exists for the product identified by the string
31## @var{feature} and 0 otherwise. The argument @var{feature} is case
32## insensitive and only the first 27 characters are checked.
33##
34## @deftypefnx {Function File} {} license ("test", @var{feature}, @var{toggle})
35## Enable or disable license testing for @var{feature}, depending on
36## @var{toggle}, which may be one of:
37##
38## @table @samp
39## @item "enable"
40## Future tests for the specified license of @var{feature} are conducted
41## as usual.
42## @item "disable"
43## Future tests for the specified license of @var{feature} return 0.
44## @end table
45##
46## @deftypefnx {Function File} {@var{retval} =} license ("checkout", @var{feature})
47## Check out a license for @var{feature}, returning 1 on success and 0
48## on failure.
49##
50## This function is provided for compatibility with @sc{matlab}.
51## @seealso{ver, version}
52## @end deftypefn
53
54## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
55
56function retval = license (varargin)
57
58 persistent __octave_licenses__;
59
60 if (isempty (__octave_licenses__))
61 __octave_licenses__ = cell ();
62 __octave_licenses__{1,1} = "Octave";
63 __octave_licenses__{1,2} = "GNU General Public License";
64 __octave_licenses__{1,3} = true;
65 if (exist ("OCTAVE_FORGE_VERSION"))
66 __octave_licenses__{2,1} = "octave-forge";
67 __octave_licenses__{2,2} = "<various licenses>";
68 __octave_licenses__{2,3} = true;
69 endif
70 endif
71
72 nout = nargout;
73 nin = nargin;
74 nr_licenses = rows (__octave_licenses__);
75
76 if (nout > 1 || nin > 3)
77 error ("type `help license' for usage info");
78 endif
79
80 if (nin == 0)
81
82 found = false;
83 for p = 1:nr_licenses
84 if (strcmp (__octave_licenses__{p,1}, "Octave"))
85 found = true;
86 break;
87 endif
88 endfor
89
90 if (found)
91 result = __octave_licenses__{p,2};
92 else
93 result = "unknown";
94 endif
95
96 if (nout == 0)
97 printf ("%s\n", result);
98 else
99 retval = result;
100 endif
101
102 elseif (nin == 1)
103
104 if (nout == 0)
105
106 if (! strcmp (varargin{1}, "inuse"))
107 usage ("license (\"inuse\")");
108 endif
109
110 for p = 1:nr_licenses
111 printf ("%s\n", __octave_licenses__{p,1});
112 endfor
113
114 else
115
116 if (! strcmp (varargin{1}, "inuse"))
117 usage ("retval = license (\"inuse\")");
118 endif
119
120 pw = getpwuid (getuid ());
121 if (isstruct (pw))
122 username = pw.name;
123 else
124 username = "octave_user";
125 endif
126
127 retval(1:nr_licenses) = struct ("feature", "", "user", "");
128 for p = 1:nr_licenses
129 retval(p).feature = __octave_licenses__{p,1};
130 retval(p).user = username;
131 endfor
132
133 endif
134
135 else
136
137 feature = varargin{2}(1:(min ([(length (varargin{2})), 27])));
138
139 if (strcmp (varargin{1}, "test"))
140
141 found = false;
142 for p = 1:nr_licenses
143 if (strcmpi (feature, __octave_licenses__{p,1}))
144 found = true;
145 break;
146 endif
147 endfor
148
149 if (nin == 2)
150 retval = found && __octave_licenses__{p,3};
151 else
152 if (found)
153 if (strcmp (varargin{3}, "enable"))
154 __octave_licenses__{p,3} = true;
155 elseif (strcmp (varargin{3}, "disable"))
156 __octave_licenses__{p,3} = false;
157 else
158 error ("toggle must be either `enable' of `disable'");
159 endif
160 else
161 error ("feature `%s' not found", feature);
162 endif
163 endif
164
165 elseif (strcmp (varargin{1}, "checkout"))
166
167 if (nin != 2)
168 usage ("retval = license (\"checkout\", feature)");
169 endif
170
171 found = false;
172 for p = 1:nr_licenses
173 if (strcmpi (feature, __octave_licenses__{p,1}))
174 found = true;
175 break;
176 endif
177 endfor
178
179 retval = found && __octave_licenses__{p,3};
180
181 else
182
183 error ("type `help license' for usage info");
184
185 endif
186
187 endif
188
189endfunction