1## Copyright (C) 2005, 2006, 2007, 2009 William Poetra Yoga Hadisoeseno
3## This file is part of Octave.
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.
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.
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/>.
20## @deftypefn {Function File} {} license
21## Display the license of Octave.
23## @deftypefnx {Function File} {} license ("inuse")
24## Display a list of packages currently being used.
26## @deftypefnx {Function File} {@var{retval} =} license ("inuse")
27## Return a structure containing the fields @code{feature} and @code{user}.
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.
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:
40## Future tests for the specified license of @var{feature} are conducted
43## Future tests for the specified license of @var{feature} return 0.
46## @deftypefnx {Function File} {@var{retval} =} license ("checkout", @var{feature})
47## Check out a license for @var{feature}, returning 1 on success and 0
50## This function is provided for compatibility with @sc{matlab}.
51## @seealso{ver, version}
54## Author: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
56function retval = license (varargin)
58 persistent __octave_licenses__;
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;
74 nr_licenses = rows (__octave_licenses__);
76 if (nout > 1 || nin > 3)
77 error ("type `help license' for usage info");
84 if (strcmp (__octave_licenses__{p,1}, "Octave"))
91 result = __octave_licenses__{p,2};
97 printf ("%s\n", result);
106 if (! strcmp (varargin{1}, "inuse"))
107 usage ("license (\"inuse\")");
110 for p = 1:nr_licenses
111 printf ("%s\n", __octave_licenses__{p,1});
116 if (! strcmp (varargin{1}, "inuse"))
117 usage ("retval = license (\"inuse\")");
120 pw = getpwuid (getuid ());
124 username = "octave_user";
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;
137 feature = varargin{2}(1:(min ([(length (varargin{2})), 27])));
139 if (strcmp (varargin{1}, "test"))
142 for p = 1:nr_licenses
143 if (strcmpi (feature, __octave_licenses__{p,1}))
150 retval = found && __octave_licenses__{p,3};
153 if (strcmp (varargin{3}, "enable"))
154 __octave_licenses__{p,3} = true;
155 elseif (strcmp (varargin{3}, "disable"))
156 __octave_licenses__{p,3} = false;
158 error ("toggle must be either `enable' of `disable'");
161 error ("feature `%s' not found", feature);
165 elseif (strcmp (varargin{1}, "checkout"))
168 usage ("retval = license (\"checkout\", feature)");
172 for p = 1:nr_licenses
173 if (strcmpi (feature, __octave_licenses__{p,1}))
179 retval = found && __octave_licenses__{p,3};
183 error ("type `help license' for usage info");